Skip to main content

neembed

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

Documentation · 日本語

Status: v0.2.0 adds evaluation, epoch validation, DataLoader interoperability examples, and a reproducible Euclidean-vs-Poincaré benchmark. 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 Poincaré-ball 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 geometry scope deliberately remains the Poincaré ball.

v0.2

The v0.2 release includes:

  • Sentence Transformers as the pretrained encoder backend
  • Poincaré-ball embeddings through Geoopt
  • optional lower-dimensional tangent-space projection
  • geodesic distance
  • manifold-aware multiple-negatives ranking / InfoNCE-style loss
  • ordinary AdamW fine-tuning
  • encode() and distance() inference helpers
  • save_pretrained() / from_pretrained() local persistence
  • ManifoldEmbeddingEvaluator with retrieval and distance metrics
  • optional epoch-end validation in ManifoldTrainer
  • ordinary PyTorch DataLoader interoperability example
  • a reproducible Euclidean-vs-Poincaré engineering benchmark

Detailed behavior, assumptions, and API signatures live in the documentation.

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. See the Training guide for the objective and batching details.

Documentation

The full guide is hosted on Read the Docs:

Examples and validation

Run the end-to-end example:

python examples/train_poincare.py

License

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

Metadata

Release files for neembed-geoopt 0.2.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.2.0
File Size Uploaded
neembed_geoopt-0.2.0.tar.gz 20.4 kB Details

Built distribution (wheel)

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

Total release size: 31.0 kB

Release files / neembed_geoopt-0.2.0.tar.gz

Download URL neembed_geoopt-0.2.0.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
74d7b57d801ad8f138c8ca8b62590da775dfa2a2689500cd081414ec9afe0266
BLAKE2b-256 checksum
How to use checksums
53ea4e5fc2090d004b486625991f8ef0c40d4598737c2fbebc0c0271bbc5282b
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 11, 2026.

Transparency log

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

Download URL neembed_geoopt-0.2.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4564f343895086627ad22bf184cb7c15efded6ed5a92814be43a11b4ce497519
BLAKE2b-256 checksum
How to use checksums
2d03887b94cf4992ec884f1a9934c147779950ce07deaec4fa2b54025281a437
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 11, 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

0.4.0

2 release files

0.3.0

2 release files

This release

0.2.0 This release

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