Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def feature_embedding(fc_i, fc_j, embedding_dict, input_feature):
fc_i_embedding = embedding_dict[fc_i.name][fc_j.name](input_feature)
if isinstance(fc_i, SparseFeat):
return NoMask()(fc_i_embedding)
else:
return SequencePoolingLayer(fc_i.combiner, supports_masking=True)(fc_i_embedding)
def __init__(self, **kwargs):
super(NoMask, self).__init__(**kwargs)
embeddings_regularizer=l2(
l2_reg_embedding),
name='sparse_emb_' +
str(i) + '-' + feat.name,
mask_zero=(feat.name in sess_feature_list)) for i, feat in
enumerate(feature_dim_dict["sparse"])}
query_emb_list = get_embedding_vec_list(sparse_embedding_dict, sparse_input, feature_dim_dict["sparse"],
sess_feature_list, sess_feature_list)
query_emb = concat_fun(query_emb_list)
deep_input_emb_list = get_embedding_vec_list(sparse_embedding_dict, sparse_input, feature_dim_dict["sparse"],
mask_feat_list=sess_feature_list)
deep_input_emb = concat_fun(deep_input_emb_list)
deep_input_emb = Flatten()(NoMask()(deep_input_emb))
tr_input = sess_interest_division(sparse_embedding_dict, user_behavior_input_dict, feature_dim_dict['sparse'],
sess_feature_list, sess_max_count, bias_encoding=bias_encoding)
Self_Attention = Transformer(att_embedding_size, att_head_num, dropout_rate=0, use_layer_norm=False,
use_positional_encoding=(not bias_encoding), seed=seed, supports_masking=True,
blinding=True)
sess_fea = sess_interest_extractor(
tr_input, sess_max_count, Self_Attention)
interest_attention_layer = AttentionSequencePoolingLayer(att_hidden_units=(64, 16), weight_normalization=True,
supports_masking=False)(
[query_emb, sess_fea, user_sess_length])
lstm_outputs = BiLSTM(len(sess_feature_list) * embedding_size,
layers=2, res_layers=0, dropout_rate=0.2, )(sess_fea)
def concat_func(inputs, axis=-1, mask=False):
if not mask:
inputs = list(map(NoMask(), inputs))
if len(inputs) == 1:
return inputs[0]
else:
return tf.keras.layers.Concatenate(axis=axis)(inputs)
'DNN': DNN,
'PredictionLayer': PredictionLayer,
'FM': FM,
'AFMLayer': AFMLayer,
'CrossNet': CrossNet,
'BiInteractionPooling': BiInteractionPooling,
'LocalActivationUnit': LocalActivationUnit,
'Dice': Dice,
'SequencePoolingLayer': SequencePoolingLayer,
'AttentionSequencePoolingLayer': AttentionSequencePoolingLayer,
'CIN': CIN,
'InteractingLayer': InteractingLayer,
'LayerNormalization': LayerNormalization,
'BiLSTM': BiLSTM,
'Transformer': Transformer,
'NoMask': NoMask,
'BiasEncoding': BiasEncoding,
'KMaxPooling': KMaxPooling,
'FGCNNLayer': FGCNNLayer,
'Hash': Hash,
'Linear':Linear,
'DynamicGRU': DynamicGRU,
'SENETLayer':SENETLayer,
'BilinearInteraction':BilinearInteraction,
'WeightedSequenceLayer':WeightedSequenceLayer,
'Add':Add
}
dense_value_list = get_dense_input(features, dense_feature_columns)
sequence_embed_dict = varlen_embedding_lookup(embedding_dict,features,sparse_varlen_feature_columns)
sequence_embed_list = get_varlen_pooling_list(sequence_embed_dict, features, sparse_varlen_feature_columns,to_list=True)
dnn_input_emb_list += sequence_embed_list
keys_emb = concat_func(keys_emb_list, mask=True)
deep_input_emb = concat_func(dnn_input_emb_list)
query_emb = concat_func(query_emb_list, mask=True)
hist = AttentionSequencePoolingLayer(att_hidden_size, att_activation,
weight_normalization=att_weight_normalization, supports_masking=True)([
query_emb, keys_emb])
deep_input_emb = Concatenate()([NoMask()(deep_input_emb), hist])
deep_input_emb = Flatten()(deep_input_emb)
dnn_input = combined_dnn_input([deep_input_emb],dense_value_list)
output = DNN(dnn_hidden_units, dnn_activation, l2_reg_dnn,
dnn_dropout, dnn_use_bn, seed)(dnn_input)
final_logit = Dense(1, use_bias=False)(output)
output = PredictionLayer(task)(final_logit)
model = Model(inputs=inputs_list, outputs=output)
return model