跳到内容

Combiner

Combiner 接收所有输入特征编码器的输出,并将它们组合起来,然后将组合后的表示提供给输出特征解码器。

您可以在配置文件的 combiner 部分指定使用哪种 Combiner,如果未指定 Combiner,则默认使用 concat Combiner。

Combiner 类型

Concat Combiner

graph LR
  I1[Encoder Output 1] --> C[Concat];
  IK[...] --> C;
  IN[Encoder Output N] --> C;
  C --> FC[Fully Connected Layers];
  FC --> ...;
  subgraph COMBINER..
  C
  FC
  end

concat Combiner 假设所有编码器输出都是大小为 b x h 的张量,其中 b 是批量大小,h 是隐藏维度,对于每个输入可以不同。如果任何输入的维度超过 2 维,例如序列或集合特征,则将 flatten_inputs 参数设置为 true。它沿着 h 维度进行拼接,然后(可选地)将拼接后的张量通过一系列全连接层。它返回最终的 b x h' 张量,其中 h' 是最后一个全连接层的大小,或者在没有全连接层的情况下是所有输入的 h 大小之和。如果只指定了单个输入特征且没有全连接层,则输入特征编码器的输出将直接通过 Combiner 而不改变。

combiner:
    type: concat
    dropout: 0.0
    num_fc_layers: 0
    output_size: 256
    norm: null
    activation: relu
    flatten_inputs: false
    residual: false
    use_bias: true
    bias_initializer: zeros
    weights_initializer: xavier_uniform
    norm_params: null
    fc_layers: null

参数

  • dropout (默认值: 0.0) : 应用于全连接层的默认 dropout 率。增加 dropout 是应对过拟合的一种常见正则化形式。dropout 表示元素被置零的概率(0.0 表示没有 dropout)。
  • num_fc_layers (默认值: 0) : 应用的全连接层堆栈数量。增加层数可以增加模型的容量,使其能够学习更复杂的特征交互。
  • output_size (默认值: 256) : 全连接层的输出大小。
  • norm (默认值: null) : 应用于全连接层开始的默认归一化类型。选项:batchlayerghostnull。详情请参阅归一化
  • activation (默认值: relu): 应用于全连接层输出的默认激活函数。选项:eluleakyRelulogSigmoidrelusigmoidtanhsoftmaxnull
  • flatten_inputs (默认值: false): 是否将输入张量展平为向量。选项:truefalse
  • residual (默认值: false): 是否为每个全连接层块添加残差连接。要求所有全连接层具有相同的 output_size。选项:truefalse
  • use_bias (默认值: true): 层是否使用偏置向量。选项:truefalse
  • bias_initializer (默认值: zeros): 偏置向量的初始化器。选项:uniformnormalconstantoneszeroseyediracxavier_uniformxavier_normalkaiming_uniformkaiming_normalorthogonalsparseidentity。或者,也可以指定一个字典,其中包含一个用于标识初始化器类型的键 type 以及其他参数键,例如 {type: normal, mean: 0, stddev: 0}。每个初始化器参数的说明,请参阅torch.nn.init

  • weights_initializer (默认值: xavier_uniform): 权重矩阵的初始化器。选项:uniformnormalconstantoneszeroseyediracxavier_uniformxavier_normalkaiming_uniformkaiming_normalorthogonalsparseidentity。或者,也可以指定一个字典,其中包含一个用于标识初始化器类型的键 type 以及其他参数键,例如 {type: normal, mean: 0, stddev: 0}。每个初始化器参数的说明,请参阅torch.nn.init

  • norm_params (默认值: null): 传递给 norm 模块的默认参数。详情请参阅归一化

  • fc_layers (默认值: null): 包含所有全连接层参数的字典列表。列表的长度决定了堆叠的全连接层数量,每个字典的内容决定了特定层的参数。每个可用层的参数包括:activationdropoutnormnorm_paramsoutput_sizeuse_biasbias_initializerweights_initializer。如果字典中缺少这些值中的任何一个,将使用作为独立参数提供的默认值。

Sequence Concat Combiner

