SSSxCCC / Recommender-System

A developing recommender system in tensorflow2. Algorithm: UserCF, ItemCF, LFM, SLIM, GMF, MLP, NeuMF, FM, DeepFM, MKR, RippleNet, KGCN and so on.
MIT License
410 stars 93 forks source link

How can I change the embedding method into transX, I want to try this way. Thank you! #2

Closed o0mahan0o closed 4 years ago

o0mahan0o commented 4 years ago

I have run your code and find it's so nice. But I don't know what is the current method for embedding. How can I use TransX for embedding. Thank you very much.

SSSxCCC commented 4 years ago

First, use Embedding or Embedding2D to create the embedding vectors you need. Then, figure out transX's loss and keep it in a variable called transX_loss. Finally, use model.add_loss(transX_loss) to make the loss work.

o0mahan0o commented 4 years ago

It's very kind of you for your answer. I tried to test the code from the day you replied, there is no progress. I would like to know if I change the code in ./Recommender_System/algorithm/MKR/model.py model_kge.compile(optimizer=optimizer_kge, loss=lambda y_true, y_pre: y_pre), or ./Recommender_System/algorithm/MKR/model.py model_kge.compile(optimizer=optimizer_kge, loss=lambda y_true, y_pre: y_pre)?

I'm a new hand. Could you give me more details? If possible, we could research together and communicate with each other. Thank you again!

SSSxCCC commented 4 years ago

If you just need to change the KGE method to transX, you don't need to change the code 'model.complie(...)'. The difference between KGE methods is the loss function. In ./Recommender_System/algorithm/MKR/model.py line 41 the variable 'kge' is the current KGE loss. Change the value of this variable into transX's loss, then your KGE method would be transX.

o0mahan0o commented 4 years ago

Thank you! I'm a student who is interested in RS and KG. I think them could make the AI more smarter. I want to research this area then write a paper for graduate. I have searched many websites and books but not much useful. So how can I train the transX's loss and make them work, then compare the ruluts to find the best one. Would you give me some courses address or materials as tips? Thank you for your help!!

SSSxCCC commented 4 years ago

Tensorflow official tutorials and guide are the best materials to learn tensorflow and keras. https://tensorflow.google.cn/tutorials https://tensorflow.google.cn/guide This project's code includes the MKR model's building and training. After you write the transX's loss, you can just run ./Recommender_System/algorithm/MKR/main.py, adjust hyper parameters, and you can get the precision and AUC result so that you can compare.

o0mahan0o commented 4 years ago

Got it! Thanks a million.

UNAecho commented 4 years ago

你好,想请教一个代码的问题。

DeepFM和model.py中,第10行(后面很多行都是如此)中:

user_embedding = tf.keras.layers.Embedding(n_user, dim, embeddings_regularizer=l2)(user_id)

这个后面的(user_id),这个是什么写法呢?为什么可以方法后面还写了一个括号,这个操作的意义是什么?

SSSxCCC commented 4 years ago

你好,想请教一个代码的问题。

DeepFM和model.py中,第10行(后面很多行都是如此)中:

user_embedding = tf.keras.layers.Embedding(n_user, dim, embeddings_regularizer=l2)(user_id)

这个后面的(user_id),这个是什么写法呢?为什么可以方法后面还写了一个括号,这个操作的意义是什么?

tf.keras.layers.Embedding(n_user, dim, embeddings_regularizer=l2)创建了一个有n_user个维度为dim的嵌入向量的对象,这个对象可以将输入的id(user_id)转化为相应的嵌入向量(user_embedding)。

UNAecho commented 4 years ago

tf.keras.layers.Embedding(n_user, dim, embeddings_regularizer=l2)创建了一个有n_user个维度为dim的嵌入向量的对象,这个对象可以将输入的id(user_id)转化为相应的嵌入向量(user_embedding)。

也就是说,tf.keras.layers.Embedding()这个方法只是返回一个def,后面的(user_id)是他的input param ?这个是python的什么特殊写法吗?

neuliyiping commented 4 years ago

您好,想请教一个功能的问题,在MKR中做推荐的时候,应该写一个什么样的函数来实现用户推荐

比如输入一个用户A的id,如何返回一个列表,列表中包含他可能喜欢的十首音乐

深度学习初学,tf还不是很会用,问的可能有点傻,但是迫切想知道如何实现,

SSSxCCC commented 4 years ago

也就是说,tf.keras.layers.Embedding()这个方法只是返回一个def,后面的(user_id)是他的input param ?这个是python的什么特殊写法吗?

这是因为python的对象只要实现了call方法就可以当作函数调用。详见python类的call使用方法。

SSSxCCC commented 4 years ago

您好,想请教一个功能的问题,在MKR中做推荐的时候,应该写一个什么样的函数来实现用户推荐

比如输入一个用户A的id,如何返回一个列表,列表中包含他可能喜欢的十首音乐

深度学习初学,tf还不是很会用,问的可能有点傻,但是迫切想知道如何实现,

对这个用户每个没有行为的物品计算兴趣度预测值,再将这些值排序,选取前十个物品就得到了推荐列表。

SSSxCCC commented 4 years ago

如果大家有什么新的问题欢迎讨论哈,对于每个新的问题还是开一个新的issue比较好。