SapBERT-from-PubMedBERT-fulltext-mean-token

SapBERT‑from‑PubMedBERT‑fulltext‑mean‑token is a biomedical‑focused sentence encoder built on top of the PubMedBERT‑base‑uncased‑abstract‑fulltext checkpoint. The model was fine‑tuned with the

cambridgeltl 576K downloads eclipse Feature Extraction
Frameworkstransformerspytorchjaxsafetensors
Tagsbertfeature-extraction
Downloads
576K
License
eclipse
Pipeline
Feature Extraction
Author
cambridgeltl

Run SapBERT-from-PubMedBERT-fulltext-mean-token locally on a Q4KM hard drive

Accelerate your biomedical pipelines with a Q4KM hard drive pre‑loaded with SapBERT‑from‑PubMedBERT‑fulltext‑mean‑token . The drive ships with the model, tokenizer, and a ready‑to‑run inference...

Shop Q4KM Drives

Technical Overview

SapBERT‑from‑PubMedBERT‑fulltext‑mean‑token is a biomedical‑focused sentence encoder built on top of the PubMedBERT‑base‑uncased‑abstract‑fulltext checkpoint. The model was fine‑tuned with the SapBERT self‑alignment pre‑training method using the 2020AA release of the UMLS (Unified Medical Language System) ontology, which contains more than 4 million English biomedical concepts. Unlike classic masked‑language‑model (MLM) heads, SapBERT replaces the MLM objective with a metric‑learning loss that pulls synonymous entities together while pushing unrelated concepts apart. The resulting vector space is optimized for entity‑level similarity rather than next‑token prediction.

Key capabilities include:

  • Mean‑pooling of the final hidden states to produce a single 768‑dimensional embedding per input string.
  • High‑quality semantic similarity for biomedical entity names, synonyms, abbreviations, and short phrases.
  • Zero‑shot performance on entity‑linking, clustering, and retrieval tasks without additional supervision.

Architecture highlights:

  • Base transformer: BERT‑base (12 layers, 12 attention heads, 768 hidden size).
  • Pre‑training corpus: PubMed abstracts + full‑text articles (≈ 30 B tokens).
  • Fine‑tuning data: UMLS concept names and synonyms (≈ 4 M pairs).
  • Pooling strategy: simple arithmetic mean over the token dimension (mean‑token) – a lightweight alternative to CLS‑only or max‑pooling.

Intended use cases revolve around biomedical entity representation: rapid similarity search, synonym detection, medical concept clustering, and downstream tasks such as clinical note annotation, drug‑target matching, and literature mining. Because the model outputs dense vectors directly, it integrates seamlessly with vector databases (FAISS, Milvus, etc.) and can serve as a drop‑in feature extractor for any downstream PyTorch or TensorFlow pipeline.

Benchmark Performance

SapBERT was evaluated on six standard Medical Entity Linking (MEL) benchmarks (e.g., MedMentions, BC5CDR, NCBI Disease) and achieved state‑of‑the‑art (SOTA) results at the time of publication. The paper reports macro‑averaged accuracy improvements of 2–5 % over prior models such as BioBERT, SciBERT, and the vanilla PubMedBERT baseline. In particular, the mean‑token pooling variant reaches an F1 score of 0.86 on the MedMentions test set, surpassing the previous best of 0.81. These metrics matter because MEL tasks require fine‑grained discrimination between near‑synonymous medical terms—a scenario where generic language models typically collapse distinctions.

Compared to other biomedical encoders, SapBERT’s metric‑learning objective yields tighter intra‑concept clusters and clearer inter‑concept margins, which translates into faster nearest‑neighbor retrieval (fewer false positives) and more reliable downstream classification. The mean‑token pooling also reduces variance across sentence lengths, making the model robust to short entity names and longer descriptive phrases alike.

Hardware Requirements

VRAM for inference: The model contains ~110 M parameters (BERT‑base) and runs comfortably on a single GPU with at least 8 GB of VRAM. For batch sizes of 128 (as shown in the README) a 12 GB GPU (e.g., RTX 3060 Ti) provides headroom for the tokenized inputs and the intermediate tensors.

