🚀 生物臨床現代BERT
生物臨床現代BERT有兩種規格可供選擇:基礎版(1.5億參數)和大型版(3.96億參數)。模型訓練的檢查點可在此處找到,我們的代碼可在GitHub倉庫中獲取。
🚀 快速開始
BioClinical ModernBERT可直接通過transformers
庫(版本需從v4.48.0開始)使用:
pip install -U transformers>=4.48.0
由於BioClinical ModernBERT是一個掩碼語言模型(MLM),你可以使用fill-mask
管道或通過AutoModelForMaskedLM
加載它。若要將BioClinical ModernBERT用於分類、檢索或問答等下游任務,請按照標準的BERT微調方法進行微調。
⚠️ 重要提示
如果你的GPU支持,我們建議使用Flash Attention 2來運行BioClinical ModernBERT,以達到最高效率。請按以下方式安裝Flash Attention,然後正常使用該模型:
pip install flash-attn
✨ 主要特性
BioClinical ModernBERT是一個領域自適應編碼器,它基於ModernBERT的基礎版和大型版構建,融入了長上下文處理能力,並在生物醫學和臨床自然語言處理的速度和性能方面有顯著提升。BioClinical ModernBERT在迄今為止最大的生物醫學和臨床語料庫上進行訓練,包含超過535億個標記。它通過利用來自不同機構、領域和地理區域的20個數據集,而不是依賴單一來源的數據,解決了先前臨床編碼器的一個關鍵侷限性。
💻 使用示例
基礎用法
from transformers import AutoTokenizer, AutoModelForMaskedLM
model_id = "thomas-sounack/BioClinical-ModernBERT-base"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForMaskedLM.from_pretrained(model_id)
text = "Mitochondria is the powerhouse of the [MASK]."
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
masked_index = inputs["input_ids"][0].tolist().index(tokenizer.mask_token_id)
predicted_token_id = outputs.logits[0, masked_index].argmax(axis=-1)
predicted_token = tokenizer.decode(predicted_token_id)
print("Predicted token:", predicted_token)
高級用法
import torch
from transformers import pipeline
from pprint import pprint
pipe = pipeline(
"fill-mask",
model="thomas-sounack/BioClinical-ModernBERT-base",
torch_dtype=torch.bfloat16,
)
input_text = "[MASK] is a disease caused by an uncontrolled division of abnormal cells in a part of the body."
results = pipe(input_text)
pprint(results)
💡 使用建議
BioClinical ModernBERT與ModernBERT類似,不像一些早期的BERT模型那樣使用標記類型ID。大多數下游使用與Hugging Face Hub上的標準BERT模型相同,只是你可以省略token_type_ids
參數。
📚 詳細文檔
📦 訓練數據
BioClinical ModernBERT在從PubMed和PMC收集的507億個生物醫學文本標記以及來自20個數據集的28億個臨床文本標記上進行訓練,具體數據集詳情如下表所示:
名稱 |
國家 |
臨床數據來源 |
臨床背景 |
樣本數量 |
標記數量(百萬) |
ACI-BENCH |
美國 |
臨床筆記 |
未報告 |
207 |
0.1 |
ADE Corpus |
多個國家 |
臨床筆記 |
未報告 |
20,896 |
0.5 |
Brain MRI Stroke |
韓國 |
放射學報告 |
神經學 |
2,603 |
0.2 |
CheXpert Plus |
美國 |
放射學報告 |
肺病學 |
223,460 |
60.6 |
CHIFIR |
澳大利亞 |
病理學報告 |
血液學/腫瘤學 |
283 |
0.1 |
CORAL |
美國 |
進展筆記 |
血液學/腫瘤學 |
240 |
0.7 |
Eye Gaze CXR |
美國 |
放射學報告 |
肺病學 |
892 |
0.03 |
Gout Chief Complaints |
美國 |
主要症狀 |
內科醫學 |
8,429 |
0.2 |
ID-68 |
英國 |
臨床筆記 |
心理學 |
78 |
0.02 |
Inspect |
美國 |
放射學報告 |
肺病學 |
22,259 |
2.8 |
MedNLI |
美國 |
臨床筆記 |
內科醫學 |
14,047 |
0.5 |
MedQA |
美國 |
國家醫學委員會考試 |
未報告 |
14,366 |
2.0 |
MIMIC-III |
美國 |
臨床筆記 |
內科醫學 |
2,021,411 |
1,047.7 |
MIMIC-IV Note |
美國 |
臨床筆記 |
內科醫學 |
2,631,243 |
1,765.7 |
MTSamples |
未報告 |
臨床筆記 |
內科醫學 |
2,358 |
1.7 |
Negex |
美國 |
出院小結 |
未報告 |
2,056 |
0.1 |
PriMock57 |
英國 |
模擬患者護理 |
內科醫學 |
57 |
0.01 |
Q-Pain |
美國 |
臨床病例 |
姑息治療 |
51 |
0.01 |
REFLACX |
美國 |
放射學報告 |
肺病學 |
2,543 |
0.1 |
Simulated Resp. Interviews |
加拿大 |
模擬患者護理 |
肺病學 |
272 |
0.6 |
🔧 訓練方法
BioClinical ModernBERT基礎版分兩個階段進行訓練。該模型從ModernBERT基礎版的最後一個穩定階段檢查點初始化,並使用相同的超參數進行訓練:學習率為3e-4,批量大小為72。
- 階段1:在來自PubMed、PMC和20個臨床數據集的1605億個標記上進行訓練。在此階段,學習率保持不變,掩碼概率設置為30%。
- 階段2:僅在20個臨床數據集上進行訓練。掩碼概率降低到15%。模型以1-sqrt學習率衰減進行3個週期的訓練。
🔍 評估結果
|
模型 |
上下文長度 |
ChemProt |
表型 |
COS |
社會史 |
去標識化 |
基礎版 |
BioBERT |
512 |
89.5 |
26.6 |
94.9 |
55.8 |
74.3 |
|
Clinical BERT |
512 |
88.3 |
25.8 |
95.0 |
55.2 |
74.2 |
|
BioMed-RoBERTa |
512 |
89.0 |
36.8 |
94.9 |
55.2 |
81.1 |
|
Clinical-BigBird |
4096 |
87.4 |
26.5 |
94.0 |
53.3 |
71.2 |
|
Clinical-Longformer |
4096 |
74.2 |
46.4 |
95.2 |
56.8 |
82.3 |
|
Clinical ModernBERT |
8192 |
86.9 |
54.9 |
93.7 |
53.8 |
44.4 |
|
ModernBERT - base |
8192 |
89.5 |
48.4 |
94.0 |
53.1 |
78.3 |
|
BioClinical ModernBERT - base |
8192 |
89.9 |
58.1 |
95.1 |
58.5 |
82.7 |
大型版 |
ModernBERT - large |
8192 |
90.2 |
58.3 |
94.4 |
54.8 |
82.1 |
|
BioClinical ModernBERT - large |
8192 |
90.8 |
60.8 |
95.1 |
57.1 |
83.8 |
📄 許可證
我們根據MIT許可證發佈BioClinical ModernBERT基礎版和大型版的模型權重以及訓練檢查點。
📚 引用
如果您在工作中使用了BioClinical ModernBERT,請引用我們的預印本:
@misc{sounack2025bioclinicalmodernbertstateoftheartlongcontext,
title={BioClinical ModernBERT: A State-of-the-Art Long-Context Encoder for Biomedical and Clinical NLP},
author={Thomas Sounack and Joshua Davis and Brigitte Durieux and Antoine Chaffin and Tom J. Pollard and Eric Lehman and Alistair E. W. Johnson and Matthew McDermott and Tristan Naumann and Charlotta Lindvall},
year={2025},
eprint={2506.10896},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2506.10896},
}