Knowledge Graph Large Language Model (KG-LLM) for Link Prediction

Dong Shu, Tianle Chen, Mingyu Jin, Chong Zhang, Mengnan Du, Yongfeng Zhang · DOI

Abstract

The Knowledge Graph Large Language Model (KG-LLM) framework bridges the gap between structured data and generative reasoning by fine-tuning LLMs to perform multi-hop link prediction. By converting complex graph paths into natural language "Chain-of-Thought" prompts, this approach enables models to leverage pre-trained linguistic logic for structural reasoning. Experimental results demonstrate state-of-the-art performance, with models like Gemma-7B reaching a 98% F1 score on standard benchmarks when utilizing In-Context Learning.

Introduction

Knowledge Graphs (KGs) are essential for representing structured information as networks of entities and relations. While predicting direct links is well-established, multi-hop link prediction—inferring a connection through a sequence of intermediate nodes—remains a significant challenge.

Traditional methods, such as Graph Neural Networks (GNNs) or embedding-based models, often function as "black boxes." They typically provide discriminative outputs (probabilities) without explaining the underlying reasoning. Furthermore, these models often struggle to generalize to unseen tasks or maintain accuracy as the number of "hops" increases. The KG-LLM framework addresses these issues by transforming structural graph problems into linguistic reasoning tasks, tapping into the "common sense" and reasoning capabilities inherent in Large Language Models (LLMs).

Methods

The KG-LLM framework consists of a two-stage process designed to bridge the gap between structured graph data and natural language processing.

The two-stage KG-LLM framework: Graph Preprocessing and Instruction Fine-Tuning.

Stage 1: Graph Preprocessing

The KG is traversed using Depth-First Search (DFS) to extract paths between 2 and 6 hops long. These structured paths are then converted into natural language prompts. For instance, a triple (Node_1, relation_x, Node_2) is translated to: "Node_1 has relation_x with Node_2."

Stage 2: Instruction Fine-Tuning

Three open-source LLMs—Flan-T5-Large, LLaMa2-7B, and Gemma-7B—are fine-tuned on these natural language prompts. Two key techniques are employed to enhance performance:

  • Chain-of-Thought (CoT): The model is trained to explain the path step-by-step (e.g., "Node 1 relates to B, which relates to C, therefore Node 1 is connected to C") rather than providing a binary answer.
  • In-Context Learning (ICL): During inference, the model is provided with a "one-shot" example to reinforce the expected reasoning format.

For larger models like LLaMa2 and Gemma, the researchers utilized 4-bit quantized LoRA (Low-Rank Adaptation) to ensure computational efficiency during the fine-tuning process.

Key Insights and Results

The core innovation of KG-LLM lies in using text as a universal interface. By textualizing graph IDs, the LLM can apply its pre-trained latent knowledge to structural connections. For example, if a model understands that "Jack bought Shampoo" and "Shampoo is related to Hair Conditioner," it can more intuitively infer a link than a model processing abstract vectors.

Comparison of standard prompts (ablation) versus KG-LLM knowledge prompts incorporating Chain-of-Thought reasoning.

Performance Benchmarks

The framework was evaluated on four real-world benchmarks: WN18RR, NELL-995, FB15k-237, and YAGO3-10. Key findings include:

  • Superior Accuracy: KG-LLM significantly outperformed traditional GNN baselines. On WN18RR, the Gemma (KG-LLM) model achieved an F1 score of 0.84 and an AUC of 0.81 without ICL.
  • Impact of Examples: With one-shot In-Context Learning, performance improved dramatically. Gemma reached a 0.98 F1 score on WN18RR, while LLaMa2 achieved 0.96 F1 on NELL-995.
  • Resilience to Complexity: Unlike traditional GNNs, which see performance degrade as path length increases, KG-LLM maintains stable performance even at 5-hop complexity.

Conclusion

KG-LLM demonstrates that LLMs can be effectively adapted for complex structural reasoning tasks by treating graph paths as linguistic sequences. While the current implementation is limited by token constraints (512 tokens) and sensitivity to the number of relation options, the results suggest a promising path forward for interpretable and high-performance link prediction. Future work will focus on refining instruction quality and expanding the model's capacity to handle deeper graph structures and broader relation sets.

Summary updated

BibTeX
@misc{shu2024knowledge,
  author = {Dong Shu and Tianle Chen and Mingyu Jin and Chong Zhang and Mengnan Du and Yongfeng Zhang},
  title = {{Knowledge Graph Large Language Model (KG-LLM) for Link Prediction}},
  year = {2024},
  eprint = {2403.07311},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.07311},
}
Figure