# 图注意力网络

图注意力网络（graph attention network，GAT）是一种用于图上机器学习的神经网络架构，它把节点的表示计算为其邻居特征的加权组合，其中权重由注意力机制产生，而非固定的归一化。它用于节点分类、链路预测和图级预测任务。

| 关键事实 | 详情 |
|---|---|
| 提出者 | 韦利奇科维奇、库库鲁尔、卡萨诺瓦、罗梅罗、廖与本吉奥，ICLR 2018（arXiv 2017）<sup>[1](https://arxiv.org/abs/1710.10903)</sup> |
| 核心操作 | 对每个节点的邻域做掩码自注意力，经 softmax 归一化 <sup>[1](https://arxiv.org/abs/1710.10903)</sup> |
| 单头复杂度 | \( O(|V|F \cdot F' + |E|F') \)，与图卷积网络相当 <sup>[1](https://arxiv.org/abs/1710.10903)</sup> |
| 直推式准确率 | 83.0 ± 0.7%（Cora）、72.5 ± 0.7%（Citeseer）、79.0 ± 0.3%（Pubmed）<sup>[1](https://arxiv.org/abs/1710.10903)</sup> |
| 归纳式 PPI 微 F1 | 0.975 ± 0.006（DGL 实现），GCN 为 0.509 ± 0.025 <sup>[2](https://docs.dgl.ai/en/0.4.x/tutorials/models/1_gnn/9_gat.html)</sup> |
| 主要局限 | 静态注意力：注意力分数的排序不取决于查询节点 <sup>[3](https://arxiv.org/abs/2105.14491v3)</sup> |
| 主要修正 | GATv2，在同等时间复杂度下提供表达能力严格更强的动态注意力 <sup>[3](https://arxiv.org/abs/2105.14491v3)</sup> |

## 工作原理

每个 GAT 层先用一个共享的线性映射 \( W \) 变换节点特征，然后为节点 \( i \) 与其邻居 \( j \) 之间的每条边计算未归一化的注意力分数：

\[ e_{ij} = \mathrm{LeakyReLU}\left( \vec{a}^{\top} [ W \cdot h_i \| W \cdot h_j ] \right) \]

其中 \( \vec{a} \in \mathbb{R}^{2F'} \) 是可学习的权重向量，\( \| \) 表示拼接，非线性激活为负斜率为 0.2 的 LeakyReLU。<sup>[1](https://arxiv.org/abs/1710.10903)</sup><sup> • </sup><sup>[4](https://ar5iv.labs.arxiv.org/html/2206.02849)</sup> 分数在邻域上经 softmax 归一化，

\[ \alpha_{ij} = \frac{\exp(e_{ij})}{\sum_{k \in \mathcal{N}_i} \exp(e_{ik})} \]

新的表示则聚合变换后的邻居特征：

\[ h_i' = \sigma\left( \sum_{j \in \mathcal{N}_i} \alpha_{ij} \, W \cdot h_j \right) \]

<sup>[1](https://arxiv.org/abs/1710.10903)</sup><sup> • </sup><sup>[5](https://petar-v.com/GAT/)</sup> 这是加性注意力，与 [Transformer](https://www.edgepedia.org/zh/transformer) 的点积注意力形成对照。<sup>[2](https://docs.dgl.ai/en/0.4.x/tutorials/models/1_gnn/9_gat.html)</sup><sup> • </sup><sup>[6](https://link.springer.com/article/10.1186/s40537-023-00876-4)</sup> 该层之所以是“掩码”的，是因为分数只对实际存在的边计算，模型因此从不会预先看到完整的图结构。<sup>[1](https://arxiv.org/abs/1710.10903)</sup>

稳定性来自多头注意力：\( K \) 个独立的注意力机制各自执行变换，在中间层将它们的输出拼接，而最后一层对各头取平均。<sup>[1](https://arxiv.org/abs/1710.10903)</sup><sup> • </sup><sup>[7](https://www.mdpi.com/1999-5903/16/9/318)</sup> PyTorch Geometric 的 GATConv 默认添加自环，支持在注意力 logits 中可选地引入边特征，并可返回逐边的注意力权重 <sup>[8](https://pytorch-geometric.readthedocs.io/en/stable/generated/torch_geometric.nn.conv.GATConv.html)</sup>；PyTorch Geometric 与 DGL 的 GATConv 都支持注意力 dropout 与残差连接（PyG 通过作用于归一化注意力系数的 'dropout' 与 'residual'；DGL 通过 'attn_drop' 与 'residual'），并且 DGL 在遇到入度为零的节点时会报错，除非另行配置。<sup>[9](https://docs.dgl.ai/generated/dgl.nn.pytorch.conv.GATConv.html)</sup>

与图卷积网络（GCN）在数学上的差别在于加权规则。GCN 用基于度数的非参数化归一化系数来缩放邻居的贡献，而 GAT 通过注意力学习这些缩放因子。<sup>[7](https://www.mdpi.com/1999-5903/16/9/318)</sup><sup> • </sup><sup>[2](https://docs.dgl.ai/en/0.4.x/tutorials/models/1_gnn/9_gat.html)</sup>

## 具体做法

最初的直推式模型堆叠两个 GAT 层，每层 \( K = 8 \) 个头、每头 8 个特征，对输入特征和归一化注意力系数施加 \( p = 0.6 \) 的 dropout，并使用 \( \lambda = 0.0005 \) 的 \( L^2 \) 正则化。<sup>[1](https://arxiv.org/abs/1710.10903)</sup> 归纳式的蛋白质-蛋白质相互作用（PPI）模型使用三个带跳跃连接的层，前两层为 \( K = 4 \) 个头、每头 256 个特征，最后一层为 \( K = 6 \) 个头、每头 121 个特征，以每批 2 张图的批大小训练。<sup>[1](https://arxiv.org/abs/1710.10903)</sup> 两个模型都使用 Glorot 初始化、学习率 0.005 的 Adam 优化器、训练节点上的交叉熵损失，以及耐心值为 100 个 epoch 的早停。<sup>[1](https://arxiv.org/abs/1710.10903)</sup>

有两点实践上的注意事项值得留意。第一，GPU 框架只有在邻域大小相同时才能高效地并行化 softmax，因此最初的实现采用带 \( -\infty \) 偏置的掩码方法，这使内存占用上升到 \( O(V) \) 个中间量；稀疏矩阵版本可将存储降至与节点数和边数成线性比例，但当时所用的框架只支持二阶稀疏乘法，从而限制了批处理。<sup>[1](https://arxiv.org/abs/1710.10903)</sup> 第二，入度为零的节点会产生无效输出，除非将该层配置为允许这类节点。<sup>[9](https://docs.dgl.ai/generated/dgl.nn.pytorch.conv.GATConv.html)</sup>

## 起源

图注意力网络在发表于 ICLR 的《图注意力网络》一文中被提出。<sup>[1](https://arxiv.org/abs/1710.10903)</sup><sup> • </sup><sup>[5](https://petar-v.com/GAT/)</sup> 该文建立在更早的图神经网络之上——斯卡尔塞利、戈里、蔡、哈根布赫纳与蒙法尔迪尼 于 2008 年在 IEEE Transactions on Neural Networks 上对这些网络作了分析 <sup>[10](https://doi.org/10.1109/tnn.2008.2005141)</sup>——也建立在 托马斯·N·基普夫与[马克斯·韦林](https://www.edgepedia.org/zh/max-welling) 于 2016 年提出的图卷积网络之上。<sup>[11](https://doi.org/10.48550/arxiv.1609.02907)</sup> 其注意力设置沿用了循环序列模型中使用的加性注意力，多头方案则沿用 Transformer 的多头注意力。<sup>[1](https://arxiv.org/abs/1710.10903)</sup>

## 变体

各种具名变体的差别主要在于注意力的计算方式，或在于注意力所作用的结构：

- **GATv2**，由 沙凯德·布罗迪、乌里·阿隆与埃兰·亚哈夫 提出（2021 年发布，发表于 ICLR 2022），重排了运算顺序，使学习到的向量 \( a \) 在 LeakyReLU 非线性之后才被应用，从而让打分成为针对每个查询-键对的 MLP，而非可折叠的线性层。<sup>[3](https://arxiv.org/abs/2105.14491v3)</sup> 在参数量相当、时间复杂度相同的条件下，它在节点预测、链路预测和图预测的 12 个基准上均优于 GAT <sup>[3](https://arxiv.org/abs/2105.14491v3)</sup>，并已在 PyTorch Geometric、DGL 与 TensorFlow GNN 中提供。<sup>[12](https://github.com/tech-srl/how_attentive_are_gats)</sup>
- **GaAN**，由张佳妮及其同事提出（2018），在多头系统中插入门控机制，使不同的头贡献不同的值，并采用键值点积注意力。<sup>[13](https://doi.org/10.48550/arxiv.1803.07294)</sup><sup> • </sup><sup>[4](https://ar5iv.labs.arxiv.org/html/2206.02849)</sup>
- **HAN**，由王晓及其同事提出（2019），处理异构图，采用层次化注意力：在基于元路径的邻居上做节点级注意力，在元路径上做语义级注意力。<sup>[14](https://doi.org/10.48550/arxiv.1903.07293)</sup>
- **带符号图注意力网络**，由黄俊杰及其同事提出（2019），以及**关系图注意力网络**，由丹·巴斯布里奇及其同事提出（2019），分别将注意力适配到带符号的边与带类型的关系上。<sup>[15](https://doi.org/10.48550/arxiv.1906.10958)</sup><sup> • </sup><sup>[16](https://doi.org/10.48550/arxiv.1904.05811)</sup>
- **图变换器网络**，由尹成俊及其同事提出（2019），以及 **DeepInf**，由邱杰中及其同事提出（2018），将注意力风格的架构分别应用于元路径图构建与社会影响力预测。<sup>[17](https://doi.org/10.48550/arxiv.1911.06455)</sup><sup> • </sup><sup>[18](https://doi.org/10.48550/arxiv.1807.05560)</sup>
- 2023 年之后的工作包括 **PD-GATv2**，这是一种面向有向加权图的残差边加权 GATv2。<sup>[19](https://link.springer.com/article/10.1007/s10489-024-05432-y)</sup>

## 应用

在引文基准上，原论文报告 Cora 上为 83.0 ± 0.7%、Citeseer 上为 72.5 ± 0.7%、Pubmed 上为 79.0 ± 0.3%，在 Cora 与 Citeseer 上分别比 GCN 提升 1.5% 和 1.6%。<sup>[1](https://arxiv.org/abs/1710.10903)</sup> 在归纳式 PPI 任务上，GAT 达到微 F1 0.975 ± 0.006，而 GCN 为 0.509 ± 0.025。<sup>[2](https://docs.dgl.ai/en/0.4.x/tutorials/models/1_gnn/9_gat.html)</sup>

在按 85/5/10 划分边的链路预测中，GAT 在 Cora 上取得 0.9027 ± 0.0023 的 AUC，在 CiteSeer 上为 0.9084 ± 0.0035，在 PubMed 上为 0.9179 ± 0.0002，在 Wiki-CS 上为 0.9293 ± 0.0014，表现与 GCN、[GraphSAGE](https://www.edgepedia.org/zh/graphsage) 和 VGAE 相近。<sup>[20](https://ar5iv.labs.arxiv.org/html/2102.12557)</sup> 在 ogbn-proteins 上，GATv2 达到 80.63 ± 0.70 的 ROC-AUC，而 8 头 GAT 为 78.63。<sup>[3](https://arxiv.org/abs/2105.14491v3)</sup> 经过现代调优（残差连接、归一化、dropout）后，GAT* 在 Cora 上达到 84.46 ± 0.55%、Citeseer 上 72.22 ± 0.84%、Pubmed 上 80.28 ± 0.64%、ogbn-arxiv 上 94.09 ± 0.37%。<sup>[21](https://www.proceedings.com/content/079/079017-3098open.pdf)</sup>

## 局限与替代方案

**静态注意力。** 布罗迪、阿隆与亚哈夫证明 GAT 计算的是静态注意力：注意力分数的排序不以查询节点为条件，因为连续施加的 \( W \) 与 \( a \) 会坍缩为单个线性层。<sup>[3](https://arxiv.org/abs/2105.14491v3)</sup> GATv2 恢复了动态注意力，并且对边噪声更稳健，因为噪声边会获得逐渐衰减的注意力 <sup>[3](https://arxiv.org/abs/2105.14491v3)</sup>；ESA 的作者指出，代价是参数量和内存消耗都翻倍。<sup>[22](https://www.nature.com/articles/s41467-025-60252-z)</sup>

**均匀注意力与困难区间。** GAT 学到的注意力分布在 Cora、Citeseer 与 Pubmed 上跨头、跨层都接近均匀，只有在 PPI 上才变得更集中。<sup>[23](https://rlgm.github.io/papers/62.pdf)</sup> 基于上下文随机块模型的理论工作表明，在“困难区间”——特征空间中类均值距离相对于标准差较小——任何注意力架构都以高概率无法区分类间边与类内边，且大多数注意力系数趋于均匀；而在容易区间，注意力能够保持重要边的权重。<sup>[24](https://jmlr.org/papers/volume24/22-125/22-125.pdf)</sup>

**过平滑。** 一项 NeurIPS 2023 的分析表明，图注意力机制无法阻止过平滑，且表达能力呈指数衰减，尽管衰减速度可能比 GCN 慢；该结论基于 128 层单头实验。<sup>[25](https://proceedings.neurips.cc/paper_files/paper/2023/file/6e4cdfdd909ea4e34bfc85a12774cba0-Paper-Conference.pdf)</sup> 缓解手段包括跳跃连接、归一化层与 Jumping Knowledge 聚合。<sup>[26](https://dl.acm.org/doi/full/10.1145/3816725)</sup>

**异配性与注意力何时有用。** 在低同配性（异配）图上，注意力网络往往优于卷积网络，其代价是参数量少于完整的消息传递网络，表达能力也较弱。<sup>[26](https://dl.acm.org/doi/full/10.1145/3816725)</sup> 一项 2025 年 ICML 基于上下文随机块模型的分析发现，当结构噪声超过特征噪声时，图注意力能改善分类；而当特征噪声占主导时，更简单的图卷积更为有效。<sup>[27](https://proceedings.mlr.press/v267/ma25w.html)</sup>

**代价与替代方案。** 单个 GAT 头的代价为 \( O(|V|F \cdot F' + |E|F') \)，与 GCN 相当，而多头注意力会将参数量与存储乘以 \( K \)。<sup>[1](https://arxiv.org/abs/1710.10903)</sup> 在 2025 年报告的计时实验中，GCN 通常是最快的方法，而 GAT 与 GATv2 属于最慢之列。<sup>[22](https://www.nature.com/articles/s41467-025-60252-z)</sup> 与图变换器相比，2024 年的一项重新评估发现，经过调优的经典 GNN（GCN、GraphSAGE、GAT）在 18 个节点分类数据集中的 17 个上排名第一；调优后的 GAT* 将 ogbn-proteins 上的性能绝对提升 12.99%，并超过 SGFormer 5.09%。<sup>[21](https://www.proceedings.com/content/079/079017-3098open.pdf)</sup><sup> • </sup><sup>[28](https://proceedings.neurips.cc/paper_files/paper/2024/file/b10ed15ff1aa864f1be3a75f1ffc021b-Paper-Datasets_and_Benchmarks_Track.pdf)</sup> 2025 年的 Edge-Set Attention 架构将图视为边集，并交错使用掩码自注意力与普通自注意力，在图级任务上优于精调的消息传递基线和近期的图变换器，不过其节点级变体在 Cora 准确率上未能超过 GCN。<sup>[22](https://www.nature.com/articles/s41467-025-60252-z)</sup>

## References

1. [Graph Attention Networks (Veličković et al., ICLR 2018; arXiv:1710.10903)](https://arxiv.org/abs/1710.10903)
2. [DGL GAT tutorial](https://docs.dgl.ai/en/0.4.x/tutorials/models/1_gnn/9_gat.html)
3. [How Attentive are Graph Attention Networks? (Brody, Alon, Yahav; GATv2; excerpts from the arXiv PDF merged here)](https://arxiv.org/abs/2105.14491v3)
4. [A Bird's-Eye Tutorial of Graph Attention Architectures](https://ar5iv.labs.arxiv.org/html/2206.02849)
5. [Graph Attention Networks, official author page (Petar Veličković)](https://petar-v.com/GAT/)
6. [A review of graph neural networks (Journal of Big Data)](https://link.springer.com/article/10.1186/s40537-023-00876-4)
7. [Graph Attention Networks: A Comprehensive Review of Methods and Applications (Future Internet, MDPI, 2024)](https://www.mdpi.com/1999-5903/16/9/318)
8. [torch_geometric.nn.conv.GATConv documentation](https://pytorch-geometric.readthedocs.io/en/stable/generated/torch_geometric.nn.conv.GATConv.html)
9. [DGL GATConv API documentation](https://docs.dgl.ai/generated/dgl.nn.pytorch.conv.GATConv.html)
10. [F. Scarselli and colleagues (2008). Computational Capabilities of Graph Neural Networks. IEEE Transactions on Neural Networks.](https://doi.org/10.1109/tnn.2008.2005141)
11. [Kipf, Thomas N., Welling, Max (2016). Semi-Supervised Classification with Graph Convolutional Networks. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1609.02907)
12. [Official GATv2 implementation repository (tech-srl)](https://github.com/tech-srl/how_attentive_are_gats)
13. [Zhang, Jiani and colleagues (2018). GaAN: Gated Attention Networks for Learning on Large and Spatiotemporal Graphs. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1803.07294)
14. [Wang, Xiao and colleagues (2019). Heterogeneous Graph Attention Network. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1903.07293)
15. [Huang, Junjie and colleagues (2019). Signed Graph Attention Networks. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1906.10958)
16. [Busbridge, Dan and colleagues (2019). Relational Graph Attention Networks. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1904.05811)
17. [Yun, Seongjun and colleagues (2019). Graph Transformer Networks. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1911.06455)
18. [Qiu, Jiezhong and colleagues (2018). DeepInf: Social Influence Prediction with Deep Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1807.05560)
19. [PD-GATv2: positive difference second generation graph attention network (Applied Intelligence, 2024)](https://link.springer.com/article/10.1007/s10489-024-05432-y)
20. [Benchmarking Graph Neural Networks on Link Prediction](https://ar5iv.labs.arxiv.org/html/2102.12557)
21. [Classic GNNs are Strong Baselines: Reassessing GNNs for Node Classification (NeurIPS proceedings)](https://www.proceedings.com/content/079/079017-3098open.pdf)
22. [An end-to-end attention-based approach for learning on graphs (Edge-Set Attention; Nature Communications, 2025; arXiv-version excerpts merged here)](https://www.nature.com/articles/s41467-025-60252-z)
23. [Statistical Characterization of Attentions in Graph Neural Networks (ICLR 2019 workshop)](https://rlgm.github.io/papers/62.pdf)
24. [Graph Attention Retrospective (JMLR)](https://jmlr.org/papers/volume24/22-125/22-125.pdf)
25. [Demystifying Oversmoothing in Attention-Based Graph Neural Networks (NeurIPS 2023)](https://proceedings.neurips.cc/paper_files/paper/2023/file/6e4cdfdd909ea4e34bfc85a12774cba0-Paper-Conference.pdf)
26. [Introduction to Graph Neural Networks for Machine Learning Engineers (ACM Computing Surveys)](https://dl.acm.org/doi/full/10.1145/3816725)
27. [Graph Attention is Not Always Beneficial: A Theoretical Analysis via Contextual Stochastic Block Models (ICML 2025, PMLR v267)](https://proceedings.mlr.press/v267/ma25w.html)
28. [Revisiting the Power of GNNs for Node Classification (NeurIPS 2024 Datasets & Benchmarks)](https://proceedings.neurips.cc/paper_files/paper/2024/file/b10ed15ff1aa864f1be3a75f1ffc021b-Paper-Datasets_and_Benchmarks_Track.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Neural networks and deep learning › Neural network architectures › Graph neural network architectures

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/graph-attention-network

English original: https://www.edgepedia.org/graph-attention-network
