EagleW / PaperRobot

Code for PaperRobot: Incremental Draft Generation of Scientific Ideas
https://aclanthology.org/P19-1191
MIT License
472 stars 134 forks source link

处理one-hop节点的代码的一个疑问 #12

Closed WongIhsin closed 4 years ago

WongIhsin commented 4 years ago

for tri in triple_dict[head]: single1 = (head, tri[0], tri[1]) in_graph.add(single1) for tri in triple_dict[tail]: single2 = (tail, tri[0], tri[1]) in_graph.add(single2) 您好,我在阅读您的代码的时候发现,在Existing paper reading/utils/utils.py文件中的get_subgraph()函数中,即246行和249行的两个for循环好像并没有执行,我尝试进行打印,发现triple_dict[head]是空字典。 我猜想可能原因是head和tail是torch.Tensor类型,而triple_dict[head]需要传入的head是int型。

EagleW commented 4 years ago

Hi @WongIhsin, Thank you very much for your interest in our research and the suggestion. I have fixed this bug for the following commit. If you have further questions, you can also contact me using the email on my Github page. Hope you have a great day!

WongIhsin commented 4 years ago

抱歉我的英文不是很好,所以还是用中文来回复了。 我觉得get_subgraph()函数中head和tail可以先head = triple[0].item(),这样可以避免included_nodes中加入tensor类型的nodes,使得adj_ingraph矩阵有多余的0行; 另外,在batch_size为200时候,included_nodes的范围大约会在10000左右,以至于adj_ingraph这个矩阵会很大,计算attention时候很容易显存溢出,并且因为shifted_pos还会进行截取,所以这里会造成很大的资源浪费。 我还阅读了https://github.com/Diego999/pyGAT的代码,发现pyGAT中的adj矩阵比较小,并不会有显存溢出的问题,并且pyGAT中的attention在更新权重的时候会都使用到。 所以我想是不是可以将shifted_pos的截取这一步移动到leakyrelu之前,可以很大程度的减少显存消耗

EagleW commented 4 years ago

@WongIhsin 对于第一个问题我已经fix了,对第二个问题,我觉得可以把to(device)放到shifted_pos, shifted_neg = convert_index([pos, neg], batch_nodes)后应该会解决一定问题吧。还有就是batchsize可以改小一点

WongIhsin commented 4 years ago

好的,非常感谢😀