Text Embeddings by Weakly-Supervised Contrastive Pre-training
Paper
•
2212.03533
•
Published
•
1
This is a LiteRT (formerly TensorFlow Lite) conversion of intfloat/e5-small-v2 for efficient on-device inference.
| Property | Value |
|---|---|
| Original Model | intfloat/e5-small-v2 |
| Format | LiteRT (.tflite) |
| File Size | 127.0 MB |
| Task | Sentence Embeddings / Retrieval |
| Max Sequence Length | 512 |
| Output Dimension | 384 |
| Pooling Mode | Mean Pooling |
Benchmarked on AMD CPU (WSL2):
| Metric | Value |
|---|---|
| Inference Latency | 92.7 ms |
| Throughput | 10.8 tokens/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="intfloat_e5-small-v2.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
tokenizer = AutoTokenizer.from_pretrained("intfloat/e5-small-v2")
def get_embedding(text: str) -> np.ndarray:
"""Get sentence embedding for input text."""
encoded = tokenizer(
text,
padding="max_length",
max_length=512,
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,)
intfloat_e5-small-v2.tflite - The LiteRT model fileThis model inherits the license from the original:
@article{wang2022text,
title={Text Embeddings by Weakly-Supervised Contrastive Pre-training},
author={Wang, Liang and Yang, Nan and Huang, Xiaolong and others},
journal={arXiv preprint arXiv:2212.03533},
year={2022}
}
Converted by Bombek1
Base model
intfloat/e5-small-v2