julien-c HF staff commited on
Commit
4572cc2
1 Parent(s): 867721c

Migrate model card from transformers-repo

Browse files

Read announcement at https://discuss.huggingface.co/t/announcement-all-model-cards-will-be-migrated-to-hf-co-model-repos/2755
Original file history: https://github.com/huggingface/transformers/commits/master/model_cards/sentence-transformers/LaBSE/README.md

Files changed (1) hide show
  1. README.md +37 -0
README.md ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LaBSE Pytorch Version
2
+ This is a pytorch port of the tensorflow version of [LaBSE](https://tfhub.dev/google/LaBSE/1).
3
+
4
+ To get the sentence embeddings, you can use the following code:
5
+ ```python
6
+ from transformers import AutoTokenizer, AutoModel
7
+
8
+ tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/LaBSE")
9
+ model = AutoModel.from_pretrained("sentence-transformers/LaBSE")
10
+
11
+ sentences = ["Hello World", "Hallo Welt"]
12
+
13
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, max_length=64, return_tensors='pt')
14
+
15
+ with torch.no_grad():
16
+ model_output = model(**encoded_input)
17
+
18
+ embeddings = model_output.pooler_output
19
+ embeddings = torch.nn.functional.normalize(embeddings)
20
+ print(embeddings)
21
+ ```
22
+
23
+
24
+ When you have [sentence-transformers](https://www.sbert.net/) installed, you can use the model like this:
25
+ ```python
26
+ from sentence_transformers import SentenceTransformer
27
+ sentences = ["Hello World", "Hallo Welt"]
28
+
29
+ model = SentenceTransformer('LaBSE')
30
+ embeddings = model.encode(sentences)
31
+ print(embeddings)
32
+ ```
33
+
34
+ ## Reference:
35
+ Fangxiaoyu Feng, Yinfei Yang, Daniel Cer, Narveen Ari, Wei Wang. [Language-agnostic BERT Sentence Embedding](https://arxiv.org/abs/2007.01852). July 2020
36
+
37
+ License: [https://tfhub.dev/google/LaBSE/1](https://tfhub.dev/google/LaBSE/1)