Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two questions about sparse relational graph construction and IG aggregation #6

Closed
HuaYZhao opened this issue Apr 12, 2021 · 5 comments

Comments

@HuaYZhao
Copy link

一、
我注意到在代码:
adj = sp.coo_matrix((vals, (np_mat[:, 0], np_mat[:, 1])), shape=(n_nodes, n_nodes))中,
np_mat[:, 0]np_mat[:, 1]是否也应当如处理cf图那样,需要加上n_users。users并未被remap到entities中去,稀疏矩阵的前n_users行与n_users列应当为users预留。
对比之前KGAT中数据预处理的实现
K, K_inv = _np_mat2sp_adj(np.array(self.relation_dict[r_id]), row_pre=self.n_users, col_pre=self.n_users)

不知道是否有理解错。

二、
我注意到在代码
user_agg = user_agg * (disen_weight * score).sum(dim=1) + user_agg # [n_users, channel]中,
user_embedding的计算公式是否与论文中的Eq[7]有所出入。
image
论文中描述的是user所对应的item与intent加权求和,而在代码中的实现,是否可以理解为先求和再加权。
以及最后+ user_agg是什么用意。
我理解的聚合应当在代码
entity_res_emb = torch.add(entity_res_emb, entity_emb) user_res_emb = torch.add(user_res_emb, user_emb) 中实现了。

希望得到您的解答与纠正。谢谢!

@huangtinglin
Copy link
Owner

Hi,感谢您的关注!

  1. 关于问题一,其实对齐与否只是个人实现问题,KGIN的实现将user-item的二部图与item侧的知识图分开,如果不需要将user、item、entity放在同一张矩阵中其实并不需要做对齐。
  2. 您所指的user_agg的计算确实是公式(7)的实现,+user_agg可以理解成一种自连接,即每次聚合均包含自身向量,这点确实没在论文中体现。除去+user_agg外,代码的写法是与公式等价的(用乘法分配律去理解会好点)。您最后所指的
entity_res_emb = torch.add(entity_res_emb, entity_emb) 
user_res_emb = torch.add(user_res_emb, user_emb)

其实是公式(13)的实现,即将每一阶的embedding相加作为final embedding。

@HuaYZhao
Copy link
Author

wow,感谢您如此迅速的回复:

  1. 关于问题一,我又仔细阅读了一遍代码。
    adj = sp.coo_matrix((vals, (np_mat[:, 0], np_mat[:, 1])), shape=(n_nodes, n_nodes)) 其中的shape让我理解为该二部图被存储在同一矩阵中。
    但后续的实现中,不同于之前的KGAT,模型中只使用了归一化的adj_interact_mat。而关于图的节点与边是经由MultiDiGraph重建的。现在我已经彻底理解了。
    2.问题二,我也大致能够理解了。非常感谢

另外,我有额外两个问题想请教您:

  1. 我注意到KGIN与KGAT的训练日志。以Amazon-Book数据集为例,仅从日志分析(机器性能是否一致),KGIN的收敛需要579个epoch,每个epoch训练平均耗时850s,总计需要约136h。KGIN收敛需要250个epoch,每个epoch训练平均耗时350s,总计需要约24h。再加上测试,似乎都需要更多的时间。与论文中提及的时间复杂度分析似乎有所出入,我想了解更多的性能细节。
    image

另外我还注意到之前的issue中提及torch_scatter的计算瓶颈。是否意味着有另外的组织实现方式,在相同的理论支撑下可以达到更好的训练性能。

2.论文中引入的意图概念,对我有很大的启发帮助。模型训练完毕后,每个意图与若干个关系绑定,每个item与若干个意图绑定,而每个user的一个interact都可以归因到一个意图上面。这里想请教您的是,未出现在图中的用户(有该用户的交互信息),对于处理这类人群,是否可以避免重新训练,有什么建议吗?非常感谢~

期待您的回复~

@huangtinglin
Copy link
Owner

很高兴一起讨论:

  1. 在每次聚集过程的实现中先计算了relation embedding与tail entity embedding的逐元素乘积,后使用torch_scatter做聚合,这也是最耗时的一步。而KGAT每次聚集相当于只是邻接矩阵乘法做聚合,邻接矩阵的元素是聚集前用attention机制计算完成的,故二者相比KGIN会耗时。我个人没做太多的优化尝试,两种直接的改进是借助其他工具例如dgl或者考虑以inductive的方式聚合。
  2. 首先intent是每个用户共有的,并不需要重新训练得到。未出现过的用户最大的问题在于自身的embedding是没经过学习的,但是在模型里,其实每个结点的final embedding更多的是由其邻域决定(equation (13)),这部分embedding是经过学习调优的。此外,其实还有很多解决冷启动的方法,例如inductive的方式学习、为每个用户引入feature作为初始embedding、考虑某些无监督方法获得更优的initial embedding。

@HuaYZhao
Copy link
Author

非常感谢您的解答,我会继续进行一些实验工作。后续如有问题会新建issue希望能够再进行讨论。
真的十分感谢~

@cabbgae
Copy link

cabbgae commented Oct 28, 2021

我想询问一下,关于公式7中的1/Nu在代码user_agg = user_agg * (disen_weight * score).sum(dim=1) + user_agg # [n_users, channel]中的何处体现出来或是我没有找对地方

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants