24
24
from ..layers .utils import NoMask , concat_fun
25
25
26
26
27
- def DSIN (dnn_feature_columns , sess_feature_list , embedding_size = 8 , sess_max_count = 5 , sess_len_max = 10 , bias_encoding = False ,
27
+ def DSIN (dnn_feature_columns , sess_feature_list , embedding_size = 8 , sess_max_count = 5 , bias_encoding = False ,
28
28
att_embedding_size = 1 , att_head_num = 8 , dnn_hidden_units = (200 , 80 ), dnn_activation = 'sigmoid' , dnn_dropout = 0 ,
29
29
dnn_use_bn = False , l2_reg_dnn = 0 , l2_reg_embedding = 1e-6 , init_std = 0.0001 , seed = 1024 , task = 'binary' ,
30
30
):
@@ -49,33 +49,12 @@ def DSIN(dnn_feature_columns, sess_feature_list, embedding_size=8, sess_max_coun
49
49
:return: A Keras model instance.
50
50
51
51
"""
52
- #check_feature_config_dict(dnn_feature_columns)
53
52
54
53
if (att_embedding_size * att_head_num != len (sess_feature_list ) * embedding_size ):
55
54
raise ValueError (
56
55
"len(session_feature_lsit) * embedding_size must equal to att_embedding_size * att_head_num ,got %d * %d != %d *%d" % (
57
56
len (sess_feature_list ), embedding_size , att_embedding_size , att_head_num ))
58
57
59
- # sparse_input, dense_input, user_behavior_input_dict, _, user_sess_length = get_input(
60
- # dnn_feature_columns, sess_feature_list, sess_max_count, sess_len_max)
61
-
62
- # def get_input(feature_dim_dict, seq_feature_list, sess_max_count, seq_max_len):
63
- # sparse_input, dense_input = build_input_features(feature_dim_dict)
64
- # user_behavior_input = {}
65
- # for idx in range(sess_max_count):
66
- # sess_input = OrderedDict()
67
- # for i, feat in enumerate(seq_feature_list):
68
- # sess_input[feat] = Input(
69
- # shape=(seq_max_len,), name='seq_' + str(idx) + str(i) + '-' + feat)
70
- #
71
- # user_behavior_input["sess_" + str(idx)] = sess_input
72
- #
73
- # user_behavior_length = {"sess_" + str(idx): Input(shape=(1,), name='seq_length' + str(idx)) for idx in
74
- # range(sess_max_count)}
75
- # user_sess_length = Input(shape=(1,), name='sess_length')
76
- #
77
- # return sparse_input, dense_input, user_behavior_input, user_behavior_length, user_sess_length
78
-
79
58
80
59
features = build_input_features (dnn_feature_columns )
81
60
@@ -85,15 +64,13 @@ def DSIN(dnn_feature_columns, sess_feature_list, embedding_size=8, sess_max_coun
85
64
varlen_sparse_feature_columns = list (filter (lambda x : isinstance (x , VarLenSparseFeat ), dnn_feature_columns )) if dnn_feature_columns else []
86
65
87
66
88
- history_feature_columns = []
67
+
89
68
sparse_varlen_feature_columns = []
90
69
history_fc_names = list (map (lambda x : "sess" + x , sess_feature_list ))
91
- #user_behavior_input_dict = {"sess_"+str(i):{} for i in range(sess_max_count)}
92
70
for fc in varlen_sparse_feature_columns :
93
71
feature_name = fc .name
94
72
if feature_name in history_fc_names :
95
73
continue
96
- #history_feature_columns.append(fc)
97
74
else :
98
75
sparse_varlen_feature_columns .append (fc )
99
76
@@ -106,13 +83,11 @@ def DSIN(dnn_feature_columns, sess_feature_list, embedding_size=8, sess_max_coun
106
83
sess_input = OrderedDict ()
107
84
for i , feat in enumerate (sess_feature_list ):
108
85
sess_input [feat ] = features ["sess_" + str (idx )+ "_" + feat ]
109
- #Input(shape=(seq_max_len,), name='seq_' + str(idx) + str(i) + '-' + feat)
86
+
110
87
111
88
user_behavior_input_dict ["sess_" + str (idx )] = sess_input
112
89
113
90
114
- #user_behavior_length = {"sess_" + str(idx): Input(shape=(1,), name='seq_length' + str(idx)) for idx in
115
- # range(sess_max_count)}
116
91
user_sess_length = Input (shape = (1 ,), name = 'sess_length' )
117
92
118
93
@@ -130,20 +105,12 @@ def DSIN(dnn_feature_columns, sess_feature_list, embedding_size=8, sess_max_coun
130
105
131
106
132
107
query_emb_list = embedding_lookup (embedding_dict ,features ,sparse_feature_columns ,sess_feature_list ,sess_feature_list )#query是单独的
133
- keys_emb_list = embedding_lookup (embedding_dict , features , history_feature_columns , history_fc_names , history_fc_names )
134
108
dnn_input_emb_list = embedding_lookup (embedding_dict ,features ,sparse_feature_columns ,mask_feat_list = sess_feature_list )
135
109
dense_value_list = get_dense_input (features , dense_feature_columns )
136
110
137
-
138
-
139
-
140
- #query_emb_list = get_embedding_vec_list(sparse_embedding_dict, sparse_input, dnn_feature_columns["sparse"],
141
- # sess_feature_list, sess_feature_list)
142
-
143
111
query_emb = concat_fun (query_emb_list )
144
112
145
- #dnn_input_emb_list = get_embedding_vec_list(sparse_embedding_dict, sparse_input, dnn_feature_columns["sparse"],
146
- # mask_feat_list=sess_feature_list)
113
+
147
114
dnn_input_emb = concat_fun (dnn_input_emb_list )
148
115
dnn_input_emb = Flatten ()(NoMask ()(dnn_input_emb ))
149
116
@@ -167,9 +134,7 @@ def DSIN(dnn_feature_columns, sess_feature_list, embedding_size=8, sess_max_coun
167
134
168
135
dnn_input_emb = Concatenate ()(
169
136
[dnn_input_emb , Flatten ()(interest_attention_layer ), Flatten ()(lstm_attention_layer )])
170
- # if len(dense_input) > 0:
171
- # deep_input_emb = Concatenate()(
172
- # [deep_input_emb] + list(dense_input.values()))
137
+
173
138
dnn_input_emb = combined_dnn_input ([dnn_input_emb ],dense_value_list )
174
139
output = DNN (dnn_hidden_units , dnn_activation , l2_reg_dnn ,
175
140
dnn_dropout , dnn_use_bn , seed )(dnn_input_emb )
@@ -184,9 +149,6 @@ def DSIN(dnn_feature_columns, sess_feature_list, embedding_size=8, sess_max_coun
184
149
[user_behavior_input_dict [sess_name ]]))
185
150
# sess_input_length_list.append(user_behavior_length_dict[sess_name])
186
151
187
- # model_input_list = get_inputs_list([sparse_input, dense_input]) + sess_input_list + [
188
- # user_sess_length]
189
- #
190
152
191
153
model = Model (inputs = inputs_list + [user_sess_length ], outputs = output )
192
154
0 commit comments