Skip to main content

Multimodal contrastive learning aligning text and omics embeddings via sentence-transformers.

Project description

mmcontext

Tests

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.

Conceptual Diagram

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mmcontext-2.0.1.tar.gz (200.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mmcontext-2.0.1-py3-none-any.whl (175.0 kB view details)

Uploaded Python 3

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

Hashes for mmcontext-2.0.1.tar.gz
Algorithm Hash digest
SHA256 30fd06ce605ce565c7dc3b57a07d40c97b75e9759b0f744dd73f8a250848a4f8
MD5 929277a5a8bd7ac8fc6754c4c4b95086
BLAKE2b-256 f2874274913881302d78cf93e5410bb5d4881f1ea38bfd0015217a21095c9b2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mmcontext-2.0.1.tar.gz:

Publisher: release.yaml on mengerj/mmcontext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for mmcontext-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 91960c4cb31a9a67b127ff370b057bd82b022d7b3d7b6851247bb23d0b04abda
MD5 94d24bc6f4d206a4c8dfa64c4454ed44
BLAKE2b-256 c3d98c029a25f6b825e5be8e0f1346b126cf978cd7ed6e8b5fac7c860af00989

See more details on using hashes here.

Provenance

The following attestation bundles were made for mmcontext-2.0.1-py3-none-any.whl:

Publisher: release.yaml on mengerj/mmcontext

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