Enhance model card with metadata, paper link, code link, and usage example

#1
by nielsr HF Staff - opened
Files changed (1) hide show
  1. README.md +127 -3
README.md CHANGED
@@ -1,3 +1,127 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pipeline_tag: text-generation
4
+ library_name: transformers
5
+ ---
6
+
7
+ # EHR-R1: A Reasoning-Enhanced Foundational Language Model for Electronic Health Record Analysis
8
+
9
+ This repository contains the **EHR-R1-8B** model, part of the **EHR-R1** series, a family of reasoning-enhanced Large Language Models (LLMs) tailored for Electronic Health Record (EHR) analysis. This work was presented in the paper [EHR-R1: A Reasoning-Enhanced Foundational Language Model for Electronic Health Record Analysis](https://huggingface.co/papers/2510.25628).
10
+
11
+ EHR-R1 aims to bridge the gap in existing LLMs for EHR analysis, which often face limitations due to narrow task coverage and a lack of EHR-oriented reasoning capabilities. This model series leverages **EHR-Ins**, a large-scale, comprehensive EHR reasoning instruction dataset, comprising 300k high-quality reasoning cases and 4M non-reasoning cases across 42 distinct EHR tasks. It employs a thinking-graph-driven framework to generate high-quality reasoning data at scale.
12
+
13
+ Through a multi-stage training paradigm, including domain adaptation, reasoning enhancement, and reinforcement learning, EHR-R1 systematically acquires domain knowledge and diverse reasoning capabilities, enabling accurate and robust EHR analysis. The models are evaluated on **EHR-Bench**, a new benchmark curated from MIMIC-IV, spanning 42 tasks.
14
+
15
+ For more details, including other models in the EHR-R1 series (EHR-R1-1.7B, EHR-R1-72B), datasets, and training scripts, please refer to the [official GitHub repository](https://github.com/MAGIC-AI4Med/EHR-R1).
16
+
17
+ <p align="center">
18
+ <img src="https://github.com/MAGIC-AI4Med/EHR-R1/raw/main/assets/teaser.png?raw=true" alt="EHR-R1 Teaser Image">
19
+ </p>
20
+
21
+ ## 💡 Key Highlights
22
+ * We open-source a large-scale instruction dataset [**EHR-Ins**](https://physionet.org/content/mimic-iv-ehr-analysis/1.0/), including 3.5M non-reasoning data and 300k reasoning data.
23
+ * We open-source a comprehensive benchmark [**EHR-Bench**](https://physionet.org/content/mimic-iv-ehr-analysis/1.0/), which covers 42 distinct EHR analysis tasks.
24
+ * We open-source EHR reasoning-enhanced LLMs **EHR-R1**, including [**EHR-R1-1.7B**](https://huggingface.co/BlueZeros/EHR-R1-1.7B), [**EHR-R1-8B**](https://huggingface.co/BlueZeros/EHR-R1-8B), and [**EHR-R1-72B**](https://huggingface.co/BlueZeros/EHR-R1-72B)
25
+ * We open-source the "thinking-graph" pipeline, which can synthesize reasoning chains for EHR analysis tasks according to the relation of EHR entities.
26
+
27
+ ## Usage with Hugging Face Transformers
28
+
29
+ To use the EHR-R1-8B model for inference with the `transformers` library, follow the example below.
30
+
31
+ ### EHR Input Format
32
+ For any EHR data, keep the EHR input with markdown format as below:
33
+ * For the event with single record:
34
+ ```markdown
35
+ ## Evant Name [Event Time (YYYY-MM-DD HH:MM:SS)]
36
+ - ItemKey_1: ItemValue_1
37
+ - ItemKey_2: ItemValue_2
38
+ - ItemKey_3: ItemValue_3
39
+ ```
40
+ * For the event with multiple records (like labevents):
41
+ ```markdown
42
+ ## Evant Name [Event Time (YYYY-MM-DD HH:MM:SS)]
43
+ | ItemKey_1 | ItemKey_2 | ItemKey_3 |
44
+ | --------- | --------- | --------- |
45
+ | ItemValue_1 | ItemValue_2 | ItemValue_3 |
46
+ | ItemValue_1 | ItemValue_2 | ItemValue_3 |
47
+ | ItemValue_1 | ItemValue_2 | ItemValue_3 |
48
+ ```
49
+
50
+ ### Inference Example
51
+ ```python
52
+ import torch
53
+ from transformers import AutoModelForCausalLM, AutoTokenizer
54
+
55
+ model_name = "BlueZeros/EHR-R1-8B" # Path to EHR-R1-8B model on Hugging Face
56
+ model = AutoModelForCausalLM.from_pretrained(
57
+ model_name,
58
+ torch_dtype="auto",
59
+ device_map="auto"
60
+ )
61
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
62
+
63
+ ehr_input = """
64
+ ## Admission
65
+ - Admit Source: Emergency Room
66
+ - Admitted From: Emergency Room
67
+ - Admission Type: Emergency
68
+ - Hospital Admission Date: 2167-12-07 00:00:00
69
+ - Hospital Discharge Date: 2167-12-10 00:00:00
70
+
71
+ ## Diagnosis [2167-12-07 10:00:00]
72
+ - Principal Diagnosis: Acute myocardial infarction
73
+ - Secondary Diagnosis: Type 2 diabetes mellitus
74
+
75
+ ## Lab Results [2167-12-07 11:30:00]
76
+ | Test Name | Result | Unit | Reference Range |
77
+ | --------- | ------ | ---- | --------------- |
78
+ | Troponin I | 12.5 | ng/mL | < 0.04 |
79
+ | Glucose | 250 | mg/dL | 70 - 100 |
80
+ """
81
+ instruction = "What is the primary diagnosis for this patient based on the provided EHR data?"
82
+ messages = [
83
+ {"role": "system", "content": "You are a helpful assistant."},
84
+ {"role": "user", "content": ehr_input + "
85
+ " + instruction}
86
+ ]
87
+
88
+ # For EHR-R1-1.7B & EHR-R1-8B, control the reasoning mode by setting enable_thinking
89
+ text = tokenizer.apply_chat_template(
90
+ messages,
91
+ tokenize=False,
92
+ add_generation_prompt=True,
93
+ enable_thinking=False, # Set to False to disable thinking mode for 1.7B/8B models
94
+ )
95
+ # For EHR-R1-72B, you can manually add <think>
96
+
97
+ </think>
98
+ at the end of the model_inputs to close the reasoning modes.
99
+ text += "<think>
100
+
101
+ </think>
102
+ " # Manually close reasoning mode for EHR-R1-72B or when enable_thinking=False
103
+
104
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
105
+ generated_ids = model.generate(
106
+ **model_inputs,
107
+ max_new_tokens=2048,
108
+ temperature=0.0,
109
+ do_sample=False, # For deterministic output
110
+ )
111
+ generated_ids = [
112
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
113
+ ]
114
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
115
+ print(response)
116
+ ```
117
+
118
+ ## Citation
119
+ If you find our work helpful or inspiring, please feel free to cite it:
120
+ ```bib
121
+ @article{liao2025ehrr1,
122
+ title={EHR-R1: A Reasoning-Enhanced Foundational Language Model for Electronic Health Record Analysis},
123
+ 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},
124
+ journal={arXiv preprint arXiv:2510.25628},
125
+ year={2025}
126
+ }
127
+ ```