ONNX Model Zoo

dayyass/universal-sentence-encoder-multilingual-large-3-pytorch

By dayyass · ↓ 0 · ♥ 14 · Updated 2024-05-22

What's in this repo

This page lists the files in dayyass/universal-sentence-encoder-multilingual-large-3-pytorch, including model.onnx.

  • 1 ONNX models (.onnx files)
  • 7 files, including 2 .py, 1 .md, 1 .onnx, 1 .pt, 1 .txt
  • Last updated 2024-05-22

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

Convert MUSE from TensorFlow to PyTorch

This repository contains code to use mUSE (Multilingual Universal Sentence Encoder) transformer model from TF Hub using PyTorch.

[!IMPORTANT] The PyTorch model can be used not only for inference, but also for additional training and fine-tuning!

Read more about the project: GitHub.

Usage

The model is available in HF Models directly through torch (currently, without native support from the transformers library).

Model initialization and usage code:

import torch
from functools import partial
from architecture import MUSE
from tokenizer import get_tokenizer, tokenize

PATH_TO_PT_MODEL = "model.pt"
PATH_TO_TF_MODEL = "universal-sentence-encoder-multilingual-large-3"

tokenizer = get_tokenizer(PATH_TO_TF_MODEL)
tokenize = partial(tokenize, tokenizer=tokenizer)

model_torch = MUSE(
    num_embeddings=128010,
    embedding_dim=512,
    d_model=512,
    num_heads=8,
)
model_torch.load_state_dict(
    torch.load(PATH_TO_PT_MODEL)
)

sentence = "Hello, world!"
res = model_torch(tokenize(sentence))

[!NOTE] Currently, the checkpoint of the original TF Hub model is used for tokenization, so it is loaded in the code above.

Model info

feature-extraction sentence-transformers
sentence-transformers onnx mteb Sentence Transformers sentence-similarity arxiv:1803.11175 arxiv:1907.04307 feature-extraction en ru ar zh
↓ 0 ♥ 14

Created: 2024-05-21

Updated: 2024-05-22

View on Hugging Face

Files (7)

.gitattributes
README.md
architecture.py
model.onnx ONNX
model.pt
requirements.txt
tokenizer.py

Related models