ONNX Model Zoo

EmbeddedLLM/all-MiniLM-L6-v2-onnx-o3-cpu

By EmbeddedLLM · ↓ 4 · ♥ 0 · Updated 2024-02-17

What's in this repo

This page lists the files in EmbeddedLLM/all-MiniLM-L6-v2-onnx-o3-cpu, including model.onnx.

  • 1 ONNX models (.onnx files)
  • 9 files, including 5 .json, 1 .md, 1 .onnx, 1 .txt
  • Last updated 2024-02-17

ONNX files

File Size Download
model.onnx — Download

How to use

These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.

README

ONNX Conversion of sentence-transformers/all-MiniLM-L6-v2

  • ONNX model for CPU with O3 optimisation
  • This is a sentence-transformers model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.

Usage

import torch
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/all-MiniLM-L6-v2-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)
token_embeddings = model(**inputs).last_hidden_state
# Pool
att_mask = inputs["attention_mask"].unsqueeze(-1).expand(token_embeddings.size()).float()
embeddings = torch.sum(token_embeddings * att_mask, 1) / torch.clamp(att_mask.sum(1), min=1e-9)
embeddings = F.normalize(embeddings, p=2, dim=1)
print(embeddings.cpu().numpy().shape)

Model info

feature-extraction sentence-transformers
sentence-transformers onnx bert feature-extraction sentence-similarity en license:apache-2.0 text-embeddings-inference endpoints_compatible region:us
↓ 4 ♥ 0

Created: 2024-02-16

Updated: 2024-02-17

View on Hugging Face

Files (9)

.gitattributes
README.md
config.json
model.onnx ONNX
ort_config.json
special_tokens_map.json
tokenizer.json
tokenizer_config.json
vocab.txt

Related models