neembed
Fine-tune pretrained sentence embedding models in non-Euclidean spaces with Geoopt.
Status: v0.3.0 adds Lorentz / Hyperboloid embeddings as the second supported hyperbolic geometry, geometry-consistency regressions, a Lorentz train/evaluate example, and a reproducible Euclidean-vs-Poincaré-vs-Lorentz engineering 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 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 save/load workflow.
v0.3
The v0.3 release includes:
- 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
- manifold-aware multiple-negatives ranking / InfoNCE-style loss
- ordinary
AdamWfine-tuning encode()anddistance()inference helperssave_pretrained()/from_pretrained()local persistence for both manifoldsManifoldEmbeddingEvaluatorwith retrieval and distance metrics- optional epoch-end validation in
ManifoldTrainer - ordinary PyTorch
DataLoaderinteroperability example - Poincaré–Lorentz geometry-consistency regression tests
- a runnable Lorentz train/evaluate/inference example
- a reproducible Euclidean-vs-Poincaré-vs-Lorentz 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, and the Architecture guide for Poincaré/Lorentz dimension, curvature, and precision semantics.
Documentation
The full guide is hosted on Read the Docs:
- Installation
- Quick Start
- Architecture
- Training
- Evaluation
- Inference
- Saving and Loading
- API Reference
Examples and validation
Run the geometry-specific examples from the repository root:
python examples/train_poincare.py
python examples/train_lorentz.py
- examples/train_poincare.py contains the minimal Poincaré workflow.
- examples/train_lorentz.py shows the same train/evaluate/inference workflow with Lorentz geometry and makes the intrinsic-vs-ambient dimension difference explicit.
- examples/train_dataloader.py shows ordinary PyTorch
DataLoadertraining and epoch validation. - experiments/README.md documents the reproducible Euclidean-vs-Poincaré-vs-Lorentz engineering benchmark and its interpretation limits.
License
neembed is released under the MIT License. Third-party dependencies retain their own licenses.
Metadata
Release files for neembed-geoopt 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| neembed_geoopt-0.3.0.tar.gz | 24.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| neembed_geoopt-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.9 kB
Release files / neembed_geoopt-0.3.0.tar.gz
| Download URL | neembed_geoopt-0.3.0.tar.gz |
|---|---|
| Size | 24.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
98e87371cfb500c548cb0ddc129267a189f0eef061ebcf911378dfb89c478def
|
|
BLAKE2b-256 checksum How to use checksums |
69387c7b9c4d9b1e5a9e1cd4d1b7b1684760a86dffea398f38be99754dccbb61
|
| 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 logRelease files / neembed_geoopt-0.3.0-py3-none-any.whl
| Download URL | neembed_geoopt-0.3.0-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bab894aeb7c20cb193f2af5d3c8cf4cc188d40d37c4bc8be965aaf1a812b2419
|
|
BLAKE2b-256 checksum How to use checksums |
9487b6150440b2c0300519267aba7e3be2766981cdc352b56a471d165f023ad2
|
| 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