Skip to content

Commit

Permalink
Remove redundant flatten layers. (tensorflow#4964)
Browse files Browse the repository at this point in the history
The output of an embeddding layer is already flattened, so the Flatten layers acted as no-ops.
  • Loading branch information
reedwm authored and Taylor Robie committed Aug 1, 2018
1 parent cde1693 commit d64bcfe
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions official/recommendation/neumf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,14 @@ def construct_model(users, items, params):
input_length=1)

# GMF part
# Flatten the embedding vector as latent features in GMF
mf_user_latent = tf.keras.layers.Flatten()(mf_embedding_user(user_input))
mf_item_latent = tf.keras.layers.Flatten()(mf_embedding_item(item_input))
mf_user_latent = mf_embedding_user(user_input)
mf_item_latent = mf_embedding_item(item_input)
# Element-wise multiply
mf_vector = tf.keras.layers.multiply([mf_user_latent, mf_item_latent])

# MLP part
# Flatten the embedding vector as latent features in MLP
mlp_user_latent = tf.keras.layers.Flatten()(mlp_embedding_user(user_input))
mlp_item_latent = tf.keras.layers.Flatten()(mlp_embedding_item(item_input))
mlp_user_latent = mlp_embedding_user(user_input)
mlp_item_latent = mlp_embedding_item(item_input)
# Concatenation of two latent features
mlp_vector = tf.keras.layers.concatenate([mlp_user_latent, mlp_item_latent])

Expand Down

0 comments on commit d64bcfe

Please sign in to comment.