跳过内容

⇅ 包特征

预处理

包特征预计以由空格分隔的元素字符串形式提供,例如 "elem5 elem0 elem5 elem1"。包特征与集合特征类似,唯一的区别在于元素可以多次出现。包特征编码器输出一个矩阵,类似于集合编码器,但矩阵的每个元素是一个浮点值,表示相应元素在包中的频率。嵌入向量通过求和聚合,并根据每个元素的频率加权。

preprocessing:
    tokenizer: space
    missing_value_strategy: fill_with_const
    fill_value: <UNK>
    lowercase: false
    most_common: 10000

参数

  • tokenizer (默认值: space) : 定义如何将数据集列的原始文本内容转换为一组元素。默认值 space 会按空格分割字符串。常见选项包括:underscore(按划线分割)、comma(按逗号分割)、json(通过 JSON 解析器将字符串解码为集合或列表)。选项:space, space_punct, ngram, characters, underscore, comma, untokenized, stripped, english_tokenize, english_tokenize_filter, english_tokenize_remove_stopwords, english_lemmatize, english_lemmatize_filter, english_lemmatize_remove_stopwords, italian_tokenize, italian_tokenize_filter, italian_tokenize_remove_stopwords, italian_lemmatize, italian_lemmatize_filter, italian_lemmatize_remove_stopwords, spanish_tokenize, spanish_tokenize_filter, spanish_tokenize_remove_stopwords, spanish_lemmatize, spanish_lemmatize_filter, spanish_lemmatize_remove_stopwords, german_tokenize, german_tokenize_filter, german_tokenize_remove_stopwords, german_lemmatize, german_lemmatize_filter, german_lemmatize_remove_stopwords, french_tokenize, french_tokenize_filter, french_tokenize_remove_stopwords, french_lemmatize, french_lemmatize_filter, french_lemmatize_remove_stopwords, portuguese_tokenize, portuguese_tokenize_filter, portuguese_tokenize_remove_stopwords, portuguese_lemmatize, portuguese_lemmatize_filter, portuguese_lemmatize_remove_stopwords, dutch_tokenize, dutch_tokenize_filter, dutch_tokenize_remove_stopwords, dutch_lemmatize, dutch_lemmatize_filter, dutch_lemmatize_remove_stopwords, greek_tokenize, greek_tokenize_filter, greek_tokenize_remove_stopwords, greek_lemmatize, greek_lemmatize_filter, greek_lemmatize_remove_stopwords, norwegian_tokenize, norwegian_tokenize_filter, norwegian_tokenize_remove_stopwords, norwegian_lemmatize, norwegian_lemmatize_filter, norwegian_lemmatize_remove_stopwords, lithuanian_tokenize, lithuanian_tokenize_filter, lithuanian_tokenize_remove_stopwords, lithuanian_lemmatize, lithuanian_lemmatize_filter, lithuanian_lemmatize_remove_stopwords, danish_tokenize, danish_tokenize_filter, danish_tokenize_remove_stopwords, danish_lemmatize, danish_lemmatize_filter, danish_lemmatize_remove_stopwords, polish_tokenize, polish_tokenize_filter, polish_tokenize_remove_stopwords, polish_lemmatize, polish_lemmatize_filter, polish_lemmatize_remove_stopwords, romanian_tokenize, romanian_tokenize_filter, romanian_tokenize_remove_stopwords, romanian_lemmatize, romanian_lemmatize_filter, romanian_lemmatize_remove_stopwords, japanese_tokenize, japanese_tokenize_filter, japanese_tokenize_remove_stopwords, japanese_lemmatize, japanese_lemmatize_filter, japanese_lemmatize_remove_stopwords, chinese_tokenize, chinese_tokenize_filter, chinese_tokenize_remove_stopwords, chinese_lemmatize, chinese_lemmatize_filter, chinese_lemmatize_remove_stopwords, multi_tokenize, multi_tokenize_filter, multi_tokenize_remove_stopwords, multi_lemmatize, multi_lemmatize_filter, multi_lemmatize_remove_stopwords, sentencepiece, clip, gpt2bpe, bert, hf_tokenizer
  • missing_value_strategy (默认值: fill_with_const) : 当集合列中存在缺失值时采用的策略。选项:fill_with_const, fill_with_mode, bfill, ffill, drop_row。详见 缺失值策略
  • fill_value (默认值: <UNK>): 在 missing_value_strategy 为 fill_with_const 时,用于替换缺失值的值。
  • lowercase (默认值: false): 如果为 true,在分词前将字符串转换为小写。选项:true, false
  • most_common (默认值: 10000): 要考虑的最常见词元的最大数量。如果数据包含的词元数量超过此值,最不常见的词元将被视为未知。

输入特征

包特征只有一种可用的编码器类型:embed

在特征级别指定的编码器参数有

  • tied (默认值 null): 与之绑定编码器权重的另一个输入特征的名称。它需要是相同类型且编码器参数相同的特征名称。

