Views
No views yet
| Property | Value |
|---|---|
| Original Model | BAAI/bge-base-en-v1.5 |
| Format | LiteRT (.tflite) |
| File Size | 416.0 MB |
| Task | Sentence Embeddings / Retrieval |
| Max Sequence Length | 512 |
| Output Dimension | 768 |
| Pooling Mode | CLS Token Pooling |
| Metric | Value |
|---|---|
| Inference Latency | 313.2 ms |
| Throughput | 3.2 tokens/sec |
| Cosine Similarity vs Original | 1.0000 ✅ |
1import numpy as np
2from ai_edge_litert.interpreter import Interpreter
3from transformers import AutoTokenizer
4
5# Load model and tokenizer
6interpreter = Interpreter(model_path="BAAI_bge-base-en-v1.5.tflite")
7interpreter.allocate_tensors()
8input_details = interpreter.get_input_details()
9output_details = interpreter.get_output_details()
10
11tokenizer = AutoTokenizer.from_pretrained("BAAI/bge-base-en-v1.5")
12
13def get_embedding(text: str) -> np.ndarray:
14 """Get sentence embedding for input text."""
15 encoded = tokenizer(
16 text,
17 padding="max_length",
18 max_length=512,
19 truncation=True,
20 return_tensors="np"
21 )
22
23 interpreter.set_tensor(input_details[0]["index"], encoded["input_ids"].astype(np.int64))
24 interpreter.set_tensor(input_details[1]["index"], encoded["attention_mask"].astype(np.int64))
25 interpreter.invoke()
26
27 return interpreter.get_tensor(output_details[0]["index"])[0]
28
29# Example
30embedding = get_embedding("Hello, world!")
31print(f"Embedding shape: {embedding.shape}") # (768,)BAAI_bge-base-en-v1.5.tflite - The LiteRT model file1@misc{bge_embedding,
2 title={C-Pack: Packaged Resources To Advance General Chinese Embedding},
3 author={Shitao Xiao and Zheng Liu and Peitian Zhang and Niklas Muennighoff},
4 year={2023},
5 eprint={2309.07597},
6 archivePrefix={arXiv}
7}