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.9.0.tar.gz (475.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.9.0-cp39-abi3-win_amd64.whl (521.2 kB view details)

Uploaded CPython 3.9+Windows x86-64

subsumer-0.9.0-cp39-abi3-manylinux_2_34_x86_64.whl (690.4 kB view details)

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

subsumer-0.9.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (655.7 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

subsumer-0.9.0-cp39-abi3-macosx_11_0_arm64.whl (606.7 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

subsumer-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl (628.2 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for subsumer-0.9.0.tar.gz
Algorithm Hash digest
SHA256 251060ae5180ca6134ab731e070d094a27233137940ada5f247fcd9116bc01b5
MD5 1c3aa4266f75a06e02c45eaabdee18ff
BLAKE2b-256 d41a897aa8a55ed4dcd23c36304b45c99bc440a0cc6b26384c707b322019cae0

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for subsumer-0.9.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 386bdaaf4c62585e654e265fdaf6868269345a44cffc9b96cae45846cc2c60fb
MD5 e37dd0286b8176ea091cfc33ca0f7213
BLAKE2b-256 acb7b381d64e6b219ee2928da3b193a0213eac9aba529286c0b306a366308a90

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsumer-0.9.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.9.0-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for subsumer-0.9.0-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 05adf0a69e11763a5bc154b01b4428f18e6f882dbfc945e3d72784275af726b7
MD5 66d3b36d6936838d9a98f962b2a14da9
BLAKE2b-256 9b14fd8cf5c7b8e28fc460cc0355a91f3f7b340ae2766d79e4526cccbb1e0380

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subsumer-0.9.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b52e9adc440b24c78fd10070db6b3765d092b483607ee885dc5e2ce878c16b2f
MD5 a2901469d9df9f2b9296ba113552e7d9
BLAKE2b-256 6bb14b8a984c9dbcd98b2539179e5ce2ba67a6a2796be694d84796b9eca0ba37

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subsumer-0.9.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af85d9f0be9ce1ac302a43bccbaaacd314e35fc92897bb605daaa5d96c78d7b5
MD5 e7a5fdb82bfd9422a0a6a7cebe12702e
BLAKE2b-256 ae4a20aac9cf1c42c2de91ff9e057365ba9adc92990d5def2fef1a5f0402dd89

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subsumer-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7e03593f56a79e4f4c02665de05d72099eb2a7f47a02dd844d35912e7bfd168a
MD5 28dde76976a7148922887fe240170f0f
BLAKE2b-256 2797da50a61ba0edbeb8b32070774130d1ce7056dccbcfa202c28351660629e2

See more details on using hashes here.

Provenance

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