Instantiates the Deep Interest Network architecture. :param dnn_feature_columns: An iterable containing all the features used by deep part of the model. :param history_feature_list: list,to indicate sequence sparse field :param dnn_use_bn: bool. Whether use BatchNormalization before ac
| 13 | |
| 14 | |
| 15 | class DIN(BaseModel): |
| 16 | """Instantiates the Deep Interest Network architecture. |
| 17 | |
| 18 | :param dnn_feature_columns: An iterable containing all the features used by deep part of the model. |
| 19 | :param history_feature_list: list,to indicate sequence sparse field |
| 20 | :param dnn_use_bn: bool. Whether use BatchNormalization before activation or not in deep net |
| 21 | :param dnn_hidden_units: list,list of positive integer or empty list, the layer number and units in each layer of deep net |
| 22 | :param dnn_activation: Activation function to use in deep net |
| 23 | :param att_hidden_size: list,list of positive integer , the layer number and units in each layer of attention net |
| 24 | :param att_activation: Activation function to use in attention net |
| 25 | :param att_weight_normalization: bool. Whether normalize the attention score of local activation unit. |
| 26 | :param l2_reg_dnn: float. L2 regularizer strength applied to DNN |
| 27 | :param l2_reg_embedding: float. L2 regularizer strength applied to embedding vector |
| 28 | :param dnn_dropout: float in [0,1), the probability we will drop out a given DNN coordinate. |
| 29 | :param init_std: float,to use as the initialize std of embedding vector |
| 30 | :param seed: integer ,to use as random seed. |
| 31 | :param task: str, ``"binary"`` for binary logloss or ``"regression"`` for regression loss |
| 32 | :param device: str, ``"cpu"`` or ``"cuda:0"`` |
| 33 | :param gpus: list of int or torch.device for multiple gpus. If None, run on `device`. `gpus[0]` should be the same gpu with `device`. |
| 34 | :return: A PyTorch model instance. |
| 35 | |
| 36 | """ |
| 37 | |
| 38 | def __init__(self, dnn_feature_columns, history_feature_list, dnn_use_bn=False, |
| 39 | dnn_hidden_units=(256, 128), dnn_activation='relu', att_hidden_size=(64, 16), |
| 40 | att_activation='Dice', att_weight_normalization=False, l2_reg_dnn=0.0, |
| 41 | l2_reg_embedding=1e-6, dnn_dropout=0, init_std=0.0001, |
| 42 | seed=1024, task='binary', device='cpu', gpus=None): |
| 43 | super(DIN, self).__init__([], dnn_feature_columns, l2_reg_linear=0, l2_reg_embedding=l2_reg_embedding, |
| 44 | init_std=init_std, seed=seed, task=task, device=device, gpus=gpus) |
| 45 | |
| 46 | self.sparse_feature_columns = list( |
| 47 | filter(lambda x: isinstance(x, SparseFeat), dnn_feature_columns)) if dnn_feature_columns else [] |
| 48 | self.varlen_sparse_feature_columns = list( |
| 49 | filter(lambda x: isinstance(x, VarLenSparseFeat), dnn_feature_columns)) if dnn_feature_columns else [] |
| 50 | |
| 51 | self.history_feature_list = history_feature_list |
| 52 | |
| 53 | self.history_feature_columns = [] |
| 54 | self.sparse_varlen_feature_columns = [] |
| 55 | self.history_fc_names = list(map(lambda x: "hist_" + x, history_feature_list)) |
| 56 | |
| 57 | for fc in self.varlen_sparse_feature_columns: |
| 58 | feature_name = fc.name |
| 59 | if feature_name in self.history_fc_names: |
| 60 | self.history_feature_columns.append(fc) |
| 61 | else: |
| 62 | self.sparse_varlen_feature_columns.append(fc) |
| 63 | |
| 64 | att_emb_dim = self._compute_interest_dim() |
| 65 | |
| 66 | self.attention = AttentionSequencePoolingLayer(att_hidden_units=att_hidden_size, |
| 67 | embedding_dim=att_emb_dim, |
| 68 | att_activation=att_activation, |
| 69 | return_score=False, |
| 70 | supports_masking=False, |
| 71 | weight_normalization=att_weight_normalization) |
| 72 |
no outgoing calls