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

CokeBERT: Contextual knowledge selection and embedding towards enhanced pre-trained language models

Yusheng Su, Xu Han, Zhengyan Zhang, Yankai Lin, Peng Li, Zhiyuan Liu, Jie Zhou, Maosong Sun

TL;DR

This paper introduces CokeBERT, a novel framework that dynamically selects and embeds relevant knowledge from knowledge graphs (KGs) based on the specific textual context. This approach addresses the limitations of existing methods that use static KG information, leading to improved performance on knowledge-driven NLP tasks and more interpretable results.

What Problem Does This Paper Address?

Pre-trained language models (PLMs) like BERT have revolutionized NLP, but they often struggle to effectively incorporate factual knowledge. While many approaches enhance PLMs by integrating information from knowledge graphs (KGs), they typically embed static subgraphs of KGs, regardless of whether that knowledge is relevant to the input text. This can lead to redundant or ambiguous information interfering with understanding. The core problem this paper tackles is how to dynamically select and embed contextually relevant knowledge from KGs to improve PLMs' language understanding capabilities.

Methods

The proposed framework, CokeBERT, consists of three main modules:

  1. Text Encoder: A standard Transformer encoder (similar to BERT) processes the input text to generate contextual embeddings.
  2. Dynamic Knowledge Context Encoder: This is the core innovation.
  3. Raw Knowledge Context Construction: For a given entity mention in the text, Coke first constructs a "raw" knowledge context by sampling K-hop subgraphs from the KG centered around that entity.
  4. Semantic-Driven Graph Neural Network (S-GNN): This S-GNN dynamically selects informative features from the raw knowledge context. It uses an attention mechanism to weigh the relevance of neighboring entities and relations based on the input textual context. This allows Coke to filter out irrelevant KG information and focus on what's pertinent. The output is a contextualized knowledge embedding for the entity.
  5. Knowledge Fusion Encoder: This module fuses the contextual entity embeddings (from the S-GNN) with the original text embeddings to produce a final representation that benefits downstream tasks.

CokeBERT also employs specific pre-training strategies, including masking token-entity alignments and a denoising entity auto-encoder task, to better integrate knowledge.

Datasets

  • Pre-training Corpus: English Wikipedia, aligned with Wikidata.
  • Downstream Tasks Datasets:
    • Entity Typing: FIGER, Open Entity.
  • Relation Classification: FewRel, TACRED.

Key Insights and Ideas

  • Dynamic Knowledge is Key: The most significant insight is that not all knowledge from a KG is equally useful for understanding a given piece of text. Dynamically selecting knowledge based on textual context is crucial for effective integration.
  • Interpretability through Attention: The attention mechanism within the S-GNN provides a degree of interpretability. By observing the attention scores, researchers can understand which KG triples are deemed most important for a given sentence, offering insights into how the model makes its decisions.
  • Beyond 1-Hop: Exploring K-hop subgraphs (specifically 2-hop) showed that considering a wider range of related knowledge can lead to better entity embeddings, suggesting that the "context" in knowledge graphs can extend beyond immediate neighbors.

Key Results

  • Performance Gains: CokeBERT significantly outperforms strong baselines (like ERNIE, K-BERT) on both entity typing and relation classification tasks. For instance, on FewRel, CokeBERT achieved improvements of 4.5% and 3.8% in F1 scores over BERTBASE and ROBERTABASE, respectively.
  • Improved Entity Typing: On the FIGER dataset, CokeBERT achieved notable improvements (3.7% and 3.5% Micro scores) over BERTBASE and ROBERTABASE, demonstrating its ability to handle noisy labels better.
  • Interpretability: Qualitative analysis showed that CokeBERT could attend to different factual triples depending on the context of the entity mentions, highlighting its dynamic and context-aware nature.

Limitations and Future Work

  • Limitations: The paper acknowledges that while CokeBERT outperforms baselines, it still relies on pre-trained PLMs and KG embeddings. The performance on TACRED was comparable to other models, suggesting that the benefits of dynamic knowledge selection might be more pronounced on datasets where KG domain alignment is stronger (like FewRel, which is similar to Wikidata).
  • Future Work: The authors suggest exploring how to inject other types of knowledge (e.g., linguistic knowledge) alongside factual knowledge. They also propose investigating methods for continually injecting emerging factual knowledge into PLMs without requiring full retraining.

Summary updated

BibTeX
@inproceedings{su2021cokebert,
  author = {Yusheng Su and Xu Han and Zhengyan Zhang and Yankai Lin and Peng Li and Zhiyuan Liu and Jie Zhou and Maosong Sun},
  title = {{CokeBERT: Contextual knowledge selection and embedding towards enhanced pre-trained language models}},
  booktitle = {AI Open},
  year = {2021},
  url = {https://openreview.net/forum?id=oEulr4CNQWd},
}
Figure