graph LR
  I1 --> X1{Tile};
  IK --> X1;
  IN --> X1;
  IO --> X1;

  X1 --> SC1;
  X1 --> SCK;
  X1 --> SCN;

  SC1 --> R[Reduce];
  SCK --> R;
  SCN --> R;
  R --> ...;
  subgraph CONCAT["TENSOR.."]
    direction TB
    SC1["emb seq 1 | emb oth" ];
    SCK[...];
    SCN["emb seq n | emb oth"];
  end
  subgraph COMBINER..
  X1
  CONCAT
  R
  end
  subgraph SF[SEQUENCE FEATS..]
  direction TB
  I1["emb seq 1" ];
  IK[...];
  IN["emb seq n"];
  end
  subgraph OF[OTHER FEATS..]
  direction TB
  IO["emb oth"]
  end

sequence_concat Combiner 假定至少有一个编码器输出是大小为 b x s x h 的张量,其中 b 是批量大小,s 是序列长度,h 是隐藏维度。可以使用 main_sequence_feature 参数指定一个序列类(sequence、text 或 time series)输入特征,其值是该序列类输入特征的名称。如果没有指定 main_sequence_feature,Combiner 将按照配置中定义的顺序遍历所有特征,并寻找一个输出为 3 维张量(sequence、text 或 time series)的特征。如果找不到,它将引发异常;否则,该特征的输出将用于沿着序列 s 维度拼接其他特征。

如果存在其他输出为 3 维张量的输入特征,Combiner 将沿着 s 维度拼接它们,这意味着所有这些特征必须具有相同的 s 维度,否则在训练期间提供具有不同长度的两个序列特征的数据点时,将引发维度不匹配错误。

其他输出为 b x h 2 维张量的特征将被复制 s 次并拼接在 s 维度上。最终输出是大小为 b x s x h' 的张量,其中 h' 是所有输入特征的 h 维度拼接后的大小。

combiner:
    type: sequence_concat
    main_sequence_feature: null
    reduce_output: null

参数

  • main_sequence_feature (默认值: null) : 用于拼接其他特征输出的 sequence、text 或 time series 特征的名称。如果未指定 main_sequence_feature,Combiner 将按照配置中定义的顺序遍历所有特征,并寻找一个输出为 3 维张量(sequence、text 或 time series)的特征。如果找不到,将引发异常;否则,该特征的输出将用于沿着序列 s 维度拼接其他特征。如果存在其他输出为 3 维张量的输入特征,Combiner 将沿着 s 维度拼接它们。所有序列类输入特征必须具有相同的 s 维度,否则将抛出错误。

  • reduce_output (默认值: null): 用于聚合集合项嵌入的策略。选项:lastsummeanavgmaxconcatattentionnoneNonenull

Sequence Combiner

graph LR
  I1 --> X1{Tile};
  IK --> X1;
  IN --> X1;
  IO --> X1;

  X1 --> SC1;
  X1 --> SCK;
  X1 --> SCN;

  SC1 --> R["Sequence Encoder"];
  SCK --> R;
  SCN --> R;
  R --> ...;
  subgraph CONCAT["TENSOR.."]
    direction TB
    SC1["emb seq 1 | emb oth" ];
    SCK[...];
    SCN["emb seq n | emb oth"];
  end
  subgraph COMBINER..
  X1
  CONCAT
  R
  end
  subgraph SF[SEQUENCE FEATS..]
  direction TB
  I1["emb seq 1" ];
  IK[...];
  IN["emb seq n"];
  end
  subgraph OF[OTHER FEATS..]
  direction TB
  IO["emb oth"]
  end

sequence Combiner 将 sequence concat combiner 与 sequence encoder 堆叠使用。关于输入张量维度的所有考量,如sequence concat combiner所述,也适用于这种情况,但主要区别在于此 Combiner 使用 sequence concat combiner 的 b x s x h' 输出(其中 b 是批量大小,s 是序列长度,h' 是所有输入特征隐藏维度之和)作为序列特征编码器部分描述的任何 sequence encoder 的输入。有关 sequence encoder 及其参数的更详细信息,请参阅该部分。sequence encoder 输出形状的所有注意事项也适用于 sequence Combiner。

combiner:
    type: sequence
    main_sequence_feature: null
    reduce_output: null
    encoder:
        type: parallel_cnn
        skip: false
        dropout: 0.0
        activation: relu
        max_sequence_length: null
        representation: dense
        vocab: null
        use_bias: true
        bias_initializer: zeros
        weights_initializer: xavier_uniform
        should_embed: true
        embedding_size: 256
        embeddings_on_cpu: false
        embeddings_trainable: true
        pretrained_embeddings: null
        reduce_output: sum
        num_conv_layers: null
        conv_layers: null
        num_filters: 256
        filter_size: 3
        pool_function: max
        pool_size: null
        output_size: 256
        norm: null
        norm_params: null
        num_fc_layers: null
        fc_layers: null

