Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,29 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
|
4 |
sentence = st.text_area("enter some text")
|
5 |
|
6 |
if sentence:
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
3 |
|
4 |
sentence = st.text_area("enter some text")
|
5 |
|
6 |
if sentence:
|
7 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
8 |
+
|
9 |
+
model = T5ForConditionalGeneration.from_pretrained("Unbabel/gec-t5_small")
|
10 |
+
tokenizer = T5Tokenizer.from_pretrained('t5-small')
|
11 |
+
|
12 |
+
sentence = "I like to swimming"
|
13 |
+
tokenized_sentence = tokenizer('gec: ' + sentence, max_length=128, truncation=True, padding='max_length', return_tensors='pt')
|
14 |
+
corrected_sentence = tokenizer.decode(
|
15 |
+
model.generate(
|
16 |
+
input_ids = tokenized_sentence.input_ids,
|
17 |
+
attention_mask = tokenized_sentence.attention_mask,
|
18 |
+
max_length=128,
|
19 |
+
num_beams=5,
|
20 |
+
early_stopping=True,
|
21 |
+
)[0],
|
22 |
+
skip_special_tokens=True,
|
23 |
+
clean_up_tokenization_spaces=True
|
24 |
+
)
|
25 |
+
st.write(corrected_sentence)
|
26 |
+
|
27 |
+
|
28 |
|
29 |
|