Instructions to use EmbeddedLLM/bge-base-en-v1.5-onnx-o3-cpu with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use EmbeddedLLM/bge-base-en-v1.5-onnx-o3-cpu with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="EmbeddedLLM/bge-base-en-v1.5-onnx-o3-cpu")# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("EmbeddedLLM/bge-base-en-v1.5-onnx-o3-cpu") model = AutoModel.from_pretrained("EmbeddedLLM/bge-base-en-v1.5-onnx-o3-cpu") - Notebooks
- Google Colab
- Kaggle
ONNX Conversion of BAAI/bge-base-en-v1.5
- ONNX model for CPU with O3 optimisation
- We exported the model with
use_raw_attention_mask=Truedue to this issue
Usage
import torch.nn.functional as F
from optimum.onnxruntime import ORTModelForFeatureExtraction
from transformers import AutoTokenizer
sentences = [
"The llama (/ˈlɑːmə/) (Lama glama) is a domesticated South American camelid.",
"The alpaca (Lama pacos) is a species of South American camelid mammal.",
"The vicuña (Lama vicugna) (/vɪˈkuːnjə/) is one of the two wild South American camelids.",
]
model_name = "EmbeddedLLM/bge-base-en-v1.5-onnx-o3-cpu"
device = "cpu"
provider = "CPUExecutionProvider"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = ORTModelForFeatureExtraction.from_pretrained(
model_name, use_io_binding=True, provider=provider, device_map=device
)
inputs = tokenizer(
sentences,
padding=True,
truncation=True,
return_tensors="pt",
max_length=model.config.max_position_embeddings,
)
inputs = inputs.to(device)
embeddings = model(**inputs).last_hidden_state[:, 0]
embeddings = F.normalize(embeddings, p=2, dim=1)
print(embeddings.cpu().numpy().shape)
- Downloads last month
- 5