Model reference · open weights
pubmedbert-embeddings-matryoshka is an open-weight embedding model from NeuML. pubmedbert-base-embeddings-matryoshka (FP32) weighs 219 MB; the smallest configuration that runs it is RTX 3060 12 GB.
For self-hosting, compare this build's requirements below with the GPU you plan to rent.
Summary of the NeuML/pubmedbert-base-embeddings-matryoshka model card, 2026-10-01
What it is
| Released by | NeuML |
|---|---|
| Released | 2024-02-24 |
| Parameters | 109M |
| VRAM | 219 MB for the weights |
What it runs on
| Card | Runs | Memory |
|---|---|---|
| RTX 3060 12 GB | fits | 11.6 GB |
| RTX 4060 Ti 16 GB | fits | 15.4 GB |
| RTX 3090 24 GB | fits | 23.4 GB |
| RTX 4090 24 GB | fits | 23.4 GB |
| RTX 5090 32 GB | fits | 31.0 GB |
| L40S 48 GB | fits | 44.0 GB |
| A100 80 GB | fits | 78.2 GB |
| H100 80 GB | fits | 78.1 GB |
| RTX PRO 6000 Blackwell 96 GB | fits | 93.8 GB |
| DGX Spark (GB10) 128 GB unified | fits | 107 GB |
| H200 141 GB | fits | 138 GB |
| B200 180 GB | fits | 176 GB |
From the model card
This is a version of PubMedBERT Embeddings with Matryoshka Representation Learning applied. This enables dynamic embeddings sizes of 64, 128, 256, 384, 512 and the full size of 768. It's important to note while this method saves space, the same computational resources are used regardless of the dimension size.
Sentence Transformers 2.4 added support for Matryoshka Embeddings. More can be read in this blog post.
This model can be used to build embeddings databases with txtai for semantic search and/or as a knowledge source for retrieval augmented generation (RAG).
import txtai
# New embeddings with requested dimensionality
embeddings = txtai.Embeddings(
path="neuml/pubmedbert-base-embeddings-matryoshka",
content=True,
dimensionality=256
)
embeddings.index(documents())
# Run a query
embeddings.search("query to run")
Alternatively, the model can be loaded with sentence-transformers.
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer("neuml/pubmedbert-base-embeddings-matryoshka")
embeddings = model.encode(sentences)
# Requested dimensionality
dimensionality = 256
print(embeddings[:, :dimensionality])
The model can also be used directly with Transformers.
from transformers import AutoTokenizer, AutoModel
import torch
# Mean Pooling - Take attention mask into account for correct averaging
def meanpooling(output, mask):
embeddings = output[0] # First element of model_output contains all token embeddings
mask = mask.unsqueeze(-1).expand(embeddings.size()).float()
return torch.sum(embeddings * mask, 1) / torch.clamp(mask.sum(1), min=1e-9)
# Sentences we want sentence embeddings for
sentences = ['This is an example sentence', 'Each sentence is converted']
# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained("neuml/pubmedbert-base-embeddings-matryoshka")
model = AutoModel.from_pretrained("neuml/pubmedbert-base-embeddings-matryoshka")
# Tokenize sentences
inputs = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
with torch.no_grad():
output = model(**inputs)
# Perform pooling. In this case, mean pooling.
embeddings = meanpooling(output, inputs['attention_mask'])
# Requested dimensionality
dimensionality = 256
print("Sentence embeddings:")
print(embeddings[:, :dimensionality])
Performance of this model compared to the top base models on the MTEB leaderboard is shown below. A popular smaller model was also evaluated along with the most downloaded PubMed similarity model on the Hugging Face Hub.
The following datasets were used to evaluate model performance.
Evaluation results from the original model are shown below for reference. The Pearson correlation coefficient is used as the evaluation metric.
| Model | PubMed QA | PubMed Subset | PubMed Summary | Average |
|---|---|---|---|---|
| all-MiniLM-L6-v2 | 90.40 | 95.92 | 94.07 | 93.46 |
| bge-base-en-v1.5 | 91.02 | 95.82 | 94.49 | 93.78 |
| gte-base | 92.97 | 96.90 | 96.24 | 95.37 |
| pubmedbert-base-embeddings | 93.27 | 97.00 | 96.58 | 95.62 |
| S-PubMedBert-MS-MARCO | 90.86 | 93.68 | 93.54 | 92.69 |
See the table below for evaluation results per dimension for pubmedbert-base-embeddings-matryoshka.
| Model | PubMed QA | PubMed Subset | PubMed Summary | Average |
|---|---|---|---|---|
| Dimensions = 64 | 92.16 | 96.14 | 95.67 | 94.66 |
| Dimensions = 128 | 92.80 | 96.58 | 96.22 | 95.20 |
| Dimensions = 256 | 93.11 | 96.82 | 96.53 | 95.49 |
| Dimensions = 384 | 93.42 | 97.00 | 96.61 | 95.68 |
| Dimensions = 512 | 93.37 | 97.07 | 96.61 | 95.68 |
| Dimensions = 768 | 93.53 | 97.13 | 96.70 | 95.79 |
This model performs slightly better overall compared to the original model.
The bigger takeaway is how competitive it is at lower dimensions. For example, Dimensions = 256 performs better than all the other models originally tested above. Even Dimensions = 64 performs better than all-MiniLM-L6-v2 and bge-base-en-v1.5.
The model was trained with the parameters:
DataLoader:
torch.utils.data.dataloader.DataLoader of length 20191 with parameters:
{'batch_size': 24, 'samQuoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.