知行编程网知行编程网  2022-05-16 14:00 知行编程网 隐藏边栏 |   抢沙发  194 
文章评分 0 次,平均分 0.0

一文读懂图注意力模型:Graph Attention

来自 | 知乎    作者 | Superbrother

链接 | https://zhuanlan.zhihu.com/p/81350196

本文仅供学术交流,如有侵权,请联系删除
一文读懂图注意力模型:Graph Attention

   GRAPH ATTENTION NETWORKS的诞生


随着GCN的大红大紫,graph领域的deep learning研究可谓变得风生水起,人工智能又出现了新的网红。GCN在一系列任务取得了突破性进展的同时,一系列的缺点也逐渐被放大。


深度学习三巨头”之一的Yoshua Bengio组提出了Graph Attention Networks(下述简称为GAT)去解决GCN存在的问题并且在不少的任务上都取得了state of art的效果是graph neural network领域值得关注的工作。



   1 聊点基础


登堂入室之前,先介绍三点基础问题。


1.1 Graph数据结构的两种“特征”

当我们说起graph或者network的数据结构,通常是包含着顶点和边的关系。研究目标聚焦在顶点之上,边诉说着顶点之间的关系。

对于任意一个顶点  ,它在图上邻居  ,构成第一种特征,即图的结构关系。

一文读懂图注意力模型:Graph Attention

图1 graph示意图

当然,除了图的结构之外,每个顶点还有自己的特征  (通常是一个高维向量)。它可以使社交网络中每个用户的个体属性;可以是生物网络中,每个蛋白质的性质;还可以使交通路网中,每个交叉口的车流量。Graph上的deep learning方法无外乎就是希望学习上面的两种特征。


1.2 GCN的局限性

GCN是处理transductive任务的一把利器(transductive任务是指:训练阶段与测试阶段都基于同样的图结构),然而GCN有两大局限性是经常被诟病的:

(a)无法完成inductive任务,即处理动态图问题。inductive任务是指:训练阶段与测试阶段需要处理的graph不同。通常是训练阶段只是在子图(subgraph)上进行,测试阶段需要处理未知的顶点。(unseen node)

(b)处理有向图的瓶颈,不容易实现分配不同的学习权重给不同的neighbor


1.3 Mask graph attention or global graph attention

还有一件事件需要提前说清楚:GAT本质上可以有两种运算方式的,这也是原文中作者提到的

  • Global graph attention
顾名思义,就是每一个顶点  都对于图上任意顶点都进行attention运算。可以理解为图1的蓝色顶点对于其余全部顶点进行一遍运算。
优点:完全不依赖于图的结构,对于inductive任务无压力
缺点:(1)丢掉了图结构的这个特征,无异于自废武功,效果可能会很差(2)运算面临着高昂的成本
  • Mask graph attention
注意力机制的运算只在邻居顶点上进行,也就是说图1的蓝色顶点只计算和橙色顶点的注意力系数。
作者在原文中GAT ARCHITECTURE这一节中写道:
"We inject the graph structure into the mechanism by performing masked attention—we only compute eij for nodes j ∈Ni, whereNi is some neighborhood of node i in the graph. "
显然作者在文中采用的是masked attention,DGL里实现的也是如此,以下的解读均基于这种方式。


   2 GAT并不难懂

和所有的attention mechanism一样,GAT的计算也分为两步走:

2.1 计算注意力系数(attention coefficient)
对于顶点  ,逐个计算它的邻居们(  )和它自己之间的相似系数

解读一下这个公式:
首先一个共享参数  的线性映射对于顶点的特征进行了增维,当然这是一种常见的特征增强(feature augment)方法

 对于顶点  的变换后的特征进行了拼接(concatenate);

最后  把拼接后的高维特征映射到一个实数上,作者是通过 single-layer feedforward neural network实现的。

显然学习顶点  之间的相关性,就是通过可学习的参数  和映射  完成的。

有了相关系数,离注意力系数就差归一化了!其实就是用个softmax
要注意这里作者用了个  ,至于原因嘛,估计是试出来的,毕竟深度玄学。

上面的步骤可以参考图2进行理解
一文读懂图注意力模型:Graph Attention

图2 第一步运算示意图
2.2 加权求和(aggregate)
完成第一步,已经成功一大半了。第二步很简单,根据计算好的注意力系数,把特征加权求和(aggregate)一下。
 就是GAT输出的对于每个顶点  的新特征(融合了邻域信息),  是激活函数。

