MaziyarPanahi commited on
Commit
70fc899
·
verified ·
1 Parent(s): 6a8fe80

Refresh README for current MLX and OpenMedKit instructions

Browse files
Files changed (1) hide show
  1. README.md +67 -48
README.md CHANGED
@@ -16,90 +16,109 @@ tags:
16
 
17
  # OpenMed-PII-Italian-FastClinical-Small-82M-v1 for OpenMed MLX
18
 
19
- This repository contains a **private MLX packaging** of [`OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1) for Apple Silicon inference with [**OpenMed**](https://github.com/maziyarpanahi/openmed).
20
 
21
- [OpenMed](https://github.com/maziyarpanahi/openmed) is the main product experience:
22
 
23
- - Install the Python package with `pip install openmed`
24
- - Enable Apple Silicon acceleration with `pip install "openmed[mlx]"`
25
- - Run the same OpenMed API you already use, now backed by MLX on macOS
26
- - For Apple apps, use **OpenMedKit** from the same GitHub repository with a CoreML bundle
 
 
27
 
28
- This MLX repo is meant to pair with:
29
 
30
- - OpenMed GitHub: [https://github.com/maziyarpanahi/openmed](https://github.com/maziyarpanahi/openmed)
31
- - OpenMed website: [https://openmed.life](https://openmed.life)
32
- - Source checkpoint: [`OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1)
33
-
34
- ## Quick Start
35
-
36
- ### Python
37
 
38
  ```bash
39
- pip install openmed
40
  pip install "openmed[mlx]"
41
  ```
42
 
43
  ```python
44
- from openmed import analyze_text
45
- from openmed.core.config import OpenMedConfig
46
 
47
- result = analyze_text(
48
- "Patient John Doe, DOB 1990-05-15, SSN 123-45-6789",
 
49
  model_name="OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1",
50
- config=OpenMedConfig(backend="mlx"),
 
51
  )
52
 
53
  for entity in result.entities:
54
  print(entity.label, entity.text, round(entity.confidence, 4))
55
  ```
56
 