参数

  • main_sequence_feature (默认值: null) : 用于拼接其他特征输出的 sequence、text 或 time series 特征的名称。如果未指定 main_sequence_feature,Combiner 将按照配置中定义的顺序遍历所有特征,并寻找一个输出为 3 维张量(sequence、text 或 time series)的特征。如果找不到,将引发异常;否则,该特征的输出将用于沿着序列 s 维度拼接其他特征。如果存在其他输出为 3 维张量的输入特征,Combiner 将沿着 s 维度拼接它们。所有序列类输入特征必须具有相同的 s 维度,否则将抛出错误。

  • reduce_output (默认值: null): 用于聚合集合项嵌入的策略。选项:lastsummeanavgmaxconcatattentionnoneNonenull

  • encoder (默认值: {"type": "parallel_cnn"}): 应用于 main_sequence_feature 的编码器。编码器必须产生一个大小为 [batch_size, sequence_length, hidden_size] 的张量。

TabNet Combiner

graph LR
  I1[Encoder Output 1] --> C[TabNet];
  IK[...] --> C;
  IN[Encoder Output N] --> C;
  C --> ...;

tabnet Combiner 实现了 TabNet 模型,该模型使用注意力和稀疏性在表格数据上实现高性能。它假定所有编码器输出都是大小为 b x h 的张量,其中 b 是批量大小,h 是隐藏维度,对于每个输入可以不同。如果输入张量形状不同,它会自动将其展平。它返回最终的 b x h' 张量,其中 h' 是用户指定的输出大小。

combiner:
    type: tabnet
    size: 32
    dropout: 0.05
    output_size: 128
    num_steps: 3
    num_total_blocks: 4
    num_shared_blocks: 2
    relaxation_factor: 1.5
    bn_epsilon: 0.001
    bn_momentum: 0.05
    bn_virtual_bs: 1024
    sparsity: 0.0001
    entmax_mode: sparsemax
    entmax_alpha: 1.5

参数

  • size (默认值: 32) : 隐藏层的大小。(Arik and Pfister, 2019) 中的 N_a
  • dropout (默认值: 0.05) : Transformer 块的 dropout 率。
  • output_size (默认值: 128) : 全连接层的输出大小。(Arik and Pfister, 2019) 中的 N_d
  • num_steps (默认值: 3): 注意力 Transformer 和特征 Transformer 计算的步数/重复次数。(Arik and Pfister, 2019) 中的 N_steps
  • num_total_blocks (默认值: 4): 每一步的总特征 Transformer 块数量。
  • num_shared_blocks (默认值: 2): 跨步骤共享的特征 Transformer 块数量。
  • relaxation_factor (默认值: 1.5): 影响特征在计算步骤中被使用的次数的因子。值为 1 表示每个特征使用一次,更高的值允许多次使用。(Arik and Pfister, 2019) 中的 gamma
  • bn_epsilon (默认值: 0.001): 添加到批量归一化分母中的 Epsilon 值。
  • bn_momentum (默认值: 0.05): 批量归一化的动量。TabNet 论文中的 1 - m_B
  • bn_virtual_bs (默认值: 1024): Ghost 批量归一化使用的虚拟批量大小。如果为 null,则使用常规批量归一化代替。TabNet 论文中的 B_v。详情请参阅Ghost 批量归一化
  • sparsity (默认值: 0.0001): 稀疏性诱导损失的乘数。(Arik and Pfister, 2019) 中的 lambda_sparse
  • entmax_mode (默认值: sparsemax): Entmax 是一种稀疏的概率映射族,它推广了 softmax 和 sparsemax。entmax_mode 控制稀疏性。选项:entmax15sparsemaxconstantadaptive
  • entmax_alpha (默认值: 1.5): 必须是介于 1.0 和 2.0 之间的数字。如果 entmax_mode 是 adaptive,则 entmax_alpha 用作可学习参数的初始值。1 对应于 softmax,2 对应于 sparsemax。

Transformer Combiner

graph LR
  I1[Encoder Output 1] --> C["Transformer Stack"];
  IK[...] --> C;
  IN[Encoder Output N] --> C;
  C --> R[Reduce];
  R --> FC[Fully Connected Layers];
  FC --> ...;
  subgraph COMBINER..
  C
  R
  FC
  end

