Reasoning Through Memorization: Nearest Neighbor Knowledge Graph Embeddings

Ningyu Zhang, Xin Xie, Xiang Chen, Shumin Deng, Chuanqi Tan, Fei Huang, Xu Cheng, Huajun ChenNLPCC 2022 · DOI

TL;DR

This paper introduces kNN-KGE, a novel approach to knowledge graph completion that addresses the challenge of reasoning about rare or emerging entities. By combining pre-trained language models with a k-nearest neighbor (kNN) retrieval mechanism from a knowledge store, kNN-KGE explicitly memorizes entities, leading to improved performance, especially in low-resource settings.

What Problem Does This Paper Address?

Knowledge Graphs (KGs) are structured representations of facts, often in the form of <subject, predicate, object> triples. However, KGs are rarely complete and are constantly evolving with new entities and relationships. A significant challenge in KG completion (predicting missing triples) is the inability of traditional embedding-based methods to effectively reason about entities that appear infrequently in the training data or are entirely new (emerging entities). These methods tend to implicitly encode knowledge within model parameters, making it difficult to handle such "cold-start" scenarios. This paper aims to bridge this gap by enabling explicit memorization and reasoning for these rare or unseen entities.

Methods

The core of kNN-KGE lies in its "semi-parametric" approach, which combines the strengths of parametric models (pre-trained language models) with non-parametric memory (a knowledge store).

  1. Masked Entity Modeling (MEM): The authors adapt the masked language model (MLM) objective from pre-trained language models (PLMs) like BERT. Instead of predicting masked words, they predict masked entities in KG triples. This transforms link prediction into an entity prediction task. For a query like (subject, predicate, ?), the model concatenates the subject, its description, the predicate, and a [MASK] token to predict the missing object. This is trained using a standard cross-entropy loss.
  2. Knowledge Store Construction: To handle rare/emerging entities, a knowledge store is built. This store contains embeddings for entities derived from two sources:
  3. Entity Descriptions: Embeddings are generated from textual descriptions of entities using PLMs.
  4. Training Triples: Embeddings are generated from the context of entities within the training triples.
  5. Memorized Inference: During inference, when a triple has a missing entity, the model first uses its MEM head to get an initial prediction. Simultaneously, it uses the [MASK] token's embedding as an "anchor" to query the knowledge store and find the k-nearest neighbors (kNN) of this anchor embedding. The final prediction is a weighted interpolation between the MEM prediction and the kNN retrieval distribution. This interpolation allows the model to leverage both its learned parametric knowledge and the explicit memorization from the knowledge store.

Datasets

The paper evaluates kNN-KGE on two widely used benchmark datasets for knowledge graph completion:

  • WN18RR: Derived from WordNet.
  • FB15k-237: Derived from Freebase.

These datasets are used for both transductive (entities and relations seen during training are also present in the test set) and inductive (entities or relations in the test set were not seen during training) settings.

Key Insights and Ideas

  • Explicit Memorization for Rare Entities: The most significant insight is that explicitly storing and retrieving entity embeddings from a knowledge store (rather than relying solely on parametric model weights) dramatically improves performance for rare or unseen entities. This is akin to how humans might recall specific facts rather than just inferring them from general knowledge.
  • Bridging Parametric and Non-Parametric Models: kNN-KGE represents one of the first attempts at a semi-parametric approach for KG completion, effectively combining the generalization capabilities of PLMs with the precise recall of a memory-based system.
  • Transforming Link Prediction to Entity Prediction: The clever use of masked entity modeling simplifies the problem and allows for efficient integration with PLMs.
  • Inductive Reasoning Boost: The knowledge store proves particularly beneficial for inductive settings, where new entities are encountered, showcasing the model's ability to adapt.

Key Results

  • State-of-the-Art Performance: kNN-KGE achieves state-of-the-art or competitive results on both WN18RR and FB15k-237 datasets across transductive and inductive settings.
  • Significant Hits@1 Improvement: The model shows a notable improvement in Hits@1 metric, indicating better precision in identifying the correct entity. For instance, on WN18RR, Hits@1 improves from 0.443 to 0.525, and on FB15k-237, from 0.252 to 0.280.
  • Low-Resource Advantage: In low-resource settings (e.g., using only 70% of training samples), kNN-KGE's performance is comparable to or better than state-of-the-art models, and the knowledge store consistently improves results.
  • Tail Entity Improvement: The model demonstrates significant gains for entities with low frequencies (occurring less than 20 times), improving MRR from 0.118 to 0.183.
  • Inference Efficiency: kNN-KGE offers a speedup compared to some existing methods, particularly in the "entire graph" inference scenario.

Limitations and Future Work

  • Efficiency of Knowledge Store: While effective, the size of the knowledge store can grow large, potentially impacting inference speed and memory usage. The authors suggest improving efficiency by using a smaller knowledge store and faster inference.
  • Dynamic KG Reasoning: The current approach is static once the knowledge store is built. Future work could explore how to edit or delete entities from the knowledge store for dynamic KG reasoning.
  • Broader Applications: The authors propose extending kNN-KGE to other tasks like question answering and fact verification.
  • Hyperparameter Tuning: The interpolation parameter $\lambda$ needs to be tuned, and the paper identifies $\lambda=0.2$ as optimal for FB15k-237. The number of neighbors $k$ also impacts performance, with convergence around $k=64$.

Summary updated

BibTeX
@inproceedings{zhang2022reasoning,
  author = {Ningyu Zhang and Xin Xie and Xiang Chen and Shumin Deng and Chuanqi Tan and Fei Huang and Xu Cheng and Huajun Chen},
  title = {{Reasoning Through Memorization: Nearest Neighbor Knowledge Graph Embeddings}},
  booktitle = {NLPCC},
  year = {2022},
  doi = {10.1007/978-3-031-44693-1\_9},
}
Figure