This is a truncated version of
sentence-transformers/LaBSE, which is, in turn, a port of
LaBSE by Google.
The current model has only English and Russian tokens left in the vocabulary.
Thus, the vocabulary is 10% of the original, and number of parameters in the whole model is 27% of the original, without any loss in the quality of English and Russian embeddings.
1import torch
2from transformers import AutoTokenizer, AutoModel
3tokenizer = AutoTokenizer.from_pretrained("cointegrated/LaBSE-en-ru")
4model = AutoModel.from_pretrained("cointegrated/LaBSE-en-ru")
5sentences = ["Hello World", "Привет Мир"]
6encoded_input = tokenizer(sentences, padding=True, truncation=True, max_length=64, return_tensors='pt')
7with torch.no_grad():
8 model_output = model(**encoded_input)
9embeddings = model_output.pooler_output
10embeddings = torch.nn.functional.normalize(embeddings)
11print(embeddings)
The model has been truncated in
this notebook.
You can adapt it for other languages (like
EIStakovskii/LaBSE-fr-de), models or datasets.
Fangxiaoyu Feng, Yinfei Yang, Daniel Cer, Narveen Ari, Wei Wang.
Language-agnostic BERT Sentence Embedding. July 2020