DoctoModernBERT-fr-large-instruct-v0.1

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.

🚀 How to Use

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})")
Downloads last month
17
Safetensors
Model size
0.4B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train bofenghuang/doctomodernbert-fr-large-instruct-v0.1