pushkarraj
commited on
Commit
·
c328898
1
Parent(s):
bb88a84
Create README.md
Browse files
README.md
CHANGED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip install transformers
|
2 |
+
!pip install spacy
|
3 |
+
!pip install gradio
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
import pandas as pd
|
7 |
+
import os
|
8 |
+
import time
|
9 |
+
from transformers import pipeline, GPT2Tokenizer, OPTForCausalLM
|
10 |
+
|
11 |
+
model=OPTForCausalLM.from_pretrained('pushkarraj/pushkar_OPT_paraphaser')
|
12 |
+
tokenizer=GPT2Tokenizer.from_pretrained('pushkarraj/pushkar_OPT_paraphaser',truncation=True)
|
13 |
+
|
14 |
+
generator=pipeline("text-generation",model=model,tokenizer=tokenizer,device=0)
|
15 |
+
|
16 |
+
def cleaned_para(input_sentence):
|
17 |
+
p=generator('<s>'+input_sentence+ '</s>>>>><p>',do_sample=True,max_length=len(input_sentence.split(" "))+200,temperature = 0.8,repetition_penalty=1.2,top_p=0.4,top_k=1)
|
18 |
+
return p[0]['generated_text'].split('</s>>>>><p>')[1].split('</p>')[0]
|
19 |
+
|
20 |
+
from __future__ import unicode_literals, print_function
|
21 |
+
from spacy.lang.en import English # updated
|
22 |
+
|
23 |
+
def sentensizer(raw_text):
|
24 |
+
nlp = English()
|
25 |
+
nlp.add_pipe("sentencizer") # updated
|
26 |
+
doc = nlp(raw_text)
|
27 |
+
sentences = [sent for sent in doc.sents]
|
28 |
+
print(sentences)
|
29 |
+
return sentences
|
30 |
+
|
31 |
+
context = "Once, a group of frogs were roaming around the forest in search of water."
|
32 |
+
text=context
|
33 |
+
def paraphraser(text):
|
34 |
+
begin=time.time()
|
35 |
+
x=[cleaned_para(str(i)) for i in sentensizer(text)]
|
36 |
+
end=time.time()
|
37 |
+
return (".".join(x))
|
38 |
+
|
39 |
+
print(paraphraser(text))
|