Skip to content

Commit d64bcfe

Browse files
reedwmTaylor Robie
authored and
Taylor Robie
committed
Remove redundant flatten layers. (tensorflow#4964)
The output of an embeddding layer is already flattened, so the Flatten layers acted as no-ops.
1 parent cde1693 commit d64bcfe

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

official/recommendation/neumf_model.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,14 @@ def construct_model(users, items, params):
152152
input_length=1)
153153

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

161160
# MLP part
162-
# Flatten the embedding vector as latent features in MLP
163-
mlp_user_latent = tf.keras.layers.Flatten()(mlp_embedding_user(user_input))
164-
mlp_item_latent = tf.keras.layers.Flatten()(mlp_embedding_item(item_input))
161+
mlp_user_latent = mlp_embedding_user(user_input)
162+
mlp_item_latent = mlp_embedding_item(item_input)
165163
# Concatenation of two latent features
166164
mlp_vector = tf.keras.layers.concatenate([mlp_user_latent, mlp_item_latent])
167165

0 commit comments

Comments
 (0)