Where Does the Signal Live?
A Web Data Recipe for Medical Encoder Pretraining
🤗 Blog | 📄 Paper | 💻 Code | 🌐 FineMed | 🩺 DoctoBERT
TL;DR
For decoder large language models (LLMs), pretraining data curation is now widely studied: model-based filters score documents for signals such as educational quality, and an LLM rephrases them into forms with greater training utility. Most domain-specific encoders have not followed this shift. Their corpora are assembled by hand from a small number of canonical in-domain sources, which caps their scale and diversity. The bottleneck is more severe outside English.
We adapt this curation to encoder pretraining for medicine, a domain where text is dense with specialized terminology and factual correctness is critical. The recipe combines two complementary levers: medical-term density filtering selects documents rich in medical terms, and signal-amplifying rephrasing uses an LLM to rewrite documents into denser variants with broader entity contexts.
On French medical NLP, the medical-term density filter outperforms the widely used educational-quality filter, and the two are complementary. LLM rephrasing alone improves over raw web data, and mixing rephrased with filtered web data yields the largest gain. The recipe produces FineMed, a French medical pretraining corpus, and FineMed-rephrased, an LLM-rephrased subset of it, together with a state-of-the-art French medical encoder family, DoctoBERT and DoctoModernBERT, evaluated on the public DrBenchmark and a proprietary clinical Named Entity Recognition (NER) task. We release these, the three distilled annotators, and the reproducible curation pipeline on the Hugging Face Hub and GitHub.
The Web Data Recipe
The web offers the scale and the source and style heterogeneity that hand-curated medical corpora lack, but it takes curation to turn that raw text into medical pretraining data. Common web data curation includes quality filtering (e.g., heuristic filters, binary quality classifiers, or educational-value scorers) and LLM rephrasing into variants that preserve meaning while changing presentation (e.g., Wikipedia-style entries, tutorials, FAQs). Neither targets richness in domain-specific terminology, which matters for downstream tasks in specialized domains such as medicine. We close this gap with the three-stage pipeline below.
Step 1: Sources and prefiltering
We draw from three web corpora: FineWeb-2, FinePDFs, and FineWiki. They have already passed standard web cleaning (e.g., language identification, quality filtering, deduplication), which we inherit as a quality baseline. However, medical content forms only a small fraction of each source and is further diluted by commercial pages, so we extract it with a pretrained multilingual domain classifier, retaining under 10% of each source.
Step 2: Multi-axis annotation
Prefiltering retains every document classified as medical, but these documents differ in their value for pretraining. We therefore score each along three complementary axes. To make annotation affordable at corpus scale, we finetune a dedicated lightweight annotator per axis via knowledge distillation from LLM teachers (following Organize-the-Web).
- Subdomain: a 15-class label for the type of medical content, distinguishing biomedical and clinical writing (papers, guidelines) from consumer-facing material (wellness blogs, commercial health pages).
- Educational quality: a 0–5 score for how instructive a document is, adapted from FineWeb-Edu's general-education rubric to a medical-education target.
- Medical-term density: how rich a document is in medical terminology, defined as the fraction of characters that fall within medical-term spans.
We release all three annotators: a subdomain classifier, an educational-quality scorer, and a medical-entity extractor. Their per-document scores become the filtering signals we study in the experiments below, where the axes, thresholds, and combinations are chosen empirically.
Step 3: Signal-amplifying rephrasing
Filtering selects whole documents but cannot enrich the medical content within them, and it discards borderline documents that still hold useful content. We therefore add a rephrasing step: an LLM rewrites each document into a faithful variant that raises medical-term density and broadens the contexts in which each medical concept appears. This is especially valuable for encoders. Because encoder MLM trains for multiple epochs over the same corpus, unlike the typical single-epoch decoder LLM, per-document gains compound across passes. Rephrasing also removes source artifacts that filtering leaves untouched, such as boilerplate and OCR errors.
We build on Massive Genre–Audience (MGA) reformulation, a two-stage recipe. Stage 1 proposes (genre, audience) pairs for a document; stage 2 rewrites it under an assigned pair (for example, recasting a clinical guideline into an FAQ written for patients). We introduce the following adaptations:
- Medical-content gating: a check at the start of stage 1 drops documents with too little medical content, which saves compute and prevents the model from fabricating medical facts.
- Diverse pair proposals: rather than letting stage 1 default to a few repeated pairs (a real risk in a narrow domain), we generate multiple candidate genres and audiences, and randomly sample one pair per document.
- Faithful densification: stage 2 removes non-medical filler while preserving context, and remains strictly meaning-preserving, inventing no facts, values, or entities (a known failure mode of unconstrained rephrasing). The one exception is personal identifiers, which are replaced with fictional values to support downstream de-identification.
- Medical surface variation: stage 2 further varies register (formal or telegraphic clinical-note style) and abbreviation density (expanded, moderate, heavy), exposing the encoder to the stylistic range of real clinical text it will face downstream.
Findings
Filtering finds the signal in medical-term density
Heterogeneous web data is already competitive with hand-curated corpora. Even unfiltered, our extracted medical web data matches one of these corpora (NACHOS) on downstream medical tasks, and beats text machine-translated from English PubMed (TransCorpus-bio-fr). Heterogeneous sourcing gives web data broader register and format coverage than a narrowly sourced corpus, and it inherits a quality floor from upstream preprocessing.
Medical-term density is the strongest single-axis filter. Used on its own, medical-term density outperforms the other two axes, with subdomain ahead of educational quality. This contrasts with decoder-LLM pretraining, where educational quality, by rewarding coherent, well-structured, textbook-like prose, is commonly used to upsample such data and boost performance. For encoder MLM in a dense-terminology domain, density matters more: trained on a corpus packed with domain-specific terms, the encoder sees more of those terms and their co-occurrences across more varied contexts, and learns stronger representations.
Educational quality and medical-term density are complementary. The strongest filter overall keeps only documents that pass both, beating each axis on its own and every curated-corpus baseline by a clear margin.
Rephrasing amplifies the signal further
Signal-amplifying rephrasing beats both raw data and standard MGA. Data rephrased with our recipe improves over raw web data by a wide margin, while standard MGA, run with the same LLM, falls below raw web data, likely because it ingests thin inputs and fabricates content.
Rephraser quality does not correlate with model size or medical tuning. A smaller model (Qwen3.5-35B-A3B) outperformed a larger one from the same family (Qwen3.5-122B-A10B). FinePhrase reports the same broad pattern: larger rephrasers do not reliably yield better data. A medically tuned model (MedGemma-27B) scored well below a generic model of similar size (Gemma-4-26B-A4B). Mixing different LLMs, intended to add diversity and reduce single-model artifacts, gave no downstream benefit.
Rephrasing and filtering combine best of all. The strongest configuration in our study mixes rephrased text with raw web data that passes our strongest filter, beating either source alone.
FineMed and the DoctoBERT family
We then apply the validated recipe at full scale across all three web sources, yielding FineMed (21.1M documents, 19.2B words). We release FineMed unfiltered with all annotations, to enable custom downstream filtering. Signal-amplifying rephrasing then produces an LLM-rewritten subset of FineMed, FineMed-rephrased (13.6M documents, 4.5B words).
We also release two encoders pretrained from scratch on that data: DoctoBERT, a classic RoBERTa architecture (111M parameters, 512-token context), and DoctoModernBERT, a more efficient, long-context ModernBERT (149M parameters, up to 8,192 tokens).
Evaluation
We compare against nine encoders in three groups: French medical, French generalist (to test whether medical pretraining adds value over French pretraining alone), and English medical (to test cross-lingual transfer).
We evaluate on an adapted version of the public benchmark DrBenchmark, filtered to 7 high-quality tasks: QUAERO (NER on EMEA drug leaflets and MEDLINE abstracts), E3C (clinical and temporal NER), DEFT2021 (clinical NER), MORFITT (biomedical specialty classification), and DIAMED (clinical diagnostic classification). Per model and task, hyperparameters are tuned on the validation split, then the mean F1 over 5 test-split seeds is reported. We also report two per-model scores aggregated across all tasks. Min-Max rescales each task's scores onto a 0–100 scale before averaging. It captures the magnitude of the gaps: a model that lags on a few tasks is penalized heavily. WP (Win Probability) is the average percentage of tasks on which a model outscores each other model. It captures rank consistency: robust to outliers, blind to effect size.
On this benchmark, DoctoBERT ranks first on both aggregate scores, ahead of the strongest baseline (TransBERT-bio-fr), and leads five of the seven tasks.
| Model | EMEA | MEDLINE | E3C-Clin | E3C-Temp | MORFITT | DEFT2021 | DIAMED | Min-Max | WP |
|---|---|---|---|---|---|---|---|---|---|
| English medical | |||||||||
| BioBERT | 58.77 | 50.29 | 55.02 | 78.29 | 66.99 | 56.72 | 59.26 | 29.97 | 15.71 |
| BioClinical-ModernBERT | 44.74 | 44.44 | 49.53 | 76.11 | 67.42 | 53.97 | 52.07 | 0.88 | 1.43 |
| ModernBERT-bio | 56.84 | 46.60 | 53.76 | 78.85 | 68.57 | 56.43 | 61.06 | 29.35 | 17.14 |
| French generalist | |||||||||
| CamemBERT | 65.43 | 56.18 | 59.82 | 83.81 | 71.54 | 62.40 | 60.26 | 69.37 | 57.14 |
| ModernCamemBERT | 61.98 | 55.46 | 57.62 | 83.11 | 70.01 | 60.01 | 53.26 | 52.69 | 28.57 |
| French medical | |||||||||
| DrBERT | 64.37 | 57.18 | 58.01 | 82.44 | 70.42 | 61.08 | 64.87 | 65.08 | 44.29 |
| CamemBERT-bio | 64.98 | 59.03 | 61.40 | 84.88 | 71.48 | 64.73 | 64.63 | 80.83 | 70.00 |
| TransBERT-bio-fr | 67.37 | 59.96 | 62.36 | 84.48 | 74.04 | 65.48 | 70.91 | 93.88 | 88.57 |
| ModernCamemBERT-bio | 65.35 | 56.81 | 58.63 | 83.31 | 71.21 | 61.35 | 67.77 | 71.37 | 54.29 |
| Ours | |||||||||
| DoctoBERT-fr | 68.39 | 62.54 | 62.75 | 84.60 | 73.36 | 66.41 | 72.56 | 98.17 | 97.14 |
| DoctoModernBERT-fr | 65.71 | 59.65 | 59.62 | 84.06 | 71.87 | 63.81 | 71.60 | 83.15 | 75.71 |
We also evaluate on a proprietary French clinical NER task from a real-world production setting, annotated with 12 entity types (e.g., pathology, drug, exam, biometry) and 9 qualifiers (e.g., negation, family relationship, date). Scores are the mean over 3 test-split seeds.
DoctoModernBERT performs best on this task. This result supports the heterogeneous-web design: the broader register coverage seen during pretraining transfers to real clinical text more effectively than the narrowly curated baselines.
| Model | Precision | Recall | F1 |
|---|---|---|---|
| English medical | |||
| BioBERT | 77.54 | 78.42 | 77.97 |
| BioClinical-ModernBERT | 78.79 | 78.69 | 78.74 |
| ModernBERT-bio | 78.06 | 79.30 | 78.67 |
| French generalist | |||
| CamemBERT | 77.19 | 79.58 | 78.36 |
| ModernCamemBERT | 78.53 | 78.71 | 78.62 |
| French medical | |||
| DrBERT | 76.77 | 77.81 | 77.28 |
| CamemBERT-bio | 77.51 | 78.90 | 78.19 |
| TransBERT-bio-fr | 76.85 | 78.66 | 77.74 |
| ModernCamemBERT-bio | 78.17 | 79.76 | 78.95 |
| Ours | |||
| DoctoBERT-fr | 77.29 | 79.68 | 78.47 |
| DoctoModernBERT-fr | 79.12 | 79.71 | 79.40 |
Future Work
We first developed and validated the recipe on French medical NLP, a lower-resource setting than English, across both academic and real-world tasks. The pipeline is language-agnostic, so we are now curating multilingual FineMed and training multilingual DoctoBERT. We will release both.
Acknowledgments
We thank Yanis Labrak and Adrien Bazoge for helpful discussions in the early stages of this work, Adrien Giraud for valuable discussions, and the MFE team at Doctolib (Issa Ka, Foucauld Estignard, Cyril Laitang, and Nicolas Perquier) for enabling evaluation on a real-world clinical task.
This work was granted access to the HPC resources of IDRIS under allocations 2025-AD011016291 and 2026-A0200617487 made by GENCI.