from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer
from torch import Tensor
import torch
import torch.nn.functional as F
model_name = "hotchpotch/vespa-onnx-intfloat-multilingual-e5-small"
onnx_file_name = "intfloat-multilingual-e5-small.onnx"
model = ORTModelForSequenceClassification.from_pretrained(
model_name, file_name=onnx_file_name
)
# override for last_hidden_states
model.output_names["logits"] = 0
tokenizer = AutoTokenizer.from_pretrained(model_name)
defaverage_pool(last_hidden_state: Tensor, attention_mask: Tensor) -> Tensor:
last_hidden = last_hidden_state.masked_fill(~attention_mask[..., None].bool(), 0.0)
return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
input_texts = [
"query: What is the capital of Japan?",
"query: 日本の首都は?", # "What is the capital of Japan?" in Japanese"passage: ニューヨークは大きな都市です年エネ年エネ", # "New York is a big city" in Japanese"passage: 東京は良い場所です", # "Tokyo is a good place" in Japanese, Tokyo is the capital of Japan.
]
batch_dict = tokenizer(
input_texts, max_length=512, padding=True, truncation=True, return_tensors="pt"
)
if"token_type_ids"notin batch_dict:
batch_dict["token_type_ids"] = torch.zeros_like(batch_dict["input_ids"])
# logits is last_hidden_state
last_hidden_states = model(**batch_dict).logits
embeddings = average_pool(last_hidden_states, batch_dict["attention_mask"])
# same vespa embeddings
embeddings = F.normalize(embeddings, p=2, dim=1)
# similarity scoreprint(embeddings[:2] @ embeddings[2:].T)
All credits for this model go to the authors of Multilingual-E5-large and the associated researchers and organizations. When using this model, please be sure to attribute the original authors.
Runs of hotchpotch vespa-onnx-intfloat-multilingual-e5-small on huggingface.co
12
Total runs
0
24-hour runs
0
3-day runs
1
7-day runs
5
30-day runs
More Information About vespa-onnx-intfloat-multilingual-e5-small huggingface.co Model
More vespa-onnx-intfloat-multilingual-e5-small license Visit here:
vespa-onnx-intfloat-multilingual-e5-small huggingface.co is an AI model on huggingface.co that provides vespa-onnx-intfloat-multilingual-e5-small's model effect (), which can be used instantly with this hotchpotch vespa-onnx-intfloat-multilingual-e5-small model. huggingface.co supports a free trial of the vespa-onnx-intfloat-multilingual-e5-small model, and also provides paid use of the vespa-onnx-intfloat-multilingual-e5-small. Support call vespa-onnx-intfloat-multilingual-e5-small model through api, including Node.js, Python, http.
vespa-onnx-intfloat-multilingual-e5-small huggingface.co is an online trial and call api platform, which integrates vespa-onnx-intfloat-multilingual-e5-small's modeling effects, including api services, and provides a free online trial of vespa-onnx-intfloat-multilingual-e5-small, you can try vespa-onnx-intfloat-multilingual-e5-small online for free by clicking the link below.
hotchpotch vespa-onnx-intfloat-multilingual-e5-small online free url in huggingface.co:
vespa-onnx-intfloat-multilingual-e5-small is an open source model from GitHub that offers a free installation service, and any user can find vespa-onnx-intfloat-multilingual-e5-small on GitHub to install. At the same time, huggingface.co provides the effect of vespa-onnx-intfloat-multilingual-e5-small install, users can directly use vespa-onnx-intfloat-multilingual-e5-small installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
vespa-onnx-intfloat-multilingual-e5-small install url in huggingface.co: