MaziyarPanahi commited on
Commit
61cdfe4
·
verified ·
1 Parent(s): 99e464a

Refresh README for current MLX and OpenMedKit instructions

Browse files
Files changed (1) hide show
  1. README.md +65 -48
README.md CHANGED
@@ -16,90 +16,107 @@ tags:
16
 
17
  # OpenMed-PII-mLiteClinical-Base-135M-v1 for OpenMed MLX
18
 
19
- This repository contains a **private MLX packaging** of [`OpenMed/OpenMed-PII-mLiteClinical-Base-135M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-mLiteClinical-Base-135M-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-mLiteClinical-Base-135M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-mLiteClinical-Base-135M-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-mLiteClinical-Base-135M-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-mLiteClinical-Base-135M-v1-mlx`](https://huggingface.co/OpenMed/OpenMed-PII-mLiteClinical-Base-135M-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-mLiteClinical-Base-135M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-mLiteClinical-Base-135M-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-mLiteClinical-Base-135M-v1 for OpenMed MLX
18
 
19
+ This repository contains an MLX packaging of [`OpenMed/OpenMed-PII-mLiteClinical-Base-135M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-mLiteClinical-Base-135M-v1) for Apple Silicon inference with [OpenMed](https://github.com/maziyarpanahi/openmed).
20
 
21
+ ## At a Glance
22
 
23
+ - **Source checkpoint:** [`OpenMed/OpenMed-PII-mLiteClinical-Base-135M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-mLiteClinical-Base-135M-v1)
24
+ - **Model family:** `distilbert` (`DistilBertForTokenClassification`)
25
+ - **Primary language hint:** English (`en`)
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 clinical note here>"
42
+ result = extract_pii(
43
+ text,
44
  model_name="OpenMed/OpenMed-PII-mLiteClinical-Base-135M-v1",
45
+ use_smart_merging=True,
46
  )
47
 
48
  for entity in result.entities:
49
  print(entity.label, entity.text, round(entity.confidence, 4))
50
  ```
51
 
52
+ On Apple Silicon, OpenMed auto-selects MLX when `openmed[mlx]` is installed. On other systems it falls back to the Hugging Face / PyTorch backend.
53
+
54
+ ## Use This Preconverted MLX Repo Directly
55
 
56
+ If you want to use this MLX snapshot explicitly, download it locally and point OpenMed at the directory:
57
 
58
+ ```bash
59
+ pip install "openmed[mlx]"
60
+ hf download OpenMed/OpenMed-PII-mLiteClinical-Base-135M-v1-mlx --local-dir ./OpenMed-PII-mLiteClinical-Base-135M-v1-mlx
61
+ ```
62
 
63
+ If this repo is still private in your environment, authenticate first with `hf auth login` or set `HF_TOKEN`.
 
 
 
 
64
 
65
+ ```python
66
+ from openmed import extract_pii
67
+ from openmed.core import OpenMedConfig
68
 
69
+ text = "<your clinical note here>"
70
+ result = extract_pii(
71
+ text,
72
+ model_name="./OpenMed-PII-mLiteClinical-Base-135M-v1-mlx",
73
+ config=OpenMedConfig(backend="mlx"),
74
+ use_smart_merging=True,
75
+ )
76
+
77
+ print(result.entities)
78
  ```
79
 
80
+ ## Swift Quick Start with OpenMedKit
81
+
82
+ OpenMedKit can download and run this MLX repo directly.
83
 
84
  ```swift
 
85
  import OpenMedKit
86
 
87
+ let modelDirectory = try await OpenMedModelStore.downloadMLXModel(
88
+ repoID: "OpenMed/OpenMed-PII-mLiteClinical-Base-135M-v1-mlx",
89
+ authToken: "<hugging-face-token-while-private>"
90
+ )
91
 
92
  let openmed = try OpenMed(
93
+ backend: .mlx(modelDirectoryURL: modelDirectory)
94
+ )
95
+
96
+ let entities = try openmed.extractPII(
97
+ "<your clinical note here>"
98
  )
99
  ```
100
 
101
+ Notes:
102
+
103
+ - Swift MLX targets Apple Silicon macOS and physical iPhone/iPad hardware.
104
+ - iOS Simulator is not a Swift MLX target.
105
+ - If you already have a bundled `.mlmodelc` or `.mlpackage`, use the CoreML backend in OpenMedKit instead.
106
+
107
+ ## Artifact Notes
108
 
109
+ This repo uses the current legacy-compatible MLX layout:
 
 
110
 
111
+ - `config.json`
112
+ - `id2label.json`
113
+ - MLX weight files (`weights.safetensors` and/or `weights.npz`)
114
 
115
+ 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.
116
 
117
+ ## Links
118
+
119
+ - Source checkpoint: [`OpenMed/OpenMed-PII-mLiteClinical-Base-135M-v1`](https://huggingface.co/OpenMed/OpenMed-PII-mLiteClinical-Base-135M-v1)
120
  - OpenMed GitHub: [https://github.com/maziyarpanahi/openmed](https://github.com/maziyarpanahi/openmed)
121
+ - MLX backend docs: [https://openmed.life/docs/mlx-backend/](https://openmed.life/docs/mlx-backend/)
122
+ - OpenMedKit docs: [https://openmed.life/docs/swift-openmedkit/](https://openmed.life/docs/swift-openmedkit/)