Skip to main content

neembed

Fine-tune pretrained sentence embedding models in non-Euclidean spaces with Geoopt.

Documentation · 日本語

Status: The latest tagged / PyPI release is v0.4.0. It adds opt-in learnable curvature, trainable manifold prototypes, a hierarchy-aware objective, caller-supplied Riemannian optimization for manifold-valued parameters, and a learnable-structure regression example while preserving the fixed-curvature model-only path. The API remains intentionally small and may still evolve before a stable 1.0 release.

neembed is a lightweight integration layer between pretrained Sentence Transformer models and manifold-valued representations. It keeps the pretrained encoder intact, optionally projects its Euclidean output, and delegates hyperbolic geometry to Geoopt.

Pretrained Sentence Encoder
        ↓
Euclidean sentence embedding
        ↓
Projection head (optional)
        ↓
Tangent-space representation
        ↓
Geoopt manifold map
        ↓
Non-Euclidean embedding

Why non-Euclidean embeddings?

Hierarchical and tree-like relations can be awkward to represent in a flat Euclidean space. Hyperbolic spaces are a natural fit for rapidly expanding structures such as:

  • taxonomies and concept hierarchies
  • knowledge graphs
  • hierarchical labels
  • tree-like semantic relations

The current API supports the Poincaré ball and Lorentz / Hyperboloid models through the same model, loss, trainer, evaluator, and sentence-model save/load workflow.

Current scope

v0.4 keeps the fixed-curvature v0.3 path backward-compatible:

  • Sentence Transformers as the pretrained encoder backend
  • Poincaré-ball and Lorentz / Hyperboloid embeddings through Geoopt
  • optional lower-dimensional tangent-space projection
  • shared public curvature semantics across the two hyperbolic models
  • geodesic distance and manifold-aware multiple-negatives ranking loss
  • ordinary AdamW fine-tuning for the model-only path
  • encode() / distance(), ManifoldEmbeddingEvaluator, DataLoader interoperability, and local save/load
  • geometry-consistency regressions and a matched Euclidean-vs-Poincaré-vs-Lorentz engineering benchmark

v0.4 also adds:

  • opt-in fixed vs learnable curvature for Poincaré and Lorentz
  • true trainable manifold-valued ManifoldPrototypes
  • ManifoldPrototypeHierarchyLoss for sentence assignments plus parent-child structure
  • an explicit caller-supplied Geoopt Riemannian optimizer path for manifold parameters
  • joint learnable-curvature / prototype training through Geoopt stabilization
  • a compact fixed-vs-learnable structure regression example

A manifold-valued output does not by itself require Riemannian optimization: encoder/projection parameters and learnable curvature are not manifold-valued points. Detailed parameter, optimizer, persistence, and numerical behavior lives in the Learnable structure guide.

Installation

pip install neembed-geoopt

The PyPI distribution is named neembed-geoopt; the Python import package remains neembed.

For development:

git clone https://github.com/t-yamsaki/neembed.git
cd neembed
pip install -e ".[dev]"

Quick start

from neembed import (
    ManifoldSentenceTransformer,
    ManifoldMultipleNegativesRankingLoss,
    ManifoldTrainer,
)

model = ManifoldSentenceTransformer(
    "sentence-transformers/all-MiniLM-L6-v2",
    manifold="poincare",
    embedding_dim=64,
    curvature=1.0,
)

loss = ManifoldMultipleNegativesRankingLoss(
    model=model,
    temperature=0.1,
)

trainer = ManifoldTrainer(model=model, loss=loss)

train_batches = [
    (["Shiba Inu", "Siamese cat"], ["dog", "cat"]),
    (["dog", "cat"], ["mammal", "feline"]),
]

trainer.fit(train_batches, epochs=1)

embeddings = model.encode(["Shiba Inu", "dog", "mammal"])
distance = model.distance(embeddings[0], embeddings[1])
print(float(distance))

Each anchor is paired with the positive at the same batch index. Because off-diagonal candidates become in-batch negatives, avoid duplicate positives within one batch. This model-only path keeps the ordinary AdamW behavior even though its outputs lie on a manifold. See the Training guide for the objective and batching details, and the Learnable structure guide before adding trainable manifold prototypes.

Documentation

The full guide is hosted on Read the Docs:

Examples and validation

Run the main references from the repository root:

python examples/train_poincare.py
python examples/train_lorentz.py
python examples/v04_learnable_structure.py

License

neembed is released under the MIT License. Third-party dependencies retain their own licenses.

Metadata

Release files for neembed-geoopt 0.4.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 neembed-geoopt 0.4.0
File Size Uploaded
neembed_geoopt-0.4.0.tar.gz 34.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for neembed-geoopt 0.4.0
File Interpreter ABI Platform
neembed_geoopt-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.1 kB

Release files / neembed_geoopt-0.4.0.tar.gz

Download URL neembed_geoopt-0.4.0.tar.gz
Size 34.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9fd40658618dd103bae8fa600bf2f6b2438c9fc3b729588ed15613e5ccdea397
BLAKE2b-256 checksum
How to use checksums
f3dd1e557541934cd7538fa330b8007ad057f65711639160ae518551f9e453d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 12, 2026.

Transparency log

Release files / neembed_geoopt-0.4.0-py3-none-any.whl

Download URL neembed_geoopt-0.4.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f456eb2926bafde4824a22be6f32e1e19cae6b9cb391cfb32c378551c8db476
BLAKE2b-256 checksum
How to use checksums
433194d9498238aeaec52399d955a2952eeb041e8c6c1fd9c09f37f6ad46cf59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 12, 2026.

Transparency log

Release history Release notifications | RSS feed

0.11.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 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