式(3)看着还有点单薄,俗话说一个篱笆三个桩,attention得靠multi-head帮!来进化增强一下
嗯,这次看起来就很健壮了,multi-head attention也可以理解成用了ensemble的方法,毕竟convolution也得靠大量的卷积核才能大显神威!
上面的步骤可以参考图3进行理解
一文读懂图注意力模型:Graph Attention

图3 第二步运算示意图


   3 谈几点深入的理解

3.1 与GCN的联系与区别
无独有偶,我们可以发现本质上而言:GCN与GAT都是将邻居顶点的特征聚合到中心顶点上(一种aggregate运算)利用graph上的local stationary学习新的顶点特征表达。不同的是GCN利用了拉普拉斯矩阵,GAT利用attention系数一定程度上而言,GAT会更强,因为 顶点特征之间的相关性被更好地融入到模型中。

3.2 为什么GAT适用于有向图?
我认为最根本的原因是GAT的运算方式是逐顶点的运算(node-wise),这一点可从公式(1)—公式(3)中很明显地看出。每一次运算都需要循环遍历图上的所有顶点来完成。逐顶点运算意味着,摆脱了拉普利矩阵的束缚,使得有向图问题迎刃而解。

3.3为什么GAT适用于inductive任务?
GAT中重要的学习参数是    ,因为上述的逐顶点运算方式,这两个参数仅与1.1节阐述的顶点特征相关,与图的结构毫无关系。所以测试任务中改变图的结构,对于GAT影响并不大,只需要改变  ,重新计算即可。

与此相反的是,GCN是一种全图的计算方式,一次计算就更新全图的节点特征。学习的参数很大程度与图结构相关,这使得GCN在inductive任务上遇到困境

目前,我们团队利用GCN和GAT在交通预测领域有不少探索,欢迎感兴趣的朋友参考。如果有帮助,还希望可以引用我们的论文。

Zhang, Z., Li, M., Lin, X., Wang, Y., & He, F. (2019). Multistep speed prediction on traffic networks: A deep learning approach considering spatio-temporal dependencies.Transportation Research Part C: Emerging Technologies,105, 297-322.

Zhang, K., He, F., Zhang, Z., Lin, X., Li, M.*, 2019. Data-driven traffic speed forecasting: graph attention temporal convolutional network. Transportmetrica B: Transport Dynamics, under review.


<pre style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-right: 8px;margin-left: 8px;max-width: 100%;letter-spacing: 0.544px;white-space: normal;color: rgb(0, 0, 0);font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;widows: 1;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">—</span></strong>完<strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">—</span></strong></span></strong></span></strong></section><section style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;widows: 1;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-top: 15px;margin-bottom: 25px;max-width: 100%;opacity: 0.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-top: 15px;margin-bottom: 25px;max-width: 100%;opacity: 0.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-right: 8px;margin-bottom: 15px;margin-left: 8px;padding-right: 0em;padding-left: 0em;max-width: 100%;color: rgb(127, 127, 127);font-size: 12px;font-family: sans-serif;line-height: 25.5938px;letter-spacing: 3px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 16px;font-family: 微软雅黑;caret-color: red;box-sizing: border-box !important;overflow-wrap: break-word !important;">为您推荐</span></strong></span></section><section style="margin: 5px 8px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(87, 107, 149);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">人工智能领域最具影响力的十大女科学家</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"  /></section><section style="margin: 5px 8px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(87, 107, 149);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">MIT最新深度学习入门课,安排起来!</span></section><section style="margin: 5px 8px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(87, 107, 149);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">有了这个神器,轻松用 Python 写个 App</span></section><section style="margin: 5px 8px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(87, 107, 149);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">「最全」实至名归,NumPy 官方早有中文教程</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"  /></section><section style="margin: 5px 8px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(87, 107, 149);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">我为什么鼓励你读计算机领域的博士?</span></section><p style="margin-right: 8px;margin-bottom: 5px;margin-left: 8px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;color: rgb(127, 127, 127);font-size: 12px;font-family: sans-serif;line-height: 1.75em;letter-spacing: 0px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"  /></p></section></section></section></section></section></section></section></section>

一文读懂图注意力模型:Graph Attention

本篇文章来源于: 深度学习这件小事

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写

发表评论

表情 格式 链接 私密 签到
扫一扫二维码分享