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.1.tar.gz (346.4 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.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

subsumer-0.8.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

subsumer-0.8.1-cp39-abi3-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.9+Windows x86-64

subsumer-0.8.1-cp39-abi3-manylinux_2_39_x86_64.whl (2.0 MB view details)

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

subsumer-0.8.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

subsumer-0.8.1-cp39-abi3-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

subsumer-0.8.1-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.1.tar.gz.

File metadata

  • Download URL: subsumer-0.8.1.tar.gz
  • Upload date:
  • Size: 346.4 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.1.tar.gz
Algorithm Hash digest
SHA256 6fd0e901ef49e9773ab01f5f6b0f0a71781711a4fcb735dd1353647934515e3d
MD5 7dc7653474973ea8bb74307ace54c2b8
BLAKE2b-256 18c8dbabc661220d60e90ffecdf664d6164fe8666954e6ff0c821a31225ed5b0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subsumer-0.8.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9f666f68776975843c6481f9d2fba875339a7f33d797e0f56be321a9d5e67049
MD5 6cea0c186953ab3d0adba44a1b92a928
BLAKE2b-256 cbe6447113727544cfa704149c012db1490a3430325b5403a408dbdd1331cbbc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subsumer-0.8.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f22822a0170db57f53d381f07ace828539ee2889930ea091022c94c258f065df
MD5 fe3d900100f99163a60cd24956e45122
BLAKE2b-256 f5e8fc0c6a90952bac5cd82f9b3354f5c42124d494fb22bd63e39f506fc63c53

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: subsumer-0.8.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.7 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.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 de61be28c0a12a1fc8ca43b93322c5911a12cfb9b1fca1edf6867e1c54fa36fb
MD5 c8f75fe11d4f7e4d70c44d8b50f09129
BLAKE2b-256 3d4172b3ecbbd4c62ebbba2861fe98e6054b741ed0bb0e8d05a355f6ae0977ff

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subsumer-0.8.1-cp39-abi3-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 dfa9a97b07e85e46eae6ab94e1562fc06a093c791b1dbc11231d444fdf03418c
MD5 93d7596ecfba94b972791af1015b26b9
BLAKE2b-256 1febaa788a4f61a16f77d83aef2941c3b15bab2817d4cfa928ecfe7d91c4f2e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subsumer-0.8.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1c342c935de08580ed3251d33696900800f037b1e06397898d15148178c57198
MD5 41c9b19c21da1ab716eca54ba86c6b64
BLAKE2b-256 d637949b85012ad9f31984e4391fb207702d47675092035d602cf4104a471d20

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subsumer-0.8.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 77eb3ed66d46589ca770a60e72ec0fdacfc9cca49968bdc1a50c1da850afced9
MD5 1653d5df2592dc8bfaa9eb1c3a9ddbfd
BLAKE2b-256 4b53bb70e32438ff536660039abc68b430b1e27509adb0de09a697bcd0983020

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for subsumer-0.8.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 26b1a94ece498607026701eed6fb4a3d657e1af576e817dc9647a3d01f98f141
MD5 e90ecede752b65dae625fcd756f67bcc
BLAKE2b-256 a4a348c7b8e6769fb74427718620f7e82d9d37c7ab051f62e0778ad367834724

See more details on using hashes here.

Provenance

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