输入特征列表中的包特征示例条目

name: bag_column_name
type: bag
tied: null
encoder: 
    type: embed

编码器类型和编码器参数也可以使用 类型全局编码器 部分一次定义并应用于所有包输入特征。

编码器

加权嵌入编码器

graph LR
  A["0.0\n1.0\n1.0\n0.0\n0.0\n2.0\n0.0"] --> B["0\n1\n5"];
  B --> C["emb 0\nemb 1\nemb 5"];
  C --> D["Weighted\n Sum\n Operation"];

加权嵌入编码器首先将元素频率向量转换为稀疏整数列表,然后将其映射为密集或稀疏嵌入(one-hot 编码)。最后,嵌入向量作为加权和进行聚合,其中每个嵌入向量与其相应元素的频率相乘。输入大小为 b,而输出大小为 b x h,其中 b 是批量大小,h 是嵌入向量的维度。

这些参数与集合输入特征使用的参数相同,除了 reduce_output 不应使用,因为加权和已经起到了降维器的作用。

encoder:
    type: embed
    dropout: 0.0
    embedding_size: 50
    output_size: 10
    activation: relu
    norm: null
    representation: dense
    force_embedding_size: false
    embeddings_on_cpu: false
    embeddings_trainable: true
    use_bias: true
    bias_initializer: zeros
    weights_initializer: xavier_uniform
    norm_params: null
    num_fc_layers: 0
    fc_layers: null
    pretrained_embeddings: null

参数

  • dropout (默认值: 0.0) : 嵌入层的 dropout 概率。
  • embedding_size (默认值: 50) : 最大嵌入大小,对于密集表示,实际大小将是 min(vocabulary_size, embedding_size),对于稀疏编码,实际大小恰好是 vocabulary_size,其中 vocabulary_size 是输入列的训练集中出现的不同字符串的数量(加上用于未知词元占位符的 1 个)。).
  • output_size (默认值: 10) : 如果 fc_layers 中尚未指定 output_size,这将是每个层使用的默认 output_size。它表示全连接层的输出大小。
  • activation (默认值: relu): 每个层将使用的默认激活函数。选项:elu, leakyRelu, logSigmoid, relu, sigmoid, tanh, softmax, null
  • norm (默认值: null): 每个层将使用的默认归一化。选项:batch, layer, null。详见 归一化
  • representation (默认值: dense): 嵌入的表示形式。可以是密集或稀疏。选项:dense, sparse
  • force_embedding_size (默认值: false): 强制嵌入大小等于词汇表大小。此参数仅在 representation 为 dense 时有效。选项:true, false
  • embeddings_on_cpu (默认值: false): 默认情况下,如果使用 GPU,嵌入矩阵存储在 GPU 显存中,以实现更快访问,但在某些情况下嵌入矩阵可能过大。此参数强制将嵌入矩阵放置在常规内存中,并使用 CPU 进行嵌入查找,这会导致 CPU 与 GPU 显存之间的数据传输,从而稍微减慢过程。选项:true, false
  • embeddings_trainable (默认值: true): 如果为 true,嵌入向量在训练过程中进行训练;如果为 false,嵌入向量是固定的。当加载预训练嵌入向量以避免微调它们时可能很有用。此参数仅在 representation 为 dense 时有效,因为稀疏的 one-hot 编码不可训练。选项:true, false
  • use_bias (默认值: true): 层是否使用偏置向量。选项:true, false
  • bias_initializer (默认值: zeros): 用于偏置向量的初始化器。选项:uniform, normal, constant, ones, zeros, eye, dirac, xavier_uniform, xavier_normal, kaiming_uniform, kaiming_normal, orthogonal, sparse, identity
  • weights_initializer (默认值: xavier_uniform): 用于权重矩阵的初始化器。选项:uniform, normal, constant, ones, zeros, eye, dirac, xavier_uniform, xavier_normal, kaiming_uniform, kaiming_normal, orthogonal, sparse, identity
  • norm_params (默认值: null): 如果 norm 是 batchlayer,则使用的参数。
  • num_fc_layers (默认值: 0): 输入特征通过堆叠的全连接层数量。它们的输出被投影到特征的输出空间。
  • fc_layers (默认值: null): 包含每个全连接层参数的字典列表。

  • pretrained_embeddings (默认值: null): 默认情况下,密集嵌入向量是随机初始化的,但此参数允许指定一个文件路径,该文件包含 GloVe 格式的嵌入向量。加载包含嵌入向量的文件时,仅保留词汇表中存在的标签对应的嵌入向量,其余的将被丢弃。如果词汇表包含在嵌入向量文件中没有匹配项的字符串,它们的嵌入向量将使用所有其他嵌入向量的平均值加上一些随机噪声进行初始化,以使它们彼此不同。此参数仅在 representation 为 dense 时有效。

输出特征

目前包类型不支持作为输出特征。