You need to change the prediction part of your code to display top Krecommended products. The current prediction code is as follows:
embd_user = tf.nn.embedding_lookup(w_user, user_batch, name="embedding_user")
embd_item = tf.nn.embedding_lookup(w_item, item_batch, name="embedding_item")
infer = tf.reduce_sum(tf.multiply(embd_user, embd_item), 1)
Here embed_useris a user attachment of a specific user, and embd_item- for a specific element. Therefore, instead of comparing particular userwith particular itemyou need to change it to compare it with all the elements. The matrix w_itemis an attachment of all elements. It can be done:
embd_user = tf.nn.embedding_lookup(w_user, user_batch, name="embedding_user")
predict = tf.matmul(embd_user, w_item, transpose_b=True)
Then you can select the index of the top Kmaximum value in the predicted output.
source
share