Recommender System (SVD) with TensorFlow

I am trying to create a collaborative filtering algorithm to offer products to specific users.

I started shortly and started working with TensorFlow (I thought it was quite efficient and flexible). I found this code that does what interests me, creates a model and trains user IDs, products and ratings: https://github.com/songgc/TF-recomm

I ran the code and trained the model.

After training the model, I will need to make predictions, that is, get offers for each user so that they can be saved in the database, from which I access the NODE.js application.

How to get this list of offers for each user when training is completed?

if __name__ == '__main__':
    df_train, df_test=get_data()
    svd(df_train, df_test)
    print("Done!")
+4
source share
2 answers

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")
 # Multiply user embedding of shape: [1 x dim] 
 # with every item embeddings of shape: [item_num, dim], 
 # to produce rank of all items of shape: [item_num]
 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.

+1
source

You can run

predict_result = sess.run(inter_op, feed_dict={user_batch:users, item_batch:items})

, , pred__result - , pred_quest DB;

+1

Source: https://habr.com/ru/post/1680687/


All Articles