ant-lingfei commited on
Commit
23e495e
·
verified ·
1 Parent(s): 397d5b9

Add LingSante MedGuard README and license

Browse files
Files changed (3) hide show
  1. LICENSE +202 -0
  2. NOTICE +14 -0
  3. README.md +169 -0
LICENSE ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or any Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any Derivative Works prepared by You or submitted to You,
127
+ provided that such additional attribution notices are consistent
128
+ with those held by the Licensor for the Derivative Works as a
129
+ whole, or that Your notices are required to be provided to any
130
+ third party.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing
143
+ the origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable for any damages, whether direct, indirect, as a result of any
160
+ action, claim, or other proceeding arising in any way out of the
161
+ use or inability to use the Work (including but not limited to
162
+ damages for loss of goodwill, work stoppage, computer failure or
163
+ malfunction, or any and all other damages), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on Your
172
+ behalf of any other Contributor, and then only if You agree to
173
+ indemnify, defend, and hold each Contributor harmless for any
174
+ liability incurred by, or claims asserted against, such Contributor
175
+ by reason of your accepting any such additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
NOTICE ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ LingSante MedGuard data attribution
2
+ =============================
3
+
4
+ LingSante MedGuard names identify project adaptations of the following sources:
5
+
6
+ - HealthBench: https://huggingface.co/datasets/openai/healthbench
7
+ - MedHallTune: https://huggingface.co/datasets/russellyq/MedHallTune
8
+ - MedSafetyBench: https://github.com/AI4LIFE-GROUP/med-safety-bench
9
+ - RxSafeBench: https://github.com/CAS-SIAT-XinHai/RxSafeBench
10
+ - MedRepBench: https://huggingface.co/datasets/MedRepBench/MedRepBench
11
+
12
+ Project code and our original annotations and adaptations are licensed under Apache-2.0.
13
+ Third-party data and images remain subject to their original licenses and terms.
14
+ See LICENSE and the source list above for details.
README.md ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <h1 align="center">LingSante MedGuard</h1>
2
+ <h3 align="center">A Capability-Enhanced Guardrail for Medical AI</h3>
3
+
4
+ <p align="center">
5
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-green.svg" alt="License: Apache 2.0"></a>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <a href="#introduction">Introduction</a> ·
10
+ <a href="#results">Results</a> ·
11
+ <a href="#method">Method</a> ·
12
+ <a href="#dataset">Dataset</a> ·
13
+ <a href="#quick-start">Quick Start</a>
14
+ </p>
15
+
16
+ ---
17
+
18
+
19
+ <a id="introduction"></a>
20
+
21
+ ## 🎯 Introduction
22
+
23
+ **LingSante MedGuard** reviews medical AI responses for safety, compliance, and ethical risks. It combines medical risk detection with specialized capabilities for interpreting rules, checking numerical reasoning, verifying evidence, locating errors, detecting hallucinations, and understanding multimodal medical entities.
24
+
25
+ **LingSante MedGuardBench** provides **14,588 medical risk-detection records** across **three JSONL files**, covering medical safety, compliance, and ethics, with **578 images**.
26
+
27
+ - 🛡️ **Medical safety:** Identify advice that may harm patients or delay appropriate care, including medication interactions and contraindications.
28
+ - ⚖️ **Medical compliance:** Assess responses against applicable professional requirements, rules, and procedures.
29
+ - 🤝 **Medical ethics:** Identify conflicts with ethical principles and safeguards in medical contexts.
30
+
31
+ - **Risk evaluation:** 14,588 records across safety, compliance, and ethics.
32
+ - **Data formats:** Three JSONL files and 578 images.
33
+
34
+ ## 💡 Key Features
35
+
36
+ - **Patient-specific risk assessment.** Evaluate medical advice in the context of patient information, clinical conditions, and applicable requirements.
37
+ - **Capability-level evaluation.** Assess medical risk localization, numerical answerability, direct and retrieval-enabled evidence verification, and text-based and multimodal hallucination detection.
38
+ - **Unified medical guardrail.** Integrate a medical risk teacher and six capability experts through supervised learning and multi-teacher on-policy distillation.
39
+ - **Text and image coverage.** Examine both written medical responses and their consistency with visual evidence.
40
+
41
+ <a id="results"></a>
42
+
43
+ ## 🏆 Benchmark Results
44
+
45
+ Results cover the full evaluation suite; the released datasets cover medical risk detection.
46
+
47
+ ### Medical Risk Detection
48
+
49
+ F1 scores (%) on the original experimental suite, including MedSafetyBench. **Full** covers text and multimodal tasks; **Text** covers text-only tasks.
50
+
51
+ | Model | Full F1 | Text F1 |
52
+ |---|---:|---:|
53
+ | **LingSante MedGuard 27B** | **87.4** | **86.6** |
54
+ | Claude-Fable-5 | 84.8 | 84.5 |
55
+ | Gemini-3.1-Pro-preview | 82.9 | 80.9 |
56
+ | **LingSante MedGuard 9B** | **82.5** | **80.4** |
57
+ | **LingSante MedGuard 4B** | **82.3** | **80.5** |
58
+ | GPT-5.6-Sol | 80.3 | 79.2 |
59
+ | Qwen3.5-397B-A17B | 79.7 | 77.8 |
60
+ | Kimi-K3 | 79.3 | 76.3 |
61
+ | Qwen3.5 27B | 79.1 | 76.5 |
62
+ | Qwen3.5 4B | 76.1 | 74.5 |
63
+ | Qwen3.5-35B-A3B | 74.1 | 71.2 |
64
+ | Qwen3.5 9B | 74.0 | 71.4 |
65
+ | Qwen3.6-35B-A3B | 73.1 | 69.3 |
66
+
67
+ ![Medical risk detection results on the original experimental suite](assets/benchmark-results.png)
68
+
69
+ <a id="method"></a>
70
+
71
+ ## 🧩 Method
72
+
73
+ ### Medical Capability Experts
74
+
75
+ Each expert provides a specific operation needed for medical risk review.
76
+
77
+ | Capability | Review operation |
78
+ |---|---|
79
+ | Medical rule understanding | Match patient facts to rule conditions, exceptions, and role constraints. |
80
+ | Medical numerical reasoning | Check formula applicability, input sufficiency, units, and calculation steps. |
81
+ | Multimodal hallucination detection | Identify fabricated findings, incorrect attributes, and unsupported conclusions. |
82
+ | Agentic medical safety verification | Retrieve sources, assess their relevance and support, and gather additional evidence when needed. |
83
+ | Medical risk localization | Locate the sentence, span, or reasoning step responsible for a risk. |
84
+ | Multimodal entity understanding | Extract medical entities, values, units, and relationships while preserving their correspondence. |
85
+
86
+ ### Two-Stage Multi-Teacher Distillation
87
+
88
+ A medical risk teacher and six capability experts form the teacher bank. In **Stage 1**, the student learns from task-specific teacher demonstrations through supervised fine-tuning. In **Stage 2**, the student generates its own trajectories, and the corresponding teacher supplies token-level feedback for on-policy updates. These stages integrate the experts' capabilities into a single medical guardrail.
89
+
90
+ ![Medical teachers, offline distillation, and on-policy distillation](assets/training-overview.png)
91
+
92
+ ## ⚖️ Case Study: Medical Rule Understanding
93
+
94
+ ![Medical rule understanding: prescription request without prior examination](assets/rule-understanding-case.png)
95
+
96
+ <a id="dataset"></a>
97
+
98
+ ## 📊 Dataset
99
+
100
+ LingSante MedGuardBench contains 14,588 records from HealthBench, MedHallTune, MedSafetyBench, RxSafeBench, and MedRepBench.
101
+
102
+ Each record includes an `upstream_dataset` field identifying its upstream dataset. The original `source` field identifies the benchmark subset.
103
+
104
+ | `source` | `upstream_dataset` |
105
+ |---|---|
106
+ | `healthbench` | [HealthBench](https://huggingface.co/datasets/openai/healthbench) |
107
+ | `medhalltune` | [MedHallTune](https://huggingface.co/datasets/russellyq/MedHallTune) |
108
+ | `med_safety_bench` | [MedSafetyBench](https://github.com/AI4LIFE-GROUP/med-safety-bench) |
109
+ | `rx_i` | [RxSafeBench](https://github.com/CAS-SIAT-XinHai/RxSafeBench) |
110
+ | `rx_c` | [RxSafeBench](https://github.com/CAS-SIAT-XinHai/RxSafeBench) |
111
+ | `medrepbench` | [MedRepBench](https://huggingface.co/datasets/MedRepBench/MedRepBench) |
112
+
113
+ ### Risk Detection
114
+
115
+ | Dataset | Evaluation focus | Records |
116
+ |---|---|---:|
117
+ | [LingSante MedGuard-Safety](data/LingSante%20MedGuard-Safety.jsonl) | Medical safety, including drug interactions, medication contraindications, and report interpretation | 10,248 |
118
+ | [LingSante MedGuard-Compliance](data/LingSante%20MedGuard-Compliance.jsonl) | Medical compliance | 3,808 |
119
+ | [LingSante MedGuard-Ethics](data/LingSante%20MedGuard-Ethics.jsonl) | Medical ethics | 532 |
120
+ | **Total** | | **14,588** |
121
+
122
+ ### Data Format
123
+
124
+ Each JSONL file contains one JSON object per line. `user_question` contains the input context or medication task. `model_response` contains the candidate response under review and is absent from Rx-I/Rx-C records. `label` is the reference `safe` or `unsafe` annotation. Sample identifiers and the original `source` values are preserved. Image paths in `images` are relative to the repository root, with image files stored in [the image directory](images).
125
+
126
+ <a id="quick-start"></a>
127
+
128
+ ## 🚀 Quick Start
129
+
130
+ ### Download the Dataset
131
+
132
+ Clone the repository to download the data:
133
+
134
+ ```bash
135
+ git clone https://code.alipay.com/guoyi.lgy/LingSante-MedGuard.git /absolute/path/to/LingSante-MedGuard
136
+ ```
137
+
138
+ ### Read Task Records
139
+
140
+ ```python
141
+ import json
142
+ from pathlib import Path
143
+
144
+ repo = Path("/absolute/path/to/LingSante-MedGuard")
145
+ dataset = repo / "data" / "LingSante MedGuard-Safety.jsonl"
146
+
147
+ with dataset.open(encoding="utf-8") as stream:
148
+ records = [json.loads(line) for line in stream if line.strip()]
149
+
150
+ print(f"Loaded {len(records):,} records")
151
+ print(records[0].keys())
152
+ ```
153
+
154
+ ### Serve a Local Model
155
+
156
+ Python 3.10+ and a compatible CUDA GPU are required.
157
+
158
+ ```bash
159
+ pip install -r /absolute/path/to/LingSante-MedGuard/scripts/requirements.txt
160
+ bash /absolute/path/to/LingSante-MedGuard/scripts/deploy_model.sh /absolute/path/to/model
161
+ ```
162
+
163
+ The service defaults to `http://127.0.0.1:8000/v1`, with model name `LingSante MedGuard`. Set `TP` for tensor parallelism. The deployment script starts the model service; it does not run evaluation or scoring.
164
+
165
+ ## 📄 License
166
+
167
+ Project code and our original annotations and adaptations are licensed under Apache-2.0.
168
+ Third-party data and images remain subject to their original licenses and terms.
169
+ See LICENSE and the source list above for details.