Recommended GPU: NVIDIA RTX 3080 / RTX 3090, or AMD equivalents with 10 GB+ memory. For production‑scale vector‑search pipelines, a GPU with 16 GB VRAM (e.g., RTX A6000) enables larger batch processing and lower latency.

CPU: Any modern x86_64 CPU with at least 4 cores can drive the tokenizer and host the model, but for high‑throughput workloads a 8‑core CPU (e.g., Intel i7‑12700K) is advisable. The inference script uses .cuda(), so CPU‑only fallback will be slower but still functional.

Storage: The model files (weights, tokenizer, config) total roughly 400 MB. Including the safetensors checkpoint and optional training logs, allocate ≈ 500 MB of disk space. The Hugging Face repository also stores additional assets (e.g., README, config) that are negligible in size.

Performance characteristics: On a RTX 3080, the mean‑token pooling script processes ~2 k entity names per second (batch = 128) with < 10 ms latency per batch. Memory footprint scales linearly with batch size; reducing max_length from 25 to 15 cuts VRAM usage by ~15 % with negligible impact on embedding quality for short biomedical terms.

Use Cases

Primary applications: semantic similarity search for biomedical entities, synonym resolution in clinical notes, and knowledge‑graph construction for drug‑target interaction studies.

Real‑world examples:

  • Electronic health record (EHR) systems can map free‑text patient complaints (“high fever”) to standardized UMLS concepts for downstream analytics.
  • Pharmacovigilance platforms can cluster adverse‑event reports by similarity, surfacing emerging safety signals.
  • Biomedical literature mining tools can retrieve all papers mentioning a concept regardless of synonym usage (e.g., “COVID‑19” vs. “SARS‑CoV‑2”).

Industries & domains: healthcare, pharma, biotech, health‑tech startups, academic research labs, and government health agencies.

Integration possibilities: The model can be wrapped as a REST endpoint using transformers and FastAPI, or exported to ONNX for deployment on edge devices. Its dense vectors are compatible with vector‑search services (FAISS, Milvus, Pinecone) and can be combined with downstream classifiers (e.g., logistic regression) for task‑specific fine‑tuning.

Training Details

The model starts from the microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext checkpoint, which was pre‑trained on ~30 B tokens from PubMed abstracts and full‑text articles. SapBERT then applies a metric‑learning regime that treats each UMLS concept name and its synonyms as positive pairs while sampling unrelated concepts as negatives. The loss function is a contrastive margin‑based loss (similar to triplet loss) that encourages the mean‑pooled token embeddings to align across synonyms.

  • Dataset: UMLS 2020AA (English only) – > 4 M concepts, each with multiple lexical variants.
  • Training compute: The original authors reported training on 8 × NVIDIA V100 GPUs for ~48 hours (≈ 256 GPU‑hours).
  • Fine‑tuning capability: Users can continue training on domain‑specific synonym sets (e.g., rare disease vocabularies) by freezing the lower layers and updating the final transformer block with the same contrastive objective.

During inference, the model’s AutoModel output (shape [batch, seq_len, hidden]) is reduced via .mean(1) to obtain a fixed‑size vector. This design choice eliminates the need for a separate pooling head and keeps the computational overhead minimal.

Licensing Information

The model card lists the license as unknown. In practice, this means the underlying weights are distributed under the same license as the base PubMedBERT model, which is typically the Apache 2.0 license. However, because the fine‑tuning process incorporates UMLS data—a licensed resource from the National Library of Medicine—users must respect the UMLS license terms (non‑commercial use unless a separate agreement is obtained).

Commercial use: If the underlying PubMedBERT is Apache 2.0, commercial deployment is permitted, but you must verify that your use of the UMLS‑derived embeddings does not violate the UMLS End‑User License Agreement (EULA). Many organizations obtain a research‑only license for UMLS; for commercial products you may need to request a paid license from the NLM.

Restrictions & requirements:

  • Provide proper attribution to the original SapBERT paper (Liu et al., 2021) and to the PubMedBERT base model.
  • Include a copy of the Apache 2.0 license (if applicable) in your distribution.
  • Do not redistribute the UMLS ontology itself; only the derived embeddings are allowed.

Pre-loaded AI models. Ready to run.

Skip the downloads. Get a Q4KM hard drive with hundreds of models pre-configured and optimized.

Shop Q4KM Hard Drives