Relphormer: Relational Graph Transformer for Knowledge Graph Representation

Zhen Bi, Siyuan Cheng, Ningyu Zhang, Xiaozhuan Liang, Feiyu Xiong, Huajun Chen · DOI

Abstract

Knowledge Graphs (KGs) are essential for various AI applications, yet representing their complex, heterogeneous structures remains a challenge. Traditional methods like translational distance models or shallow Graph Neural Networks often fail to capture global semantics or suffer from slow inference. This paper introduces Relphormer, a novel Transformer-based framework designed specifically for KG representation. By incorporating a structure-aware self-attention mechanism and treating relations as sequence tokens, Relphormer effectively bridges the gap between graph topology and textual semantics. Experimental results demonstrate that Relphormer achieves state-of-the-art performance in link prediction, question answering, and recommendation tasks while significantly improving inference efficiency.

Introduction

Knowledge Graphs (KGs) serve as the backbone for modern information retrieval and recommendation systems, powering platforms from Google Search to Netflix. However, effectively embedding these heterogeneous networks—where entities are connected by diverse relation types—is difficult. While Transformers have revolutionized Natural Language Processing (NLP), their application to KGs is hindered by the graph's non-sequential nature and the computational cost of scoring candidates in large-scale graphs. Relphormer addresses these issues by reimagining the Transformer architecture for relational data, treating relations as first-class citizens and incorporating structural biases.

Methodology

Relphormer introduces three primary architectural innovations to make the Transformer "graph-literate":

1. Triple2Seq

To handle graph data, Relphormer utilizes a dynamic sampling strategy called Triple2Seq. It samples a "center triple" and its local neighborhood, converting the resulting sub-graph into a sequence. Crucially, it treats relations as special nodes within the sequence rather than mere edge labels. This allows the model to learn global semantic interactions between entities and relations directly.

2. Structure-enhanced Self-attention

Standard self-attention mechanisms lack inherent knowledge of graph topology. Relphormer introduces a "structural bias" derived from the graph's adjacency matrix (and its powers). This bias effectively instructs the model to prioritize nodes that are topologically closer in the actual graph, preserving the geometric integrity of the KG during the attention process.

3. Masked Knowledge Modeling (MKM)

Inspired by BERT’s Masked Language Modeling, Relphormer is pre-trained by masking an entity or a relation in a triple and asking the model to predict the missing piece. This "parametric" approach allows the model to act as a direct score function, predicting the right answer rather than scoring thousands of candidates.

The Relphormer framework: from Knowledge Graph sampling (Triple2Seq) to structure-enhanced self-attention and downstream tasks.

Experimental Results

Relphormer was rigorously evaluated across six diverse benchmarks covering KG completion (WN18RR, FB15K-237, UMLS), question answering (FreebaseQA, WebQuestionSP), and recommendation (MovieLens).

Performance and Efficiency

On the FB15K-237 dataset, Relphormer achieved a Hits@1 of 0.314, significantly outperforming the previous Transformer-based state-of-the-art, HittER (0.279). In question answering, it demonstrated a 6.8% improvement on FreebaseQA, proving that its representations translate effectively to downstream reasoning tasks.

Furthermore, Relphormer offers a massive speedup in inference. Traditional models often require scoring every possible triple, which is computationally expensive. By using the MKM head as a direct predictor, Relphormer is roughly $|E|$ times faster (where $|E|$ is the number of entities) than models like KG-BERT.

Performance comparison on the MovieLens recommendation task, showing Relphormer outperforming KGBERT and BERT4REC in Hit@1 and MRR.

Conclusion and Future Work

Relphormer demonstrates that Transformers can be highly effective for Knowledge Graph representation when augmented with structure-aware mechanisms. By treating relations as sequence tokens and utilizing masked modeling for efficiency, it sets a new standard for relational learning. While the model showed some sensitivity to structural sparsity in datasets like WN18RR, future work will explore more efficient sampling strategies and deeper graph contexts to further enhance performance.

Summary updated

BibTeX
@inproceedings{bi2024relphormer,
  author = {Zhen Bi and Siyuan Cheng and Ningyu Zhang and Xiaozhuan Liang and Feiyu Xiong and Huajun Chen},
  title = {{Relphormer: Relational Graph Transformer for Knowledge Graph Representation}},
  booktitle = {Neurocomputing},
  year = {2024},
  url = {https://openreview.net/forum?id=YqTiGENPBJ},
}
Figure