Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -69,6 +69,22 @@ def class_judgement(text: str) -> str:
|
|
69 |
lines.append(f"{lab}: {p:.3f}")
|
70 |
return "\n".join(lines)
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
# =========================
|
73 |
# 範例資料(只放兩個)
|
74 |
# - 閱讀測驗:id=1
|
|
|
69 |
lines.append(f"{lab}: {p:.3f}")
|
70 |
return "\n".join(lines)
|
71 |
|
72 |
+
def class_judgement(text:str) -> dict:
|
73 |
+
"""Predicts two task distributions for the input text."""
|
74 |
+
batch_x = tokenizer(
|
75 |
+
text, max_length=MAX_LEN, padding=True, truncation=True, return_tensors="pt"
|
76 |
+
).to("cuda")
|
77 |
+
|
78 |
+
with torch.no_grad():
|
79 |
+
task0_output, task1_output = model.model(batch_x["input_ids"], batch_x["attention_mask"])
|
80 |
+
probs_0 = torch.nn.functional.softmax(task0_output, dim=1).squeeze().tolist()
|
81 |
+
|
82 |
+
# 任務0(程度等級)
|
83 |
+
task0_id2label = {0: '入門基礎', 1: '進階高階', 2: '流利精通'}
|
84 |
+
|
85 |
+
predictions_0 = {task0_id2label[i]: round(probs_0[i], 3) for i in range(len(probs_0))}
|
86 |
+
return predictions_0
|
87 |
+
|
88 |
# =========================
|
89 |
# 範例資料(只放兩個)
|
90 |
# - 閱讀測驗:id=1
|