cointegrated commited on
Commit
1bb5b6c
1 Parent(s): 2f4ac72

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +32 -0
README.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: ["ru"]
3
+ tags:
4
+ - russian
5
+ - paraphrasing
6
+ - paraphraser
7
+ - paraphrase
8
+ license: mit
9
+ widget:
10
+ - text: "fill | Каждый охотник желает знать, где сидит фазан."
11
+ ---
12
+
13
+ This is a paraphraser for Russian sentences described [in this Habr post](https://habr.com/ru/post/564916/).
14
+
15
+ It is recommended to use the model with the `encoder_no_repeat_ngram_size` argument:
16
+ ```
17
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
18
+ MODEL_NAME = 'cointegrated/rut5-base-paraphraser'
19
+ model = T5ForConditionalGeneration.from_pretrained(MODEL_NAME)
20
+ tokenizer = T5Tokenizer.from_pretrained(MODEL_NAME)
21
+ model.cuda();
22
+ model.eval();
23
+
24
+ def paraphrase(text, beams=5, grams=4, do_sample=False):
25
+ x = tokenizer(text, return_tensors='pt', padding=True).to(model.device)
26
+ max_size = int(x.input_ids.shape[1] * 1.5 + 10)
27
+ out = model.generate(**x, encoder_no_repeat_ngram_size=grams, num_beams=beams, max_length=max_size, do_sample=do_sample)
28
+ return tokenizer.decode(out[0], skip_special_tokens=True)
29
+
30
+ print(paraphrase('Каждый охотник желает знать, где сидит фазан.'))
31
+ # Все охотники хотят знать где фазан сидит.
32
+ ```