57
- You can use the source model ID directly through OpenMed, or download this private MLX packaging from [`OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1-mlx`](https://huggingface.co/OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1-mlx) for a preconverted path.
 
 
58
 
59
- ### Swift
60
 
61
- Use Swift with **OpenMedKit**, not with MLX weight files directly.
 
 
 
62
 
63
- 1. Open Xcode and go to **File > Add Package Dependencies...**
64
- 2. Paste the OpenMed repository URL:
65
- `https://github.com/maziyarpanahi/openmed`
66
- 3. Choose the package product **OpenMedKit** from the repository.
67
- 4. Add a compatible CoreML model bundle plus `id2label.json` to your app target.
68
 
69
- After that, import OpenMedKit in Swift:
 
 
70
 
71
- ```swift
72
- import OpenMedKit
 
 
 
 
 
 
 
 
73
  ```
74
 
75
- Then load your bundled CoreML model and label map:
 
 
76
 
77
  ```swift
78
- import Foundation
79
  import OpenMedKit
80
 
81
- let modelFolder = Bundle.main.resourceURL!
82
- let modelURL = modelFolder.appendingPathComponent("OpenMedPII.mlmodelc")
83
- let labelsURL = modelFolder.appendingPathComponent("id2label.json")
 
84
 
85
  let openmed = try OpenMed(
86
- modelURL: modelURL,
87
- id2labelURL: labelsURL
 
 
 
88
  )
89
  ```
90
 
91
- This private MLX artifact remains the right choice for:
 
 
 
 
 
 
92
 
93
- - Python services on Apple Silicon
94
- - local MLX inference on macOS
95
- - private preconverted packaging on the Hub
96
 
97
- If a given architecture or environment cannot be exported cleanly as `safetensors`, OpenMed falls back to `weights.npz` so the model remains usable.
 
 
98
 
99
- ## Credits
100
 
101
- - Base checkpoint: [`OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1)
 
 
102
  - OpenMed GitHub: [https://github.com/maziyarpanahi/openmed](https://github.com/maziyarpanahi/openmed)
103
- - OpenMed website: [https://openmed.life](https://openmed.life)
104
- - MLX packaging and runtime support: [**OpenMed**](https://github.com/maziyarpanahi/openmed)
105
- - Swift runtime for Apple apps: **OpenMedKit** from the OpenMed repository
 
16
 
17
  # OpenMed-PII-Italian-FastClinical-Small-82M-v1 for OpenMed MLX
18
 
19
+ This repository contains an MLX packaging of [`OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1) for Apple Silicon inference with [OpenMed](https://github.com/maziyarpanahi/openmed).
20
 
21
+ ## At a Glance
22
 
23
+ - **Source checkpoint:** [`OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1)
24
+ - **Model family:** `roberta` (`RobertaForTokenClassification`)
25
+ - **Primary language hint:** Italian (`it`)
26
+ - **Artifact layout:** legacy-compatible MLX (`config.json`, `id2label.json`, MLX weight files)
27
+ - **Python MLX:** supported through `openmed[mlx]` on Apple Silicon Macs
28
+ - **Swift MLX:** supported today in OpenMedKit on Apple Silicon macOS and real iPhone/iPad hardware
29
 
30
+ ## Python Quick Start
31
 
32
+ Use the standard OpenMed API if you want OpenMed to choose the right runtime automatically:
 
 
 
 
 
 
33
 
34
  ```bash
 
35
  pip install "openmed[mlx]"
36
  ```
37
 
38
  ```python
39
+ from openmed import extract_pii
 
40
 
41
+ text = "<your Italian clinical note here>"
42
+ result = extract_pii(
43
+ text,
44
  model_name="OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1",
45
+ lang="it",
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 auto-selects MLX when `openmed[mlx]` is installed. On other systems it 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-Italian-FastClinical-Small-82M-v1-mlx --local-dir ./OpenMed-PII-Italian-FastClinical-Small-82M-v1-mlx
62
+ ```
63
 
64
+ If this repo is still 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 Italian clinical note here>"
71
+ result = extract_pii(
72
+ text,
73
+ model_name="./OpenMed-PII-Italian-FastClinical-Small-82M-v1-mlx",
74
+ config=OpenMedConfig(backend="mlx"),
75
+ lang="it",
76
+ use_smart_merging=True,
77
+ )
78
+
79
+ print(result.entities)
80
  ```
81
 
82
+ ## Swift Quick Start with OpenMedKit
83
+
84
+ OpenMedKit can download and run this MLX repo directly.
85
 
86
  ```swift
 
87
  import OpenMedKit
88
 
89
+ let modelDirectory = try await OpenMedModelStore.downloadMLXModel(
90
+ repoID: "OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1-mlx",
91
+ authToken: "<hugging-face-token-while-private>"
92
+ )
93
 
94
  let openmed = try OpenMed(
95
+ backend: .mlx(modelDirectoryURL: modelDirectory)
96
+ )
97
+
98
+ let entities = try openmed.extractPII(
99
+ "<your Italian clinical note here>"
100
  )
101
  ```
102
 
103
+ Notes:
104
+
105
+ - Swift MLX targets Apple Silicon macOS and physical iPhone/iPad hardware.
106
+ - iOS Simulator is not a Swift MLX target.
107
+ - If you already have a bundled `.mlmodelc` or `.mlpackage`, use the CoreML backend in OpenMedKit instead.
108
+
109
+ ## Artifact Notes
110
 
111
+ This repo uses the current legacy-compatible MLX layout:
 
 
112
 
113
+ - `config.json`
114
+ - `id2label.json`
115
+ - MLX weight files (`weights.safetensors` and/or `weights.npz`)
116
 
117
+ Tokenizer assets are not bundled in this repo layout. OpenMed and OpenMedKit keep backward compatibility by falling back to the source tokenizer reference in `config.json` when needed.
118
 
119
+ ## Links
120
+
121
+ - Source checkpoint: [`OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-Italian-FastClinical-Small-82M-v1)
122
  - OpenMed GitHub: [https://github.com/maziyarpanahi/openmed](https://github.com/maziyarpanahi/openmed)
123
+ - MLX backend docs: [https://openmed.life/docs/mlx-backend/](https://openmed.life/docs/mlx-backend/)
124
+ - OpenMedKit docs: [https://openmed.life/docs/swift-openmedkit/](https://openmed.life/docs/swift-openmedkit/)