copied model from Norwegian
Browse files
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title: DeUnCaser
|
3 |
emoji: 🌖
|
4 |
colorFrom: green
|
5 |
colorTo: red
|
|
|
1 |
---
|
2 |
+
title: DeUnCaser - multi
|
3 |
emoji: 🌖
|
4 |
colorFrom: green
|
5 |
colorTo: red
|
app.py
CHANGED
@@ -2,12 +2,13 @@
|
|
2 |
import streamlit as st
|
3 |
from transformers import T5ForConditionalGeneration, T5TokenizerFast, T5Config
|
4 |
|
5 |
-
#mytext= 'Vi bruker ikke tegnsetting eller store bokstaver når vi prater. Vi slår også sammen ord, og i praksis er dermed heller ikke mellomrom meningsbærende. Prøv å fjerne tegnsetting, store bokstaver og mellomrom fra dette avsnittet. Se om den nye North-T5-modellen greier å sette sammen til et nytt meningsbærende avsnitt.'
|
6 |
-
option_changed = 0
|
7 |
|
|
|
|
|
|
|
8 |
@st.cache(allow_output_mutation=True, suppress_st_warning=True)
|
9 |
def load_model():
|
10 |
-
model_name = "
|
11 |
config = T5Config.from_pretrained(model_name)
|
12 |
model = T5ForConditionalGeneration.from_pretrained(model_name,config=config)
|
13 |
tokenizer = T5TokenizerFast.from_pretrained(model_name)
|
@@ -19,19 +20,35 @@ def deuncase(model, tokenizer, text):
|
|
19 |
**encoded_txt
|
20 |
)
|
21 |
return tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
22 |
-
|
23 |
-
st.
|
24 |
-
|
25 |
-
expander = st.sidebar.expander("About")
|
26 |
-
expander.write("This web app adds spaces, punctation and capitalisation back into the text.")
|
27 |
-
expander.write("You can use the examples below, but too really test the effect of the model: Write or copy text from the Internet, and then manually remove spaces, puctation, cases etc. Try to restore the text.")
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
|
|
|
|
|
|
30 |
option = st.sidebar.selectbox(
|
31 |
"Examples:",
|
32 |
-
("
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
|
|
35 |
|
36 |
run = st.button('Run DeUnCaser')
|
37 |
|
|
|
2 |
import streamlit as st
|
3 |
from transformers import T5ForConditionalGeneration, T5TokenizerFast, T5Config
|
4 |
|
|
|
|
|
5 |
|
6 |
+
if 'textbox' not in st.session_state:
|
7 |
+
st.session_state['textbox'] = "We are not using punctation or capital letters when we are speaking. Actually we hardly even use pauses between words. Still we are able to make sense out of the text. This demo shows that a T5-model is able to reconstruct the sentences, even if these parts of the text is removed. Try removing spaces, capital letters and puctation from this text, and then see if the model can recpnstruct it. Did it work?"
|
8 |
+
|
9 |
@st.cache(allow_output_mutation=True, suppress_st_warning=True)
|
10 |
def load_model():
|
11 |
+
model_name = "pere/multi-sentencefix-mt5"
|
12 |
config = T5Config.from_pretrained(model_name)
|
13 |
model = T5ForConditionalGeneration.from_pretrained(model_name,config=config)
|
14 |
tokenizer = T5TokenizerFast.from_pretrained(model_name)
|
|
|
20 |
**encoded_txt
|
21 |
)
|
22 |
return tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
23 |
+
def uncase():
|
24 |
+
st.session_state['textbox'] = st.session_state['textbox'].lower()
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
def unpunct():
|
27 |
+
trans_chars = "'\",.:;-_*?/\n"
|
28 |
+
trans_table = st.session_state['textbox'].maketrans("", "", trans_chars)
|
29 |
+
st.session_state['textbox'] = st.session_state['textbox'].translate(trans_table)
|
30 |
+
|
31 |
+
def unspace():
|
32 |
+
st.session_state['textbox'] = st.session_state['textbox'].replace(" ","")
|
33 |
+
|
34 |
+
def sidebar_callback():
|
35 |
+
st.session_state['textbox'] = st.session_state['prefilled']
|
36 |
|
37 |
+
st.title("DeUnCaser")
|
38 |
+
st.sidebar.write("This web app adds spaces, punctation and capitalisation back into the text.")
|
39 |
+
st.sidebar.write("You can use the examples below, but too really test the effect of the model: Write or copy text from the Internet, and then manually remove spaces, puctation, cases etc. Try to restore the text.")
|
40 |
option = st.sidebar.selectbox(
|
41 |
"Examples:",
|
42 |
+
("This model is crated by Per Egil Kummervold. This is not a common name in English. Do you think the model will understand that it is a name?","Some Norwegian text: Vi bruker ikke tegnsetting eller store bokstaver når vi prater. Vi slår også sammen ord, og i praksis er dermed heller ikke mellomrom meningsbærende. Prøv å fjerne tegnsetting, store bokstaver og mellomrom fra dette avsnittet. Se om den nye North-T5-modellen greier å sette sammen til et nytt meningsbærende avsnitt.","areyouabletoreadthistextwillthemodelbeableto"),key='prefilled',on_change=sidebar_callback)
|
43 |
+
|
44 |
+
placeholder = st.empty()
|
45 |
+
st.sidebar.write("\nText Tools:")
|
46 |
+
st.sidebar.button('Remove Punctation', on_click=unpunct)
|
47 |
+
st.sidebar.button('Remove Casing', on_click=uncase)
|
48 |
+
st.sidebar.button('Remove Spaces', on_click=unspace)
|
49 |
|
50 |
+
with placeholder:
|
51 |
+
text = st.text_area(f"Input text",max_chars=1000,height=140,key="textbox")
|
52 |
|
53 |
run = st.button('Run DeUnCaser')
|
54 |
|