C-Pack: Packaged Resources To Advance General Chinese Embedding
Paper
•
2309.07597
•
Published
•
1
This is a LiteRT (formerly TensorFlow Lite) conversion of BAAI/bge-small-en-v1.5 for efficient on-device inference.
| Property | Value |
|---|---|
| Original Model | BAAI/bge-small-en-v1.5 |
| Format | LiteRT (.tflite) |
| File Size | 127.2 MB |
| Task | Sentence Embeddings / Retrieval |
| Max Sequence Length | 512 |
| Output Dimension | 384 |
| Pooling Mode | CLS Token Pooling |
Benchmarked on AMD CPU (WSL2):
| Metric | Value |
|---|---|
| Inference Latency | 100.2 ms |
| Throughput | 10.0/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="BAAI_bge-small-en-v1.5.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
tokenizer = AutoTokenizer.from_pretrained("BAAI/bge-small-en-v1.5")
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,)
BAAI_bge-small-en-v1.5.tflite - The LiteRT model fileThis model inherits the license from the original:
@misc{bge_embedding,
title={C-Pack: Packaged Resources To Advance General Chinese Embedding},
author={Shitao Xiao and Zheng Liu and Peitian Zhang and Niklas Muennighoff},
year={2023},
eprint={2309.07597},
archivePrefix={arXiv},
}
Converted by Bombek1
Base model
BAAI/bge-small-en-v1.5