transformer Combiner 使用一系列 Transformer 块(来自Attention Is All You Need)组合输入特征。它假定所有编码器输出都是大小为 b x h 的张量,其中 b 是批量大小,h 是隐藏维度,对于每个输入可以不同。如果输入张量形状不同,它会自动将其展平。然后,它将每个输入张量投影到相同的隐藏/嵌入大小,并使用一系列 Transformer 层进行编码。最后,transformer combiner 对 Transformer 堆栈的输出应用降维(reduction),然后可选地通过全连接层。输出是一个大小为 b x h' 的张量,其中 h' 是最后一个全连接层的大小或隐藏/嵌入大小;或者,如果未应用降维,则输出是一个大小为 b x n x h' 的张量,其中 n 是输入特征的数量,h' 是隐藏/嵌入大小。

了解更多关于 Transformer 的资源

combiner:
    type: transformer
    dropout: 0.1
    num_fc_layers: 0
    output_size: 256
    norm: null
    fc_dropout: 0.0
    transformer_output_size: 256
    hidden_size: 256
    num_layers: 1
    num_heads: 8
    use_bias: true
    bias_initializer: zeros
    weights_initializer: xavier_uniform
    norm_params: null
    fc_layers: null
    fc_activation: relu
    fc_residual: false
    reduce_output: mean

参数

  • dropout (默认值: 0.1) : Transformer 块的 dropout 率。
  • num_fc_layers (默认值: 0) : 堆叠全连接层的数量(仅当 reduce_output 不为 null 时适用)。
  • output_size (默认值: 256) : 全连接层的输出大小。
  • norm (默认值: null) : 应用于全连接层开始的默认归一化类型。选项:batchlayerghostnull。详情请参阅归一化
  • fc_dropout (默认值: 0.0) : 应用于全连接层的默认 dropout 率。增加 dropout 是应对过拟合的一种常见正则化形式。dropout 表示元素被置零的概率(0.0 表示没有 dropout)。
  • transformer_output_size (默认值: 256): Transformer 块中自注意力后的全连接层大小。这通常与 hidden_sizeembedding_size 相同。
  • hidden_size (默认值: 256): TransformerStack 的隐藏单元数量,以及每个传入输入特征在馈入 TransformerStack 之前被投影到的维度。
  • num_layers (默认值: 1): Transformer 层的数量。
  • num_heads (默认值: 8): Transformer 块中自注意力的头数。
  • use_bias (默认值: true): 层是否使用偏置向量。选项:truefalse
  • bias_initializer (默认值: zeros): 偏置向量的初始化器。选项:uniformnormalconstantoneszeroseyediracxavier_uniformxavier_normalkaiming_uniformkaiming_normalorthogonalsparseidentity。或者,也可以指定一个字典,其中包含一个用于标识初始化器类型的键 type 以及其他参数键,例如 {type: normal, mean: 0, stddev: 0}。每个初始化器参数的说明,请参阅torch.nn.init

  • weights_initializer (默认值: xavier_uniform): 权重矩阵的初始化器。选项:uniformnormalconstantoneszeroseyediracxavier_uniformxavier_normalkaiming_uniformkaiming_normalorthogonalsparseidentity。或者,也可以指定一个字典,其中包含一个用于标识初始化器类型的键 type 以及其他参数键,例如 {type: normal, mean: 0, stddev: 0}。每个初始化器参数的说明,请参阅torch.nn.init

  • norm_params (默认值: null): 传递给 norm 模块的默认参数。详情请参阅归一化

  • fc_layers (默认值: null): 包含所有全连接层参数的字典列表。列表的长度决定了堆叠的全连接层数量,每个字典的内容决定了特定层的参数。每个可用层的参数包括:activationdropoutnormnorm_paramsoutput_sizeuse_biasbias_initializerweights_initializer。如果字典中缺少这些值中的任何一个,将使用作为独立参数提供的默认值。
  • fc_activation (默认值: relu): 应用于全连接层输出的默认激活函数。选项:eluleakyRelulogSigmoidrelusigmoidtanhsoftmaxnull
  • fc_residual (默认值: false): 是否为每个全连接层块添加残差连接。要求所有全连接层具有相同的 output_size。选项:truefalse
  • reduce_output (默认值: mean): 用于聚合 Transformer 输出的策略。选项:lastsummeanavgmaxconcatattentionnoneNonenull

TabTransformer Combiner

