Created
June 24, 2020 15:07
-
-
Save eggie5/fd79b72642cde7f007321d55a781a8bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generalized Matrix Factorization | |
def GMF(num_users, num_items, k, reg): | |
"""Models the interaction between user/item LV w/ linear dot-product""" | |
print("using dot-product interaction term") | |
seed = 1 | |
uid = Input((1,), name="uid") | |
iid = Input((1,), name="iid") | |
item_bias = Embedding( | |
num_items, | |
1, | |
input_length=1, | |
name="item_bias", | |
embeddings_regularizer=regularizers.l2(reg), | |
embeddings_initializer=initializers.glorot_normal(seed=seed), | |
) | |
user_emb = Embedding( | |
num_users, | |
k, | |
input_length=1, | |
name="user_embedding", | |
embeddings_regularizer=regularizers.l2(reg), | |
embeddings_initializer=initializers.glorot_normal(seed=seed), | |
) | |
item_emb = Embedding( | |
num_items, | |
k, | |
input_length=1, | |
name="item_embedding", | |
embeddings_regularizer=regularizers.l2(reg), | |
embeddings_initializer=initializers.glorot_normal(seed=seed), | |
) | |
u = Flatten(name="u")(user_emb(uid)) | |
i = Flatten(name="i")(item_emb(iid)) | |
i_b = Flatten(name="i_b")(item_bias(iid)) | |
xui = Add(name="xui")([i_b, Dot(1)([u, i])]) | |
model = Model(inputs=[uid, iid], outputs=xui, name="xui") | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment