MaziyarPanahi commited on
Commit
47cb7c3
·
0 Parent(s):

OpenMed mmBERT-ClinicalScope-Spanish-Base-v1

Browse files
Files changed (7) hide show
  1. .gitattributes +36 -0
  2. LICENSE +201 -0
  3. README.md +242 -0
  4. config.json +89 -0
  5. model.safetensors +3 -0
  6. tokenizer.json +3 -0
  7. tokenizer_config.json +25 -0
.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 a 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 such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - es
5
+ library_name: transformers
6
+ pipeline_tag: text-classification
7
+ base_model: jhu-clsp/mmBERT-base
8
+ tags:
9
+ - medical
10
+ - clinical-nlp
11
+ - negation-detection
12
+ - uncertainty-detection
13
+ - speculation
14
+ - scope-detection
15
+ - spanish
16
+ - modernbert
17
+ - openmed
18
+ model-index:
19
+ - name: mmBERT-ClinicalScope-Spanish-Base-v1
20
+ results:
21
+ - task:
22
+ type: text-classification
23
+ name: Negation and uncertainty scope of a marked word
24
+ dataset:
25
+ name: Held-out Spanish clinical sentences (2,028 marked words)
26
+ type: custom
27
+ split: held-out
28
+ metrics:
29
+ - type: f1
30
+ value: 93.42
31
+ name: Macro F1 (three classes)
32
+ - type: accuracy
33
+ value: 95.86
34
+ name: Accuracy
35
+ - type: f1
36
+ value: 96.67
37
+ name: F1 negation_scope
38
+ - type: f1
39
+ value: 87.10
40
+ name: F1 uncertainty_scope
41
+ - type: f1
42
+ value: 96.50
43
+ name: F1 outside_scope
44
+ ---
45
+
46
+ <p align="center">
47
+ <a href="https://huggingface.co/OpenMed"><img src="https://cdn-avatars.huggingface.co/v1/production/uploads/5fd5e18a90b6dc4633f6d292/qWeFUOCMgN4q-ET102lRZ.png" alt="OpenMed" width="110"></a>
48
+ </p>
49
+
50
+ <h1 align="center">OpenMed mmBERT ClinicalScope Spanish Base v1</h1>
51
+
52
+ <p align="center">
53
+ <a href="https://huggingface.co/OpenMed"><img alt="OpenMed on Hugging Face" src="https://img.shields.io/badge/OpenMed-2%2C300%2B%20open%20models-ff9d00"></a>
54
+ <a href="https://github.com/maziyarpanahi/openmed"><img alt="OpenMed SDK on GitHub" src="https://img.shields.io/github/stars/maziyarpanahi/openmed?label=OpenMed%20SDK&logo=github"></a>
55
+ <a href="https://pypi.org/project/openmed/"><img alt="pip install openmed" src="https://img.shields.io/pypi/v/openmed?label=pip%20install%20openmed&color=3775a9"></a>
56
+ <img alt="License Apache-2.0" src="https://img.shields.io/badge/license-Apache--2.0-blue">
57
+ </p>
58
+
59
+ **OpenMed's open model for negation and uncertainty in Spanish clinical text.** Mark one word of a Spanish clinical sentence and it says whether the word is inside a negation scope (*no se observa neumonía*), inside an uncertainty scope (*probable infección urinaria*) or outside both. Trained and evaluated by [OpenMed](https://huggingface.co/OpenMed). Apache-2.0, 307.5M parameters, runs on CPU.
60
+
61
+ | Developed by | [OpenMed](https://huggingface.co/OpenMed) |
62
+ |---|---|
63
+ | Task | Negation and uncertainty scope of one marked word, three classes: `negation_scope`, `uncertainty_scope`, `outside_scope` |
64
+ | Input | One Spanish sentence with one word marked: `Texto: ...⟦word⟧...` |
65
+ | Output | the class and its score |
66
+ | Parameters | 307.5M |
67
+ | Decoding | Highest-scoring class, no threshold |
68
+ | Language | Spanish |
69
+ | License | Apache-2.0 |
70
+
71
+ ## About OpenMed
72
+
73
+ OpenMed builds open models and open-source tools for clinical and biomedical text that run on your own hardware.
74
+
75
+ - **[2,300+ open models on Hugging Face](https://huggingface.co/OpenMed)** for clinical NER, de-identification and more.
76
+ - **[The OpenMed Python SDK](https://github.com/maziyarpanahi/openmed)**, Apache-2.0: `pip install openmed` for de-identification, clinical NER, and FHIR and HL7 tooling, all local.
77
+ - New models every week: follow [OpenMed on Hugging Face](https://huggingface.co/OpenMed) and [@OpenMed_AI on X](https://x.com/OpenMed_AI).
78
+
79
+ ## Quick start
80
+
81
+ ```bash
82
+ pip install -U "transformers>=5.17" torch
83
+ ```
84
+
85
+ ```python
86
+ import re
87
+
88
+ import torch
89
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
90
+
91
+ repo = "OpenMed/mmBERT-ClinicalScope-Spanish-Base-v1"
92
+ tokenizer = AutoTokenizer.from_pretrained(repo)
93
+ model = AutoModelForSequenceClassification.from_pretrained(repo).eval()
94
+
95
+
96
+ def mark(sentence, start, end):
97
+ """The evaluated input: "Texto: " and the sentence, with the word between ⟦ and ⟧."""
98
+ return "Texto: " + sentence[:start] + "⟦" + sentence[start:end] + "⟧" + sentence[end:]
99
+
100
+
101
+ def scope(sentence, words=None):
102
+ """Label every word of the sentence (or only `words`): negation, uncertainty or outside scope."""
103
+ found = [m for m in re.finditer(r"\w+(?:-\w+)*", sentence) if words is None or m.group() in words]
104
+ texts = [mark(sentence, m.start(), m.end()) for m in found]
105
+ with torch.inference_mode():
106
+ probs = model(**tokenizer(texts, padding=True, return_tensors="pt")).logits.softmax(-1)
107
+ return [(m.group(), model.config.id2label[int(p.argmax())], float(p.max())) for m, p in zip(found, probs)]
108
+
109
+
110
+ sentence = "No se observa neumonía ni derrame pleural; probable infección urinaria."
111
+ for word, label, score in scope(sentence):
112
+ print(f"{word:<10} {label:<17} {score:.2f}")
113
+ ```
114
+
115
+ ```text
116
+ No outside_scope 1.00
117
+ se negation_scope 0.92
118
+ observa negation_scope 1.00
119
+ neumonía negation_scope 1.00
120
+ ni negation_scope 0.99
121
+ derrame negation_scope 1.00
122
+ pleural negation_scope 1.00
123
+ probable uncertainty_scope 0.73
124
+ infección uncertainty_scope 1.00
125
+ urinaria uncertainty_scope 0.97
126
+ ```
127
+
128
+ ### How it reads the input
129
+
130
+ - `mark()` builds the input the model was trained and evaluated on: `Texto: ` and the sentence, with the marked word between `⟦` and `⟧`. Keep it exactly as written and mark one word at a time.
131
+ - `scope()` marks every word of the sentence in turn, or only the words you pass, for example `scope(sentence, words={"neumonía", "infección"})`. Pass one sentence at a time.
132
+ - The label is the highest-scoring of the three classes, the decoding behind the evaluation; there is no threshold. Scores are not calibrated probabilities.
133
+ - Read the labels of nouns and adjectives: those are the words it was trained and scored on. Cue words (*no*, *sin*, *probable*) and verbs also get a label, but those were never scored.
134
+ - The training sentences had their punctuation split off by spaces (*neumonía ;*). Normal punctuation works: the quick-start sentence written that way gives the same labels.
135
+
136
+ ### Many sentences, GPU
137
+
138
+ - Many sentences: `scope()` batches the words of one sentence; call it in a loop for many sentences.
139
+ - On a GPU, move the model with `model.to("cuda")` and the batch with `tokenizer(...).to("cuda")`.
140
+
141
+ ## Evaluation
142
+
143
+ **Held-out Spanish clinical sentences:** 2,028 marked words (867 inside a negation scope, 165 inside an uncertainty scope, 996 outside both) in 1,277 sentences of an existing human-annotated corpus of Spanish clinical text with negation and uncertainty scopes. The held-out sentences come from two clinical specialties (cardiology and traumatology) that were kept out of training and tuning. The model was trained on 7,755 marked words from 14 other specialties for two fixed epochs, checked on 2,258 more from two further specialties (internal medicine and urology), and these 2,028 were scored once at the end, with the model, the references and the scoring code frozen first. Marked words are nouns and adjectives of three or more letters; the cue words themselves (*no*, *sin*, *posible*) are never marked. The source has no patient identifiers, so the split is by specialty and sentence, not by patient. Macro F1 averages the F1 of the three classes.
144
+
145
+ | Model | Macro F1 | Accuracy |
146
+ |---|---:|---:|
147
+ | **OpenMed mmBERT ClinicalScope Spanish Base v1** (this model) | **93.42** | 95.86 |
148
+ | Supervised lexical reference: word and character TF-IDF with logistic regression, trained on the same marked words with the marked sentence and six words of context on each side | 80.40 | 86.29 |
149
+ | [fastino/GLiNER2.5-Decide-1B](https://huggingface.co/fastino/GLiNER2.5-Decide-1B) zero-shot with the same task and prompts | 33.26 | 41.52 |
150
+ | Before OpenMed fine-tuning: [jhu-clsp/mmBERT-base](https://huggingface.co/jhu-clsp/mmBERT-base) with a new, untrained three-class head (a control, not a baseline) | 23.95 | 24.46 |
151
+ | Lexical control that sees only the marked word, no context | 49.52 | 59.71 |
152
+
153
+ This model scores **+13.02 macro F1 points** above the supervised lexical reference (95% CI +10.51 to +15.49, paired bootstrap over 1,274 sentence groups, 2,000 resamples). Against the untrained head the change is +69.47 points, but that head is only a control: the real hurdles are the lexical reference and the Decide zero-shot row (+60.16 points, 95% CI +57.96 to +62.22). The lexical control that sees only the marked word reaches 49.52: scope depends on the context, not on the word.
154
+
155
+ ### By class
156
+
157
+ | Class | Marked words | Precision | Recall | F1 | F1, lexical reference |
158
+ |---|---:|---:|---:|---:|---:|
159
+ | negation_scope | 867 | 96.12 | 97.23 | 96.67 | 87.81 |
160
+ | **uncertainty_scope** | 165 | 93.10 | 81.82 | **87.10** | 65.49 |
161
+ | outside_scope | 996 | 96.02 | 96.99 | 96.50 | 87.90 |
162
+
163
+ **Uncertainty is the hardest class: 87.10 F1, recall 81.82.** Of the 165 uncertain words it finds 135; it reads 18 as outside and 12 as negation. Uncertain words are also the rarest in the data.
164
+
165
+ Two harder slices: in sentences that hold both a negation and an uncertainty scope (107 marked words), accuracy is 91.59 (lexical reference 63.55); for words outside scope in sentences that do have a scope (705), recall is 96.17 (lexical reference 85.67), so the model does not stretch a scope over the whole sentence.
166
+
167
+ ## The OpenMed Spanish clinical scope models
168
+
169
+ Same training words, same 2,028 held-out words, same lexical reference (80.40 macro F1). The mmBERT model scores higher overall at about a quarter of the parameters; the Decide model finds 2 more of the 165 uncertain words.
170
+
171
+ | Model | Parameters | Code | Macro F1 | Uncertainty F1 | Change vs lexical reference (95% CI) |
172
+ |---|---:|---|---:|---:|---:|
173
+ | **OpenMed mmBERT ClinicalScope Spanish Base v1** (this model) | 307.5M | Transformers | **93.42** | 87.10 | +13.02 (+10.51 to +15.49) |
174
+ | [OpenMed GLiNER2.5 ClinicalScope Spanish Decide 1B v1](https://huggingface.co/OpenMed/GLiNER2.5-ClinicalScope-Spanish-Decide-1B-v1) | 1.19B | OpenMed SDK | 91.83 | 84.83 | +11.43 (+9.06 to +13.72) |
175
+
176
+ ## Examples
177
+
178
+ Real outputs of this model with the quick-start `scope()` helper (Transformers 5.22.1, on CPU). The sentences are synthetic, written in Spanish for this card. Each word was marked in turn; runs of words inside a scope are in bold with their scope, and words outside both are plain.
179
+
180
+ *Quick start:* No **se observa neumonía ni derrame pleural**<sub>negation</sub>; **probable infección urinaria**<sub>uncertainty</sub>.
181
+
182
+ 1. *Negation list:* Sin **fiebre ni disnea**<sub>negation</sub>; refiere dolor torácico opresivo desde ayer.
183
+ 2. *Probable:* **Probable infección urinaria**<sub>uncertainty</sub>, pendiente de urocultivo.
184
+ 3. *Ruled out:* Se descarta **trombosis venosa profunda mediante**<sub>negation</sub> ecografía doppler.
185
+ 4. *Suspicion:* Sospecha **de fractura de escafoides**<sub>uncertainty</sub>, se solicita resonancia magnética.
186
+ 5. *Not ruled out:* No puede **descartarse**<sub>negation</sub> **una rotura parcial del ligamento cruzado anterior**<sub>uncertainty</sub>.
187
+ 6. *Negation then a finding:* No **se palpan adenopatías cervicales**<sub>negation</sub> y el abdomen es blando y depresible.
188
+ 7. *Both scopes:* Niega **dolor abdominal**<sub>negation</sub>, aunque podría **tratarse de una apendicitis incipiente**<sub>uncertainty</sub>.
189
+ 8. *Double negation:* No es **imposible**<sub>negation</sub> **que exista una lesión meniscal**<sub>uncertainty</sub>.
190
+ 9. *Scope to the end:* No **hay evidencia de metástasis hepáticas ni óseas en el estudio actual**<sub>negation</sub>.
191
+ 10. *Hedged impression:* Impresiona de celulitis, sin **datos de absceso**<sub>negation</sub>.
192
+ 11. *Plan to rule out:* Descartar **tromboembolismo pulmonar**<sub>negation</sub>.
193
+ 12. *Family history:* Su padre falleció de un infarto de miocardio.
194
+
195
+ ## Good to know
196
+
197
+ - A scope stops at the end of its clause: in example 1, *fiebre* and *disnea* are negated and *dolor torácico* after the semicolon is outside; in the quick start the negation stops at the semicolon and *probable* opens an uncertainty scope.
198
+ - One sentence can hold both scopes: example 7 negates *dolor abdominal* and puts *apendicitis incipiente* in an uncertainty scope.
199
+ - A negated doubt reads as uncertainty, not negation: *No puede descartarse una rotura* (example 5) and the double negation *No es imposible que exista una lesión* (example 8) put *rotura* and *lesión* in an uncertainty scope.
200
+ - It misses some hedges: *Impresiona de celulitis* (example 10) leaves *celulitis* outside, although the phrase means the finding is only suspected. *Sospecha de* (example 4) is caught.
201
+ - A plan reads as a negation: *Descartar tromboembolismo pulmonar* (example 11) puts *tromboembolismo* in a negation scope, though nothing has been ruled out yet.
202
+ - A negation scope can run to the end of the sentence: *estudio actual*, where the findings were looked for, is inside the negation in example 9. In example 3 the scope takes in *mediante* and stops before *ecografía doppler*.
203
+ - Outside is not the same as present: *infarto* in example 12 is outside both scopes, but it is the father's history. The model reads negation and uncertainty only; it does not say who has a condition, or when.
204
+ - Most scores sit near 1.00 (77 of the 113 words above round to 1.00), so use them to rank words, not as probabilities.
205
+ - Cue words mostly come back outside (*No* in the quick start, *Sin* and *Sospecha* in examples 1 and 4). They were never scored, so read the findings.
206
+
207
+ ## Limitations
208
+
209
+ - It labels one marked word at a time for negation and uncertainty scope. It is not a full clinical assertion model: *outside* does not mean a condition is present, and it does not handle family history, time, hypotheticals or who the condition belongs to.
210
+ - Trained and tested on held-out sentences of one Spanish clinical corpus, split by specialty and sentence, not by patient; patient-level independence cannot be checked. It has not been validated on other institutions, other kinds of notes or other languages; the examples above are synthetic.
211
+ - Uncertainty is the weak class: 87.10 F1 and 81.82 recall; it missed 30 of the 165 uncertain words in the evaluation.
212
+ - Only nouns and adjectives were marked in training and evaluation. Labels on cue words, verbs and function words were not scored.
213
+ - Scores are not calibrated probabilities.
214
+ - It labels words. It does not give medical advice and is not a medical device.
215
+
216
+ ## Built on
217
+
218
+ OpenMed fine-tuned this model from [jhu-clsp/mmBERT-base](https://huggingface.co/jhu-clsp/mmBERT-base) by Johns Hopkins University CLSP (MIT), built with the open-source [Transformers](https://github.com/huggingface/transformers) library. Training and evaluation data: held-out and training sentences of an existing human-annotated corpus of Spanish clinical text, annotated for negation and uncertainty cues and their scopes. Thank you to Johns Hopkins University CLSP for releasing mmBERT-base openly.
219
+
220
+ This model is released under Apache-2.0. No training or evaluation text is included in this repository.
221
+
222
+ ## Citation
223
+
224
+ ```bibtex
225
+ @misc{panahi2025openmedner,
226
+ title={OpenMed NER: Open-Source, Domain-Adapted State-of-the-Art Transformers for Biomedical NER Across 12 Public Datasets},
227
+ author={Maziyar Panahi},
228
+ year={2025},
229
+ eprint={2508.01630},
230
+ archivePrefix={arXiv}
231
+ }
232
+
233
+ @misc{marone2025mmbert,
234
+ title={mmBERT: A Modern Multilingual Encoder with Annealed Language Learning},
235
+ author={Marc Marone and Orion Weller and William Fleshman and Eugene Yang and Dawn Lawrie and Benjamin Van Durme},
236
+ year={2025},
237
+ eprint={2509.06888},
238
+ archivePrefix={arXiv}
239
+ }
240
+ ```
241
+
242
+ <p align="center"><b>OpenMed</b> · <a href="https://huggingface.co/OpenMed">Hugging Face</a> · <a href="https://github.com/maziyarpanahi/openmed">GitHub</a> · <a href="https://pypi.org/project/openmed/">PyPI</a> · <a href="https://x.com/OpenMed_AI">X</a></p>
config.json ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ModernBertForSequenceClassification"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 2,
8
+ "classifier_activation": "gelu",
9
+ "classifier_bias": false,
10
+ "classifier_dropout": 0.0,
11
+ "classifier_pooling": "mean",
12
+ "cls_token_id": 1,
13
+ "decoder_bias": true,
14
+ "deterministic_flash_attn": false,
15
+ "dtype": "float32",
16
+ "embedding_dropout": 0.0,
17
+ "eos_token_id": 1,
18
+ "global_attn_every_n_layers": 3,
19
+ "gradient_checkpointing": false,
20
+ "hidden_activation": "gelu",
21
+ "hidden_size": 768,
22
+ "id2label": {
23
+ "0": "negation_scope",
24
+ "1": "uncertainty_scope",
25
+ "2": "outside_scope"
26
+ },
27
+ "initializer_cutoff_factor": 2.0,
28
+ "initializer_range": 0.02,
29
+ "intermediate_size": 1152,
30
+ "label2id": {
31
+ "negation_scope": 0,
32
+ "outside_scope": 2,
33
+ "uncertainty_scope": 1
34
+ },
35
+ "layer_norm_eps": 1e-05,
36
+ "layer_types": [
37
+ "full_attention",
38
+ "sliding_attention",
39
+ "sliding_attention",
40
+ "full_attention",
41
+ "sliding_attention",
42
+ "sliding_attention",
43
+ "full_attention",
44
+ "sliding_attention",
45
+ "sliding_attention",
46
+ "full_attention",
47
+ "sliding_attention",
48
+ "sliding_attention",
49
+ "full_attention",
50
+ "sliding_attention",
51
+ "sliding_attention",
52
+ "full_attention",
53
+ "sliding_attention",
54
+ "sliding_attention",
55
+ "full_attention",
56
+ "sliding_attention",
57
+ "sliding_attention",
58
+ "full_attention"
59
+ ],
60
+ "local_attention": 128,
61
+ "mask_token_id": 4,
62
+ "max_position_embeddings": 8192,
63
+ "mlp_bias": false,
64
+ "mlp_dropout": 0.0,
65
+ "model_type": "modernbert",
66
+ "norm_bias": false,
67
+ "norm_eps": 1e-05,
68
+ "num_attention_heads": 12,
69
+ "num_hidden_layers": 22,
70
+ "pad_token_id": 0,
71
+ "position_embedding_type": "sans_pos",
72
+ "problem_type": "single_label_classification",
73
+ "rope_parameters": {
74
+ "full_attention": {
75
+ "rope_theta": 160000,
76
+ "rope_type": "default"
77
+ },
78
+ "sliding_attention": {
79
+ "rope_theta": 160000,
80
+ "rope_type": "default"
81
+ }
82
+ },
83
+ "sep_token_id": 1,
84
+ "sparse_pred_ignore_index": -100,
85
+ "sparse_prediction": false,
86
+ "tie_word_embeddings": true,
87
+ "transformers_version": "5.17.0",
88
+ "vocab_size": 256000
89
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d9d902c76e6ca5fa749ed451d00ccfe9b8bc055a925a993705b6dbf36d2fe34
3
+ size 1230144500
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22fd4a60565f25fee8ebd2866aab07456dd46cbbeb45eaf506529ed8451ee58f
3
+ size 34363343
tokenizer_config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<bos>",
4
+ "clean_up_tokenization_spaces": false,
5
+ "cls_token": "<bos>",
6
+ "eos_token": "<eos>",
7
+ "extra_special_tokens": [
8
+ "<start_of_turn>",
9
+ "<end_of_turn>"
10
+ ],
11
+ "is_local": true,
12
+ "local_files_only": true,
13
+ "mask_token": "<mask>",
14
+ "model_input_names": [
15
+ "input_ids",
16
+ "attention_mask"
17
+ ],
18
+ "model_max_length": 8192,
19
+ "pad_token": "<pad>",
20
+ "padding_side": "right",
21
+ "sep_token": "<eos>",
22
+ "spaces_between_special_tokens": false,
23
+ "tokenizer_class": "TokenizersBackend",
24
+ "unk_token": "<unk>"
25
+ }