multilingual-e5-small → Core ML (fp16, enumerated shapes, pooling inside)
Browse files- .gitattributes +1 -0
- MultilingualE5Small.mlpackage/Data/com.apple.CoreML/model.mlmodel +3 -0
- MultilingualE5Small.mlpackage/Data/com.apple.CoreML/weights/weight.bin +3 -0
- MultilingualE5Small.mlpackage/Manifest.json +18 -0
- README.md +49 -0
- config.json +26 -0
- special_tokens_map.json +9 -0
- tokenizer.json +3 -0
- tokenizer_config.json +20 -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
|
MultilingualE5Small.mlpackage/Data/com.apple.CoreML/model.mlmodel
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:121f9988a394565994f5aa26cd8a86a7d32b76e0e5b986ecee07070e5b2f8b27
|
| 3 |
+
size 283336
|
MultilingualE5Small.mlpackage/Data/com.apple.CoreML/weights/weight.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ff0331d7b3e44efd122d3592caf82a09e1d88a0bbd458fc8a24223ebb14a3ba7
|
| 3 |
+
size 235028736
|
MultilingualE5Small.mlpackage/Manifest.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"fileFormatVersion": "1.0.0",
|
| 3 |
+
"itemInfoEntries": {
|
| 4 |
+
"E8077791-CA4B-40BC-AB6D-7AD2E8D812F4": {
|
| 5 |
+
"author": "com.apple.CoreML",
|
| 6 |
+
"description": "CoreML Model Specification",
|
| 7 |
+
"name": "model.mlmodel",
|
| 8 |
+
"path": "com.apple.CoreML/model.mlmodel"
|
| 9 |
+
},
|
| 10 |
+
"F2378018-85B9-4DA1-B8A7-7AB3C0E11498": {
|
| 11 |
+
"author": "com.apple.CoreML",
|
| 12 |
+
"description": "CoreML Model Weights",
|
| 13 |
+
"name": "weights",
|
| 14 |
+
"path": "com.apple.CoreML/weights"
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"rootModelIdentifier": "E8077791-CA4B-40BC-AB6D-7AD2E8D812F4"
|
| 18 |
+
}
|
README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
base_model: intfloat/multilingual-e5-small
|
| 4 |
+
language:
|
| 5 |
+
- ru
|
| 6 |
+
- en
|
| 7 |
+
- multilingual
|
| 8 |
+
tags:
|
| 9 |
+
- coreml
|
| 10 |
+
- sentence-embeddings
|
| 11 |
+
- e5
|
| 12 |
+
library_name: coreml
|
| 13 |
+
pipeline_tag: feature-extraction
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# multilingual-e5-small · Core ML
|
| 17 |
+
|
| 18 |
+
[intfloat/multilingual-e5-small](https://huggingface.co/intfloat/multilingual-e5-small)
|
| 19 |
+
converted to a Core ML **ML Program** (fp16) for on-device semantic search in
|
| 20 |
+
the DND Master app (iPad / iPhone / Mac).
|
| 21 |
+
|
| 22 |
+
## What is inside
|
| 23 |
+
|
| 24 |
+
| File | Purpose |
|
| 25 |
+
|---|---|
|
| 26 |
+
| `MultilingualE5Small.mlpackage` | Core ML model. Inputs `input_ids`, `attention_mask` (`int32`, shape `[1, L]`, L ∈ {16, 32, 64, 128, 256, 512}); output `embedding` `[1, 384]` — masked mean pooling and L2 normalisation are inside the graph. |
|
| 27 |
+
| `tokenizer.json`, `tokenizer_config.json`, `special_tokens_map.json`, `config.json` | XLM-R tokenizer files from the upstream repo, unchanged. |
|
| 28 |
+
|
| 29 |
+
Pad token id is `1` (`<pad>`), attention mask is 1 for real tokens. Use the
|
| 30 |
+
e5 prefixes: `query: ` for queries, `passage: ` for documents.
|
| 31 |
+
|
| 32 |
+
## Conversion notes
|
| 33 |
+
|
| 34 |
+
- coremltools 9.0, torch 2.7.0, transformers 4.46.3, `minimum_deployment_target = iOS18`.
|
| 35 |
+
- Enumerated input shapes instead of a `RangeDim`: with a flexible range Core ML
|
| 36 |
+
returned NaN (“Data-dependent shapes were disabled”).
|
| 37 |
+
- The additive attention mask was replaced by `-1e4` before tracing: the
|
| 38 |
+
default `finfo(float32).min` overflows to `-inf` in fp16 and the softmax
|
| 39 |
+
produces NaN.
|
| 40 |
+
- Parity with the PyTorch reference: cosine 1.000000 on test sentences; parity
|
| 41 |
+
with an MLX fp16 embedding of a 12 270-chunk Russian corpus: min cosine 0.9997.
|
| 42 |
+
- Recommended compute units: `.cpuAndNeuralEngine`. The GPU path is ~25× slower
|
| 43 |
+
for this graph on Apple silicon.
|
| 44 |
+
|
| 45 |
+
The conversion script lives in the app repository (`BestiaryEmbedder/convert-e5-coreml.py`).
|
| 46 |
+
|
| 47 |
+
## License
|
| 48 |
+
|
| 49 |
+
The weights are derived from `intfloat/multilingual-e5-small` (MIT).
|
config.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "tmp/",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"BertModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"classifier_dropout": null,
|
| 8 |
+
"hidden_act": "gelu",
|
| 9 |
+
"hidden_dropout_prob": 0.1,
|
| 10 |
+
"hidden_size": 384,
|
| 11 |
+
"initializer_range": 0.02,
|
| 12 |
+
"intermediate_size": 1536,
|
| 13 |
+
"layer_norm_eps": 1e-12,
|
| 14 |
+
"max_position_embeddings": 512,
|
| 15 |
+
"model_type": "bert",
|
| 16 |
+
"num_attention_heads": 12,
|
| 17 |
+
"num_hidden_layers": 12,
|
| 18 |
+
"pad_token_id": 0,
|
| 19 |
+
"position_embedding_type": "absolute",
|
| 20 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
| 21 |
+
"torch_dtype": "float32",
|
| 22 |
+
"transformers_version": "4.29.0",
|
| 23 |
+
"type_vocab_size": 2,
|
| 24 |
+
"use_cache": true,
|
| 25 |
+
"vocab_size": 250037
|
| 26 |
+
}
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<s>",
|
| 3 |
+
"cls_token": "<s>",
|
| 4 |
+
"eos_token": "</s>",
|
| 5 |
+
"mask_token": "<mask>",
|
| 6 |
+
"pad_token": "<pad>",
|
| 7 |
+
"sep_token": "</s>",
|
| 8 |
+
"unk_token": "<unk>"
|
| 9 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0b44a9d7b51c3c62626640cda0e2c2f70fdacdc25bbbd68038369d14ebdf4c39
|
| 3 |
+
size 17082730
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<s>",
|
| 3 |
+
"clean_up_tokenization_spaces": true,
|
| 4 |
+
"cls_token": "<s>",
|
| 5 |
+
"eos_token": "</s>",
|
| 6 |
+
"mask_token": {
|
| 7 |
+
"__type": "AddedToken",
|
| 8 |
+
"content": "<mask>",
|
| 9 |
+
"lstrip": true,
|
| 10 |
+
"normalized": true,
|
| 11 |
+
"rstrip": false,
|
| 12 |
+
"single_word": false
|
| 13 |
+
},
|
| 14 |
+
"model_max_length": 512,
|
| 15 |
+
"pad_token": "<pad>",
|
| 16 |
+
"sep_token": "</s>",
|
| 17 |
+
"sp_model_kwargs": {},
|
| 18 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
| 19 |
+
"unk_token": "<unk>"
|
| 20 |
+
}
|