Spaces:
Sleeping
Sleeping
Annalyn Ng
commited on
Commit
•
ecfe3e6
1
Parent(s):
93be2eb
add preprocessing to add mask
Browse files
app.py
CHANGED
@@ -12,12 +12,18 @@ mask_token = tokenizer.mask_token
|
|
12 |
text = f"雨天,我整个人就便{mask_token}了,不想出外,甚至不想去上课。"
|
13 |
target_word = "懒惰"
|
14 |
|
|
|
|
|
|
|
|
|
15 |
def eval_prob(target_word, text):
|
|
|
|
|
16 |
# Get index of target_word
|
17 |
idx = tokenizer.encode(target_word)[2]
|
18 |
|
19 |
# Get logits
|
20 |
-
inputs = tokenizer(
|
21 |
token_logits = model(**inputs).logits
|
22 |
|
23 |
# Find the location of the MASK and extract its logits
|
@@ -36,8 +42,8 @@ def eval_prob(target_word, text):
|
|
36 |
gr.Interface(
|
37 |
fn=eval_prob,
|
38 |
inputs=[
|
39 |
-
gr.Textbox(placeholder="
|
40 |
-
gr.Textbox(placeholder=f"
|
41 |
],
|
42 |
outputs="text",
|
43 |
title="Chinese Sentence Grading",
|
|
|
12 |
text = f"雨天,我整个人就便{mask_token}了,不想出外,甚至不想去上课。"
|
13 |
target_word = "懒惰"
|
14 |
|
15 |
+
def add_mask(target_word, text):
|
16 |
+
text_mask = text.replace(target_word, mask_token)
|
17 |
+
return text_mask
|
18 |
+
|
19 |
def eval_prob(target_word, text):
|
20 |
+
|
21 |
+
text_mask = add_mask(target_word, text)
|
22 |
# Get index of target_word
|
23 |
idx = tokenizer.encode(target_word)[2]
|
24 |
|
25 |
# Get logits
|
26 |
+
inputs = tokenizer(text_mask, return_tensors="pt")
|
27 |
token_logits = model(**inputs).logits
|
28 |
|
29 |
# Find the location of the MASK and extract its logits
|
|
|
42 |
gr.Interface(
|
43 |
fn=eval_prob,
|
44 |
inputs=[
|
45 |
+
gr.Textbox(placeholder="夸大"),
|
46 |
+
gr.Textbox(placeholder=f"我们使用 Generative AI 已经很长时间了,所以他们最近的媒体报道可能被夸大了。"),
|
47 |
],
|
48 |
outputs="text",
|
49 |
title="Chinese Sentence Grading",
|