Last active
June 14, 2021 20:51
-
-
Save kylebgorman/d8a6b1342dddfb4e95c46ff39f87a4cb to your computer and use it in GitHub Desktop.
Embedding with rubert.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Documented in: https://metatext.io/models/DeepPavlov-rubert-base-cased | |
import transformers | |
model_name = "DeepPavlov/rubert-base-cased" | |
model = transformers.AutoModel.from_pretrained(model_name) | |
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name) | |
sentence = "Все счастливые семьи похожи друг на друга, каждая несчастливая семья несчастлива по-своему." | |
tokenized = tokenizer(sentence, return_tensors="pt") | |
embeddings = model(**tokenized, output_hidden_states=True).hidden_states[0] | |
print(embeddings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment