Instructions to use haihengh/all-MiniLM-L6-v2-coreml with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use haihengh/all-MiniLM-L6-v2-coreml with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("haihengh/all-MiniLM-L6-v2-coreml") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
all-MiniLM-L6-v2 Core ML
Core ML conversion of sentence-transformers/all-MiniLM-L6-v2 for on-device text embeddings on iOS/macOS.
Model Details
| Property | Value |
|---|---|
| Parameters | 22.7M |
| Embedding dim | 384 |
| Max input tokens | 256 |
| Original model | ~90 MB (FP32) |
| Core ML size | ~43 MB (FP16) |
| Compute units | CPU + Neural Engine |
| Min deployment | iOS 18 / macOS 15 |
Files
all-minilm-l6-v2.mlpackage/β Core ML model package (portable format). Compile withxcrun coremlcompilerfor your target device.all-minilm-l6-v2.mlmodelc/β Pre-compiled model for Apple Silicon Macs.tokenizer/β BERT WordPiece tokenizer (tokenizer.json,vocab.txt, config files).
Usage
Swift (iOS/macOS)
import CoreML
let model = try MLModel(contentsOf: modelURL)
let prediction = try await model.prediction(input: [
"input_ids": inputIds,
"attention_mask": attentionMask,
"token_type_ids": tokenTypeIds
])
let embedding = prediction.featureValue(for: "div_1")!.multiArrayValue!
// Shape: (1, 384), L2-normalized
Python (validation)
import coremltools as ct
from transformers import AutoTokenizer
model = ct.models.MLModel("all-minilm-l6-v2.mlpackage")
tokenizer = AutoTokenizer.from_pretrained("tokenizer/")
encoded = tokenizer("Hello world", return_tensors="np",
padding="max_length", truncation=True, max_length=256)
prediction = model.predict({
"input_ids": encoded["input_ids"].astype("int32"),
"attention_mask": encoded["attention_mask"].astype("int32"),
"token_type_ids": encoded["token_type_ids"].astype("int32"),
})
embedding = prediction["div_1"] # (1, 384), L2-normalized
Accuracy
| Metric | Value |
|---|---|
| Max element diff vs PyTorch FP32 | ~0.001 |
| Cosine similarity vs original | > 0.99995 |
Conversion was done with FP16 precision β effectively lossless for semantic search.
Conversion Pipeline
sentence-transformers/all-MiniLM-L6-v2 (PyTorch)
β torch.export (dynamo)
β coremltools 9.0 (FP16, iOS18)
β all-minilm-l6-v2.mlpackage
β xcrun coremlcompiler
β all-minilm-l6-v2.mlmodelc
License
Apache 2.0 (same as the original model).
- Downloads last month
- -