graph LR
  I1[Cat Emb 1] --> T1["Concat"];
  IK[...] --> T1;
  IN[Cat Emb N] --> T1;
  N1[Number ...] --> T4["Concat"];
  B1[Binary ...] --> T4;
  T1 --> T2["Transformer"];
  T2 --> T3["Reduce"];
  T3 --> T4;
  T4 --> T5["FC Layers"];
  T5 --> ...;
  subgraph COMBINER..
  CAT
  T4
  T5
  end
  subgraph ENCODER OUT..
  I1
  IK
  IN
  N1
  B1
  end
  subgraph CAT["CATEGORY PIPELINE.."]
  direction TB
  T1
  T2
  T3
  end

tabtransformer Combiner 通过以下一系列操作组合输入特征。Combiner 将除二元和数值特征之外的所有编码器输出投影到嵌入空间。这些特征被像序列一样拼接,并经过一个 Transformer。在 Transformer 之后,数值和二元特征(大小为 1)被拼接,然后与 Transformer 的输出拼接,并传递给一系列全连接层(来自TabTransformer: Tabular Data Modeling Using Contextual Embeddings)。它假定所有编码器输出都是大小为 b x h 的张量,其中 b 是批量大小,h 是隐藏维度,对于每个输入可以不同。如果输入张量形状不同,它会自动将其展平。然后,它将每个输入张量投影到相同的隐藏/嵌入大小,并使用一系列 Transformer 层进行编码。最后,transformer combiner 对 Transformer 堆栈的输出应用降维(reduction),然后进行上述拼接和可选的全连接层。输出是一个大小为 b x h' 的张量,其中 h' 是最后一个全连接层的大小或隐藏/嵌入大小;或者,如果未应用降维,则输出是一个大小为 b x n x h' 的张量,其中 n 是输入特征的数量,h' 是隐藏/嵌入大小。

combiner:
    type: tabtransformer
    dropout: 0.1
    num_fc_layers: 0
    output_size: 256
    norm: null
    fc_dropout: 0.0
    embed_input_feature_name: null
    transformer_output_size: 256
    hidden_size: 256
    num_layers: 1
    num_heads: 8
    use_bias: true
    bias_initializer: zeros
    weights_initializer: xavier_uniform
    norm_params: null
    fc_layers: null
    fc_activation: relu
    fc_residual: false
    reduce_output: concat

参数

  • dropout (默认值: 0.1) : Transformer 块的 dropout 率。
  • num_fc_layers (默认值: 0) : 堆叠全连接层的数量(仅当 reduce_output 不为 null 时适用)。
  • output_size (默认值: 256) : 全连接层的输出大小。
  • norm (默认值: null) : 应用于全连接层开始的默认归一化类型。选项:batchlayerghostnull。详情请参阅归一化
  • fc_dropout (默认值: 0.0) : 应用于全连接层的默认 dropout 率。增加 dropout 是应对过拟合的一种常见正则化形式。dropout 表示元素被置零的概率(0.0 表示没有 dropout)。
  • embed_input_feature_name (默认值: null) : 此值控制嵌入的大小。有效值包括使用 hidden_size 值的 add,或设置为特定值的整数。如果是整数值,其值必须小于 hidden_size。
  • transformer_output_size (默认值: 256): Transformer 块中自注意力后的全连接层大小。这通常与 hidden_sizeembedding_size 相同。
  • hidden_size (默认值: 256): TransformerStack 的隐藏单元数量,以及每个传入输入特征在馈入 TransformerStack 之前被投影到的维度。
  • num_layers (默认值: 1): Transformer 层的数量。
  • num_heads (默认值: 8): Transformer 块中自注意力的头数。
  • use_bias (默认值: true): 层是否使用偏置向量。选项:truefalse
  • bias_initializer (默认值: zeros): 偏置向量的初始化器。选项:uniformnormalconstantoneszeroseyediracxavier_uniformxavier_normalkaiming_uniformkaiming_normalorthogonalsparseidentity。或者,也可以指定一个字典,其中包含一个用于标识初始化器类型的键 type 以及其他参数键,例如 {type: normal, mean: 0, stddev: 0}。每个初始化器参数的说明,请参阅torch.nn.init

  • weights_initializer (默认值: xavier_uniform): 权重矩阵的初始化器。选项:uniformnormalconstantoneszeroseyediracxavier_uniformxavier_normalkaiming_uniformkaiming_normalorthogonalsparseidentity。或者,也可以指定一个字典,其中包含一个用于标识初始化器类型的键 type 以及其他参数键,例如 {type: normal, mean: 0, stddev: 0}。每个初始化器参数的说明,请参阅torch.nn.init

  • norm_params (默认值: null): 传递给 norm 模块的默认参数。详情请参阅归一化

  • fc_layers (默认值: null): 包含所有全连接层参数的字典列表。列表的长度决定了堆叠的全连接层数量,每个字典的内容决定了特定层的参数。每个可用层的参数包括:activationdropoutnormnorm_paramsoutput_sizeuse_biasbias_initializerweights_initializer。如果字典中缺少这些值中的任何一个,将使用作为独立参数提供的默认值。
  • fc_activation (默认值: relu): 应用于全连接层输出的默认激活函数。选项:eluleakyRelulogSigmoidrelusigmoidtanhsoftmaxnull
  • fc_residual (默认值: false): 是否为每个全连接层块添加残差连接。要求所有全连接层具有相同的 output_size。选项:truefalse
  • reduce_output (默认值: concat): 用于聚合 Transformer 输出的策略。选项:lastsummeanavgmaxconcatattentionnoneNonenull

