Skip to main content

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

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

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

subsumer-0.8.0.tar.gz (335.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

subsumer-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (641.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

subsumer-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (641.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

subsumer-0.8.0-cp39-abi3-win_amd64.whl (506.6 kB view details)

Uploaded CPython 3.9+Windows x86-64

subsumer-0.8.0-cp39-abi3-manylinux_2_34_x86_64.whl (668.9 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

subsumer-0.8.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (642.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

subsumer-0.8.0-cp39-abi3-macosx_11_0_arm64.whl (604.9 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

subsumer-0.8.0-cp39-abi3-macosx_10_12_x86_64.whl (624.5 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file subsumer-0.8.0.tar.gz.

File metadata

  • Download URL: subsumer-0.8.0.tar.gz
  • Upload date:
  • Size: 335.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for subsumer-0.8.0.tar.gz
Algorithm Hash digest
SHA256 7a8fe5d760e74040fc6f4aac41342113e59a4b52de63bdeb9c385887c4bd6fdf
MD5 b96dfa55941b5b753a983a7cc4aae0b8
BLAKE2b-256 96bc3de9fb1513e6ae7e9c3c10f8904d3f3f92048996802ee65fd95f3b7d8cd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.0.tar.gz:

Publisher: python-publish.yml on arclabs561/subsume

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsumer-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 357122ec4f01e1b0aa11aaacc13a004abb8950e20760eecad248aa1f353092f9
MD5 96a1e2f7c2bfec6a86895f00341d4f14
BLAKE2b-256 d5d34387d84b8f44dad97ceeacb8abecc0d4feea8335fe88099ad1fd21dfbc9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: python-publish.yml on arclabs561/subsume

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsumer-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 69516a12545f816a541432ece2cb208c6ae95819adfcc2efb4e764b73a03ae25
MD5 80a97effa5d790ea98e46dc225cc17e4
BLAKE2b-256 10401e6db03b306ec8025f968df80f2138d6f4e78ac31a08421d7040f55da855

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: python-publish.yml on arclabs561/subsume

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsumer-0.8.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: subsumer-0.8.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 506.6 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for subsumer-0.8.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4ae3b0963db3b3f81680aa2f2fa88c53d90409c0a3eb341e6167687be14c4de6
MD5 4a67b7b0e03f1f8643e63c148b0fdc93
BLAKE2b-256 6a80050e856d29755410ae1f3077fcea88a1bdeefbb2d937d361a7ffc84c8f18

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.0-cp39-abi3-win_amd64.whl:

Publisher: python-publish.yml on arclabs561/subsume

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsumer-0.8.0-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.0-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bea920c6c3182bb372a48373eb3a3c33e41f371a34baeff452e795ff7dd21cad
MD5 5239eab1034ce8365cfeae28846760ce
BLAKE2b-256 3b1917997f2a0d8908e1d708d248279aa6dd83e7d94c7aaefe7edba31b89a909

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.0-cp39-abi3-manylinux_2_34_x86_64.whl:

Publisher: python-publish.yml on arclabs561/subsume

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsumer-0.8.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 24401c2caca3d554e1fa7781bb4db6047176ebff06429e82aee485956595a7d8
MD5 a65f1e8c163416cdabbada03f62a0de4
BLAKE2b-256 a21152443a2d304fdec6cd796fc5f28495f744b367c375d7ef0e0808db002afb

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: python-publish.yml on arclabs561/subsume

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsumer-0.8.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 02295d034aeeed18f3016e04f698818fe53b5006085f20f2b46f1a7be7f51380
MD5 11a655e80e88412d67b7372e8a683123
BLAKE2b-256 0b892596e63fa19aa7901ce11340ffed1a90d65e05a66c17d9b7efef1862034c

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on arclabs561/subsume

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsumer-0.8.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3bda51c6a93bf6f728863854195f47e6ee25f892ba50af71d0e0b746439c5047
MD5 8e55d2434b3154f6ea876f28b8c36098
BLAKE2b-256 c37a81f90db06de877a2e1da56cabd3f66878c2067c60987877ed51b456c9ffa

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: python-publish.yml on arclabs561/subsume

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page