Downloads · 30 days
0
dayyass/universal-sentence-encoder-multilingual-large-3-pytorch
universal-sentence-encoder-multilingual-large-3-pytorch is a feature extraction model from dayyass. Use it when you need embeddings to search or compare text. It is set up for sentence-transformers. The card lists the license as mit.
This repository contains code to use mUSE (Multilingual Universal Sentence Encoder) transformer model from TF Hub using PyTorch.
Downloads · 30 days
0
Access
Public
Updated May 22, 2024
Repo size
677 MB
Likes
15
Public
Click a slice to open those files.
.onnx340 MB · 50%
From the Hugging Face model README
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.
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.