Comparator Combiner

graph LR
  I1[Entity 1 Embed 1] --> C1[Concat];
  IK[...] --> C1;
  IN[Entity 1 Embed N] --> C1;
  C1 --> FC1[FC Layers];
  FC1 --> COMP[Compare];

  I2[Entity 2 Embed 1] --> C2[Concat];
  IK2[...] --> C2;
  IN2[Entity 2 Embed N] --> C2;
  C2 --> FC2[FC Layers];
  FC2 --> COMP;

  COMP --> ...;

  subgraph ENTITY1["ENTITY 1.."]
  I1
  IK
  IN
  end

  subgraph ENTITY2["ENTITY 2.."]
  I2
  IK2
  IN2
  end

  subgraph COMBINER..
  C1
  FC1
  C2
  FC2
  COMP
  end

comparator Combiner 比较由特征列表定义的两个实体的隐藏表示。它假定所有编码器输出都是大小为 b x h 的张量,其中 b 是批量大小,h 是隐藏维度,对于每个输入可以不同。如果输入张量形状不同,它会自动将其展平。然后,它拼接每个实体的表示,并将它们都投影到大小为 output_size 的向量。最后,它通过点积、元素乘法、绝对差和双线性积来比较两个实体表示。它返回最终的 b x h' 张量,其中 h' 是四种比较结果拼接后的大小。

combiner:
    type: comparator
    entity_1:
    - feature_1
    - feature_2
    entity_2:
    - feature_3
    dropout: 0.0
    num_fc_layers: 1
    output_size: 256
    norm: null
    activation: relu
    use_bias: true
    bias_initializer: zeros
    weights_initializer: xavier_uniform
    norm_params: null
    fc_layers: null

参数

  • entity_1 (默认值: null) : 构成第一个要比较实体的输入特征名称列表 [feature_1, feature_2, ...]必需
  • entity_2 (默认值: null) : 构成第二个要比较实体的输入特征名称列表 [feature_1, feature_2, ...]必需
  • dropout (默认值: 0.0) : 应用于全连接层的默认 dropout 率。增加 dropout 是应对过拟合的一种常见正则化形式。dropout 表示元素被置零的概率(0.0 表示没有 dropout)。
  • num_fc_layers (默认值: 1) : 应用的全连接层堆栈数量。增加层数可以增加模型的容量,使其能够学习更复杂的特征交互。
  • output_size (默认值: 256) : 全连接层的输出大小。
  • norm (默认值: null) : 应用于全连接层开始的默认归一化类型。选项:batchlayerghostnull。详情请参阅归一化
  • activation (默认值: relu): 应用于全连接层输出的默认激活函数。选项:eluleakyRelulogSigmoidrelusigmoidtanhsoftmaxnull
  • use_bias (默认值: true): 层是否使用偏置向量。选项:truefalse
  • bias_initializer (默认值: zeros): 偏置向量的初始化器。选项:uniformnormalconstantoneszeroseyediracxavier_uniformxavier_normalkaiming_uniformkaiming_normalorthogonalsparseidentity。或者,也可以指定一个字典,其中包含一个用于标识初始化器类型的键 type 以及其他参数键,例如 {type: normal, mean: 0, stddev: 0}。每个初始化器参数的说明,请参阅torch.nn.init

  • weights_initializer (默认值: xavier_uniform): 权重矩阵的初始化器。选项:uniformnormalconstantoneszeroseyediracxavier_uniformxavier_normalkaiming_uniformkaiming_normalorthogonalsparseidentity。或者,也可以指定一个字典,其中包含一个用于标识初始化器类型的键 type 以及其他参数键,例如 {type: normal, mean: 0, stddev: 0}。每个初始化器参数的说明,请参阅torch.nn.init

  • norm_params (默认值: null): 传递给 norm 模块的默认参数。详情请参阅归一化

  • fc_layers (默认值: null): 包含所有全连接层参数的字典列表。列表的长度决定了堆叠的全连接层数量,每个字典的内容决定了特定层的参数。每个可用层的参数包括:activationdropoutnormnorm_paramsoutput_sizeuse_biasbias_initializerweights_initializer。如果字典中缺少这些值中的任何一个,将使用作为独立参数提供的默认值。

