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.2.tar.gz (352.5 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.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

subsumer-0.8.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

subsumer-0.8.2-cp39-abi3-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.9+Windows x86-64

subsumer-0.8.2-cp39-abi3-manylinux_2_39_x86_64.whl (2.1 MB view details)

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

subsumer-0.8.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

subsumer-0.8.2-cp39-abi3-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

subsumer-0.8.2-cp39-abi3-macosx_10_12_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: subsumer-0.8.2.tar.gz
  • Upload date:
  • Size: 352.5 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.2.tar.gz
Algorithm Hash digest
SHA256 bdfcb7f4d2c1a74e00d520c3edb76c474238cd4f57768961ec78d2185e7b4709
MD5 21d09844c49ab39c1d5b51c09326ccdb
BLAKE2b-256 6eb5a2a6f457c3960c7d4f066b089c935ea6e2cc9f0ef8bb8b10d99f89a201ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.2.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.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2cb36753e7149b5cab069d7dad802a9034b23cd6fd15bf3869b57871c57e566f
MD5 f4b0289ef654ce0d3094614bf56d0103
BLAKE2b-256 23ddd3e46ca9d35e848fb1d5603312a24feaa6c462cb9371acd1d849c4ce8b41

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.2-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.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0ec5f33d2d006350cf0cc9fdbbffac7319b7d6e1a7f85eb2d5884e552d83eadd
MD5 7237afa66a391f91b547e03fd915dc4c
BLAKE2b-256 27625580ee385ce24c07f54b885209c7291734ca9d6e74a40486e351527dcf30

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.2-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.2-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: subsumer-0.8.2-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • 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.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f727df2901590344b0d35ed5daca070417ec7c249b0a40dec4b3cebcd82ad778
MD5 82a6ad961f93a4a9361a76a61c53ace2
BLAKE2b-256 a0e6899bd48fbbb9e2edb0ad237a6222be7e61514bab75d24d560a5e383595fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.2-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.2-cp39-abi3-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.2-cp39-abi3-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 b229f0571704210b86626ab5adcdd402e21140ec58556135b28345f77da5161a
MD5 650e3eb5567360b5ac46ad0e2e9a39b3
BLAKE2b-256 ece5179fc6c0062ebcfb27b8bb61f70afeae8e0781602617a6e8235c816b6b90

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.2-cp39-abi3-manylinux_2_39_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.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3ff5b0db8bb1413666aba324338118be403af7ae605643a50aca46e0f23640f9
MD5 fd4a0c7f778194235182bbad585daed9
BLAKE2b-256 9cec01f3f47dc9f7f3be06ca5c1280ebc7c46c8b819e7b88e13429ba928d9d1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.2-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.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7be6e86bd5fa35887ed2b6c8fac503c451762dd83f18cc124aa7e7bb21d3698b
MD5 823804c95481d8483a95ce6ebf3b26a9
BLAKE2b-256 cd288cd2e3f8236aa240108f54b705e0defaab63dbb6fc1983016f1e037204d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.2-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.2-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for subsumer-0.8.2-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e879b767ad831814f75ecf5e5afa61baf1c2bb6c8776f388344ab5c880ded7db
MD5 89877dbf1ada82c7323775f58443f688
BLAKE2b-256 2a6dc3ede0f19c76abb40abe77cd87c81f95a8f69a7baf2bde358762eb99f55c

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.8.2-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