Spaces:
Runtime error
Runtime error
show mean surprisal
Browse files
app.py
CHANGED
@@ -112,8 +112,12 @@ def highlight_token(token: str, score: float):
|
|
112 |
)
|
113 |
|
114 |
|
115 |
-
def create_highlighted_text(
|
116 |
-
|
|
|
|
|
|
|
|
|
117 |
for token, score in tokens2scores:
|
118 |
highlighted_text += highlight_token(token, score)
|
119 |
return highlighted_text
|
@@ -161,7 +165,9 @@ def main(input_text: str) -> Tuple[str, str, str]:
|
|
161 |
offsets = calc_offsets(sudachi_tokenize(input_text))
|
162 |
tokens2surprisal = aggregate_surprisals_by_offset(char2surprisal, offsets)
|
163 |
tokens2surprisal = normalize_surprisals(tokens2surprisal)
|
164 |
-
highlighted_text = create_highlighted_text(
|
|
|
|
|
165 |
|
166 |
(
|
167 |
baseline_mean_surprisal,
|
@@ -172,7 +178,7 @@ def main(input_text: str) -> Tuple[str, str, str]:
|
|
172 |
)
|
173 |
baseline_tokens2surprisal = normalize_surprisals(baseline_tokens2surprisal)
|
174 |
baseline_highlighted_text = create_highlighted_text(
|
175 |
-
"学習前モデル", baseline_tokens2surprisal
|
176 |
)
|
177 |
|
178 |
diff_tokens2surprisal = calculate_surprisal_diff(
|
@@ -189,7 +195,7 @@ def main(input_text: str) -> Tuple[str, str, str]:
|
|
189 |
if __name__ == "__main__":
|
190 |
demo = gr.Interface(
|
191 |
fn=main,
|
192 |
-
title="
|
193 |
description="テキストを入力すると、読みにくさに応じてハイライトされて出力されます。",
|
194 |
show_label=True,
|
195 |
inputs=gr.Textbox(
|
|
|
112 |
)
|
113 |
|
114 |
|
115 |
+
def create_highlighted_text(
|
116 |
+
label: str, tokens2scores: List[Tuple[str, float]], mean_surprisal: float
|
117 |
+
):
|
118 |
+
highlighted_text: str = (
|
119 |
+
"<h2><b>" + label + f"</b>(サプライザル平均値: {mean_surprisal})</h2>"
|
120 |
+
)
|
121 |
for token, score in tokens2scores:
|
122 |
highlighted_text += highlight_token(token, score)
|
123 |
return highlighted_text
|
|
|
165 |
offsets = calc_offsets(sudachi_tokenize(input_text))
|
166 |
tokens2surprisal = aggregate_surprisals_by_offset(char2surprisal, offsets)
|
167 |
tokens2surprisal = normalize_surprisals(tokens2surprisal)
|
168 |
+
highlighted_text = create_highlighted_text(
|
169 |
+
"学習後モデル", tokens2surprisal, mean_surprisal
|
170 |
+
)
|
171 |
|
172 |
(
|
173 |
baseline_mean_surprisal,
|
|
|
178 |
)
|
179 |
baseline_tokens2surprisal = normalize_surprisals(baseline_tokens2surprisal)
|
180 |
baseline_highlighted_text = create_highlighted_text(
|
181 |
+
"学習前モデル", baseline_tokens2surprisal, baseline_mean_surprisal
|
182 |
)
|
183 |
|
184 |
diff_tokens2surprisal = calculate_surprisal_diff(
|
|
|
195 |
if __name__ == "__main__":
|
196 |
demo = gr.Interface(
|
197 |
fn=main,
|
198 |
+
title="読みにくい箇所を検出するAI(デモ)",
|
199 |
description="テキストを入力すると、読みにくさに応じてハイライトされて出力されます。",
|
200 |
show_label=True,
|
201 |
inputs=gr.Textbox(
|