Team Ai
Modelpublic

NeuML/biomedbert-base-colbert

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
4likes587downloads
Model Card

BiomedBERT ColBERT

This is a multi-vector (ColBERT-style late interaction) embedding model finetuned from microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext. It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.

Usage (txtai)

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

python
import txtai

embeddings = txtai.Embeddings(
  path="neuml/biomedbert-base-colbert",
  content=True
)
embeddings.index(documents())

# Run a query
embeddings.search("query to run")

Late interaction models excel as reranker pipelines.

python
from txtai.pipeline import Reranker, Similarity

similarity = Similarity(path="neuml/biomedbert-base-colbert", lateencode=True)
ranker = Reranker(embeddings, similarity)
ranker("query to run")

Usage (Sentence Transformers)

This model can be used with Sentence Transformers as a multi-vector (ColBERT-style late interaction) retriever via the MultiVectorEncoder:

bash
pip install "sentence-transformers>=6.0.0"
python
from sentence_transformers import MultiVectorEncoder

model = MultiVectorEncoder("NeuML/biomedbert-base-colbert")

query = "Which planet is known as the Red Planet?"
documents = [
    "Venus is often called Earth's twin because of its similar size and proximity.",
    "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
    "Jupiter, the largest planet in our solar system, has a prominent red spot.",
    "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
]

query_embeddings = model.encode_query(query)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings[0].shape)
# (14, 128) (17, 128)

# MaxSim late-interaction scoring (higher is more relevant)
scores = model.similarity(query_embeddings, document_embeddings)
print(scores)
# tensor([[9.9712, 12.4123, 11.0444, 11.9934]])

Usage (PyLate)

Alternatively, the model can be loaded with PyLate.

python
from pylate import rank, models

queries = [
    "query A",
    "query B",
]

documents = [
    ["document A", "document B"],
    ["document 1", "document C", "document B"],
]

documents_ids = [
    [1, 2],
    [1, 3, 2],
]

model = models.ColBERT(
    model_name_or_path="neuml/biomedbert-base-colbert",
)

queries_embeddings = model.encode(
    queries,
    is_query=True,
)

documents_embeddings = model.encode(
    documents,
    is_query=False,
)

reranked_documents = rank.rerank(
    documents_ids=documents_ids,
    queries_embeddings=queries_embeddings,
    documents_embeddings=documents_embeddings,
)

Evaluation Results

Performance of these models are compared to previously released models trained on medical literature. The most commonly used small embeddings model is also included for comparison.

The following datasets were used to evaluate model performance.

  • —PubMed QA
  • —Subset: pqalabeled, Split: train, Pair: (question, longanswer)
  • —PubMed Subset
  • —Split: test, Pair: (title, text)
  • —PubMed Summary
  • —Subset: pubmed, Split: validation, Pair: (article, abstract)

Evaluation results are shown below. The Pearson correlation coefficient is used as the evaluation metric.

ModelPubMed QAPubMed SubsetPubMed SummaryAverage
all-MiniLM-L6-v290.4095.9294.0793.46
bioclinical-modernbert-base-embeddings92.4997.1097.0495.54
**biomedbert-base-colbert**94.5997.1896.2195.99
biomedbert-base-reranker97.6699.7698.8198.74
pubmedbert-base-embeddings93.2797.0096.5895.62
pubmedbert-base-embeddings-8M90.0594.2994.1592.83

This is the best performing model we've released that's not a cross-encoder. With MUVERA encoding, this model can be used to index large datasets for semantic search. It can also be used as a faster re-ranker vs. a cross-encoder model.

Full Model Architecture

ColBERT(
  (0): Transformer({'max_seq_length': 511, 'do_lower_case': False, 'architecture': 'BertModel'})
  (1): Dense({'in_features': 768, 'out_features': 128, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'use_residual': False})
)