<jupyter_start><jupyter_text>DIEN (Deep Interest Evolution Network)Deep Interest Evolution Network (DIEN) uses interest extractor layer to capture temporal interests from history behavior sequence. At this layer, an auxiliary loss is proposed to supervise interest extracting at each step. As user interests are diverse, especially in the e-commerce system, interest evolving layer is proposed to capture interest evolving process that is relative to the target item. At interest evolving layer, attention mechanism is embedded into the sequential structure novelly, and the effects of relative interests are strengthened during interest evolution.<jupyter_code>import numpy as np

from deepctr.models import DIEN
from deepctr.utils import SingleFeat
use_neg=True

uid = np.array([0, 1, 2])
iid = np.array([1, 2, 3])  # 0 is mask value
igender = np.array([1, 2, 1])  # 0 is mask value
ugender = np.array([0, 1, 0])
score = np.array([0.1, 0.2, 0.3])
behavior_length = np.array([3, 3, 2])

hist_iid = np.array([[1, 2, 3, 0], [1, 2, 3, 0], [1, 2, 0, 0]])
hist_igender = np.array([[1, 1, 2, 0], [2, 1, 1, 0], [2, 1, 0, 0]])

behavior_feature_list = ["item", "item_gender"]

feature_dim_dict = {"sparse": [SingleFeat('user', 3), SingleFeat('gender', 2), SingleFeat('item', 3 + 1), 
                               SingleFeat('item_gender', 2 + 1)], "dense": [SingleFeat('score', 0)]}

feature_dict = {'user': uid, 'gender': ugender, 'item': iid, 'item_gender': igender,
                'hist_item': hist_iid, 'hist_item_gender': hist_igender,
                'score': score}
x = [feature_dict[feat.name] for feat in feature_dim_dict["sparse"]] + [
     feature_dict[feat.name] for feat in feature_dim_dict["dense"]] + [
     feature_dict['hist_' + feat] for feat in behavior_feature_list]
if use_neg:
    feature_dict['neg_hist_item'] = np.array([[1, 2, 3, 0], [1, 2, 3, 0], [1, 2, 0, 0]])
    feature_dict['neg_hist_item_gender'] = np.array([[1, 1, 2, 0], [2, 1, 1, 0], [2, 1, 0, 0]])
    x += [feature_dict['neg_hist_' + feat] for feat in behavior_feature_list]

x += [behavior_length]
y = [1, 0, 1]
model = DIEN(feature_dim_dict, behavior_feature_list, hist_len_max=4, embedding_size=8,
             dnn_hidden_units=[4, 4, 4], dnn_dropout=0.6, gru_type="AUGRU", use_negsampling=True)

model.compile('adam', 'binary_crossentropy',
              metrics=['binary_crossentropy'])
history = model.fit(x, y, verbose=1, epochs=10, validation_split=0.5)<jupyter_output>Train on 1 samples, validate on 2 samples
Epoch 1/10
1/1 [==============================] - 1s 1s/sample - loss: 1.4490 - binary_crossentropy: 0.5027 - val_loss: 1.3939 - val_binary_crossentropy: 0.6842
Epoch 2/10
1/1 [==============================] - 0s 10ms/sample - loss: 1.6351 - binary_crossentropy: 0.6888 - val_loss: 1.3935 - val_binary_crossentropy: 0.6838
Epoch 3/10
1/1 [==============================] - 0s 13ms/sample - loss: 1.7443 - binary_crossentropy: 0.7980 - val_loss: 1.3930 - val_binary_crossentropy: 0.6833
Epoch 4/10
1/1 [==============================] - 0s 8ms/sample - loss: 1.3437 - binary_crossentropy: 0.3974 - val_loss: 1.3925 - val_binary_crossentropy: 0.6828
Epoch 5/10
1/1 [==============================] - 0s 9ms/sample - loss: 1.6300 - binary_crossentropy: 0.6837 - val_loss: 1.3921 - val_binary_crossentropy: 0.6824
Epoch 6/10
1/1 [==============================] - 0s 11ms/sample - loss: 1.6370 - binary_crossentropy: 0.6907 - val_loss: 1.3918 - val_binary_cross[...]
{'fraction_non_alphanumeric': 0.18701298701298702, 'fraction_numerical': 0.0735930735930736, 'mean_word_length': 4.415625, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '65798', 'license': 'Unlicense', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1199, 'n_words': 352, 'path': '5.0.1 - Embeddings - Dien.ipynb', 'repo_name': 'harashm/ExpertDL', 'size': '3465'}