BertNet: Harvesting Knowledge Graphs with Arbitrary Relations from Pretrained Language Models

Shibo Hao, Bowen Tan, Kaiwen Tang, Bin Ni, Xiyan Shao, Hengzhe Zhang, Eric P. Xing, Zhiting Hu

Introduction

Knowledge Graphs (KGs) are the backbone of modern AI, yet their construction remains a significant bottleneck. Traditional approaches rely on labor-intensive human curation or text mining from specific corpora, which often fails to capture the vast, implicit knowledge stored within Large Language Models (LLMs). BertNet addresses this by providing a framework to automatically "harvest" large-scale KGs from pretrained models like BERT and RoBERTa.

The BertNet Framework

Unlike previous methods restricted to fixed relation sets, BertNet allows users to define arbitrary and complex relations using a simple prompt and a few example entity pairs. This enables the extraction of nuanced knowledge, such as "A is capable of but not good at B."

Overview of the BertNet framework for harvesting arbitrary relations from black-box language models.

By treating the language model as a "black box" of knowledge, BertNet extracts structured triples that represent the model's internal beliefs, effectively turning a neural network into a queryable symbolic graph.

Methodology: From Prompts to Structured Knowledge

The BertNet pipeline operates in two primary stages: Prompt Creation and Entity Pair Search.

The full BertNet pipeline, illustrating the iterative prompt creation and the weighted entity pair search process.

1. Diverse Weighted Prompts

To overcome linguistic noise, BertNet expands an initial user prompt into a diverse set of semantically equivalent queries. For instance, "A is a potential risk for B" might be paraphrased into "A may lead to B." These prompts are then weighted based on their compatibility with the provided example entity pairs, ensuring that the most reliable phrasings carry the most weight during extraction.

2. Efficient Search-and-Rescore

Searching for entity pairs $(h, t)$ across a model's entire vocabulary is computationally prohibitive ($O(V^2)$). BertNet implements an efficient search strategy using:

  • Pruning: A Depth-First Search (DFS) combined with a "minimum token log-likelihood" (MTL) threshold. If a partial entity's probability drops too low, the search branch is discarded.
  • Re-scoring: Candidate pairs are re-ranked using the full weighted average of the prompt ensemble to maximize accuracy and consistency.

Key Insights: The Distillation Paradox

A notable discovery in the BertNet study is the "Distillation Paradox." Researchers found that DistilBERT, a compressed version of BERT, often achieved higher accuracy in knowledge extraction than its larger teacher model, BERT-base. This suggests that the distillation process may act as a denoising mechanism, preserving core factual knowledge while stripping away peripheral linguistic noise.

Results and Performance

BertNet was evaluated across benchmarks like ConceptNet and LAMA, as well as a new set of 487 "Auto" relations. Key findings include:

  • Scale and Novelty: Successfully harvested over 122,000 tuples using RoBERTa-large, many of which were absent from existing symbolic KGs.
  • Accuracy: Achieved 73% accuracy on complex human-defined relations, significantly outperforming baselines like AutoPrompt (33%).
  • Flexibility: Demonstrated the ability to extract N-ary relations (e.g., "A can do B at C"), proving the framework's versatility for complex data modeling.

Conclusion and Future Work

BertNet transforms black-box language models into interpretable, symbolic Knowledge Graphs. By enabling the extraction of arbitrary relations without heavy fine-tuning, it provides a powerful tool for auditing model knowledge and building more comprehensive AI systems. While powerful, the framework currently faces challenges in domain specificity and potential inheritance of training data biases. Future work will focus on applying BertNet to specialized scientific domains and even larger model architectures.

Summary updated

BibTeX
@inproceedings{hao2023bertnet,
  author = {Shibo Hao and Bowen Tan and Kaiwen Tang and Bin Ni and Xiyan Shao and Hengzhe Zhang and Eric P. Xing and Zhiting Hu},
  title = {{BertNet: Harvesting Knowledge Graphs with Arbitrary Relations from Pretrained Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.findings-acl.309},
}
Figure