Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -33,15 +33,17 @@ def id_replace_complex(s, threshold=0.4):
|
|
33 |
# if score >= threshold select tokens[idx]
|
34 |
compl_tok = [tokens[idx] for idx, x in enumerate(
|
35 |
cwi_pipe(cands)) if x['score'] >= threshold]
|
36 |
-
|
|
|
37 |
# potentially parallelizable, depends on desired behaviour
|
38 |
for t in compl_tok:
|
39 |
idx = s.index(t)
|
40 |
s = s[:idx] + '<mask>' + s[idx+len(t):]
|
41 |
# get top candidate for mask fill in complex token
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
45 |
|
46 |
|
47 |
def generate_candidate_text(s, model, tokenizer, tokenized=False):
|
@@ -72,10 +74,10 @@ def rank_candidate_text(sentences):
|
|
72 |
|
73 |
def full_pipeline(source, simpl_model, simpl_tok, tokens, lexical=False):
|
74 |
|
75 |
-
modified, complex_words = id_replace_complex(source, threshold=0.2) if lexical else (source, None)
|
76 |
cands = generate_candidate_text(tokens+modified, simpl_model, simpl_tok)
|
77 |
output = rank_candidate_text(cands)
|
78 |
-
return output, complex_words
|
79 |
|
80 |
def main():
|
81 |
|
@@ -117,10 +119,10 @@ def main():
|
|
117 |
if (submit):
|
118 |
|
119 |
tokens = " ".join([t+str(v) for t, v in zip(aug_tok, user_values)]) + " "
|
120 |
-
output, words = full_pipeline(input_sentence, simpl_model, simpl_tok, tokens, lexical)
|
121 |
-
|
122 |
-
|
123 |
-
c1, c2 = st.columns([1,2])
|
124 |
|
125 |
with c1:
|
126 |
st.markdown("#### Words identified as complex")
|
@@ -132,6 +134,15 @@ def main():
|
|
132 |
st.markdown("None :smile:")
|
133 |
|
134 |
with c2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
st.markdown(f"#### Original Sentence:\n > {input_sentence}")
|
136 |
st.markdown(f"#### Output Sentence:\n > {output}")
|
137 |
|
|
|
33 |
# if score >= threshold select tokens[idx]
|
34 |
compl_tok = [tokens[idx] for idx, x in enumerate(
|
35 |
cwi_pipe(cands)) if x['score'] >= threshold]
|
36 |
+
|
37 |
+
replacements = []
|
38 |
# potentially parallelizable, depends on desired behaviour
|
39 |
for t in compl_tok:
|
40 |
idx = s.index(t)
|
41 |
s = s[:idx] + '<mask>' + s[idx+len(t):]
|
42 |
# get top candidate for mask fill in complex token
|
43 |
+
top_result = fill_pipe(s)[0]
|
44 |
+
s = top_result['sequence']
|
45 |
+
replacements.append(top_result['token_str'])
|
46 |
+
return s, compl_tok, replacements
|
47 |
|
48 |
|
49 |
def generate_candidate_text(s, model, tokenizer, tokenized=False):
|
|
|
74 |
|
75 |
def full_pipeline(source, simpl_model, simpl_tok, tokens, lexical=False):
|
76 |
|
77 |
+
modified, complex_words, replacements = id_replace_complex(source, threshold=0.2) if lexical else (source, None, None)
|
78 |
cands = generate_candidate_text(tokens+modified, simpl_model, simpl_tok)
|
79 |
output = rank_candidate_text(cands)
|
80 |
+
return output, complex_words, replacements
|
81 |
|
82 |
def main():
|
83 |
|
|
|
119 |
if (submit):
|
120 |
|
121 |
tokens = " ".join([t+str(v) for t, v in zip(aug_tok, user_values)]) + " "
|
122 |
+
output, words, replacements = full_pipeline(input_sentence, simpl_model, simpl_tok, tokens, lexical)
|
123 |
+
|
124 |
+
|
125 |
+
c1, c2, c3 = st.columns([1,1,2])
|
126 |
|
127 |
with c1:
|
128 |
st.markdown("#### Words identified as complex")
|
|
|
134 |
st.markdown("None :smile:")
|
135 |
|
136 |
with c2:
|
137 |
+
st.markdown("#### Their mask-predicted replacement")
|
138 |
+
if replacements:
|
139 |
+
for w in replacements:
|
140 |
+
st.markdown(f"* {w}")
|
141 |
+
|
142 |
+
else:
|
143 |
+
st.markdown("None :smile:")
|
144 |
+
|
145 |
+
with c3:
|
146 |
st.markdown(f"#### Original Sentence:\n > {input_sentence}")
|
147 |
st.markdown(f"#### Output Sentence:\n > {output}")
|
148 |
|