LibKGE is a PyTorch-based library for efficient training, evaluation, and hyperparameter optimization of knowledge graph embeddings (KGE). It is highly configurable, easy to use, and extensible. Other KGE frameworks are listed below.
The key goal of LibKGE is to foster reproducible research into (as well as meaningful comparisons between) KGE models and training methods. As we argue in our ICLR 2020 paper (see video), the choice of training strategy and hyperparameters are very influential on model performance, often more so than the model class itself. LibKGE aims to provide clean implementations of training, hyperparameter optimization, and evaluation strategies that can be used with any model. Every potential knob or heuristic implemented in the framework is exposed explicitly via well-documented configuration files (e.g., see here and here). LibKGE also provides the most common KGE models and new ones can be easily added (contributions welcome!).
For link prediction tasks, rule-based systems such as AnyBURL are a competitive alternative to KGE.
# retrieve and install project in development mode
git clone https://github.com/uma-pi1/kge.git
cd kge
pip install -e .
# download and preprocess datasets
cd data
sh download_all.sh
cd ..
# train an example model on toy dataset (you can omit '--job.device cpu' when you have a gpu)
kge start examples/toy-complex-train.yaml --job.device cpu
- Features
- Results and pretrained models
- Using LibKGE
- Currently supported KGE models
- Extending LibKGE
- Known issues
- Changelog
- Other KGE frameworks
- How to cite
- Training
- Training types: negative sampling, 1vsAll, KvsAll
- Losses: binary cross entropy (BCE), Kullback-Leibler divergence (KL), margin ranking (MR), squared error (SE)
- All optimizers and learning rate schedulers of PyTorch supported and can be chosen individually for different parameters (e.g., different for entity and for relation embeddings)
- Learning rate warmup
- Early stopping
- Checkpointing
- Stop (e.g., via
Ctrl-C
) and resume at any time - Automatic memory management to support large batch sizes (see config key
train.subbatch_auto_tune
)
- Hyperparameter tuning
- Evaluation
- Entity ranking metrics: Mean Reciprocal Rank (MRR), HITS@k with/without filtering
- Drill-down by: relation type, relation frequency, head or tail
- Extensive logging and tracing
- Detailed progress information about training, hyper-parameter tuning, and evaluation is recorded in machine readable formats
- Quick export of all/selected parts of the traced data into CSV or YAML files to facilitate analysis
- KGE models
- All models can be used with or without reciprocal relations
- RESCAL (code, config)
- TransE (code, config)
- TransH (code, config)
- DistMult (code, config)
- ComplEx (code, config)
- ConvE (code, config)
- RelationalTucker3/TuckER (code, config)
- CP (code, config)
- SimplE (code, config)
- RotatE (code, config)
- Transformer ("No context" model) (code, config)
- Embedders
We list some example results (filtered MRR and HITS@k on test data) obtained with LibKGE below. These results are obtained by running automatic hyperparameter search as described here.
These results are not necessarily the best results that can be achieved using LibKGE, but they are comparable in that a common experimental setup (and equal amount of work) has been used for hyperparameter optimization for each model. Since we use filtered MRR for model selection, our results may not be indicative of the achievable model performance for other validation metrics (such as HITS@10, which has been used for model selection elsewhere).
We report performance numbers on the entire test set, including the triples that contain entities not seen during training. This is not done consistently throughout existing KGE implementations: some frameworks remove unseen entities from the test set, which leads to a perceived increase in performance (e.g., roughly add +3pp to our WN18RR MRR numbers for this method of evaluation).
We also provide pretrained models for these results. Each pretrained model is given in the form of a LibKGE checkpoint, which contains the model as well as additional information (such as the configuration being used). See the documentation below on how to use checkpoints.
MRR | Hits@1 | Hits@3 | Hits@10 | Config file | Pretrained model | |
---|---|---|---|---|---|---|
RESCAL | 0.356 | 0.263 | 0.393 | 0.541 | config.yaml | 1vsAll-kl |
TransE | 0.313 | 0.221 | 0.347 | 0.497 | config.yaml | NegSamp-kl |
DistMult | 0.343 | 0.250 | 0.378 | 0.531 | config.yaml | NegSamp-kl |
ComplEx | 0.348 | 0.253 | 0.384 | 0.536 | config.yaml | NegSamp-kl |
ConvE | 0.339 | 0.248 | 0.369 | 0.521 | config.yaml | 1vsAll-kl |
RotatE | 0.333 | 0.240 | 0.368 | 0.522 | config.yaml | NegSamp-bce |
MRR | Hits@1 | Hits@3 | Hits@10 | Config file | Pretrained model | |
---|---|---|---|---|---|---|
RESCAL | 0.467 | 0.439 | 0.480 | 0.517 | config.yaml | KvsAll-kl |
TransE | 0.228 | 0.053 | 0.368 | 0.520 | config.yaml | NegSamp-kl |
DistMult | 0.452 | 0.413 | 0.466 | 0.530 | config.yaml | KvsAll-kl |
ComplEx | 0.475 | 0.438 | 0.490 | 0.547 | config.yaml | 1vsAll-kl |
ConvE | 0.442 | 0.411 | 0.451 | 0.504 | config.yaml | KvsAll-kl |
RotatE | 0.478 | 0.439 | 0.494 | 0.553 | config.yaml | NegSamp-bce |
MRR | Hits@1 | Hits@3 | Hits@10 | Config file | Pretrained model | |
---|---|---|---|---|---|---|
RESCAL | 0.644 | 0.544 | 0.708 | 0.824 | config.yaml | NegSamp-kl |
TransE | 0.676 | 0.542 | 0.787 | 0.875 | config.yaml | NegSamp-bce |
DistMult | 0.841 | 0.806 | 0.863 | 0.903 | config.yaml | 1vsAll-kl |
ComplEx | 0.838 | 0.807 | 0.856 | 0.893 | config.yaml | 1vsAll-kl |
ConvE | 0.825 | 0.781 | 0.855 | 0.896 | config.yaml | KvsAll-bce |
RotatE | 0.783 | 0.727 | 0.820 | 0.877 | config.yaml | NegSamp-kl |
MRR | Hits@1 | Hits@3 | Hits@10 | Config file | Pretrained model | |
---|---|---|---|---|---|---|
RESCAL | 0.948 | 0.943 | 0.951 | 0.956 | config.yaml | 1vsAll-kl |
TransE | 0.553 | 0.315 | 0.764 | 0.924 | config.yaml | NegSamp-bce |
DistMult | 0.941 | 0.932 | 0.948 | 0.954 | config.yaml | 1vsAll-kl |
ComplEx | 0.951 | 0.947 | 0.953 | 0.958 | config.yaml | KvsAll-kl |
ConvE | 0.947 | 0.943 | 0.949 | 0.953 | config.yaml | 1vsAll-kl |
RotatE | 0.946 | 0.943 | 0.948 | 0.953 | config.yaml | NegSamp-kl |
LibKGE supports large datasets such as Wikidata5M (4.8M entities). The result given below was found by automatic hyperparameter search similar to the one used for the smaller datasets above, but with some values fixed (training with shared negative sampling, embedding dimension: 128, batch size: 1024, optimizer: Adagrad, regularization: weighted). We ran 30 pseudo-random configurations for 20 epochs, and then reran the configuration that performed best on validation data for 200 epochs.
MRR | Hits@1 | Hits@3 | Hits@10 | Config file | Pretrained model | |
---|---|---|---|---|---|---|
ComplEx | 0.301 | 0.245 | 0.331 | 0.397 | config.yaml | NegSamp-kl |
The result given below was found by the same automatic hyperparameter search used for Wikidata5M. We reran the configuration that performed best on validation data for 400 epochs.
MRR | Hits@1 | Hits@3 | Hits@10 | Config file | Pretrained model | |
---|---|---|---|---|---|---|
ComplEx | 0.551 | 0.476 | 0.596 | 0.682 | config.yaml | NegSamp-kl |
CoDEx is a Wikidata-based KG completion benchmark. The results here have been obtained using the automatic hyperparameter search used for the Freebase and WordNet datasets, but with fewer epochs and Ax trials for CoDEx-M and CoDEx-L. See the CoDEx paper (EMNLP 2020) for details.
MRR | Hits@1 | Hits@3 | Hits@10 | Config file | Pretrained model | |
---|---|---|---|---|---|---|
RESCAL | 0.404 | 0.293 | 0.4494 | 0.623 | config.yaml | 1vsAll-kl |
TransE | 0.354 | 0.219 | 0.4218 | 0.634 | config.yaml | NegSamp-kl |
ComplEx | 0.465 | 0.372 | 0.5038 | 0.646 | config.yaml | 1vsAll-kl |
ConvE | 0.444 | 0.343 | 0.4926 | 0.635 | config.yaml | 1vsAll-kl |
TuckER | 0.444 | 0.339 | 0.4975 | 0.638 | config.yaml | KvsAll-kl |
MRR | Hits@1 | Hits@3 | Hits@10 | Config file | Pretrained model | |
---|---|---|---|---|---|---|
RESCAL | 0.317 | 0.244 | 0.3477 | 0.456 |