Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
•
1908.10084
•
Published
•
9
This is a LiteRT (formerly TensorFlow Lite) conversion of sentence-transformers/all-MiniLM-L6-v2 for efficient on-device inference.
| Property | Value |
|---|---|
| Original Model | sentence-transformers/all-MiniLM-L6-v2 |
| Format | LiteRT (.tflite) |
| File Size | 85.8 MB |
| Task | Sentence Embeddings / Semantic Similarity |
| Max Sequence Length | 128 |
| Output Dimension | 384 |
| Pooling Mode | Mean Pooling |
Benchmarked on AMD CPU (WSL2):
| Metric | Value |
|---|---|
| Inference Latency | 10.6 ms |
| Throughput | 94.7/sec |
| Cosine Similarity vs Original | 1.0000 ✅ |
import numpy as np
from ai_edge_litert.interpreter import Interpreter
from transformers import AutoTokenizer
# Load model and tokenizer
interpreter = Interpreter(model_path="sentence-transformers_all-MiniLM-L6-v2.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
def get_embedding(text: str) -> np.ndarray:
"""Get sentence embedding for input text."""
encoded = tokenizer(
text,
padding="max_length",
max_length=128,
truncation=True,
return_tensors="np"
)
interpreter.set_tensor(input_details[0]["index"], encoded["input_ids"].astype(np.int64))
interpreter.set_tensor(input_details[1]["index"], encoded["attention_mask"].astype(np.int64))
interpreter.invoke()
return interpreter.get_tensor(output_details[0]["index"])[0]
# Example
embedding = get_embedding("Hello, world!")
print(f"Embedding shape: {embedding.shape}") # (384,)
sentence-transformers_all-MiniLM-L6-v2.tflite - The LiteRT model fileThis model inherits the license from the original:
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "EMNLP 2019",
year = "2019",
url = "https://arxiv.org/abs/1908.10084",
}
Converted by Bombek1
Base model
sentence-transformers/all-MiniLM-L6-v2