Study design · Research feature

Model uses global and local EHR memories to cite evidence in clinical reasoning

A new AI model analyzes electronic health records by combining a global trajectory memory with local event memories to cite evidence when answering clinical questions.

Adapted from research by Chaiho Shin, Kwangsoo Kim.

arXiv preprint revision · 2026-10-01 · Attribution & reuse
In this article
Editorial illustration of linked workflow.

Editor’s introduction

The study evaluates GLoC-EHR, a model designed to reason over electronic health records by maintaining a fixed-size global memory of the patient’s entire clinical trajectory and a local memory of specific events. It generates hospital course summaries and concept descriptions while citing evidence from the record, trained through rationale fine-tuning and group relative policy optimization. On three MIMIC-IV tasks, GLoC-EHR achieves the highest macro AUROC when answering directly, outperforming zero-shot LLMs and matching fine-tuned EHR encoders. When citing evidence, it maintains similar performance to its direct counterpart, with a small drop in macro AUROC and a notable reduction in unsupported evidence terms. The local memory contributes distinct, record-matching findings, especially under strict alignment, without affecting overall accuracy. The model was trained on data from a single health system and shows transferability to a new dataset, though performance may vary across cohorts. Future work will include semantic matching and clinician review of cited findings.

Introduction

Electronic health records (EHRs) capture diagnoses, medication orders, procedures, and measurements over time, providing a rich longitudinal account of a patient’s health and care. These records offer both a broader view of the patient’s clinical trajectory and specific observations relevant to a clinical question. However, clinically relevant information can be dispersed across lengthy, heterogeneous patient records, making it challenging for clinicians to identify and synthesize information needed to guide patient care.

To harness longitudinal EHR data for clinical prediction, EHR-based models have been developed for a wide range of clinical outcome-prediction tasks. In particular, pretrained EHR encoders learn contextual representations of medical codes from patient histories. BEHRT adapts masked language modeling to diagnosis sequences with age and visit information; Med-BERT learns transferable diagnosis representations through large-scale pretraining; and CEHR-BERT incorporates temporal information across multiple structured domains. These models provide a reusable foundation for prediction and can reduce the need for labeled data. However, their usual downstream interface is a task-specific predictive head: adapting to a new outcome generally requires fitting a new head or fine-tuning the model with corresponding labels. Thus, transfer remains dependent on task-specific supervision, even when the underlying representation is reused. Moreover, an outcome score alone does not express the recorded findings that support a clinical inference. Extending these representations to natural-language reasoning therefore requires connecting the encoded record, the clinical question, and the evidence supporting an answer.

One approach to connecting structured EHRs with language models, which encode substantial clinical knowledge, is to serialize medical codes into textual descriptions that the models can embed or reason over. Serialization retains an explicit account of the selected events at a growing context cost. In our downstream cohorts, serializing even the 24-hour observation window yields an average of 4.7k tokens (90th percentile: 14k), increasing to 12.8k (48k) for the full index admission. Other approaches use intermediate textual summaries or fuse language-model embeddings of domain-specific pseudo-notes. Such compression may omit details needed to substantiate a clinical inference. A distinct approach, Llemr, aligns individually encoded clinical events with a generative language model, reducing the input length relative to textual serialization. However, the resulting input still scales with the number of events.

Connecting structured EHRs with language models makes clinical information available for reasoning, but does not by itself ensure that the generated reasoning is supported by the patient’s record. Recent work, including EHRMIND and EHR-R1, develops EHR-based reasoning through reinforcement learning with rewards for final-answer correctness, which do not explicitly distinguish supported from unsupported findings.

Structured EHR representations

RETAIN uses reverse-time attention over visits and variables, and the BERT-style encoders discussed above learn reusable contextual code representations. Autoregressive and time-to-event foundation models are instead pretrained to forecast future events in patient timelines. We build on contextual representations to support language generation grounded in the record.

EHR–language alignment

Clinical text connects structured records with language models in several roles: serialized records read or embedded for prediction, post-training for EHR reasoning, including reinforcement learning, modality-specialist agents that summarize non-text inputs, and pseudo-notes embedded by a frozen language model. Closest to our setting, Llemr connects a frozen clinical event encoder to an LLM through a projection, as multimodal LLMs do for images, time series, and individual health data, and trains it with schema alignment followed by reasoning instruction tuning. Our interface adds a compressed trajectory memory to a separate memory of selected events, and our reward checks whether the generated findings are supported by the record.

Evidence support and rationale faithfulness

Attribution metrics check whether generated statements are supported by a source, but a rationale’s consistency with its input differs from its faithfulness to the process that produced an answer. ERASER separates agreement with evidence annotations from behavioral tests of comprehensiveness and sufficiency, and studies of natural language explanations and chain-of-thought use interventions to test whether stated reasons affect predictions. Accordingly, our matching reward for group relative policy optimization (GRPO) measures support in the record rather than causation, and we evaluate it together with evidence coverage and an intervention that removes cited versus comparable uncited local representations before regenerating the response.

