EHR-R1 is a family of reasoning-enhanced Large Language Models (LLMs) specifically tailored for Electronic Health Record (EHR) analysis. It is developed based on EHR-Ins, a large-scale, comprehensive EHR reasoning instruction dataset, and is trained through a multi-stage paradigm including domain adaptation, reasoning enhancement, and reinforcement learning. This approach systematically acquires domain knowledge and diverse reasoning capabilities, enabling accurate and robust EHR analysis. The project also introduces EHR-Bench, a new benchmark curated from MIMIC-IV for comprehensive assessment across 42 distinct EHR tasks.
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
34model_name ="BlueZeros/EHR-R1-8B"# This specific EHR-R1-8B model5model = AutoModelForCausalLM.from_pretrained(6 model_name,7 torch_dtype="auto",8 device_map="auto"9)10tokenizer = AutoTokenizer.from_pretrained(model_name)1112ehr_input ="{YOUR FOMATTED EHR INPUT}"13instruction ="{YOUR TASK INSTRUCTION}"14messages =[15{"role":"system","content":"You are a helpful assistant."},16{"role":"user","content": ehr_input +"\n"+ instruction}17]1819# For EHR-R1-1.7B & EHR-R1-8B, control the reasoning mode by setting enable_thinking20text = tokenizer.apply_chat_template(21 messages,22 tokenize=False,23 add_generation_prompt=True,24 enable_thinking=False,25).to(model.device)26# For EHR-R1-72B, you can manually add `<think>\n\n</think>` at the end of the model_inputs to close the reasoning modes.27text +="<think>\n\n</think>"2829model_inputs = tokenizer([text], return_tensors="pt").to(model.device)30generated_ids = model.generate(31**model_inputs,32 max_new_tokens=2048,33 temperature=0.034)35generated_ids =[36 output_ids[len(input_ids):]for input_ids, output_ids inzip(model_inputs.input_ids, generated_ids)37]38response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]39print(response)
📖 Citation
If you find our work helpful or inspiring, please feel free to cite it:
bib
1@article{liao2025ehrr1,
2 title={{EHR-R1: A Reasoning-Enhanced Foundational Language Model for Electronic Health Record Analysis}},
3 author={Liao, Yusheng and Wu, Chaoyi and Liu, Junwei and Jiang, Shuyang and Qiu, Pengcheng and Wang, Haowen and Yue, Yun and Zhen, Shuai and Wang, Jian and Fan, Qianrui and Gu, Jinjie and Zhang, Ya and Wang, Yanfeng and Wang, Yu and Xie, Weidi},
4 journal={arXiv preprint arXiv:2510.25628},
5 year={2025}
6}