Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
|
3 |
+
license: apache-2.0
|
4 |
+
inference: false
|
5 |
+
|
6 |
+
---
|
7 |
+
```
|
8 |
+
from transformers import AutoTokenizer, AutoModelWithLMHead
|
9 |
+
|
10 |
+
import torch
|
11 |
+
if torch.cuda.is_available():
|
12 |
+
device = torch.device("cuda")
|
13 |
+
else :
|
14 |
+
device = "cpu"
|
15 |
+
|
16 |
+
tokenizer = AutoTokenizer.from_pretrained("salesken/paraphrase_generation")
|
17 |
+
model = AutoModelWithLMHead.from_pretrained("salesken/paraphrase_generation").to(device)
|
18 |
+
|
19 |
+
input_query="every moment is a fresh beginning"
|
20 |
+
query= input_query + " ~~ "
|
21 |
+
|
22 |
+
input_ids = tokenizer.encode(query.lower(), return_tensors='pt').to(device)
|
23 |
+
sample_outputs = model.generate(input_ids,
|
24 |
+
do_sample=True,
|
25 |
+
num_beams=1,
|
26 |
+
max_length=128,
|
27 |
+
temperature=0.9,
|
28 |
+
top_n= 0.99,
|
29 |
+
top_k = 30,
|
30 |
+
num_return_sequences=40)
|
31 |
+
paraphrases = []
|
32 |
+
for i in range(len(sample_outputs)):
|
33 |
+
r = tokenizer.decode(sample_outputs[i], skip_special_tokens=True).split('||')[0]
|
34 |
+
r = r.split(' ~~ ')[1]
|
35 |
+
if r not in paraphrases:
|
36 |
+
paraphrases.append(r)
|
37 |
+
|
38 |
+
print(paraphrases)
|
39 |
+
|
40 |
+
|
41 |
+
```
|
42 |
+
|
43 |
+
|
44 |
+
To evaluate if a paraphrase is a semantic variation to the input query or just a surface level variation & rank the generated paraphrases, use the following model:
|
45 |
+
|
46 |
+
https://huggingface.co/salesken/paraphrase_diversity_ranker
|
47 |
+
|
48 |
+
|