Document the Laya Core ML buckets
Browse files
README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
library_name: coreml
|
| 4 |
+
tags:
|
| 5 |
+
- core-ml
|
| 6 |
+
- text-classification
|
| 7 |
+
- on-device
|
| 8 |
---
|
| 9 |
+
|
| 10 |
+
# Core ML models for Privacy AI
|
| 11 |
+
|
| 12 |
+
Core ML conversions used by [Privacy AI](https://apps.apple.com/app/id6738392421), mirrored here so
|
| 13 |
+
the app downloads from one place.
|
| 14 |
+
|
| 15 |
+
## `laya/` — Laya multilingual typed-decision model
|
| 16 |
+
|
| 17 |
+
A **non-autoregressive decision model**: it answers typed questions about a piece of text and
|
| 18 |
+
returns probabilities in a single forward pass. It never generates text.
|
| 19 |
+
|
| 20 |
+
| Primitive | Question | Answer |
|
| 21 |
+
|---|---|---|
|
| 22 |
+
| `choice` | "which of these labels?" | softmax over the option set |
|
| 23 |
+
| `noul` | "is this statement true?" | `P(true)` |
|
| 24 |
+
| `score` | "how much, on this ordinal scale?" | the expected level |
|
| 25 |
+
|
| 26 |
+
Two sequence-length buckets of the same checkpoint, both `e8` (int8 embedding table, float16
|
| 27 |
+
encoder and head):
|
| 28 |
+
|
| 29 |
+
| File | Sequence length | Reads about | Installed |
|
| 30 |
+
|---|---:|---:|---:|
|
| 31 |
+
| `laya/laya_multilingual_e8_L512_options32.mlmodelc` | 512 | 380 tokens of state | 484 MB |
|
| 32 |
+
| `laya/laya_multilingual_e8_L1024_options32.mlmodelc` | 1024 | 765 tokens of state | 487 MB |
|
| 33 |
+
|
| 34 |
+
Both share `laya/tokenizer.json` (Gemma 256k BPE). They cost nearly the same on disk because the
|
| 35 |
+
256k embedding table dominates, so the choice between them is about context length and latency,
|
| 36 |
+
not size.
|
| 37 |
+
|
| 38 |
+
### Interface
|
| 39 |
+
|
| 40 |
+
```
|
| 41 |
+
inputs: input_ids int32 [1, L] attention_mask int32 [1, L]
|
| 42 |
+
marker_map float32 [1, 32, L] question_type float32 [1, 3]
|
| 43 |
+
outputs: logits [1, 32] probabilities [1, 32] action_probabilities [1, 2]
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
`question_type` is a one-hot over `choice=0, score=1, noul=2`. `marker_map` row *i* is a one-hot at
|
| 47 |
+
the position of option *i*'s `[MASK]` token. Up to 32 options per question.
|
| 48 |
+
|
| 49 |
+
Sequence format:
|
| 50 |
+
|
| 51 |
+
```
|
| 52 |
+
[CLS] <type> question: <instructions> [SEP] ([MASK] <option>)* [SEP] <state> [SEP]
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
with `head_max_len = 256` and each option's body clipped to 48 tokens.
|
| 56 |
+
|
| 57 |
+
### Notes
|
| 58 |
+
|
| 59 |
+
- `logits` are **raw and uncalibrated** — the checkpoint ships no fitted temperature. Apply your own
|
| 60 |
+
temperature before the softmax if you need calibrated confidence.
|
| 61 |
+
- `action_probabilities` is already softmaxed inside the graph.
|
| 62 |
+
- Run with `cpuAndNeuralEngine` if you need predictions to survive app backgrounding; the GPU
|
| 63 |
+
partition cannot submit work in the background. `.all` is roughly 3x faster at L512 when the app
|
| 64 |
+
is in the foreground.
|
| 65 |
+
|
| 66 |
+
### Provenance
|
| 67 |
+
|
| 68 |
+
Converted from [`convaiinnovations/laya`](https://huggingface.co/convaiinnovations/laya)
|
| 69 |
+
(`multilingual`, revision `1c5edc17a7acd8701df6fc341c0d179f1c62c982`), encoder
|
| 70 |
+
[`jhu-clsp/mmBERT-base`](https://huggingface.co/jhu-clsp/mmBERT-base). Conversion originally
|
| 71 |
+
published as [`FluidInference/laya-coreml`](https://huggingface.co/FluidInference/laya-coreml).
|
| 72 |
+
|
| 73 |
+
Apache 2.0, as upstream.
|