Skip to main content

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

EL++ ontology embedding

import subsumer

# Load normalized EL++ axioms (GALEN, Gene Ontology, Anatomy formats)
axioms = subsumer.load_el_axioms("data/go_normalized.tsv")
print(f"Classes: {axioms['num_classes']}, Roles: {axioms['num_roles']}")
print(f"NF2 (C ⊑ D): {len(axioms['nf2'])} axioms")

# Compute inclusion loss: how much box A fails to fit inside box B
loss = subsumer.el_inclusion_loss(
    center_a=[0.0, 0.0], offset_a=[0.5, 0.5],
    center_b=[0.0, 0.0], offset_b=[2.0, 2.0],
)
print(f"Inclusion loss: {loss:.4f}")  # 0.0 (A inside B)

# Compute intersection loss: C1 AND C2 should be inside D
loss = subsumer.el_intersection_loss(
    center_c1=[0.0], offset_c1=[2.0],
    center_c2=[1.0], offset_c2=[2.0],
    center_d=[0.5], offset_d=[2.0],
)
print(f"Intersection loss: {loss:.4f}")  # 0.0 (intersection fits)

License

MIT OR Apache-2.0

Release files for subsumer 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for subsumer 0.9.0
File Size Uploaded
subsumer-0.9.0.tar.gz 475.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for subsumer 0.9.0
File
subsumer-0.9.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
subsumer-0.9.0-cp39-abi3-manylinux_2_34_x86_64.whl CPython 3.9 abi3 Linux glibc 2.34+ x86-64 Details
subsumer-0.9.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
subsumer-0.9.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
subsumer-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 3.6 MB

Release files / subsumer-0.9.0.tar.gz

Download URL subsumer-0.9.0.tar.gz
Size 475.5 kB
Tags Source
SHA-256 checksum
How to use checksums
251060ae5180ca6134ab731e070d094a27233137940ada5f247fcd9116bc01b5
BLAKE2b-256 checksum
How to use checksums
d41a897aa8a55ed4dcd23c36304b45c99bc440a0cc6b26384c707b322019cae0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.

Transparency log

Release files / subsumer-0.9.0-cp39-abi3-win_amd64.whl

Download URL subsumer-0.9.0-cp39-abi3-win_amd64.whl
Size 521.2 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
386bdaaf4c62585e654e265fdaf6868269345a44cffc9b96cae45846cc2c60fb
BLAKE2b-256 checksum
How to use checksums
acb7b381d64e6b219ee2928da3b193a0213eac9aba529286c0b306a366308a90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.

Transparency log

Release files / subsumer-0.9.0-cp39-abi3-manylinux_2_34_x86_64.whl

Download URL subsumer-0.9.0-cp39-abi3-manylinux_2_34_x86_64.whl
Size 690.4 kB
Tags CPython 3.9 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
05adf0a69e11763a5bc154b01b4428f18e6f882dbfc945e3d72784275af726b7
BLAKE2b-256 checksum
How to use checksums
9b14fd8cf5c7b8e28fc460cc0355a91f3f7b340ae2766d79e4526cccbb1e0380
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.

Transparency log

Release files / subsumer-0.9.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL subsumer-0.9.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 655.7 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
b52e9adc440b24c78fd10070db6b3765d092b483607ee885dc5e2ce878c16b2f
BLAKE2b-256 checksum
How to use checksums
6bb14b8a984c9dbcd98b2539179e5ce2ba67a6a2796be694d84796b9eca0ba37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.

Transparency log

Release files / subsumer-0.9.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL subsumer-0.9.0-cp39-abi3-macosx_11_0_arm64.whl
Size 606.7 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
af85d9f0be9ce1ac302a43bccbaaacd314e35fc92897bb605daaa5d96c78d7b5
BLAKE2b-256 checksum
How to use checksums
ae4a20aac9cf1c42c2de91ff9e057365ba9adc92990d5def2fef1a5f0402dd89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.

Transparency log

Release files / subsumer-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL subsumer-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 628.2 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
7e03593f56a79e4f4c02665de05d72099eb2a7f47a02dd844d35912e7bfd168a
BLAKE2b-256 checksum
How to use checksums
2797da50a61ba0edbeb8b32070774130d1ce7056dccbcfa202c28351660629e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.0 This release

6 release files

0.8.2

8 release files

0.8.1

8 release files

0.8.0

8 release files

0.7.5

8 release files

0.7.3

4 release files

0.7.2

4 release files

0.7.1

4 release files

0.7.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page