Geometric region embeddings for knowledge graph subsumption (Python bindings for the subsume Rust crate)
Project description
subsume-python
Python bindings for subsume: geometric region embeddings for knowledge graph subsumption.
Install
pip install subsumer
From source
pip install maturin
cd subsume-python
maturin develop
Quick Start
Box embeddings
import subsumer
box_a = subsumer.BoxEmbedding([0.0, 0.0], [1.0, 1.0], 1.0)
box_b = subsumer.BoxEmbedding([0.2, 0.2], [0.8, 0.8], 1.0)
prob = box_a.containment_prob(box_b)
print(f"P(B inside A) = {prob:.4f}")
Training box embeddings on a knowledge graph
import subsumer
# From string triples (head contains tail)
triples = [("animal", "hypernym", "dog"), ("animal", "hypernym", "cat")]
trainer, ids = subsumer.BoxEmbeddingTrainer.from_triples(triples)
result = trainer.fit(ids)
print(f"MRR: {result['mrr']:.3f}")
# With full configuration
config = subsumer.TrainingConfig(dim=32, epochs=50, learning_rate=0.01)
trainer, ids = subsumer.BoxEmbeddingTrainer.from_triples(triples, config=config)
result = trainer.fit(ids)
# From files (WN18RR format: train.txt, valid.txt, test.txt)
train, val, test, ents, rels = subsumer.load_dataset("data/wn18rr")
config = subsumer.TrainingConfig(dim=32, epochs=50, learning_rate=0.01)
trainer = subsumer.BoxEmbeddingTrainer.from_config(config)
result = trainer.fit(train, val_triples=val, num_entities=len(ents))
print(f"MRR: {result['mrr']:.3f}, Hits@10: {result['hits_at_10']:.3f}")
# Score individual triples after training
score = trainer.predict(head_id=0, relation_id=0, tail_id=1)
# Score all entities as tails
scores = trainer.score_tails(head_id=0, relation_id=0)
# Export learned embeddings as numpy arrays
entity_ids, min_bounds, max_bounds = trainer.export_embeddings()
# min_bounds and max_bounds are (n_entities, dim) numpy arrays
Cone embeddings
import subsumer
# ConE-style cone embeddings for DAG / partial-order relations
triples = [("animal", "hypernym", "dog"), ("animal", "hypernym", "cat")]
trainer, ids = subsumer.ConeEmbeddingTrainer.from_triples(triples)
result = trainer.fit(ids)
print(f"MRR: {result['mrr']:.3f}")
# Evaluate on separate test set
test_result = trainer.evaluate(test_triples)
# Export learned cones (axes + apertures) as numpy arrays
entity_ids, axes, apertures = trainer.export_embeddings()
# axes and apertures are (n_entities, dim) numpy arrays
License
MIT OR Apache-2.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file subsumer-0.7.3.tar.gz.
File metadata
- Download URL: subsumer-0.7.3.tar.gz
- Upload date:
- Size: 296.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1904cddb29b13a50e1c9d9b90d7665c35f058cc76eb560249dc45ad9b11b436f
|
|
| MD5 |
678827b29afc93bd6f89f69cb6cde2bb
|
|
| BLAKE2b-256 |
0df7ba157a183976df90a87a2b992d402bdcc547c681e9f45ad834878ee2b97c
|
Provenance
The following attestation bundles were made for subsumer-0.7.3.tar.gz:
Publisher:
python-publish.yml on arclabs561/subsume
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
subsumer-0.7.3.tar.gz -
Subject digest:
1904cddb29b13a50e1c9d9b90d7665c35f058cc76eb560249dc45ad9b11b436f - Sigstore transparency entry: 1155183756
- Sigstore integration time:
-
Permalink:
arclabs561/subsume@3497df3fabe2488891bd4558e2d626b3cce0c618 -
Branch / Tag:
refs/tags/py-v0.7.3 - Owner: https://github.com/arclabs561
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@3497df3fabe2488891bd4558e2d626b3cce0c618 -
Trigger Event:
push
-
Statement type:
File details
Details for the file subsumer-0.7.3-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: subsumer-0.7.3-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 544.2 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6d6d0fc2de7b33a99e5dcafddf6dc4c0b0b22be8406545b2d216a43d809f9c8
|
|
| MD5 |
ad5e095ec181aabab16c6fe89e40e95b
|
|
| BLAKE2b-256 |
947cbffb050f07cfe56468a3a2483146b12cd075e10dcf5e327b3120752085a0
|
Provenance
The following attestation bundles were made for subsumer-0.7.3-cp314-cp314-macosx_11_0_arm64.whl:
Publisher:
python-publish.yml on arclabs561/subsume
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
subsumer-0.7.3-cp314-cp314-macosx_11_0_arm64.whl -
Subject digest:
f6d6d0fc2de7b33a99e5dcafddf6dc4c0b0b22be8406545b2d216a43d809f9c8 - Sigstore transparency entry: 1155183760
- Sigstore integration time:
-
Permalink:
arclabs561/subsume@3497df3fabe2488891bd4558e2d626b3cce0c618 -
Branch / Tag:
refs/tags/py-v0.7.3 - Owner: https://github.com/arclabs561
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@3497df3fabe2488891bd4558e2d626b3cce0c618 -
Trigger Event:
push
-
Statement type:
File details
Details for the file subsumer-0.7.3-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: subsumer-0.7.3-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 453.0 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f06082d04c63014429209331e0cab08f51e08c3a90ad05c35128ed59d031871
|
|
| MD5 |
f8a219764282446da6c9b77ec08365c8
|
|
| BLAKE2b-256 |
15c72c718215b46bd480976174fd19bde08da7504afbb80c42afca50e922afd4
|
Provenance
The following attestation bundles were made for subsumer-0.7.3-cp312-cp312-win_amd64.whl:
Publisher:
python-publish.yml on arclabs561/subsume
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
subsumer-0.7.3-cp312-cp312-win_amd64.whl -
Subject digest:
6f06082d04c63014429209331e0cab08f51e08c3a90ad05c35128ed59d031871 - Sigstore transparency entry: 1155183763
- Sigstore integration time:
-
Permalink:
arclabs561/subsume@3497df3fabe2488891bd4558e2d626b3cce0c618 -
Branch / Tag:
refs/tags/py-v0.7.3 - Owner: https://github.com/arclabs561
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@3497df3fabe2488891bd4558e2d626b3cce0c618 -
Trigger Event:
push
-
Statement type:
File details
Details for the file subsumer-0.7.3-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: subsumer-0.7.3-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 614.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b07de653e5ad6c12146e8e8144b03be047bab67331cfd8bd39e64de855b0077
|
|
| MD5 |
3ea0aee93526a924bad565d1273901ad
|
|
| BLAKE2b-256 |
206a1577f345eb488e01a94f10b15d897d75afef17dcd3afa4695139f33fa619
|
Provenance
The following attestation bundles were made for subsumer-0.7.3-cp312-cp312-manylinux_2_34_x86_64.whl:
Publisher:
python-publish.yml on arclabs561/subsume
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
subsumer-0.7.3-cp312-cp312-manylinux_2_34_x86_64.whl -
Subject digest:
0b07de653e5ad6c12146e8e8144b03be047bab67331cfd8bd39e64de855b0077 - Sigstore transparency entry: 1155183765
- Sigstore integration time:
-
Permalink:
arclabs561/subsume@3497df3fabe2488891bd4558e2d626b3cce0c618 -
Branch / Tag:
refs/tags/py-v0.7.3 - Owner: https://github.com/arclabs561
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@3497df3fabe2488891bd4558e2d626b3cce0c618 -
Trigger Event:
push
-
Statement type: