shobrunjb commited on
Commit
9758bca
·
verified ·
1 Parent(s): 7b57b7a

prpobability update

Browse files
Files changed (1) hide show
  1. app.py +11 -4
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
- # Return the two results separately
59
- return pred_task1, pred_task2
 
 
 
 
 
 
 
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,