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: Menger, Jonatan, Sonia Maria Krissmer, Clemens Kreutz, Harald Binder, and Maren Hackenberg. "mmContext: an open framework for multimodal contrastive learning of omics and text data." bioRxiv (2025): 2025-12. 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{menger2025mmcontext,
  author = {Menger, Jonatan and Krissmer, Sonia Maria and Kreutz, Clemens and Binder, Harald and Hackenberg, Maren},
  title = {mmContext: an open framework for multimodal contrastive learning of omics and text data},
  journal = {bioRxiv},
  year = {2025},
  doi = {10.1101/2025.12}
}

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.0.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.0-py3-none-any.whl (174.9 kB view details)

Uploaded Python 3

File details

Details for the file mmcontext-2.0.0.tar.gz.

File metadata

  • Download URL: mmcontext-2.0.0.tar.gz
  • Upload date:
  • Size: 200.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.14

File hashes

Hashes for mmcontext-2.0.0.tar.gz
Algorithm Hash digest
SHA256 cfb3534ef5ae9a9c15622dce96ae0b80e35c4510e31b6a263a2dff7d41861eac
MD5 5d86d17416718bcdd725addfe8757671
BLAKE2b-256 830515bb3cd2c4a50c83fe5d0f655fb8527dee0d56bc10dffcb678b54f1554c0

See more details on using hashes here.

File details

Details for the file mmcontext-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: mmcontext-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 174.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.14

File hashes

Hashes for mmcontext-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 564c8b1cbd660c66f8ee06f925c39fd33a95c8bf2c3ebd8b5ce9957d00ffa0a5
MD5 d3169ee3d9ac050382d51daf0ba5fee4
BLAKE2b-256 d46ee74948bf4b3a6819db6669d003994550415c6578d4818436d5c04e2c352c

See more details on using hashes here.

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