Skip to main content

UltraMS

Pretrained models for MS/MS spectra.

pip install ultrams
Model Use Weights
Unsupervised General spectrum embeddings Hugging Face
MoNA Contrastive Spectrum similarity learned on MoNA Hugging Face
Search Final spectrum search model Hugging Face

Get an embedding

from ultrams import UltraMS

model = UltraMS.from_pretrained("unsupervised")
embedding = model.encode(
    mz=[100.1, 121.1, 150.0], intensity=[20, 100, 35], precursor_mz=301.2
).embedding  # NumPy vector

Fine-tune with PyTorch

UltraMS is a torch.nn.Module. Each item in dataset contains mz, intensity, precursor_mz, and a numeric target. The batch converter prepares variable-length spectra for DataLoader.

import torch
from torch.utils.data import DataLoader
from ultrams import UltraMS

device = "cuda" if torch.cuda.is_available() else "cpu"
model = UltraMS.from_pretrained("unsupervised", device=device).train()
head = torch.nn.Linear(model.embedding_dim, 1).to(device)
loader = DataLoader(dataset, batch_size=16, collate_fn=model.batch_converter())
optimizer = torch.optim.AdamW([*model.parameters(), *head.parameters()], lr=1e-5)

for batch in loader:
    batch = {name: value.to(device) for name, value in batch.items()}
    prediction = head(model(batch["peaks"], batch["attention_mask"], batch["precursor_mz"]))
    loss = torch.nn.functional.mse_loss(prediction.squeeze(-1), batch["target"])
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

Fine-tune in one call

Each item in labelled_spectra contains mz, intensity, precursor_mz, and label.

model = UltraMS.from_pretrained("unsupervised")
predictor = model.finetune(labelled_spectra, task="regression", epochs=5)
prediction = predictor.predict([100.1, 121.1, 150.0], [20, 100, 35], precursor_mz=301.2)

Use task="classification" for class labels. Fine-tuning saves the model, training configuration, and loss history in ultrams_finetune/. A downloaded model.pt can be loaded with UltraMS.from_checkpoint(path).

The current pretraining code is in training.

Metadata

Release files for ultrams 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ultrams 0.1.1
File Size Uploaded
ultrams-0.1.1.tar.gz 15.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ultrams 0.1.1
File Interpreter ABI Platform
ultrams-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.3 kB

Release files / ultrams-0.1.1.tar.gz

Download URL ultrams-0.1.1.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1afea53a3b69d97c0812bdcdd8dc798844cbbf72f95c86d321061b01ce530516
BLAKE2b-256 checksum
How to use checksums
eb1602b4f123f5bc1b4a1b9cb1f4a52b9f576b5627ecac56c5b52a2fa3de34ec
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 Sep 23, 2026.

Transparency log

Release files / ultrams-0.1.1-py3-none-any.whl

Download URL ultrams-0.1.1-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5aae01cd7698253c0427316c56414bb2d3a6530b21ca1c9cd4efa52704d51a7d
BLAKE2b-256 checksum
How to use checksums
c4d09bb80ff7e084daaf3122f886b85e4f6bb5f5af84f5609f9e3a8e59e5765b
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 Sep 23, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 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