Graph Transformer for Graph-to-Sequence Learning

Deng Cai, Wai Lam

Abstract

Traditional Graph Neural Networks (GNNs) often struggle with long-range dependencies due to their inherent locality. We present the Graph Transformer, an architecture that enables global communication between all nodes in a graph. By integrating structural information via shortest-path relation encodings into a multi-head attention mechanism, the model captures complex semantic and syntactic relationships more effectively than local GNNs. Our approach achieves state-of-the-art results on AMR-to-text generation and syntax-based neural machine translation.

Introduction

Many natural language processing (NLP) tasks require mapping structured representations, such as Abstract Meaning Representation (AMR) graphs or dependency trees, into linear text sequences. Conventional approaches rely on GNNs, which update node states based on immediate neighbors. This "locality" constraint necessitates deep architectures to capture distant relationships, often leading to information loss or "washing out" over many layers. Furthermore, handling labeled edges often involves complex graph transformations that increase computational overhead.

The Graph Transformer addresses these challenges by treating the input graph as a fully connected structure where every node can attend to every other node. This global receptive field allows for capturing long-range dependencies in a single step while explicitly respecting the graph's topological constraints.

Methodology

The core innovation of the Graph Transformer lies in its adaptation of the standard Transformer architecture for graph-structured data.

Relation-Enhanced Global Attention

Unlike standard Transformers that treat inputs as sequences, the Graph Transformer incorporates the graph's topology directly into the attention mechanism. The attention score between any two nodes $i$ and $j$ is computed using their features and a dedicated relation encoding that represents the structural connection between them.

The Graph Transformer architecture featuring a Graph Encoder with Relation-Enhanced Global Attention and a Sequence Decoder.

Shortest Path Relation Encoding

To define the relationship between arbitrary nodes, the model utilizes the shortest path between them. This path, consisting of a sequence of edges and intermediate nodes, is processed by a Bi-directional Gated Recurrent Unit (Bi-GRU) to generate a fixed-length relation vector. This ensures that the model understands the specific semantic role (e.g., "object" vs. "subject") even when nodes are separated by multiple hops.

The model further enhances representation through:

  • Bidirectionality: Reverse edges are added to facilitate upstream information flow.
  • Global Node: A virtual node connected to all other nodes captures a holistic graph representation.
  • Copy Mechanism: Integrated into the decoder to handle rare entities by copying them from the input graph.

Experimental Setup

The model was evaluated on two primary benchmarks:

  1. AMR-to-Text Generation: Using the LDC2015E86 and LDC2017T10 datasets.
  2. Syntax-based Neural Machine Translation (NMT): Using WMT16 English-German and English-Czech datasets, where source sentences are augmented with dependency trees.

Results and Discussion

The Graph Transformer established new state-of-the-art benchmarks, achieving 27.4 BLEU on LDC2015E86 and 29.8 BLEU on LDC2017T10, outperforming previous GNN-based models by up to 2.2 points. In syntax-based NMT, the model reached 21.3 BLEU (En-De) and 14.1 BLEU (En-Cs), surpassing previous ensemble systems with a single-model approach.

Robustness to Graph Topology

A key advantage of the Graph Transformer is its stability across varying graph diameters. While GNN performance typically degrades as the distance between nodes increases, the Graph Transformer maintains high performance because its receptive field is inherently global.

Comparison of performance (chrF++) across different graph diameters, showing the Graph Transformer's stability compared to GNN-based baselines.

Analysis of the attention heads revealed specialization: some heads focus on local neighborhoods, while others consistently attend to nodes more than five hops away. This multi-scale awareness allows the model to handle complex reentrancies (nodes with multiple parents) more effectively than tree-based or local GNN approaches.

Conclusion and Future Work

The Graph Transformer demonstrates that global attention, when combined with explicit relation encoding, is a powerful paradigm for graph-to-sequence learning. While the $O(N^2)$ complexity of global attention is manageable for typical NLP graphs, future work may explore scaling to larger knowledge graphs. Additionally, investigating more sophisticated path aggregation methods beyond the shortest-path heuristic could further refine the model's structural awareness.

Summary updated

BibTeX
@inproceedings{cai2020graph,
  author = {Deng Cai and Wai Lam},
  title = {{Graph Transformer for Graph-to-Sequence Learning}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2020},
  doi = {10.1609/aaai.v34i05.6243},
}
Figure