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. The two rows below show the required data format; replace them with your labelled spectra.

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

dataset = [
    {"mz": [100.1, 121.1, 150.0], "intensity": [20, 100, 35], "precursor_mz": 301.2, "target": 0.5},
    {"mz": [102.1, 135.2, 167.3], "intensity": [40, 100, 25], "precursor_mz": 315.3, "target": 0.7},
]

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=2, 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()
    print(f"loss: {loss.item():.4f}")

Fine-tune in one call

For a shorter route, provide the same spectra with a label field.

import torch
from ultrams import UltraMS

labelled_spectra = [
    {"mz": [100.1, 121.1, 150.0], "intensity": [20, 100, 35], "precursor_mz": 301.2, "label": 0.5},
    {"mz": [102.1, 135.2, 167.3], "intensity": [40, 100, 25], "precursor_mz": 315.3, "label": 0.7},
]

device = "cuda" if torch.cuda.is_available() else "cpu"
model = UltraMS.from_pretrained("unsupervised", device=device)
predictor = model.finetune(labelled_spectra, task="regression", epochs=1)
prediction = predictor.predict([100.1, 121.1, 150.0], [20, 100, 35], precursor_mz=301.2)
print(prediction)

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.2

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.2
File Size Uploaded
ultrams-0.1.2.tar.gz 15.5 kB Details

Built distribution (wheel)

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

Total release size: 31.7 kB

Release files / ultrams-0.1.2.tar.gz

Download URL ultrams-0.1.2.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b3db7a6c9b48e7da02d58285d1b46347aa918c1fe4b64839eb72fe25b69305c6
BLAKE2b-256 checksum
How to use checksums
2248ddb21fa4769f856b2c7b38e1846ceaec18b4e2b35fe52b89a33991d1f551
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.2-py3-none-any.whl

Download URL ultrams-0.1.2-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8081730b63581c8a4e9b80333e1928fbdcb1f172c7062ced05b43dc1ce918f7b
BLAKE2b-256 checksum
How to use checksums
d7c038e1fea3a3152593d6fde095b4e13885ca0807f72d71789c59d7e5a2ac37
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

This release

0.1.2 This release

2 release files

0.1.1

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