ramsrigouthamg commited on
Commit
b484b9e
1 Parent(s): f0ec0a3

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +48 -0
README.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install transformers==4.10.2
2
+
3
+ !pip install sentencepiece==0.1.96
4
+
5
+ ```
6
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
7
+
8
+ model = AutoModelForSeq2SeqLM.from_pretrained("ramsrigouthamg/t5-large-paraphraser-diverse-high-quality")
9
+ tokenizer = AutoTokenizer.from_pretrained("ramsrigouthamg/t5-large-paraphraser-diverse-high-quality")
10
+
11
+ import torch
12
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
13
+ print ("device ",device)
14
+ model = model.to(device)
15
+
16
+ # Beam Search
17
+
18
+ context = "Once, a group of frogs were roaming around the forest in search of water."
19
+ text = "paraphrase: "+context + " </s>"
20
+
21
+ encoding = tokenizer.encode_plus(text,max_length =128, padding=True, return_tensors="pt")
22
+ input_ids,attention_mask = encoding["input_ids"].to(device), encoding["attention_mask"].to(device)
23
+
24
+ model.eval()
25
+ beam_outputs = model.generate(
26
+ input_ids=input_ids,attention_mask=attention_mask,
27
+ max_length=128,
28
+ early_stopping=True,
29
+ num_beams=15,
30
+ num_return_sequences=3
31
+
32
+ )
33
+
34
+ print ("\n\n")
35
+ print ("Original: ",context)
36
+ for beam_output in beam_outputs:
37
+ sent = tokenizer.decode(beam_output, skip_special_tokens=True,clean_up_tokenization_spaces=True)
38
+ print (sent)
39
+ ```
40
+
41
+ **Output from the above code**
42
+
43
+ ```
44
+ Original: Once, a group of frogs were roaming around the forest in search of water.
45
+ paraphrasedoutput: A herd of frogs were wandering around the woods in search of water.
46
+ paraphrasedoutput: A herd of frogs was wandering around the woods in search of water.
47
+ paraphrasedoutput: A herd of frogs were wandering around the forest in search of water at one time.
48
+ ```