KG-BERT
BERT-Base fine-tuned to say whether a head-relation-tail triple is plausible.
Graphs and geometry · 641 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
At a glance
- Task
- Graphs and geometry
- Parameters
- 109.5M
- Operations
- 641
- Framework
- PyTorch
- Recurrent
- No
- Published
- 2019
- Cited by
- 1,127 (as of 27 November 2026)
- Authors
- Liang Yao, Chengsheng Mao, Yuan Luo
- Source
- GitHub: yao8839836/kg-bert
- License
- Apache-2.0
- Checked
- Passed: the trace was replayed operation by operation and matched the model's own output for this input.
Files
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
Details
- Stable ID
- m1471
- Graph hash
- dc50cf74c66d3a48cf77c41b2f5b2531e50817868f5f51dc80ab6bf708160e09
- Skeleton hash
- bc0a4bc0f528c0f7c31c7552e580482d8bcd73ae6142e5684caa33c392fd90af
- Architecture hash
- 5fb04e3d8266fb2797eda408fed81c98d0ab12d4a54d541382e2c8ed8515a50e
- Diagram SHA-256
- c6de8135d9fac9fb15acf6f2bda3962848cd4925750d43c8ce7e3c47a42a1908
- TorchLens version
- 2.36.0
- Renderer
- graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
- Check
- Forward pass replayed in PyTorch
What it is
KG-BERT, Knowledge Graph Bidirectional Encoder Representations from Transformer, uses a pre-trained language model to complete knowledge graphs that suffer from incompleteness. The idea is to treat entities, relations and triples as textual sequences, turning knowledge graph completion into a sequence classification problem, and then fine-tune BERT on those sequences. The authors describe this as, to the best of their knowledge, the first study to model triples' plausibility with a pre-trained contextual language model.
The captured member is the triple-classification version, KG-BERT(a), where the sentences of head, relation and tail are packed into one sequence. Every input starts with the special classification token [CLS], and the entity and relation sentences are separated by [SEP]. Head and tail tokens share one segment embedding while the relation tokens get a different one. The final hidden state of [CLS] is the aggregate sequence representation, and the only new parameters are the classification layer weights, so the score is a sigmoid over a 2-dimensional vector whose entries sum to 1. Negative triples are generated simply by replacing the head or tail entity of a positive triple with a random entity.
The backbone is pre-trained BERT-Base with 12 layers, 12 self-attention heads and a hidden size of 768, which the authors found better than BERT-Large in general and less sensitive to hyper-parameters. For triple classification they sample 1 negative triple per positive triple to keep the binary classes balanced. The repository is modified from pytorch-pretrained-BERT and tested on Python 3.5+, running bert-base-uncased on WN11 with a maximum sequence length of 20.
Key idea. Scoring a knowledge-graph triple by feeding its head, relation and tail text to BERT as one [SEP]-separated sequence and fine-tuning a two-way classifier on the [CLS] state.
- KG-BERT
- KG-BERT(a)
- BERT for Knowledge Graph Completion
- knowledge graph completion
- triple classification
- link prediction
- WN11
- FB13
- Yao
- BertForSequenceClassification
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
Cite the paper
@misc{yao2019kgbertbertknowledgegraph,
title={KG-BERT: BERT for Knowledge Graph Completion},
author={Liang Yao and Chengsheng Mao and Yuan Luo},
year={2019},
eprint={1909.03193},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/1909.03193},
}