File size: 1,932 Bytes
5071fce
 
 
6afb4da
a074b00
5071fce
 
 
403d5d1
d98a25d
8b030aa
d98a25d
 
 
bf1d265
8b030aa
 
 
d98a25d
5c031c4
d98a25d
19d6696
5c031c4
5071fce
 
 
 
 
 
 
 
 
 
0eef91c
55c9f62
5071fce
 
88398ac
5071fce
55c9f62
cee8178
55c9f62
2c8c876
55c9f62
9c2a796
 
2c8c876
55c9f62
a6b69ef
2c8c876
9dfb4ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
from transformers import T5ForConditionalGeneration, AutoTokenizer

st.title("SpellCorrectorT5")
st.markdown('SpellCorrectorT5 is a fine-tuned version of **pre-trained t5-small model** modelled on randomly selected 50000 sentences modified by [imputing random noises/errors](./random_noiser.py) and trained using transformers. It not only looks for _spelling errors but also looks for the semantics_ in the sentence and suggest other possible words for the incorrect word.')
ttokenizer = AutoTokenizer.from_pretrained("./")
tmodel = T5ForConditionalGeneration.from_pretrained('./')

form = st.form("T5-form")

examples =["Look if ther is fire on the top",
           "Where os you're car?",
           "Iu is going to rain",
           "Feel free to raach out to me",
           "Will return it to yu once it is donr",
           "Wheir do you live?",
           "It wis great mieting with you all"
           ]

input_text = form.selectbox(label="Choose an example",
        options=examples)        
form.write("(or)")
input_text = form.text_input(label='Enter your own sentence', value=input_text)
submit = form.form_submit_button("Submit")

if submit:
  input_ids = ttokenizer.encode('seq: '+ input_text, return_tensors='pt')
  
  # generate text until the output length (which includes the context length) reaches 50
  outputs = tmodel.generate(
    input_ids,
    do_sample=True, 
    max_length=50,
    top_p=0.99, 
    num_return_sequences=1
  )
  
  st.subheader("Suggested sentence: ")
  
  out_text = ttokenizer.decode(outputs[0], skip_special_tokens=True)
  st.success(out_text)
  
  st.markdown("### Edited sentence:")
  c_text = " "
  for x in out_text.split(" "):
    if x in input_text.split(" "):
      c_text = c_text + x + " "
    else:
      c_text = c_text + '<span style="font-weight:bold; color:rgb(0,255,0);>"' + x + '</span>' + " "
      
  st.markdown(c_text, unsafe_allow_html=True)