MaziyarPanahi commited on
Commit
34fdb3c
Β·
verified Β·
1 Parent(s): db35493

Upload MLX packaging for OpenMed-ZeroShot-NER-DNA-Multi-209M-mlx

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* 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
 
 
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
README.md ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: OpenMed/OpenMed-ZeroShot-NER-DNA-Multi-209M
4
+ pipeline_tag: token-classification
5
+ library_name: openmed
6
+ tags:
7
+ - openmed
8
+ - mlx
9
+ - apple-silicon
10
+ - zero-shot-ner
11
+ - gliner
12
+ - medical
13
+ - clinical
14
+ ---
15
+
16
+ # OpenMed-ZeroShot-NER-DNA-Multi-209M for OpenMed MLX
17
+
18
+ This repository contains an OpenMed MLX conversion of [`OpenMed/OpenMed-ZeroShot-NER-DNA-Multi-209M`](https://huggingface.co/OpenMed/OpenMed-ZeroShot-NER-DNA-Multi-209M) for Apple Silicon inference with [OpenMed](https://github.com/maziyarpanahi/openmed).
19
+
20
+ Artifact metadata:
21
+
22
+ - OpenMed MLX task: `zero-shot-ner`
23
+ - OpenMed MLX family: `gliner-uni-encoder-span`
24
+ - Weight format: `safetensors`
25
+ - Runtime API: `GLiNERMLXPipeline`
26
+
27
+ [OpenMed](https://github.com/maziyarpanahi/openmed) is the main product experience:
28
+
29
+ - Install the Python package with `pip install openmed`
30
+ - Enable Apple Silicon acceleration with `pip install "openmed[mlx]"`
31
+ - Load this MLX model directly from the Hub or from a local snapshot
32
+ - For Apple apps, use OpenMedKit from the same GitHub repository with a compatible CoreML bundle
33
+
34
+ This MLX repo is meant to pair with:
35
+
36
+ - OpenMed GitHub: [https://github.com/maziyarpanahi/openmed](https://github.com/maziyarpanahi/openmed)
37
+ - OpenMed website: [https://openmed.life](https://openmed.life)
38
+ - Source checkpoint: [`OpenMed/OpenMed-ZeroShot-NER-DNA-Multi-209M`](https://huggingface.co/OpenMed/OpenMed-ZeroShot-NER-DNA-Multi-209M)
39
+
40
+ ## Quick Start
41
+
42
+ ```bash
43
+ pip install openmed
44
+ pip install "openmed[mlx]"
45
+ ```
46
+
47
+ ```python
48
+ from huggingface_hub import snapshot_download
49
+ from openmed.mlx.inference import GLiNERMLXPipeline
50
+
51
+ model_path = snapshot_download("OpenMed/OpenMed-ZeroShot-NER-DNA-Multi-209M-mlx")
52
+ pipe = GLiNERMLXPipeline(model_path)
53
+
54
+ entities = pipe.predict_entities(
55
+ "Patient John Doe was seen at Stanford Hospital.",
56
+ labels=["person", "organization", "location"],
57
+ threshold=0.5,
58
+ )
59
+
60
+ for entity in entities:
61
+ print(entity)
62
+ ```
63
+
64
+ Prompt packing metadata included with the model:
65
+
66
+ ```json
67
+ {
68
+ "kind": "gliner-words",
69
+ "entity_token": "<<ENT>>",
70
+ "separator_token": "<<SEP>>",
71
+ "class_token_index": 250103,
72
+ "embed_marker_token": true,
73
+ "split_mode": "words"
74
+ }
75
+ ```
76
+
77
+ ## Swift and Apple Apps
78
+
79
+ Use Swift with OpenMedKit, not with MLX weight files directly.
80
+
81
+ 1. Open Xcode and go to File > Add Package Dependencies.
82
+ 2. Paste the OpenMed repository URL: `https://github.com/maziyarpanahi/openmed`
83
+ 3. Choose the package product OpenMedKit from the repository.
84
+ 4. Add a compatible CoreML model bundle plus `id2label.json` to your app target.
85
+
86
+ This MLX model is for Python services on Apple Silicon, local MLX inference on macOS, and Hub-hosted model distribution. If a given environment cannot write `weights.safetensors`, OpenMed falls back to `weights.npz` so the model remains usable.
87
+
88
+ ## Credits
89
+
90
+ - Base checkpoint: [`OpenMed/OpenMed-ZeroShot-NER-DNA-Multi-209M`](https://huggingface.co/OpenMed/OpenMed-ZeroShot-NER-DNA-Multi-209M)
91
+ - OpenMed GitHub: [https://github.com/maziyarpanahi/openmed](https://github.com/maziyarpanahi/openmed)
92
+ - OpenMed website: [https://openmed.life](https://openmed.life)
93
+ - MLX conversion and runtime support: OpenMed
94
+ - Swift runtime for Apple apps: OpenMedKit from the OpenMed repository
config.json ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "transformers_version": "5.5.0",
3
+ "architectures": [
4
+ "GLiNERSpanModel"
5
+ ],
6
+ "output_hidden_states": false,
7
+ "return_dict": true,
8
+ "dtype": null,
9
+ "chunk_size_feed_forward": 0,
10
+ "is_encoder_decoder": false,
11
+ "id2label": {
12
+ "0": "LABEL_0",
13
+ "1": "LABEL_1"
14
+ },
15
+ "label2id": {
16
+ "LABEL_0": 0,
17
+ "LABEL_1": 1
18
+ },
19
+ "problem_type": null,
20
+ "vocab_size": 250105,
21
+ "hidden_size": 512,
22
+ "num_hidden_layers": 12,
23
+ "num_attention_heads": 12,
24
+ "intermediate_size": 3072,
25
+ "hidden_act": "gelu",
26
+ "hidden_dropout_prob": 0.1,
27
+ "attention_probs_dropout_prob": 0.1,
28
+ "max_position_embeddings": 512,
29
+ "type_vocab_size": 0,
30
+ "initializer_range": 0.02,
31
+ "layer_norm_eps": 1e-07,
32
+ "relative_attention": true,
33
+ "max_relative_positions": -1,
34
+ "pad_token_id": 0,
35
+ "bos_token_id": null,
36
+ "eos_token_id": null,
37
+ "position_biased_input": false,
38
+ "pos_att_type": [
39
+ "p2c",
40
+ "c2p"
41
+ ],
42
+ "pooler_dropout": 0.0,
43
+ "pooler_hidden_act": "gelu",
44
+ "legacy": true,
45
+ "tie_word_embeddings": true,
46
+ "pooler_hidden_size": 768,
47
+ "_name_or_path": "OpenMed/OpenMed-ZeroShot-NER-DNA-Multi-209M",
48
+ "model_type": "deberta-v2",
49
+ "position_buckets": 256,
50
+ "norm_rel_ebd": "layer_norm",
51
+ "share_att_key": true,
52
+ "output_attentions": false,
53
+ "encoder_hidden_size": 768,
54
+ "dropout": 0.4,
55
+ "max_width": 12,
56
+ "num_rnn_layers": 1,
57
+ "embed_ent_token": true,
58
+ "embed_rel_token": true,
59
+ "model_name": "microsoft/mdeberta-v3-base",
60
+ "ent_token": "<<ENT>>",
61
+ "sep_token": "<<SEP>>",
62
+ "_mlx_task": "zero-shot-ner",
63
+ "_mlx_family": "gliner-uni-encoder-span",
64
+ "_mlx_model_type": "deberta-v2",
65
+ "_mlx_runtime": {
66
+ "experimental": true
67
+ },
68
+ "class_token_index": 250103,
69
+ "_mlx_prompt_spec": {
70
+ "kind": "gliner-words",
71
+ "entity_token": "<<ENT>>",
72
+ "separator_token": "<<SEP>>",
73
+ "class_token_index": 250103,
74
+ "embed_marker_token": true,
75
+ "split_mode": "words"
76
+ },
77
+ "embed_class_token": true,
78
+ "rel_token_index": null,
79
+ "text_token_index": null,
80
+ "example_token_index": null,
81
+ "pooling_strategy": "first",
82
+ "class_token_pooling": "first",
83
+ "logit_scale_init_value": 1.0,
84
+ "_mlx_position_offset": 0,
85
+ "embedding_size": 768,
86
+ "_mlx_weights_format": "safetensors"
87
+ }
id2label.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "0": "LABEL_0",
3
+ "1": "LABEL_1"
4
+ }
openmed-mlx.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "format": "openmed-mlx",
3
+ "format_version": 2,
4
+ "task": "zero-shot-ner",
5
+ "family": "gliner-uni-encoder-span",
6
+ "source_model_id": "OpenMed/OpenMed-ZeroShot-NER-DNA-Multi-209M",
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
+ "prompt_spec": {
27
+ "kind": "gliner-words",
28
+ "entity_token": "<<ENT>>",
29
+ "separator_token": "<<SEP>>",
30
+ "class_token_index": 250103,
31
+ "embed_marker_token": true,
32
+ "split_mode": "words"
33
+ },
34
+ "runtime": {
35
+ "experimental": true
36
+ }
37
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4429a446347c64e61dae3f01f56cb59b4ac4afa78b72dd04cd9a28475f122202
3
+ size 16034568
tokenizer_config.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": true,
3
+ "backend": "tokenizers",
4
+ "bos_token": "[CLS]",
5
+ "cls_token": "[CLS]",
6
+ "do_lower_case": false,
7
+ "eos_token": "[SEP]",
8
+ "extra_special_tokens": [
9
+ "[PAD]",
10
+ "[CLS]",
11
+ "[SEP]",
12
+ "▁<extra_id_99>",
13
+ "▁<extra_id_98>",
14
+ "▁<extra_id_97>",
15
+ "▁<extra_id_96>",
16
+ "▁<extra_id_95>",
17
+ "▁<extra_id_94>",
18
+ "▁<extra_id_93>",
19
+ "▁<extra_id_92>",
20
+ "▁<extra_id_91>",
21
+ "▁<extra_id_90>",
22
+ "▁<extra_id_89>",
23
+ "▁<extra_id_88>",
24
+ "▁<extra_id_87>",
25
+ "▁<extra_id_86>",
26
+ "▁<extra_id_85>",
27
+ "▁<extra_id_84>",
28
+ "▁<extra_id_83>",
29
+ "▁<extra_id_82>",
30
+ "▁<extra_id_81>",
31
+ "▁<extra_id_80>",
32
+ "▁<extra_id_79>",
33
+ "▁<extra_id_78>",
34
+ "▁<extra_id_77>",
35
+ "▁<extra_id_76>",
36
+ "▁<extra_id_75>",
37
+ "▁<extra_id_74>",
38
+ "▁<extra_id_73>",
39
+ "▁<extra_id_72>",
40
+ "▁<extra_id_71>",
41
+ "▁<extra_id_70>",
42
+ "▁<extra_id_69>",
43
+ "▁<extra_id_68>",
44
+ "▁<extra_id_67>",
45
+ "▁<extra_id_66>",
46
+ "▁<extra_id_65>",
47
+ "▁<extra_id_64>",
48
+ "▁<extra_id_63>",
49
+ "▁<extra_id_62>",
50
+ "▁<extra_id_61>",
51
+ "▁<extra_id_60>",
52
+ "▁<extra_id_59>",
53
+ "▁<extra_id_58>",
54
+ "▁<extra_id_57>",
55
+ "▁<extra_id_56>",
56
+ "▁<extra_id_55>",
57
+ "▁<extra_id_54>",
58
+ "▁<extra_id_53>",
59
+ "▁<extra_id_52>",
60
+ "▁<extra_id_51>",
61
+ "▁<extra_id_50>",
62
+ "▁<extra_id_49>",
63
+ "▁<extra_id_48>",
64
+ "▁<extra_id_47>",
65
+ "▁<extra_id_46>",
66
+ "▁<extra_id_45>",
67
+ "▁<extra_id_44>",
68
+ "▁<extra_id_43>",
69
+ "▁<extra_id_42>",
70
+ "▁<extra_id_41>",
71
+ "▁<extra_id_40>",
72
+ "▁<extra_id_39>",
73
+ "▁<extra_id_38>",
74
+ "▁<extra_id_37>",
75
+ "▁<extra_id_36>",
76
+ "▁<extra_id_35>",
77
+ "▁<extra_id_34>",
78
+ "▁<extra_id_33>",
79
+ "▁<extra_id_32>",
80
+ "▁<extra_id_31>",
81
+ "▁<extra_id_30>",
82
+ "▁<extra_id_29>",
83
+ "▁<extra_id_28>",
84
+ "▁<extra_id_27>",
85
+ "▁<extra_id_26>",
86
+ "▁<extra_id_25>",
87
+ "▁<extra_id_24>",
88
+ "▁<extra_id_23>",
89
+ "▁<extra_id_22>",
90
+ "▁<extra_id_21>",
91
+ "▁<extra_id_20>",
92
+ "▁<extra_id_19>",
93
+ "▁<extra_id_18>",
94
+ "▁<extra_id_17>",
95
+ "▁<extra_id_16>",
96
+ "▁<extra_id_15>",
97
+ "▁<extra_id_14>",
98
+ "▁<extra_id_13>",
99
+ "▁<extra_id_12>",
100
+ "▁<extra_id_11>",
101
+ "▁<extra_id_10>",
102
+ "▁<extra_id_9>",
103
+ "▁<extra_id_8>",
104
+ "▁<extra_id_7>",
105
+ "▁<extra_id_6>",
106
+ "▁<extra_id_5>",
107
+ "▁<extra_id_4>",
108
+ "▁<extra_id_3>",
109
+ "▁<extra_id_2>",
110
+ "▁<extra_id_1>",
111
+ "▁<extra_id_0>"
112
+ ],
113
+ "is_local": false,
114
+ "mask_token": "[MASK]",
115
+ "model_max_length": 1000000000000000019884624838656,
116
+ "pad_token": "[PAD]",
117
+ "sep_token": "[SEP]",
118
+ "split_by_punct": false,
119
+ "tokenizer_class": "DebertaV2Tokenizer",
120
+ "unk_id": 3,
121
+ "unk_token": "[UNK]",
122
+ "vocab_type": "spm"
123
+ }
weights.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8eb02a569688a3ce1320f98e5025ca54beb1241d59608c04475cfbe3ee7b5634
3
+ size 1155815268