序列化组件的配置方式

序列模型(DIN、BST)的组件化配置方式需要把输入特征放置在同一个feature_group内。

序列模型一般包含 history behavior sequencetarget item 两部分,且每部分都可能包含多个属性(子特征)。

在序列组件输入的feature_group内,按照顺序定义 history behavior sequencetarget item的各个子特征。

框架按照特征定义的类型feature_type字段来识别某个具体的特征是属于 history behavior sequence 还是 target item。 所有 SequenceFeature 类型的子特征都被识别为history behavior sequence的一部分; 所有非SequenceFeature 类型的子特征都被识别为target item的一部分。

两部分的子特征的顺序需要保持一致。在下面的例子中,

  • concat([cate_id,brand], axis=-1)target item最终的embedding(2D);

  • concat([tag_category_list, tag_brand_list], axis=-1)history behavior sequence最终的embedding(3D)

model_config: {
  model_name: 'DIN'
  model_class: 'RankModel
  ...
  feature_groups: {
    group_name: 'sequence'
    feature_names: "cate_id"
    feature_names: "brand"
    feature_names: "tag_category_list"
    feature_names: "tag_brand_list"
    wide_deep: DEEP
  }
  backbone {
    blocks {
      name: 'seq_input'
      inputs {
        feature_group_name: 'sequence'
      }
      input_layer {
        output_seq_and_normal_feature: true
      }
    }
    blocks {
      name: 'DIN'
      inputs {
        block_name: 'seq_input'
      }
      keras_layer {
        class_name: 'DIN'
        din {
          attention_dnn {
            hidden_units: 32
            hidden_units: 1
            activation: "dice"
          }
          need_target_feature: true
        }
      }
    }
    ...
  }
}

使用序列组件时,必须配置一个input_layer类型的block,并且配置output_seq_and_normal_feature: true参数,如下。

blocks {
  name: 'seq_input'
  inputs {
    feature_group_name: 'sequence'
  }
  input_layer {
    output_seq_and_normal_feature: true
  }
}

完整的例子