Spaces:
Runtime error
Runtime error
Update app.py
Browse filesT5 task sentence paraphrasing
app.py
CHANGED
|
@@ -324,7 +324,28 @@
|
|
| 324 |
# grad.Interface(text2text_sentiment, inputs=para, outputs=out).launch()
|
| 325 |
|
| 326 |
#-----------------------------------------------------------------------------------
|
| 327 |
-
# 14. Text-to-Text Generation using the T5 model - Task 5 grammar check.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
|
| 329 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 330 |
import gradio as grad
|
|
@@ -332,14 +353,17 @@ import gradio as grad
|
|
| 332 |
text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
|
| 333 |
mdl = T5ForConditionalGeneration.from_pretrained("t5-small")
|
| 334 |
|
| 335 |
-
def
|
| 336 |
-
|
| 337 |
-
|
|
|
|
|
|
|
| 338 |
tokens = mdl.generate(**enc)
|
| 339 |
response=text2text_tkn.batch_decode(tokens)
|
| 340 |
return response
|
| 341 |
|
| 342 |
-
|
|
|
|
| 343 |
out=grad.Textbox(lines=1, label="Whether the sentence is acceptable or not")
|
| 344 |
|
| 345 |
-
grad.Interface(
|
|
|
|
| 324 |
# grad.Interface(text2text_sentiment, inputs=para, outputs=out).launch()
|
| 325 |
|
| 326 |
#-----------------------------------------------------------------------------------
|
| 327 |
+
# 14. Text-to-Text Generation using the T5 model - Task 5 grammar check - this doesn't work great unfortunately.
|
| 328 |
+
|
| 329 |
+
# from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 330 |
+
# import gradio as grad
|
| 331 |
+
|
| 332 |
+
# text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
|
| 333 |
+
# mdl = T5ForConditionalGeneration.from_pretrained("t5-small")
|
| 334 |
+
|
| 335 |
+
# def text2text_acceptable_sentence(text):
|
| 336 |
+
# inp = "cola sentence: "+text
|
| 337 |
+
# enc = text2text_tkn(inp, return_tensors="pt")
|
| 338 |
+
# tokens = mdl.generate(**enc)
|
| 339 |
+
# response=text2text_tkn.batch_decode(tokens)
|
| 340 |
+
# return response
|
| 341 |
+
|
| 342 |
+
# para=grad.Textbox(lines=1, label="English Text", placeholder="Text in English")
|
| 343 |
+
# out=grad.Textbox(lines=1, label="Whether the sentence is acceptable or not")
|
| 344 |
+
|
| 345 |
+
# grad.Interface(text2text_acceptable_sentence, inputs=para, outputs=out).launch()
|
| 346 |
+
|
| 347 |
+
#-----------------------------------------------------------------------------------
|
| 348 |
+
# 15. Text-to-Text Generation using the T5 model - Task 6 sentence paraphasing
|
| 349 |
|
| 350 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 351 |
import gradio as grad
|
|
|
|
| 353 |
text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
|
| 354 |
mdl = T5ForConditionalGeneration.from_pretrained("t5-small")
|
| 355 |
|
| 356 |
+
def text2text_paraphrase(sentence1,sentence2):
|
| 357 |
+
inp1 = "mrpc sentence1: "+sentence1
|
| 358 |
+
inp2 = "sentence2: "+sentence2
|
| 359 |
+
combined_inp=inp1+" "+inp2
|
| 360 |
+
enc = text2text_tkn(combined_inp, return_tensors="pt")
|
| 361 |
tokens = mdl.generate(**enc)
|
| 362 |
response=text2text_tkn.batch_decode(tokens)
|
| 363 |
return response
|
| 364 |
|
| 365 |
+
sent1=grad.Textbox(lines=1, label="Sentence1", placeholder="Text in English")
|
| 366 |
+
sent2=grad.Textbox(lines=1, label="Sentence2", placeholder="Text in English")
|
| 367 |
out=grad.Textbox(lines=1, label="Whether the sentence is acceptable or not")
|
| 368 |
|
| 369 |
+
grad.Interface(text2text_paraphrase, inputs=[sent1,sent2], outputs=out).launch()
|