Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
tags:
|
| 4 |
+
- knowledge-graph
|
| 5 |
+
- link-prediction
|
| 6 |
+
- ComplEx
|
| 7 |
+
- CoDEx
|
| 8 |
+
- LibKGE
|
| 9 |
+
- wikidata
|
| 10 |
+
datasets:
|
| 11 |
+
- CoDEx-S
|
| 12 |
+
metrics:
|
| 13 |
+
- mrr
|
| 14 |
+
- hits@1
|
| 15 |
+
- hits@10
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# CoDEx-S ComplEx — Winner Model
|
| 19 |
+
|
| 20 |
+
Knowledge graph link prediction on **CoDEx-S** using **ComplEx** embeddings,
|
| 21 |
+
trained with the [LibKGE](https://github.com/uma-pi1/kge) framework.
|
| 22 |
+
Reproduces and slightly improves results from the
|
| 23 |
+
[CoDEx paper (EMNLP 2020)](https://arxiv.org/pdf/2009.07810.pdf).
|
| 24 |
+
|
| 25 |
+
## Results (Validation Set — Filtered with Test)
|
| 26 |
+
|
| 27 |
+
| Metric | This Model | Paper |
|
| 28 |
+
|---------|-----------|-------|
|
| 29 |
+
| MRR | 0.474 | 0.465 |
|
| 30 |
+
| Hits@1 | 0.377 | 0.372 |
|
| 31 |
+
| Hits@3 | 0.522 | 0.504 |
|
| 32 |
+
| Hits@10 | 0.664 | 0.646 |
|
| 33 |
+
|
| 34 |
+
Training stopped early at epoch **345** via early stopping.
|
| 35 |
+
|
| 36 |
+
## Dataset — CoDEx-S
|
| 37 |
+
|
| 38 |
+
| | Count |
|
| 39 |
+
|-|-------|
|
| 40 |
+
| Entities | 2,034 |
|
| 41 |
+
| Relations | 42 |
|
| 42 |
+
| Train triples | 32,888 |
|
| 43 |
+
| Valid triples | 1,827 |
|
| 44 |
+
| Test triples | 1,828 |
|
| 45 |
+
|
| 46 |
+
## Hyperparameters
|
| 47 |
+
|
| 48 |
+
| Parameter | Value |
|
| 49 |
+
|-----------|-------|
|
| 50 |
+
| Embedding dim | 512 |
|
| 51 |
+
| Optimizer | Adam |
|
| 52 |
+
| Learning rate | 0.000339 |
|
| 53 |
+
| Batch size | 1024 |
|
| 54 |
+
| Max epochs | 400 |
|
| 55 |
+
| Training type | 1vsAll |
|
| 56 |
+
| Loss | KL divergence |
|
| 57 |
+
| LR scheduler | ReduceLROnPlateau |
|
| 58 |
+
| Entity dropout | 0.079 |
|
| 59 |
+
| Relation dropout | 0.056 |
|
| 60 |
+
|
| 61 |
+
## Load in Your App
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
import sys
|
| 65 |
+
sys.path.insert(0, r"C:/path/to/codex/kge")
|
| 66 |
+
|
| 67 |
+
from huggingface_hub import hf_hub_download
|
| 68 |
+
from kge.model import KgeModel
|
| 69 |
+
from kge.util.io import load_checkpoint
|
| 70 |
+
import torch
|
| 71 |
+
|
| 72 |
+
# Download from Hugging Face
|
| 73 |
+
path = hf_hub_download(
|
| 74 |
+
repo_id="aaryaupadhya20/codex-s-complex-winner",
|
| 75 |
+
filename="winner_model.pt"
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
# Load model
|
| 79 |
+
checkpoint = load_checkpoint(path, device="cpu")
|
| 80 |
+
winner_model = KgeModel.create_from(checkpoint)
|
| 81 |
+
winner_model.eval()
|
| 82 |
+
|
| 83 |
+
print("winner_model ready!")
|
| 84 |
+
|
| 85 |
+
# Score a triple using entity/relation integer indices
|
| 86 |
+
s = torch.tensor([0]) # head entity index
|
| 87 |
+
p = torch.tensor([1]) # relation index
|
| 88 |
+
o = torch.tensor([2]) # tail entity index
|
| 89 |
+
|
| 90 |
+
score = winner_model.score_spo(s, p, o, direction="o")
|
| 91 |
+
print("Score:", score.item())
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
## Citation
|
| 95 |
+
|
| 96 |
+
```bibtex
|
| 97 |
+
@inproceedings{safavi-koutra-2020-codex,
|
| 98 |
+
title = "CoDEx: A Comprehensive Knowledge Graph Completion Benchmark",
|
| 99 |
+
author = "Safavi, Tara and Koutra, Danai",
|
| 100 |
+
booktitle = "Proceedings of EMNLP 2020",
|
| 101 |
+
year = "2020",
|
| 102 |
+
url = "https://arxiv.org/pdf/2009.07810.pdf"
|
| 103 |
+
}
|
| 104 |
+
```
|