Initial int4 v0.1.0 bundle
Browse files- .gitattributes +1 -0
- MANIFEST.json +12 -0
- README.md +79 -0
- id2label.json +35 -0
- model_config.json +11 -0
- tokenizer.json +3 -0
- tokenizer_config.json +11 -0
- weights.safetensors +3 -0
.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
|
MANIFEST.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "privacy-filter-int4-v0.1.0",
|
| 3 |
+
"version": "0.1.0",
|
| 4 |
+
"variant": "int4",
|
| 5 |
+
"files": {
|
| 6 |
+
"weights.safetensors": "c2b21e76d88c16239f512d5f9b7c36468ed331c892dafab4c3281d870e361ec8",
|
| 7 |
+
"tokenizer.json": "0614fe83cadab421296e664e1f48f4261fa8fef6e03e63bb75c20f38e37d07d3",
|
| 8 |
+
"tokenizer_config.json": "6c14af9ce1a284d3c3c5146b26efe4cd589c68e1dd4e9d94455606ec911ba774",
|
| 9 |
+
"id2label.json": "82ec14dd6f97ce46c227689a06507f258919e48235591a90bfc1cb73f97f5a32",
|
| 10 |
+
"model_config.json": "db5c0180d6e454987f207ccc00dfc1ceb5f710b0d43a3113d090e5d3cf640b87"
|
| 11 |
+
}
|
| 12 |
+
}
|
README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: openai/privacy-filter
|
| 4 |
+
tags:
|
| 5 |
+
- mlx
|
| 6 |
+
- token-classification
|
| 7 |
+
- privacy
|
| 8 |
+
- pii-detection
|
| 9 |
+
- bioes
|
| 10 |
+
library_name: mlx
|
| 11 |
+
pipeline_tag: token-classification
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# privacy-filter-mlx (int4)
|
| 15 |
+
|
| 16 |
+
MLX-converted, int4-quantized weights of [openai/privacy-filter](https://huggingface.co/openai/privacy-filter),
|
| 17 |
+
packaged for use with [PrivacyFilterKit](https://github.com/kokluch/privacy-filter-swift) — a Swift package
|
| 18 |
+
that runs on-device PII detection on Apple platforms via [MLX-Swift](https://github.com/ml-explore/mlx-swift).
|
| 19 |
+
|
| 20 |
+
## Bundle contents
|
| 21 |
+
|
| 22 |
+
| File | Purpose |
|
| 23 |
+
|------|---------|
|
| 24 |
+
| `weights.safetensors` | int4 affine-quantized weights (group_size=64). Embedding + classifier head kept full-precision. |
|
| 25 |
+
| `tokenizer.json` | Hugging Face tokenizer (copied verbatim from upstream). |
|
| 26 |
+
| `tokenizer_config.json` | Tokenizer config. |
|
| 27 |
+
| `id2label.json` | 33-label BIOES table (8 entity types: account_number, private_address, private_date, private_email, private_person, private_phone, private_url, secret). |
|
| 28 |
+
| `model_config.json` | Architecture parameters consumed by the Swift runtime. |
|
| 29 |
+
| `MANIFEST.json` | SHA-256 hashes of every file in the bundle. |
|
| 30 |
+
|
| 31 |
+
## Architecture
|
| 32 |
+
|
| 33 |
+
- 8 transformer layers, hidden size 640, 14 attention heads (2 KV heads, GQA)
|
| 34 |
+
- 128 local experts, top-4 MoE routing
|
| 35 |
+
- 200 064 vocab, 131 072 max position embeddings, sliding-window attention (128)
|
| 36 |
+
- 33-label BIOES head; the Swift decoder derives a BIOES validity mask at runtime
|
| 37 |
+
(no learned CRF transition matrix in the upstream checkpoint)
|
| 38 |
+
|
| 39 |
+
## Usage (Swift)
|
| 40 |
+
|
| 41 |
+
```swift
|
| 42 |
+
import PrivacyFilterKit
|
| 43 |
+
|
| 44 |
+
let bundle = URL(fileURLWithPath: "/path/to/privacy-filter-int4-v0.1.0")
|
| 45 |
+
let filter = try await PrivacyFilter(source: .directory(bundle))
|
| 46 |
+
let entities = try await filter.detect(in: "Email me at jane@example.com")
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
See the [PrivacyFilterKit README](https://github.com/kokluch/privacy-filter-swift) for the full API.
|
| 50 |
+
|
| 51 |
+
## Conversion pipeline
|
| 52 |
+
|
| 53 |
+
The conversion was produced by the scripts in [`privacy-filter-swift/scripts/`](https://github.com/kokluch/privacy-filter-swift/tree/main/scripts):
|
| 54 |
+
|
| 55 |
+
1. `01_download_hf.py` — download the upstream checkpoint
|
| 56 |
+
2. `02_export_config.py` — extract label table, tokenizer, normalized model config
|
| 57 |
+
3. `03_convert_mlx.py` — rename keys, downcast to bf16, write MLX-friendly safetensors
|
| 58 |
+
4. `04_quantize_mlx.py` — int4 affine quantization (embedding + classifier head full-precision)
|
| 59 |
+
5. `06_export_bundle.py` — assemble bundle + MANIFEST + tar.gz archive
|
| 60 |
+
|
| 61 |
+
## License
|
| 62 |
+
|
| 63 |
+
Apache 2.0, inherited from the upstream model. See [LICENSE](https://www.apache.org/licenses/LICENSE-2.0.txt).
|
| 64 |
+
|
| 65 |
+
## Modifications from upstream
|
| 66 |
+
|
| 67 |
+
This bundle is a derivative of `openai/privacy-filter`. Significant changes:
|
| 68 |
+
|
| 69 |
+
- Weights converted from PyTorch safetensors to MLX-format safetensors (key rename + bf16 cast).
|
| 70 |
+
- int4 affine-quantized (group_size=64). Embedding, classifier head, and any transition matrix
|
| 71 |
+
are kept full-precision.
|
| 72 |
+
- Bundle adds `model_config.json`, `id2label.json`, and `MANIFEST.json` for the Swift runtime;
|
| 73 |
+
no model logic is changed.
|
| 74 |
+
|
| 75 |
+
## Credits
|
| 76 |
+
|
| 77 |
+
- Upstream model: [`openai/privacy-filter`](https://huggingface.co/openai/privacy-filter)
|
| 78 |
+
- Swift runtime: [PrivacyFilterKit](https://github.com/kokluch/privacy-filter-swift)
|
| 79 |
+
- Conversion runtime: [MLX](https://github.com/ml-explore/mlx) / [MLX-Swift](https://github.com/ml-explore/mlx-swift)
|
id2label.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"0": "O",
|
| 3 |
+
"1": "B-account_number",
|
| 4 |
+
"2": "I-account_number",
|
| 5 |
+
"3": "E-account_number",
|
| 6 |
+
"4": "S-account_number",
|
| 7 |
+
"5": "B-private_address",
|
| 8 |
+
"6": "I-private_address",
|
| 9 |
+
"7": "E-private_address",
|
| 10 |
+
"8": "S-private_address",
|
| 11 |
+
"9": "B-private_date",
|
| 12 |
+
"10": "I-private_date",
|
| 13 |
+
"11": "E-private_date",
|
| 14 |
+
"12": "S-private_date",
|
| 15 |
+
"13": "B-private_email",
|
| 16 |
+
"14": "I-private_email",
|
| 17 |
+
"15": "E-private_email",
|
| 18 |
+
"16": "S-private_email",
|
| 19 |
+
"17": "B-private_person",
|
| 20 |
+
"18": "I-private_person",
|
| 21 |
+
"19": "E-private_person",
|
| 22 |
+
"20": "S-private_person",
|
| 23 |
+
"21": "B-private_phone",
|
| 24 |
+
"22": "I-private_phone",
|
| 25 |
+
"23": "E-private_phone",
|
| 26 |
+
"24": "S-private_phone",
|
| 27 |
+
"25": "B-private_url",
|
| 28 |
+
"26": "I-private_url",
|
| 29 |
+
"27": "E-private_url",
|
| 30 |
+
"28": "S-private_url",
|
| 31 |
+
"29": "B-secret",
|
| 32 |
+
"30": "I-secret",
|
| 33 |
+
"31": "E-secret",
|
| 34 |
+
"32": "S-secret"
|
| 35 |
+
}
|
model_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"hiddenSize": 640,
|
| 3 |
+
"numLayers": 8,
|
| 4 |
+
"numAttentionHeads": 14,
|
| 5 |
+
"numKeyValueHeads": 2,
|
| 6 |
+
"numExperts": 128,
|
| 7 |
+
"topK": 4,
|
| 8 |
+
"vocabSize": 200064,
|
| 9 |
+
"maxPositionEmbeddings": 131072,
|
| 10 |
+
"numLabels": 33
|
| 11 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0614fe83cadab421296e664e1f48f4261fa8fef6e03e63bb75c20f38e37d07d3
|
| 3 |
+
size 27868174
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"eos_token": "<|endoftext|>",
|
| 4 |
+
"model_input_names": [
|
| 5 |
+
"input_ids",
|
| 6 |
+
"attention_mask"
|
| 7 |
+
],
|
| 8 |
+
"model_max_length": 128000,
|
| 9 |
+
"pad_token": "<|endoftext|>",
|
| 10 |
+
"tokenizer_class": "TokenizersBackend"
|
| 11 |
+
}
|
weights.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c2b21e76d88c16239f512d5f9b7c36468ed331c892dafab4c3281d870e361ec8
|
| 3 |
+
size 971369779
|