通用参数

这些参数以类似方式在多个 Combiner(以及一些 encoder / decoder)中使用。

归一化

应用于全连接堆栈开始的归一化。如果 fc_layers 没有指定 norm,这将是用于每一层的默认 norm。选项之一:

  • null: 无归一化
  • batch: 批量归一化
  • layer: 层归一化
  • ghost: Ghost 批量归一化
批量归一化

应用论文 Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift 中描述的批量归一化。有关更多详细信息,请参阅PyTorch 批量归一化文档

norm: batch
norm_params:
  eps: 0.001
  momentum: 0.1
  affine: true
  track_running_stats: true

参数

  • eps (默认值: 0.001): 添加到批量归一化分母中的 Epsilon 值。
  • momentum (默认值: 0.1): 用于计算 running_mean 和 running_var 的值。可以设置为 None 以使用累积移动平均(即简单平均)。默认值: 0.1
  • affine (默认值: true): 一个布尔值,设置为 true 时,此模块具有可学习的仿射参数。
  • track_running_stats (默认值: true): 一个布尔值,设置为 true 时,此模块跟踪 running mean 和 variance;设置为 false 时,此模块不跟踪此类统计信息,并将统计缓冲区 running_mean 和 running_var 初始化为 null。当这些缓冲区为 null 时,此模块在训练和评估模式下始终使用批量统计信息。
层归一化

应用论文 Layer Normalization 中描述的层归一化。有关更多详细信息,请参阅PyTorch 层归一化文档

norm: layer
norm_params:
  eps: 0.00001
  elementwise_affine: true

参数

  • eps (默认值: 0.00001): 添加到分母中以确保数值稳定性的值。
  • elementwise_affine (默认值: true): 一个布尔值,设置为 true 时,此模块具有可学习的逐元素仿射参数,初始化为一(权重)和零(偏置)。
Ghost 批量归一化

Ghost 批量归一化是一种旨在解决“泛化差距”的技术,即在使用非常大的批量大小时训练过程会崩溃。如果您正在使用大批量大小(通常以千为单位)以最大化 GPU 利用率,但模型收敛不好,启用 Ghost 批量归一化可能是一种提高收敛性的有用技术。

使用 Ghost 批量归一化时,您可以指定一个 virtual_batch_size(默认值 128),表示进行训练的“理想”批量大小(忽略吞吐量或 GPU 利用率)。Ghost 批量归一化会将每个批量细分为大小为 virtual_batch_size 的子批量,并对每个子批量应用批量归一化。

Ghost 批量归一化一个显著缺点是计算成本高于传统批量归一化,因此仅建议在最大化吞吐量的批量大小远大于获得最佳收敛性的批量大小(高出一个或多个数量级)时使用它。

该方法在论文 Train Longer, Generalize Better: Closing the Generalization Gap in Large Batch Training of Neural Networks 中被提出,并因其在 TabNet 中的使用而普及。

norm: ghost
norm_params:
  virtual_batch_size: 128
  epsilon: 0.001
  momentum: 0.05

参数

  • virtual_batch_size (默认值: 128): Ghost 批量归一化使用的虚拟批量大小。如果为 null,则使用常规批量归一化代替。TabNet 论文中的 B_v
  • epsilon (默认值: 0.001): 添加到批量归一化分母中的 Epsilon 值。
  • momentum (默认值: 0.05): 批量归一化的动量。TabNet 论文中的 1 - m_B