tranz
Point-embedding knowledge graph completion: TransE, RotatE, ComplEx, DistMult.
Train on any triple file, export embeddings, predict missing links. 1-N scoring with BCE loss for fast convergence.
[]
= "0.3.1"
Dual-licensed under MIT or Apache-2.0.
Models
| Model | Scoring function | Space | Reference |
|---|---|---|---|
| TransE | ||h + r - t|| |
Real | Bordes et al., 2013 |
| RotatE | ||h * r - t|| |
Complex | Sun et al., 2019 |
| ComplEx | Re(h * r * conj(t)) |
Complex | Trouillon et al., 2016 |
| DistMult | h * r * t |
Real | Yang et al., 2015 |
Quick start
Install with cargo install tranz --features candle.
# Train with 1-N scoring (recommended)
# Train with negative sampling (classic)
# Predict from saved embeddings
Benchmark: WN18RR
| Model | Mode | Dim | Epochs | MRR | H@1 | H@10 |
|---|---|---|---|---|---|---|
| ComplEx | 1-N + softmax CE | 50 | 10 | 0.361 | 0.354 | 0.372 |
| DistMult | 1-N + softmax CE | 50 | 10 | 0.298 | 0.269 | 0.347 |
| TransE | neg. sampling (SANS) | 100 | 100 | 0.156 | 0.002 | 0.421 |
1-N scoring with softmax cross-entropy converges much faster than negative sampling. Published ComplEx MRR on WN18RR is ~0.47 at convergence (dim=2000).
Library usage
use ;
use load_dataset;
use evaluate_link_prediction;
// Load dataset
let ds = load_dataset.unwrap;
let mut interned = ds.into_interned;
interned.add_reciprocals;
// Create model and query
let model = new;
let top10 = model.top_k_tails;
// Evaluate
let metrics = evaluate_link_prediction;
Generic triple loading
use load_triples;
let ds = load_triples.unwrap;
let ds = ds.split; // 80/10/10
let interned = ds.into_interned;
Embedding export
use ;
// Export to w2v TSV
export_embeddings.unwrap;
// Flat f32 matrix for FAISS/Qdrant
let flat: = flatten_matrix;
Training (requires candle feature)
Two training modes:
1-N scoring (recommended): scores all entities per query via matmul + BCE loss. Faster convergence, no negative sampling noise.
Negative sampling (classic): samples k negatives per positive with self-adversarial weighting (SANS).
use ;
let config = TrainConfig ;
let result = train.unwrap;
Companion to subsume
subsume embeds entities as geometric regions (boxes, cones) where containment encodes subsumption. tranz embeds entities as points where distance/similarity encodes relational facts.
- subsume: ontology completion, taxonomy expansion, logical query answering
- tranz: link prediction, relation extraction, knowledge base completion