chenchongthu / JNSKR

This is our implementation of JNSKR: Jointly Non-Sampling Learning for Knowledge Graph Enhanced Recommendation (SIGIR 2020)
28 stars 5 forks source link

Questions about JNSKR source code #7

Open liulu1998 opened 3 years ago

liulu1998 commented 3 years ago
  1. What's the meaning of max_user_pi and max_relation_pi in JNSKR ?

  2. What's the meaning of pos_num_r and pos_num_u in JNSKR ?

https://github.com/chenchongthu/JNSKR/blob/c9c2bca5a59df8fde2ea7e1580ac40dec9aacc5b/Model/JNSKR.py#L85 https://github.com/chenchongthu/JNSKR/blob/c9c2bca5a59df8fde2ea7e1580ac40dec9aacc5b/Model/JNSKR.py#L105

  1. It seems that the way calculating Attention Weight in your code is NOT the same as Equ. (11)

image

https://github.com/chenchongthu/JNSKR/blob/c9c2bca5a59df8fde2ea7e1580ac40dec9aacc5b/Model/JNSKR.py#L62-L65


I'm working on a project about knowledge-enhanced RS and deeply interested in your work. Thanks for your time and patience, looking forward to your reply.

chenchongthu commented 3 years ago

Hi, thank you for your interest in our work!

为了说的清楚点,也节省时间,我直接用中文解答一下吧,

1、max_user_pi,是对于每个商品,最多的交互用户的数量;max_relation_pi是对于每个商品最多的交互关系数量。因为tensorflow中的输入需要是一个对齐的tensor, 所以我们输入的每个训练batch的shape为 [batch_size, max_user_pi],对于数量不足的商品,我们用“self.n_users”补齐。 2、因为我们的输入tensor是补齐的,所以首先用 tf.cast(tf.not_equal(self.input_iu, self.n_users)操作来所补得“self.n_users”置为0,这样就不会被更新计算到。 3、这两种计算attention的方法基本上没啥区别,可以互换。

liulu1998 commented 3 years ago

@chenchongthu 谢谢你的回复!我懂了。

我又有一个问题: L2 正则化 是否要计算 H_i ? 此处并没有计算 H_i 的范数 ↓

https://github.com/chenchongthu/JNSKR/blob/c9c2bca5a59df8fde2ea7e1580ac40dec9aacc5b/Model/JNSKR.py#L130

H_i 在此处定义的 ↓ https://github.com/chenchongthu/JNSKR/blob/c9c2bca5a59df8fde2ea7e1580ac40dec9aacc5b/Model/JNSKR.py#L50

chenchongthu commented 3 years ago

一般情况下大家不对预测层进行L2约束,所以加不加都可以,我们在这篇文章中基本上是用dropout来防止过拟合的,所以L2在这个工作里影响不大

Stevenn9981 commented 3 years ago

你好,我想问一下,我在把Main_JNSKR.py代码里的数据集路径从amazon-book改到yelp2018的时候会报错。

`Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1334, in _do_call return fn(*args) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1319, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1407, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[32] = 45920 is not in [0, 45920) [[{{node embedding_lookup_9}} = GatherV2[Taxis=DT_INT32, Tindices=DT_INT32, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](uidWg/read, _arg_users_0_1, embedding_lookup_9/axis)]] [[{{node embedding_lookup_7/_109}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_23_embedding_lookup_7", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "Main_JNSKR.py", line 143, in ret = test(sess, model, users_to_test, item_test) File "/home/JNSKR/Model/utility/our_test.py", line 148, in test rate_batch = model.eval(sess, feed_dict=feed_dict) File "/home/JNSKR/Model/JNSKR.py", line 141, in eval batch_predictions = sess.run(self.batch_predictions, feed_dict) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 929, in run run_metadata_ptr) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1152, in _run feed_dict_tensor, options, run_metadata) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1328, in _do_run run_metadata) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1348, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[32] = 45920 is not in [0, 45920) [[node embedding_lookup_9 (defined at /home/JNSKR/Model/JNSKR.py:156) = GatherV2[Taxis=DT_INT32, Tindices=DT_INT32, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](uidWg/read, _arg_users_0_1, embedding_lookup_9/axis)]] [[{{node embedding_lookup_7/_109}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_23_embedding_lookup_7", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

Caused by op 'embedding_lookup_9', defined at: File "Main_JNSKR.py", line 97, in model._build_graph() File "/home/JNSKR/Model/JNSKR.py", line 167, in _build_graph self._creat_prediction() File "/home/JNSKR/Model/JNSKR.py", line 156, in _creat_prediction u_e = tf.nn.embedding_lookup(self.uid_W, self.users) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/embedding_ops.py", line 313, in embedding_lookup transform_fn=None) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/embedding_ops.py", line 133, in _embedding_lookup_and_transform result = _clip(array_ops.gather(params[0], ids, name=name), File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/array_ops.py", line 2675, in gather return gen_array_ops.gather_v2(params, indices, axis, name=name) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 3332, in gather_v2 "GatherV2", params=params, indices=indices, axis=axis, name=name) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/util/deprecation.py", line 488, in new_func return func(*args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 3274, in create_op op_def=op_def) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1770, in init self._traceback = tf_stack.extract_stack()

InvalidArgumentError (see above for traceback): indices[32] = 45920 is not in [0, 45920) [[node embedding_lookup_9 (defined at /home/JNSKR/Model/JNSKR.py:156) = GatherV2[Taxis=DT_INT32, Tindices=DT_INT32, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](uidWg/read, _arg_users_0_1, embedding_lookup_9/axis)]] [[{{node embedding_lookup_7/_109}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_23_embedding_lookup_7", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]`

请问更换数据集跑实验是不是还有其他地方需要改动呢?不好意思我现在对TensorFlow的使用还不是很熟悉。

chenchongthu commented 3 years ago

你好,更换数据集需要更改两个地方,一个是Main_JNSKR.py代码里,另一个是utility下的parser.py里:

parser.add_argument('--dataset', nargs='?', default='amazon-book', help='Choose a dataset from {yelp2018, last-fm, amazon-book}')