Update app.py
Browse files
app.py
CHANGED
@@ -4,23 +4,23 @@ from transformers import pipeline
|
|
4 |
unmasker = pipeline('fill-mask', model='dsfsi/zabantu-xlm-roberta')
|
5 |
|
6 |
sample_sentences = {
|
7 |
-
'zulu': "Le ndoda ithi
|
8 |
-
'tshivenda': "Mufana
|
9 |
-
'sepedi': "Mosadi o
|
10 |
-
'tswana': "Monna o
|
11 |
-
'tsonga': "N'wana wa xisati u
|
12 |
}
|
13 |
|
14 |
def fill_mask_for_languages(sentences):
|
15 |
results = {}
|
16 |
for language, sentence in sentences.items():
|
17 |
-
masked_sentence = sentence.replace('
|
18 |
unmasked = unmasker(masked_sentence)
|
19 |
results[language] = unmasked
|
20 |
return results
|
21 |
|
22 |
def replace_mask(sentence, predicted_word):
|
23 |
-
return sentence.replace("
|
24 |
|
25 |
st.title("Fill Mask| Zabantu-XLM-Roberta")
|
26 |
st.write(f"")
|
@@ -33,7 +33,7 @@ with col1:
|
|
33 |
))
|
34 |
|
35 |
if st.button("Submit"):
|
36 |
-
user_masked_sentence = user_sentence.replace('
|
37 |
|
38 |
with col2:
|
39 |
if 'user_masked_sentence' in locals():
|
|
|
4 |
unmasker = pipeline('fill-mask', model='dsfsi/zabantu-xlm-roberta')
|
5 |
|
6 |
sample_sentences = {
|
7 |
+
'zulu': "Le ndoda ithi izo <mask> ukudla.",
|
8 |
+
'tshivenda': "Mufana uyo <mask> vhukuma.",
|
9 |
+
'sepedi': "Mosadi o <mask> pheka.",
|
10 |
+
'tswana': "Monna o <mask> tsamaya.",
|
11 |
+
'tsonga': "N'wana wa xisati u <mask> ku tsaka."
|
12 |
}
|
13 |
|
14 |
def fill_mask_for_languages(sentences):
|
15 |
results = {}
|
16 |
for language, sentence in sentences.items():
|
17 |
+
masked_sentence = sentence.replace('<mask>', unmasker.tokenizer.mask_token)
|
18 |
unmasked = unmasker(masked_sentence)
|
19 |
results[language] = unmasked
|
20 |
return results
|
21 |
|
22 |
def replace_mask(sentence, predicted_word):
|
23 |
+
return sentence.replace("<mask>", f"**{predicted_word}**")
|
24 |
|
25 |
st.title("Fill Mask| Zabantu-XLM-Roberta")
|
26 |
st.write(f"")
|
|
|
33 |
))
|
34 |
|
35 |
if st.button("Submit"):
|
36 |
+
user_masked_sentence = user_sentence.replace('<mask>', unmasker.tokenizer.mask_token)
|
37 |
|
38 |
with col2:
|
39 |
if 'user_masked_sentence' in locals():
|