prpobability update
Browse files
app.py
CHANGED
@@ -48,15 +48,22 @@ def classify(text):
|
|
48 |
logits_task1, logits_task2 = model(input_ids, attention_mask)
|
49 |
|
50 |
# Softmax to get probabilities
|
51 |
-
probs_task1 = F.softmax(logits_task1, dim=1).cpu().numpy()
|
52 |
-
probs_task2 = F.softmax(logits_task2, dim=1).cpu().numpy()
|
53 |
|
54 |
# Predict label with highest probability
|
55 |
pred_task1 = label_mapping_task1[probs_task1.argmax()]
|
56 |
pred_task2 = label_mapping_task2[probs_task2.argmax()]
|
57 |
|
58 |
-
#
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
# Gradio Interface
|
62 |
iface = gr.Interface(fn=classify,
|
|
|
48 |
logits_task1, logits_task2 = model(input_ids, attention_mask)
|
49 |
|
50 |
# Softmax to get probabilities
|
51 |
+
probs_task1 = F.softmax(logits_task1, dim=1).cpu().numpy()[0] # Extract the first batch item
|
52 |
+
probs_task2 = F.softmax(logits_task2, dim=1).cpu().numpy()[0] # Extract the first batch item
|
53 |
|
54 |
# Predict label with highest probability
|
55 |
pred_task1 = label_mapping_task1[probs_task1.argmax()]
|
56 |
pred_task2 = label_mapping_task2[probs_task2.argmax()]
|
57 |
|
58 |
+
# Format probabilities as percentages
|
59 |
+
probs_task1_str = ", ".join([f"{label}: {prob*100:.2f}%" for label, prob in zip(label_mapping_task1, probs_task1)])
|
60 |
+
probs_task2_str = ", ".join([f"{label}: {prob*100:.2f}%" for label, prob in zip(label_mapping_task2, probs_task2)])
|
61 |
+
|
62 |
+
# Combine label predictions with their probabilities
|
63 |
+
result_task1 = f"{pred_task1} ({probs_task1_str})"
|
64 |
+
result_task2 = f"{pred_task2} ({probs_task2_str})"
|
65 |
+
|
66 |
+
return result_task1, result_task2
|
67 |
|
68 |
# Gradio Interface
|
69 |
iface = gr.Interface(fn=classify,
|