MaziyarPanahi commited on
Commit
94e3edd
·
verified ·
1 Parent(s): 6b53a61

Upload MLX packaging for OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1-mlx

Browse files
Files changed (7) hide show
  1. README.md +106 -0
  2. config.json +199 -0
  3. id2label.json +78 -0
  4. openmed-mlx.json +26 -0
  5. tokenizer.json +0 -0
  6. tokenizer_config.json +21 -0
  7. weights.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1
4
+ pipeline_tag: token-classification
5
+ library_name: openmed
6
+ tags:
7
+ - openmed
8
+ - mlx
9
+ - apple-silicon
10
+ - token-classification
11
+ - pii
12
+ - de-identification
13
+ - medical
14
+ - clinical
15
+ - bert
16
+ ---
17
+
18
+ # OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1 for OpenMed MLX
19
+
20
+ This repository contains an MLX packaging of [`OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1) for Apple Silicon inference with [OpenMed](https://github.com/maziyarpanahi/openmed).
21
+
22
+ ## At a Glance
23
+
24
+ - Source checkpoint: [`OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1)
25
+ - Model family: `bert` (`BertForTokenClassification`)
26
+ - Primary language hint: Portuguese (`pt`)
27
+ - Artifact layout: legacy-compatible MLX (`config.json`, `id2label.json`, MLX weight files)
28
+ - Weight format: `safetensors`
29
+ - Python MLX: supported through `openmed[mlx]` on Apple Silicon Macs
30
+
31
+ ## Python Quick Start
32
+
33
+ Use the standard OpenMed API if you want OpenMed to choose the right runtime automatically:
34
+
35
+ ```bash
36
+ pip install "openmed[mlx]"
37
+ ```
38
+
39
+ ```python
40
+ from openmed import extract_pii
41
+
42
+ text = "<your clinical note here>"
43
+ result = extract_pii(
44
+ text,
45
+ model_name="OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1",
46
+ use_smart_merging=True,
47
+ )
48
+
49
+ for entity in result.entities:
50
+ print(entity.label, entity.text, round(entity.confidence, 4))
51
+ ```
52
+
53
+ On Apple Silicon, OpenMed can use this preconverted MLX artifact when `openmed[mlx]` is installed. On other systems, OpenMed falls back to the Hugging Face / PyTorch backend.
54
+
55
+ ## Use This Preconverted MLX Repo Directly
56
+
57
+ If you want to use this MLX snapshot explicitly, download it locally and point OpenMed at the directory:
58
+
59
+ ```bash
60
+ pip install "openmed[mlx]"
61
+ hf download OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1-mlx --local-dir ./OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1-mlx
62
+ ```
63
+
64
+ If this repo is private in your environment, authenticate first with `hf auth login` or set `HF_TOKEN`.
65
+
66
+ ```python
67
+ from openmed import extract_pii
68
+ from openmed.core import OpenMedConfig
69
+
70
+ text = "<your clinical note here>"
71
+ result = extract_pii(
72
+ text,
73
+ model_name="./OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1-mlx",
74
+ config=OpenMedConfig(backend="mlx"),
75
+ use_smart_merging=True,
76
+ )
77
+
78
+ print(result.entities)
79
+ ```
80
+
81
+ ## Swift Status
82
+
83
+ This repo is based on `bert`. Python MLX supports this artifact today, and this family is in the current OpenMedKit Swift MLX support matrix.
84
+
85
+ If you are building an Apple app today, the recommended paths for this model are:
86
+
87
+ - Python MLX for evaluation or local workflows on Apple Silicon
88
+ - CoreML in OpenMedKit if you already have a compatible bundled Apple export
89
+ - Track the current Swift support matrix in the [OpenMedKit docs](https://openmed.life/docs/swift-openmedkit/)
90
+
91
+ ## Artifact Notes
92
+
93
+ This repo uses the current legacy-compatible MLX layout:
94
+
95
+ - `config.json`
96
+ - `id2label.json`
97
+ - MLX weight files (`weights.safetensors` and/or `weights.npz`)
98
+
99
+ Tokenizer assets are bundled in this repo.
100
+
101
+ ## Links
102
+
103
+ - Source checkpoint: [`OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1)
104
+ - OpenMed GitHub: [https://github.com/maziyarpanahi/openmed](https://github.com/maziyarpanahi/openmed)
105
+ - MLX backend docs: [https://openmed.life/docs/mlx-backend/](https://openmed.life/docs/mlx-backend/)
106
+ - OpenMedKit docs: [https://openmed.life/docs/swift-openmedkit/](https://openmed.life/docs/swift-openmedkit/)
config.json ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "transformers_version": "5.5.0",
3
+ "architectures": [
4
+ "BertForTokenClassification"
5
+ ],
6
+ "output_hidden_states": false,
7
+ "return_dict": true,
8
+ "dtype": "float32",
9
+ "chunk_size_feed_forward": 0,
10
+ "is_encoder_decoder": false,
11
+ "id2label": {
12
+ "0": "O",
13
+ "1": "B-ACCOUNTNAME",
14
+ "2": "B-AGE",
15
+ "3": "B-AMOUNT",
16
+ "4": "B-BANKACCOUNT",
17
+ "5": "B-BIC",
18
+ "6": "B-BITCOINADDRESS",
19
+ "7": "B-BUILDINGNUMBER",
20
+ "8": "B-CITY",
21
+ "9": "B-COUNTY",
22
+ "10": "B-CREDITCARD",
23
+ "11": "B-CREDITCARDISSUER",
24
+ "12": "B-CURRENCY",
25
+ "13": "B-CURRENCYCODE",
26
+ "14": "B-CURRENCYNAME",
27
+ "15": "B-CURRENCYSYMBOL",
28
+ "16": "B-CVV",
29
+ "17": "B-DATE",
30
+ "18": "B-DATEOFBIRTH",
31
+ "19": "B-EMAIL",
32
+ "20": "B-ETHEREUMADDRESS",
33
+ "21": "B-EYECOLOR",
34
+ "22": "B-FIRSTNAME",
35
+ "23": "B-GENDER",
36
+ "24": "B-GPSCOORDINATES",
37
+ "25": "B-HEIGHT",
38
+ "26": "B-IBAN",
39
+ "27": "B-IMEI",
40
+ "28": "B-IPADDRESS",
41
+ "29": "B-JOBDEPARTMENT",
42
+ "30": "B-JOBTITLE",
43
+ "31": "B-LASTNAME",
44
+ "32": "B-LITECOINADDRESS",
45
+ "33": "B-MACADDRESS",
46
+ "34": "B-MASKEDNUMBER",
47
+ "35": "B-MIDDLENAME",
48
+ "36": "B-OCCUPATION",
49
+ "37": "B-ORDINALDIRECTION",
50
+ "38": "B-ORGANIZATION",
51
+ "39": "B-PASSWORD",
52
+ "40": "B-PHONE",
53
+ "41": "B-PIN",
54
+ "42": "B-PREFIX",
55
+ "43": "B-SECONDARYADDRESS",
56
+ "44": "B-SEX",
57
+ "45": "B-SSN",
58
+ "46": "B-STATE",
59
+ "47": "B-STREET",
60
+ "48": "B-TIME",
61
+ "49": "B-URL",
62
+ "50": "B-USERAGENT",
63
+ "51": "B-USERNAME",
64
+ "52": "B-VIN",
65
+ "53": "B-VRM",
66
+ "54": "B-ZIPCODE",
67
+ "55": "I-ACCOUNTNAME",
68
+ "56": "I-AGE",
69
+ "57": "I-AMOUNT",
70
+ "58": "I-CITY",
71
+ "59": "I-COUNTY",
72
+ "60": "I-CURRENCY",
73
+ "61": "I-CURRENCYNAME",
74
+ "62": "I-DATE",
75
+ "63": "I-DATEOFBIRTH",
76
+ "64": "I-EYECOLOR",
77
+ "65": "I-GENDER",
78
+ "66": "I-HEIGHT",
79
+ "67": "I-JOBTITLE",
80
+ "68": "I-ORGANIZATION",
81
+ "69": "I-PHONE",
82
+ "70": "I-SECONDARYADDRESS",
83
+ "71": "I-SSN",
84
+ "72": "I-STATE",
85
+ "73": "I-STREET",
86
+ "74": "I-TIME",
87
+ "75": "I-USERAGENT"
88
+ },
89
+ "label2id": {
90
+ "B-ACCOUNTNAME": 1,
91
+ "B-AGE": 2,
92
+ "B-AMOUNT": 3,
93
+ "B-BANKACCOUNT": 4,
94
+ "B-BIC": 5,
95
+ "B-BITCOINADDRESS": 6,
96
+ "B-BUILDINGNUMBER": 7,
97
+ "B-CITY": 8,
98
+ "B-COUNTY": 9,
99
+ "B-CREDITCARD": 10,
100
+ "B-CREDITCARDISSUER": 11,
101
+ "B-CURRENCY": 12,
102
+ "B-CURRENCYCODE": 13,
103
+ "B-CURRENCYNAME": 14,
104
+ "B-CURRENCYSYMBOL": 15,
105
+ "B-CVV": 16,
106
+ "B-DATE": 17,
107
+ "B-DATEOFBIRTH": 18,
108
+ "B-EMAIL": 19,
109
+ "B-ETHEREUMADDRESS": 20,
110
+ "B-EYECOLOR": 21,
111
+ "B-FIRSTNAME": 22,
112
+ "B-GENDER": 23,
113
+ "B-GPSCOORDINATES": 24,
114
+ "B-HEIGHT": 25,
115
+ "B-IBAN": 26,
116
+ "B-IMEI": 27,
117
+ "B-IPADDRESS": 28,
118
+ "B-JOBDEPARTMENT": 29,
119
+ "B-JOBTITLE": 30,
120
+ "B-LASTNAME": 31,
121
+ "B-LITECOINADDRESS": 32,
122
+ "B-MACADDRESS": 33,
123
+ "B-MASKEDNUMBER": 34,
124
+ "B-MIDDLENAME": 35,
125
+ "B-OCCUPATION": 36,
126
+ "B-ORDINALDIRECTION": 37,
127
+ "B-ORGANIZATION": 38,
128
+ "B-PASSWORD": 39,
129
+ "B-PHONE": 40,
130
+ "B-PIN": 41,
131
+ "B-PREFIX": 42,
132
+ "B-SECONDARYADDRESS": 43,
133
+ "B-SEX": 44,
134
+ "B-SSN": 45,
135
+ "B-STATE": 46,
136
+ "B-STREET": 47,
137
+ "B-TIME": 48,
138
+ "B-URL": 49,
139
+ "B-USERAGENT": 50,
140
+ "B-USERNAME": 51,
141
+ "B-VIN": 52,
142
+ "B-VRM": 53,
143
+ "B-ZIPCODE": 54,
144
+ "I-ACCOUNTNAME": 55,
145
+ "I-AGE": 56,
146
+ "I-AMOUNT": 57,
147
+ "I-CITY": 58,
148
+ "I-COUNTY": 59,
149
+ "I-CURRENCY": 60,
150
+ "I-CURRENCYNAME": 61,
151
+ "I-DATE": 62,
152
+ "I-DATEOFBIRTH": 63,
153
+ "I-EYECOLOR": 64,
154
+ "I-GENDER": 65,
155
+ "I-HEIGHT": 66,
156
+ "I-JOBTITLE": 67,
157
+ "I-ORGANIZATION": 68,
158
+ "I-PHONE": 69,
159
+ "I-SECONDARYADDRESS": 70,
160
+ "I-SSN": 71,
161
+ "I-STATE": 72,
162
+ "I-STREET": 73,
163
+ "I-TIME": 74,
164
+ "I-USERAGENT": 75,
165
+ "O": 0
166
+ },
167
+ "problem_type": null,
168
+ "vocab_size": 30522,
169
+ "hidden_size": 1024,
170
+ "num_hidden_layers": 24,
171
+ "num_attention_heads": 16,
172
+ "intermediate_size": 4096,
173
+ "hidden_act": "gelu",
174
+ "hidden_dropout_prob": 0.1,
175
+ "attention_probs_dropout_prob": 0.1,
176
+ "max_position_embeddings": 512,
177
+ "type_vocab_size": 2,
178
+ "initializer_range": 0.02,
179
+ "layer_norm_eps": 1e-12,
180
+ "pad_token_id": 0,
181
+ "use_cache": false,
182
+ "classifier_dropout": null,
183
+ "is_decoder": false,
184
+ "add_cross_attention": false,
185
+ "bos_token_id": null,
186
+ "eos_token_id": null,
187
+ "tie_word_embeddings": true,
188
+ "_name_or_path": "OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1",
189
+ "gradient_checkpointing": false,
190
+ "model_type": "bert",
191
+ "position_embedding_type": "absolute",
192
+ "output_attentions": false,
193
+ "_mlx_task": "token-classification",
194
+ "_mlx_family": "bert",
195
+ "_mlx_position_offset": 0,
196
+ "_mlx_model_type": "bert",
197
+ "num_labels": 76,
198
+ "_mlx_weights_format": "safetensors"
199
+ }
id2label.json ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "0": "O",
3
+ "1": "B-ACCOUNTNAME",
4
+ "2": "B-AGE",
5
+ "3": "B-AMOUNT",
6
+ "4": "B-BANKACCOUNT",
7
+ "5": "B-BIC",
8
+ "6": "B-BITCOINADDRESS",
9
+ "7": "B-BUILDINGNUMBER",
10
+ "8": "B-CITY",
11
+ "9": "B-COUNTY",
12
+ "10": "B-CREDITCARD",
13
+ "11": "B-CREDITCARDISSUER",
14
+ "12": "B-CURRENCY",
15
+ "13": "B-CURRENCYCODE",
16
+ "14": "B-CURRENCYNAME",
17
+ "15": "B-CURRENCYSYMBOL",
18
+ "16": "B-CVV",
19
+ "17": "B-DATE",
20
+ "18": "B-DATEOFBIRTH",
21
+ "19": "B-EMAIL",
22
+ "20": "B-ETHEREUMADDRESS",
23
+ "21": "B-EYECOLOR",
24
+ "22": "B-FIRSTNAME",
25
+ "23": "B-GENDER",
26
+ "24": "B-GPSCOORDINATES",
27
+ "25": "B-HEIGHT",
28
+ "26": "B-IBAN",
29
+ "27": "B-IMEI",
30
+ "28": "B-IPADDRESS",
31
+ "29": "B-JOBDEPARTMENT",
32
+ "30": "B-JOBTITLE",
33
+ "31": "B-LASTNAME",
34
+ "32": "B-LITECOINADDRESS",
35
+ "33": "B-MACADDRESS",
36
+ "34": "B-MASKEDNUMBER",
37
+ "35": "B-MIDDLENAME",
38
+ "36": "B-OCCUPATION",
39
+ "37": "B-ORDINALDIRECTION",
40
+ "38": "B-ORGANIZATION",
41
+ "39": "B-PASSWORD",
42
+ "40": "B-PHONE",
43
+ "41": "B-PIN",
44
+ "42": "B-PREFIX",
45
+ "43": "B-SECONDARYADDRESS",
46
+ "44": "B-SEX",
47
+ "45": "B-SSN",
48
+ "46": "B-STATE",
49
+ "47": "B-STREET",
50
+ "48": "B-TIME",
51
+ "49": "B-URL",
52
+ "50": "B-USERAGENT",
53
+ "51": "B-USERNAME",
54
+ "52": "B-VIN",
55
+ "53": "B-VRM",
56
+ "54": "B-ZIPCODE",
57
+ "55": "I-ACCOUNTNAME",
58
+ "56": "I-AGE",
59
+ "57": "I-AMOUNT",
60
+ "58": "I-CITY",
61
+ "59": "I-COUNTY",
62
+ "60": "I-CURRENCY",
63
+ "61": "I-CURRENCYNAME",
64
+ "62": "I-DATE",
65
+ "63": "I-DATEOFBIRTH",
66
+ "64": "I-EYECOLOR",
67
+ "65": "I-GENDER",
68
+ "66": "I-HEIGHT",
69
+ "67": "I-JOBTITLE",
70
+ "68": "I-ORGANIZATION",
71
+ "69": "I-PHONE",
72
+ "70": "I-SECONDARYADDRESS",
73
+ "71": "I-SSN",
74
+ "72": "I-STATE",
75
+ "73": "I-STREET",
76
+ "74": "I-TIME",
77
+ "75": "I-USERAGENT"
78
+ }
openmed-mlx.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "format": "openmed-mlx",
3
+ "format_version": 2,
4
+ "task": "token-classification",
5
+ "family": "bert",
6
+ "source_model_id": "OpenMed/OpenMed-PII-Portuguese-ClinicalBGE-Large-335M-v1",
7
+ "config_path": "config.json",
8
+ "label_map_path": "id2label.json",
9
+ "preferred_weights": "weights.safetensors",
10
+ "fallback_weights": [
11
+ "weights.npz"
12
+ ],
13
+ "available_weights": [
14
+ "weights.safetensors"
15
+ ],
16
+ "weights_format": "safetensors",
17
+ "quantization": null,
18
+ "max_sequence_length": 512,
19
+ "tokenizer": {
20
+ "path": ".",
21
+ "files": [
22
+ "tokenizer.json",
23
+ "tokenizer_config.json"
24
+ ]
25
+ }
26
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "clean_up_tokenization_spaces": true,
4
+ "cls_token": "[CLS]",
5
+ "do_basic_tokenize": true,
6
+ "do_lower_case": true,
7
+ "is_local": false,
8
+ "mask_token": "[MASK]",
9
+ "max_length": 512,
10
+ "model_max_length": 512,
11
+ "never_split": null,
12
+ "pad_token": "[PAD]",
13
+ "sep_token": "[SEP]",
14
+ "stride": 0,
15
+ "strip_accents": null,
16
+ "tokenize_chinese_chars": true,
17
+ "tokenizer_class": "BertTokenizer",
18
+ "truncation_side": "right",
19
+ "truncation_strategy": "longest_first",
20
+ "unk_token": "[UNK]"
21
+ }
weights.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b93afe8ca6f8361c79ae3f3b5ff745736433549ade6d0a7c8b19f4fa86670165
3
+ size 1336723265