Chih-Hsu Lin commited on
Commit
419133c
1 Parent(s): 2512f99

Added uncertainty

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -21,13 +21,16 @@ def pred_is_elon_musk(text):
21
  results = model(input_ids=ids, token_type_ids=None,
22
  attention_mask=masks)
23
  logis = results['logits'].detach()
24
- prob = F.softmax(logis, dim=1)[0]
25
  prediction = np.argmax(logis.numpy(), axis=1).flatten()
26
- if prediction[0] == 1:
27
- output = f"It's from Elon Musk with {prob[0]*100: 0.2f}% probability."
 
 
 
28
  else:
29
- output = f"It's NOT from Elon Musk with {prob[1]*100: 0.2f}% probability."
30
- return output
31
 
32
  iface = gr.Interface(pred_is_elon_musk, inputs="text",
33
  outputs="text", title='“Is the tweet from Elon Musk?” Classifier',
 
21
  results = model(input_ids=ids, token_type_ids=None,
22
  attention_mask=masks)
23
  logis = results['logits'].detach()
24
+ prob = F.softmax(logis, dim=1)[0][1]
25
  prediction = np.argmax(logis.numpy(), axis=1).flatten()
26
+ output1 = f"It's from Elon Musk with {prob*100: 0.2f}% probability."
27
+ if 0.4 <= prob <= 0.6:
28
+ output2 = f"Therefore, maybe it's from Elon Musk or maybe not."
29
+ elif prediction[0] == 1:
30
+ output2 = f"Therefore, maybe it is from Elon Musk."
31
  else:
32
+ output2 = f"Therefore, maybe it is Not from Elon Musk."
33
+ return output1+output2
34
 
35
  iface = gr.Interface(pred_is_elon_musk, inputs="text",
36
  outputs="text", title='“Is the tweet from Elon Musk?” Classifier',