Generating Synthetic Free-text Medical Records with Low Re-identification Risk using Masked Language Modeling

Samuel Belkadi, Libo Ren, Nicolo Micheletti, Lifeng Han, Goran Nenadic

TL;DR

This paper introduces a lightweight (~120M parameter) pipeline that uses Masked Language Modeling (MLM) instead of traditional autoregressive models to generate synthetic free-text medical records. By masking and replacing non-essential text while strictly preserving core medical entities, the system achieves a high HIPAA-compliant privacy recall of 96% and a low re-identification risk of 3.5%, all while maintaining excellent data utility for downstream AI training.

What Problem Does This Paper Address?

Electronic medical records (EMRs), such as clinical notes and discharge summaries, are goldmines for biomedical research and healthcare AI development. However, strict privacy regulations (like HIPAA) restrict access to this data to protect patient confidentiality.

To share data safely, researchers have turned to synthetic data generation. Recently, Causal Language Models (CLMs)—like GPT-3.5—have been the go-to approach. But autoregressive CLMs suffer from three major drawbacks in clinical settings:

  1. Privacy Leaks: They can easily memorize and regurgitate sensitive patient information from their training data.
  2. Lack of Control: It is difficult to precisely tune the balance between data diversity (uniqueness) and fidelity (medical accuracy).
  3. High Cost: Running massive LLMs for data generation is computationally expensive.

The authors tackle these challenges by shifting the paradigm from causal generation to masked language modeling, creating a highly controllable, private, and lightweight alternative.

Methods

The authors propose a two-step pipeline consisting of a Masker and a Mask-Filling System.

Figure 1: Design of the entire system, showcasing the Masker and Mask-Filling components.
  1. The Masker: This component processes the raw clinical text in three phases:
  2. De-identification: Uses Philter (a regex-based tool) to identify and completely remove Protected Health Information (PHI) across six categories (names, dates, IDs, etc.).
  3. Medical Entity Recognition: Uses a fine-tuned Stanza NER model to identify critical medical concepts (PROBLEMS, TESTS, TREATMENTS) that must be retained to preserve clinical validity.
  4. Part-of-Speech (POS) Tagging: Uses Stanza to tag the remaining text. Users can then specify masking ratios for specific parts of speech (e.g., mask 70% of nouns and 50% of verbs) to introduce controlled diversity.
  5. The Mask-Filling System: An encoder-only MLM based on Bio_ClinicalBERT (~120M parameters) fills in the masked tokens based on the surrounding context. The authors compared two filling strategies:
  6. Simultaneous Chunk Filling: Fills all masks at once, either deterministically or stochastically.
  7. Iterative Mask Filling: Fills masks one by one within a context window, providing stronger contextual cues and generating higher-quality text.

Datasets

The system was trained and evaluated on the i2b2 2014 shared task dataset for PHI de-identification. This dataset contains 1,304 English clinical records (discharge summaries, admission notes, and doctor correspondences) from 296 diabetic patients. It is pre-divided into 790 training and 514 testing samples, and includes HIPAA-compliant PHI annotations.

Key Insights and Ideas

  • The Power of "Fill-in-the-Blanks": Unlike autoregressive models that generate text from scratch (and can hallucinate entire patient profiles), an MLM-based approach keeps the structural backbone of the original record intact. It only swaps out non-essential words, inherently bounding the risk of privacy leaks.
  • Iterative Context Matters: Iterative mask filling significantly outperforms simultaneous filling. By updating the context token-by-token, the model reduces uncertainty and preserves the original clinical meaning much better, even at high masking ratios.
  • Accidental Readability Boost: Interestingly, synthetic text often scores better on readability metrics than the original doctor notes. This is because the MLM tends to replace complex or highly specific non-medical jargon with simpler, more common words.

Key Results

The authors evaluated four system configurations (System_S for simultaneous, System_I for iterative, followed by the masking ratio):

  • Privacy: The Masker achieved a 96% recall rate for HIPAA-PHI categories. The re-identification risk (the probability of the MLM accidentally re-inserting a masked PHI phrase longer than two tokens) was remarkably low at 3.5%.
  • Data Utility: To test if the synthetic data is useful for training other AI models, the authors trained a downstream Named Entity Recognition (NER) model on the synthetic text. As shown in the downstream task results, when the synthetic dataset was augmented (x2), it achieved an F1 score of 0.836, which is incredibly close to the model trained on real data (0.842).
Extracted table from page 5 showing downstream NER task results
  • Lexical Similarity: Iterative filling maintained higher semantic preservation (BERTScore) even when 90% of the non-medical tokens were masked.
Extracted table from page 4 showing lexical similarities

Limitations and Future Work

While the system excels at privacy and utility, the authors note a few key limitations:

  • Temporal and Event Coherence: The model sometimes struggles to align temporal information consistently or maintain logic across interconnected events (e.g., keeping track of which name belongs to which role in a multi-person discussion).
  • Entity-Type Blindness: The current MLM fills blanks based purely on context. Informing the MLM of the type of entity it is replacing (e.g., telling it "fill this blank with a verb") could significantly improve generation quality.

Future directions include integrating logic-based components to handle timelines, exploring guided prompting with LLMs for the mask-filling step, and expanding testing to specialized domains like radiology or oncology.

Summary updated

Abstract

The vast amount of available medical records has the potential to improve healthcare and biomedical research. However, privacy restrictions make these data accessible for internal use only. Recent works have addressed this problem by generating synthetic data using Causal Language Modeling. Unfortunately, by taking this approach, it is often impossible to guarantee patient privacy while offering the ability to control the diversity of generations without increasing the cost of generating such data. In contrast, we present a system for generating synthetic free-text medical records using Masked Language Modeling. The system preserves critical medical information while introducing diversity in the generations and minimising re-identification risk. The system's size is about 120M parameters, minimising inference cost. The results demonstrate high-quality synthetic data with a HIPAA-compliant PHI recall rate of 96% and a re-identification risk of 3.5%. Moreover, downstream evaluations show that the generated data can effectively train a model with performance comparable to real data.
BibTeX
@inproceedings{belkadi2025generating,
  author = {Samuel Belkadi and Libo Ren and Nicolo Micheletti and Lifeng Han and Goran Nenadic},
  title = {{Generating Synthetic Free-text Medical Records with Low Re-identification Risk using Masked Language Modeling}},
  booktitle = {Student Research Workshop @ NAACL},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-srw.20},
}
Figure