poltextlab commited on
Commit
7ec1f1b
1 Parent(s): 13fe76b

fix to remap then get the labels

Browse files
Files changed (1) hide show
  1. interfaces/sentiment.py +5 -3
interfaces/sentiment.py CHANGED
@@ -39,10 +39,12 @@ def predict(text, model_id, tokenizer_id):
39
  logits = model(**inputs).logits
40
 
41
  probs = torch.nn.functional.softmax(logits, dim=1).cpu().numpy().flatten()
42
- output_pred = {model.config.id2label[i]: probs[i] for i in np.argsort(probs)[::-1]}
 
 
 
 
43
 
44
- predicted_label = max(output_pred, key=output_pred.get)
45
- output_pred = {4: 2, 5: 1}.get(predicted_label, 0)
46
 
47
  output_info = f'<p style="text-align: center; display: block">Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.</p>'
48
  return output_pred, output_info
 
39
  logits = model(**inputs).logits
40
 
41
  probs = torch.nn.functional.softmax(logits, dim=1).cpu().numpy().flatten()
42
+ predicted_class_id = probs.argmax()
43
+ predicted_class_id = {4: 2, 5: 1}.get(predicted_class_id, 0)
44
+
45
+
46
+ output_pred = {model.config.id2label[i]: predicted_class_id[i] for i in np.argsort(predicted_class_id)[::-1]}
47
 
 
 
48
 
49
  output_info = f'<p style="text-align: center; display: block">Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.</p>'
50
  return output_pred, output_info