Transformers and large language models are efficient feature extractors for electronic health record studies

Kevin Yuan, Chang Ho Yoon, Qingze Gu, Henry Munby, A. Sarah Walker, Tingting Zhu, David W. EyreCommunications 2025

Introduction

Electronic Health Records (EHRs) contain a wealth of clinical information, but much of it is trapped in unstructured free-text notes. While researchers traditionally rely on structured ICD-10 codes for large-scale studies, these codes often lack the granularity and timing required for high-fidelity research. This paper explores whether modern Natural Language Processing (NLP), specifically transformer-based models and Large Language Models (LLMs), can efficiently extract clinical "ground truth" from these records.

The "ICD-10 Gap" and Data Distribution

A primary challenge in EHR research is the "lossy" nature of diagnostic codes. ICD-10 codes are frequently recorded after the fact or remain too vague to be useful for specific clinical questions, such as identifying the exact source of an infection. The researchers found that free-text indications resolved unspecific cases into clear infection sources 31% more often than official codes.

Global frequency of infection sources and associated relative uncertainty.

As shown in the global frequency data, categories like "No Specific Source" and "Prophylaxis" dominate, but a significant tail of specific indications exists. The relative uncertainty remains high for rarer categories like "Neurological" and "ENT," highlighting the difficulty of extracting these specific features.

Methodology: Small Models vs. Large Giants

The study compared several approaches to classify nearly a million antibiotic prescriptions:

  • Traditional Methods: Regex and XGBoost.
  • Transformers: Bio+Clinical BERT (fine-tuned on medical text).
  • LLMs: GPT-4 (zero-shot) and fine-tuned GPT-3.5.

A key finding was the effectiveness of the "Pareto Principle" in labeling. By labeling only the 4,000 most frequent unique strings, the team covered 84% of all prescriptions. This strategy allowed for high-performance training without the need to manually review every single record.

Distribution of distinct source combinations and their frequencies.

Performance and Efficiency

Bio+Clinical BERT emerged as the clear winner, achieving an F1 score of 0.97 on internal data and 0.98 on external datasets. Interestingly, this relatively small, domain-specific model outperformed the much larger GPT-4. While GPT-4 provided a strong zero-shot baseline (F1 0.71–0.86), the fine-tuned BERT model was both more accurate and more computationally efficient for large-scale research, processing 10,000 records in roughly 83 seconds.

Conclusion

Transformers, particularly those pre-trained on clinical text, offer a powerful and practical solution for extracting features from EHRs. They bridge the gap left by structured codes, providing the granularity needed for modern clinical research while remaining efficient enough for deployment in real-world hospital datasets. Future work will likely focus on applying these techniques to longer clinical narratives and ensuring data privacy through locally-hosted models.

Summary updated

BibTeX
@inproceedings{yuan2025transformers,
  author = {Kevin Yuan and Chang Ho Yoon and Qingze Gu and Henry Munby and A. Sarah Walker and Tingting Zhu and David W. Eyre},
  title = {{Transformers and large language models are efficient feature extractors for electronic health record studies}},
  booktitle = {Communications},
  year = {2025},
  doi = {10.1038/s43856-025-00790-1},
}
Figure