NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Knowledge Context Modeling with Pre-trained Language Models for Contrastive Knowledge Graph Completion

Guangqian Yang, Yi Liu, Lei Zhang, Licheng Zhang, Hongtao Xie, Zhendong Mao

Abstract

Knowledge Graph Completion (KGC) is vital for addressing the inherent incompleteness of Knowledge Graphs. While text-based methods using Pre-trained Language Models (PLMs) have shown promise, they often overlook the rich structural information in an entity's neighborhood. This paper introduces KnowC, a framework that models "knowledge context" by incorporating neighboring triples as prompts for PLMs. Evaluated on WN18RR, FB15k-237, and Wikidata5M, KnowC achieves state-of-the-art performance, demonstrating that local graph structure significantly enhances the semantic representation of entities.

Introduction: Why Context is King

Knowledge Graphs (KGs) are the backbone of modern AI, powering everything from search engines to recommendation systems. However, these graphs are notoriously incomplete. While Pre-trained Language Models (PLMs) have revolutionized Knowledge Graph Completion (KGC) by encoding entity descriptions, they often suffer from "tunnel vision"—focusing only on the target triple and ignoring the rich neighborhood of facts surrounding it.

At ACL 2024, researchers from the University of Science and Technology of China and People’s Daily Online introduced KnowC, a framework that treats a triple's neighborhood as a "knowledge context" to significantly boost prediction accuracy. By sampling and encoding an entity's local neighborhood, the model gains the "contextual clues" necessary to achieve state-of-the-art results on major benchmarks like WN18RR and Wikidata5M.

The Problem: Isolated Descriptions

Most text-based KGC methods represent a triple $(h, r, t)$ by feeding the names or descriptions of the head ($h$), relation ($r$), and tail ($t$) into a model like BERT. The problem is that these descriptions are often static and isolated.

Imagine trying to predict the nationality of "James Harden." If the model only sees his name, it relies entirely on the knowledge it "memorized" during pre-training. However, if the model also sees the neighboring fact "(James Harden, Born In, Los Angeles)," the answer becomes much more obvious. Existing models neglect this "knowledge context"—the web of 1-hop neighbors that provide vital supplemental information about an entity's role and relationships.

The KnowC Framework

The authors propose the KnowC framework, which utilizes a bi-encoder architecture (two BERT models) to encode the head-relation pair and the candidate tail separately.

The KnowC framework architecture, illustrating how neighbor triples are sampled and used as prompts for the PLM to complete the knowledge graph.
  1. Knowledge Context as Prompts: For a head entity $h$, KnowC gathers its 1-hop neighbors and concatenates them into a text string: h : r1, t1; r2, t2.... This string is used as a supplemental prompt alongside the entity's original description.
  2. Neighbor Sampling Strategies: Since entities can have hundreds of neighbors but PLMs have limited token capacities, the authors devised three sampling strategies: Random Sampling, kNN Sampling (using relation similarity), and Dynamic Sampling (randomly sampling different neighbors in every training epoch to increase robustness).
  3. Contrastive Learning: The model is trained using the InfoNCE loss with an additive margin, encouraging the model to rank the correct tail entity higher than a large pool of "negative" candidates.
  4. Graph-based Re-ranking: During inference, the model slightly boosts the scores of entities that are already $n$-hop neighbors in the graph, leveraging the principle of spatial locality.

Key Results

KnowC achieved State-of-the-Art (SOTA) performance on several metrics, particularly on sparse and large-scale graphs.

Performance comparison of KnowC against embedding-based and text-based baselines on WN18RR and FB15k-237 benchmarks.
  • WN18RR: Achieved an MRR (Mean Reciprocal Rank) of 69.9, outperforming the previous best text-based model (GHN) at 67.8.
  • Wikidata5M: In the transductive setting, KnowC reached an MRR of 42.6, a significant jump over SimKGC (35.8). On the inductive setting (Wikidata5M-Ind), KnowC achieved an MRR of 73.2, proving that context allows PLMs to reason about entities they have never seen before.

Insights and Discussion

  • Context Disambiguates Semantics: Neighboring triples act as a form of "feature engineering" for text models. They help the model understand complex relationship patterns like inversion, symmetry, and composition.
  • The Density Dilemma: KnowC performs exceptionally well on sparse graphs (WN18RR) and massive graphs (Wikidata5M). However, on very dense graphs like FB15k-237, the benefit of adding neighbors is smaller because the graph structure is already highly redundant.
  • Limitations: Adding neighbors increases input token length, hitting the quadratic complexity limits of Transformers. Future work could explore more natural language templates for linearization or efficient ways to incorporate multi-hop paths.

Summary updated

BibTeX
@inproceedings{yang2024knowledge,
  author = {Guangqian Yang and Yi Liu and Lei Zhang and Licheng Zhang and Hongtao Xie and Zhendong Mao},
  title = {{Knowledge Context Modeling with Pre-trained Language Models for Contrastive Knowledge Graph Completion}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.509},
}
Figure