Multimodal contrastive learning aligning text and omics embeddings via sentence-transformers.
Project description
mmcontext
Multimodal contrastive learning aligning text and omics embeddings via sentence-transformers.
mmcontext enables joint embedding spaces where natural-language descriptions and biological data (single-cell gene expression) can be compared directly. Built on the sentence-transformers v5.4+ multimodal API.
Paper
mmcontext is described in detail in our paper: Jonatan Menger, Sonia Maria Krissmer, Clemens Kreutz, Harald Binder, Maren Hackenberg, mmContext: an open framework for multimodal contrastive learning of omics and text data, Bioinformatics, Volume 42, Issue 6, June 2026, btag338, https://doi.org/10.1093/bioinformatics/btag338 If you use mmcontext in your research, please cite our work.
Installation
pip install mmcontext
Or install from source with development dependencies:
git clone https://github.com/mengerj/mmcontext.git
cd mmcontext
pip install -e ".[dev,test,eval,train]"
Quick Start
Using a Pre-trained Model
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("jo-mengr/mmcontext-pubmedbert-gs10k", trust_remote_code=True)
# Encode text queries
text_embeddings = model.encode(["CD4+ T cell", "B cell precursor"])
Pre-trained models are available on Hugging Face under the jo-mengr organization.
See the pretrained inference tutorial for a complete guide.
Building a Pipeline
from mmcontext.embed import build_pipeline
pipeline = build_pipeline(
text_model="microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract",
omics_dim=512, # dimension of your omics vectors
shared_dim=256, # joint embedding space dimension
)
Evaluation
from mmcontext.eval import get
LabelSimilarity = get("LabelSimilarity")
evaluator = LabelSimilarity(similarity="cosine")
result = evaluator.compute(
omics_embeddings=omics_emb,
label_embeddings=label_emb,
query_labels=labels,
true_labels=true_labels,
label_key="cell_type",
)
See the evaluate model 2.0 notebook for a complete evaluation workflow.
Architecture
mmcontext 2.0 uses the sentence-transformers module pipeline pattern:
Input -> MMContextModule -> AdapterModule -> Pooling -> Normalize
The MMContextModule handles both text (tokenize -> AutoModel) and omics (VectorStore lookup) modalities. The AdapterModule projects omics vectors into the text model's embedding space.
Data is stored in AnnData format (.h5ad/zarr), with a memory-efficient VectorStore for runtime omics lookups.
Multi-Model Benchmarking
For systematic comparisons across multiple models and datasets, see the companion repository: mmcontext-benchmark.
Dataset Preparation
To prepare training datasets from AnnData objects, see adata-hf-datasets.
Contributing
Contributions and suggestions are very welcome! Please open an issue to propose enhancements, report bugs, or ask questions.
Citation
@article{menger2026mmcontext,
title={mmContext: an open framework for multimodal contrastive learning of omics and text data},
author={Menger, Jonatan and Krissmer, Sonia Maria and Kreutz, Clemens and Binder, Harald and Hackenberg, Maren},
journal={Bioinformatics},
volume={42},
number={6},
pages={btag338},
year={2026},
publisher={Oxford University Press}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mmcontext-2.0.1.tar.gz.
File metadata
- Download URL: mmcontext-2.0.1.tar.gz
- Upload date:
- Size: 200.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30fd06ce605ce565c7dc3b57a07d40c97b75e9759b0f744dd73f8a250848a4f8
|
|
| MD5 |
929277a5a8bd7ac8fc6754c4c4b95086
|
|
| BLAKE2b-256 |
f2874274913881302d78cf93e5410bb5d4881f1ea38bfd0015217a21095c9b2d
|
Provenance
The following attestation bundles were made for mmcontext-2.0.1.tar.gz:
Publisher:
release.yaml on mengerj/mmcontext
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mmcontext-2.0.1.tar.gz -
Subject digest:
30fd06ce605ce565c7dc3b57a07d40c97b75e9759b0f744dd73f8a250848a4f8 - Sigstore transparency entry: 2058272221
- Sigstore integration time:
-
Permalink:
mengerj/mmcontext@4d96287b1a8ca62f2f8a194d121c4b9b3aa32d08 -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/mengerj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@4d96287b1a8ca62f2f8a194d121c4b9b3aa32d08 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mmcontext-2.0.1-py3-none-any.whl.
File metadata
- Download URL: mmcontext-2.0.1-py3-none-any.whl
- Upload date:
- Size: 175.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91960c4cb31a9a67b127ff370b057bd82b022d7b3d7b6851247bb23d0b04abda
|
|
| MD5 |
94d24bc6f4d206a4c8dfa64c4454ed44
|
|
| BLAKE2b-256 |
c3d98c029a25f6b825e5be8e0f1346b126cf978cd7ed6e8b5fac7c860af00989
|
Provenance
The following attestation bundles were made for mmcontext-2.0.1-py3-none-any.whl:
Publisher:
release.yaml on mengerj/mmcontext
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mmcontext-2.0.1-py3-none-any.whl -
Subject digest:
91960c4cb31a9a67b127ff370b057bd82b022d7b3d7b6851247bb23d0b04abda - Sigstore transparency entry: 2058272479
- Sigstore integration time:
-
Permalink:
mengerj/mmcontext@4d96287b1a8ca62f2f8a194d121c4b9b3aa32d08 -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/mengerj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@4d96287b1a8ca62f2f8a194d121c4b9b3aa32d08 -
Trigger Event:
release
-
Statement type: