DrBenchmark/FrenchMedMCQA
Viewer • Updated • 3.11k • 157 • 2
How to use bofenghuang/doctomodernbert-fr-large-instruct-v0.1 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("fill-mask", model="bofenghuang/doctomodernbert-fr-large-instruct-v0.1") # Load model directly
from transformers import AutoTokenizer, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("bofenghuang/doctomodernbert-fr-large-instruct-v0.1")
model = AutoModelForMaskedLM.from_pretrained("bofenghuang/doctomodernbert-fr-large-instruct-v0.1", device_map="auto")This model builds on DoctoModernBERT-fr-large, finetuned with ModernBERT Instruct style answer token prediction. The prompt places an anchor token ([unused0]) right before a masked slot, and the model fills that slot with a single token: 1 if the option above it is correct, 0 if it isn't.
This is an early, exploratory checkpoint from an ongoing instruction tuning experiment, so expect some mistakes.
import torch
from transformers import AutoTokenizer, AutoModelForMaskedLM
model_id = "bofenghuang/doctomodernbert-fr-large-instruct-v0.1" # or a local path
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForMaskedLM.from_pretrained(model_id).eval()
question = "Concernant la prise en charge de la fièvre chez un enfant de 3 ans, indiquer la (les) proposition(s) exacte(s) :"
options = {
"a": "L'administration de paracétamol à une dose adaptée au poids est recommandée",
"b": "L'aspirine est l'antipyrétique de première intention",
"c": "Une hydratation régulière doit être assurée",
"d": "Il est recommandé de couvrir l'enfant avec plusieurs couches de vêtements",
"e": "Un bain d'eau froide est recommandé pour faire baisser la température",
}
prompt = (
"** Instructions **\n"
"You are a medical expert. Read the following multiple-choice question. "
"One or more options may be correct. For each option, answer 1 if it is "
"correct and 0 otherwise.\n"
"** Question **\n"
f"{question}\n"
"** Options **\n"
+ "\n".join(f"- {k}: {v}" for k, v in options.items())
+ "\n** Answers **"
+ "".join(f"\n{k}: [unused0] {tokenizer.mask_token}" for k in options)
)
inputs = tokenizer(prompt, return_tensors="pt")
mask_pos = (inputs["input_ids"][0] == tokenizer.mask_token_id).nonzero(as_tuple=True)[0]
true_id, false_id = tokenizer.convert_tokens_to_ids(["1", "0"])
with torch.no_grad():
logits = model(**inputs).logits[0]
for k, pos in zip(options, mask_pos):
p_correct = torch.softmax(logits[pos, [false_id, true_id]], dim=-1)[1].item()
print(f"{k}: {'correct' if p_correct > 0.5 else 'incorrect'} (P={p_correct:.3f})")