hopwise.model.sequential_recommender.dien

Reference:

Guorui Zhou et al. “Deep Interest Evolution Network for Click-Through Rate Prediction” in AAAI 2019

Reference code:

Classes

DIEN

DIEN has an interest extractor layer to capture temporal interests from history behavior sequence,and an

InterestExtractorNetwork

In e-commerce system, user behavior is the carrier of latent interest, and interest will change after

InterestEvolvingLayer

As the joint influence from external environment and internal cognition, different kinds of user interests are

AGRUCell

Attention based GRU (AGRU). AGRU uses the attention score to replace the update gate of GRU, and changes the

AUGRUCell

Effect of GRU with attentional update gate (AUGRU). AUGRU combines attention mechanism and GRU seamlessly.

DynamicRNN

Module Contents

class hopwise.model.sequential_recommender.dien.DIEN(config, dataset)

Bases: hopwise.model.abstract_recommender.SequentialRecommender

DIEN has an interest extractor layer to capture temporal interests from history behavior sequence,and an interest evolving layer to capture interest evolving process that is relative to the target item. At interest evolving layer, attention mechanism is embedded intothe sequential structure novelly, and the effects of relative interests are strengthened during interest evolution.

input_type
device
alpha
gru
pooling_mode
dropout_prob
LABEL_FIELD
embedding_size
mlp_hidden_size
NEG_ITEM_SEQ
types = ['user', 'item']
user_feat
item_feat
att_list
interest_mlp_list
dnn_mlp_list
interset_extractor
interest_evolution
embedding_layer
dnn_mlp_layers
dnn_predict_layer
sigmoid
loss
other_parameter_name = ['embedding_layer']
_init_weights(module)
forward(user, item_seq, neg_item_seq, item_seq_len, next_items)
calculate_loss(interaction)

Calculate the training loss for a batch data.

Parameters:

interaction (Interaction) – Interaction class of the batch.

Returns:

Training loss, shape: []

Return type:

torch.Tensor

predict(interaction)

Predict the scores between users and items.

Parameters:

interaction (Interaction) – Interaction class of the batch.

Returns:

Predicted scores for given users and items, shape: [batch_size]

Return type:

torch.Tensor

class hopwise.model.sequential_recommender.dien.InterestExtractorNetwork(input_size, hidden_size, mlp_size)

Bases: torch.nn.Module

In e-commerce system, user behavior is the carrier of latent interest, and interest will change after user takes one behavior. At the interest extractor layer, DIEN extracts series of interest states from sequential user behaviors.

gru
auxiliary_net
forward(keys, keys_length, neg_keys=None)
auxiliary_loss(h_states, click_seq, noclick_seq, keys_length)

Computes the auxiliary loss.

Parameters:
  • h_states (torch.Tensor) – The output of GRUs’ hidden layer, shape [batch_size, history_length - 1, embedding_size].

  • click_seq (torch.Tensor) – The sequence that users consumed, shape [batch_size, history_length - 1, embedding_size].

  • noclick_seq (torch.Tensor) – The sequence that users did not consume, shape [batch_size, history_length - 1, embedding_size].

  • keys_length (torch.Tensor) – The true length of the user history sequence.

Returns:

auxiliary loss

Return type:

torch.Tensor

class hopwise.model.sequential_recommender.dien.InterestEvolvingLayer(mask_mat, input_size, rnn_hidden_size, att_hidden_size=(80, 40), activation='sigmoid', softmax_stag=True, gru='GRU')

Bases: torch.nn.Module

As the joint influence from external environment and internal cognition, different kinds of user interests are evolving over time. Interest Evolving Layer can capture interest evolving process that is relative to the target item.

mask_mat
gru = 'GRU'
final_output(outputs, keys_length)

Get the last effective value in the interest evolution sequence :param outputs: the output of DynamicRNN after pad_packed_sequence :type outputs: torch.Tensor :param keys_length: the true length of the user history sequence :type keys_length: torch.Tensor

Returns:

The user’s CTR for the next item

Return type:

torch.Tensor

forward(queries, keys, keys_length)
class hopwise.model.sequential_recommender.dien.AGRUCell(input_size, hidden_size, bias=True)

Bases: torch.nn.Module

Attention based GRU (AGRU). AGRU uses the attention score to replace the update gate of GRU, and changes the

hidden state directly.

Formally:

..math: {h}_{t}^{prime}=left(1-a_{t}

ight) * {h}_{t-1}^{prime}+a_{t} * ilde{{h}}_{t}^{prime}

\({h}_{t}^{\prime}\), \(h_{t-1}^{\prime}\), \({h}_{t-1}^{\prime}\), :math: ` ilde{{h}}_{t}^{prime}` are the hidden state of AGRU

input_size
hidden_size
bias = True
weight_ih
weight_hh
forward(input, hidden_output, att_score)
class hopwise.model.sequential_recommender.dien.AUGRUCell(input_size, hidden_size, bias=True)

Bases: torch.nn.Module

Effect of GRU with attentional update gate (AUGRU). AUGRU combines attention mechanism and GRU seamlessly.

Formally:
..math: ilde{{u}}_{t}^{prime}=a_{t} * {u}_{t}^{prime}

{h}_{t}^{prime}=left(1- ilde{{u}}_{t}^{prime}

ight) circ {h}_{t-1}^{prime}+ ilde{{u}}_{t}^{prime} circ ilde{{h}}_{t}^{prime}

input_size
hidden_size
bias = True
weight_ih
weight_hh
forward(input, hidden_output, att_score)
class hopwise.model.sequential_recommender.dien.DynamicRNN(input_size, hidden_size, bias=True, gru='AGRU')

Bases: torch.nn.Module

input_size
hidden_size
forward(input, att_scores=None, hidden_output=None)