Views
No views yet
RuPAWS: https://github.com/ivkrotova/rupaws_dataset based on Quora and QQP;ru_paraphraser: https://huggingface.co/merionum/ru_paraphraser;content_5.tsv).text1 + text2 and text2 + text1 pairs):| source \ label | 0 | 1 |
|---|---|---|
| detox | 1412 | 3843 |
| paraphraser | 5539 | 1688 |
| rupaws_qqp | 1112 | 792 |
| rupaws_wiki | 3526 | 2166 |
learning_rate = 1e-5
batch_size = 8
gradient_accumulation_steps = 4
n_epochs = 3
max_grad_norm = 1.01import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4model = AutoModelForSequenceClassification.from_pretrained('SkolkovoInstitute/ruRoberta-large-paraphrase-v1')
5tokenizer = AutoTokenizer.from_pretrained('SkolkovoInstitute/ruRoberta-large-paraphrase-v1')
6
7def get_similarity(text1, text2):
8 """ Predict the probability that two Russian sentences are paraphrases of each other. """
9 with torch.inference_mode():
10 batch = tokenizer(
11 text1, text2,
12 truncation=True, max_length=model.config.max_position_embeddings, return_tensors='pt',
13 ).to(model.device)
14 proba = torch.softmax(model(**batch).logits, -1)
15 return proba[0][1].item()
16
17print(get_similarity('Я тебя люблю', 'Ты мне нравишься')) # 0.9798
18print(get_similarity('Я тебя люблю', 'Я тебя ненавижу')) # 0.0008