Description-informed EHR encoder

The encoder is pretrained with masked-concept prediction and a contrastive objective that aligns masked event states with their target concept descriptions. We apply code-ID dropout to discourage shortcut learning through exclusive reliance on learned code-ID embeddings and encourage the encoder to use description embeddings. At prediction targets, both the code-ID and description inputs are masked to prevent target-description leakage. The pretrained encoder is then frozen during interface alignment and downstream adaptation. Description processing, embedding equations, pretraining objectives, and sampling settings are specified in Appendix A.1.

Text alignment of the two routes

We align the global–local interface with clinical text at both the trajectory and concept levels. For trajectory-level alignment, we pair the structured event sequence of a hospital admission with the Brief Hospital Course (BHC) section of its discharge summary, treating them as structured and free-text views of the same admission. For concept-level alignment, we pair individual medical concepts with their textual descriptions. We train the global route first and the local route second, keeping the EHR encoder and base language model frozen throughout alignment.

Trajectory alignment

The global route is trained to generate the paired BHC text from the structured admission trajectory. Response-only next-token prediction updates the resampler and global cross-attention modules, with the local route disabled. BHC text serves as supervision for communicating trajectory-level information; downstream inputs consist of the structured observation window and the task instruction.

Reward design

The answer term rewards a correct outcome, the format term encourages a parseable response, and the length term discourages excessive generation. Invalid answers and statements of the outcome itself (e.g., that the patient died) receive a fixed failure reward below any valid total.

Group relative policy optimization

Starting from supervised initialization, we sample a group of responses to each patient–task prompt and standardize their rewards within the group. Responses with higher relative reward are reinforced, and a reference-policy KL term regularizes the update. Two auxiliary losses complement the reward. The answer loss is the cross-entropy of the gold answer at the answer position; it supplies a correctness signal even when all responses in a group give the same answer, so that the answer reward does not vary within the group. The evidence-sufficiency loss is the cross-entropy of the gold answer given only the task prompt and the response’s evidence bullets, with the reasoning prose removed and both EHR memories switched off, as in select-then-predict rationales; it asks whether the cited findings are informative about the outcome, and it is a loss rather than a reward because the reward form favored shorter evidence lists. The encoder and memory constructors remain frozen; the language model and cross-attention interfaces are updated. Reward coefficients, matcher rules, sampling settings, and the precise policy-update implementation are specified in Appendix A.7. To examine whether cited local representations affect the model’s answer, we also define a matched regeneration intervention alongside support and coverage measurements (Appendix A.8).

Data and tasks

Our main dataset is MIMIC-IV v2.2, converted to the OMOP Common Data Model (CDM), with BHC targets from MIMIC-IV-Ext-BHC. It comprises the 128,350 patients with at least one admission that has a BHC. Patients are split 7:1:2 into training, validation, and test sets; every stage, from alignment to the downstream tasks, uses this split and trains only on training patients. We predict three common binary outcomes: in-hospital mortality and long length of stay (more than 7 days) from the first 24 hours of an inpatient admission, and 30-day readmission from the full index admission. EHRSHOT serves as an external validation cohort without retraining. Appendix B gives the cohort flow, task definitions, and sample sizes.

Protocol

Supervised models are selected by validation AUROC (macro AUROC for multi-task models) and retrained with seeds 42–46; we report the test mean and SD, averaging the three tasks within each seed for macro scores. Zero-shot LLMs are evaluated once. GLoC-EHR (Reasoning) is a single GRPO run, for which we report the mean and SD over five sampled chains per case, reflecting decoding rather than training variability. Direct GLoC-EHR variants score only the answer tokens, renormalized over Yes/No (Appendix A.6).

Conclusion

GLoC-EHR gives a language model a fixed-size global memory of an EHR trajectory and a bounded local memory of selected events, aligns both with clinical text, and trains evidence-cited reasoning with rewards for correct answers and record-supported evidence. Answering directly, it matches or exceeds fine-tuned EHR encoders in macro AUROC on three MIMIC-IV tasks, far above zero-shot LLMs. Citing evidence first costs little discrimination after GRPO (0.008 macro AUROC below the direct multi-task model, with a larger AUPRC gap), whereas rationale SFT alone reaches only 0.658. At a similar macro AUROC, the evidence terms lower the share of unsupported evidence from 0.58 to 0.44, and the local route adds distinct supported findings and shapes which findings are cited, with no detectable effect on the answer. Without retraining, GLoC-EHR transfers to EHRSHOT on par with EHR-BERT and answers unseen laboratory questions better than its zero-shot backbone.

Limitations and future work

Our evidence matching is lexical: it checks that each cited finding appears in the patient’s record, but not whether the finding is clinically correct or whether the model relied on it to answer. Future work includes semantic matching of paraphrased findings, for both the reward and the evaluation, and clinician review of the cited evidence. GLoC-EHR (Reasoning) comes from a single training run on data from one health system; additional runs and cohorts would further test the stability of these effects. We also plan to recalibrate its probabilities for each new cohort: on EHRSHOT, the mean predicted probability of a long stay was 0.57 against a prevalence of 0.31.

AI use statement

In this work, we used generative AI tools to assist with translation and to provide feedback on the design of the methodology and experiments. Apart from the teacher rationales used as SFT targets, which are part of our method (Section 3.4), we have not used generative AI tools to generate synthetic data sets, and tasks involving mathematical claims, proofs, or qualitative and thematic data analysis are not applicable to this work. Additionally, we used generative AI tools to draft parts of the paper and edit it for readability, to create and edit analysis and plotting code and figures, and to search for and identify relevant literature. We have reviewed all AI-assisted work: the authors wrote the main content of the paper and revised all AI-drafted text, read and verified every cited work, and checked all AI-assisted code and results. We take responsibility for the final content of this work, including text, claims or artifacts produced with the aid of generative AI.

Method

Section 3 describes the architecture and training stages, and Appendix A specifies the encoder, the interface, the alignment schedule, rationale SFT, the GRPO settings, the reward coefficients, and the full evidence matcher. GRPO training of GLoC-EHR (Reasoning) took about 55 hours on four NVIDIA H200 GPUs.

Evaluation

Section 4 and Appendix C specify the metrics, seeds, sampling settings, bootstrap procedures, and the handling of chains without an answer. Main results are reported as means and standard deviations over five seeds or five sampled chains.

Findings

Raw representations are strongly anisotropic, as observed for other pretrained language models. Input-token means occupy an effective rank of 295 of 2,048 dimensions, and final hidden states collapse further to 70, with a mean pairwise cosine of 0.89. In the raw input space, random qualified concepts have a cosine of 0.61, and 48% of qualified tokens have a different concept with the same qualifier as their nearest neighbour. Whitening restores isotropy (effective rank 1,793 for input-token means and 1,908 for final hidden states) and drives the cosine between unrelated concepts to zero while keeping variants of the same concept close (0.94). Removing only the first principal component leaves the space anisotropic (effective rank 116, random-pair cosine 0.36). Whitened final hidden states give the clearest concept structure: 98.4% of qualified tokens that have a sibling variant find it as their nearest neighbour, compared with 91.1% for whitened and 75.3% for raw input-token means, and the share of same-qualifier neighbours is lowest (31.9%). The forward pass thus composes a multi-token description into a concept-level vector that qualifier words perturb less than a token average does.

Supervised rationale initialization

The reasoning branch starts from the aligned model rather than the direct checkpoint. Approximately 2.5K examples, balanced across task and label, use rationales generated by Qwen3.5-397B-A17B. The teacher receives the gold outcome and a textual rendering of the observed EHR; its outputs are label-conditioned, post-hoc rationales, not independent annotations of clinical causality. After format and content checks, the student is trained to reproduce the rationale and final answer while seeing only the structured EHR interface and task instruction. The EHR encoder remains frozen throughout, while the base LLM, resampler, and both cross-attention interfaces are updated.

Sample

The intervention is applied to the first 500 test cases of each task and to 1,000 further readmission cases, added to test whether a readmission effect seen in the first 500 replicates. Under greedy decoding, 2,280 of the 2,500 chains reach the answer anchor, and 2,062 of them cite at least one concept held in local memory (mortality 453 with 17 positives, long LOS 441 with 152, readmission 1,168 with 75). A chain cites 3.2 such concepts on average, occupying 4.3 of the slots of about 44 distinct concepts in local memory; cited and control concepts have similar informativeness (0.826 vs. 0.833, against 0.715 for all local concepts).

Results

The intervention measures output sensitivity to cited local representations, not causal effects of the corresponding clinical events. Global memory and unmasked local slots remain available, so a small intervention effect can reflect redundant evidence. A cross-attention gate probe also differs from complete route removal: in a global-cross-attention-off probe, the 64 inserted global embeddings remain in the LLM sequence. Such a probe measures the incremental effect of global cross-attention and cannot be described as removing all global information.

Use of the split

Every stage fits its parameters on training patients only: EHR-BERT pretraining, both alignment stages (189,115 training and 27,076 validation admission–BHC pairs), rationale SFT, GRPO, and all supervised baselines. The teacher rationales for SFT are generated from training records only. Checkpoints are chosen per stage: EHR-BERT pretraining and global alignment by validation loss; the supervised baselines and the direct GLoC-EHR variants by validation AUROC (Section 4.2); rationale SFT by early stopping on a held-out 10% of its training examples (Appendix A.6); and concept alignment and GRPO use their final checkpoints (Appendices A.5 and C.2). The downstream tasks inherit the split, so test records are used neither to fit model parameters nor to select checkpoints. bin thresholds were derived from the full cohort before splitting. Neither uses outcome labels, and refitting the bins on training patients alone would change the value bin of 0.35% of measurement events.