Spaces:
Running
Running
vickeee465
commited on
Commit
·
796fe47
1
Parent(s):
4e7da96
changed output logic
Browse files
app.py
CHANGED
|
@@ -55,10 +55,12 @@ def predict(text, model_id, tokenizer_id):
|
|
| 55 |
logits = model(**inputs).logits
|
| 56 |
|
| 57 |
probs = torch.nn.functional.softmax(logits, dim=1).cpu().numpy().flatten()
|
| 58 |
-
|
| 59 |
-
probability_pred = f"{round(100*probs.max(), 2)}%"
|
| 60 |
-
return label_pred, probability_pred
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
def predict_wrapper(text, language):
|
| 64 |
model_id = build_huggingface_path(language)
|
|
@@ -69,8 +71,8 @@ def predict_wrapper(text, language):
|
|
| 69 |
|
| 70 |
results = []
|
| 71 |
for sentence in sentences:
|
| 72 |
-
|
| 73 |
-
results.append(
|
| 74 |
|
| 75 |
output_info = f'Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.'
|
| 76 |
return results, output_info
|
|
|
|
| 55 |
logits = model(**inputs).logits
|
| 56 |
|
| 57 |
probs = torch.nn.functional.softmax(logits, dim=1).cpu().numpy().flatten()
|
| 58 |
+
return probs
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
def get_most_probable_label(probs):
|
| 61 |
+
label = model.config.id2label[probs.argmax()]
|
| 62 |
+
probability = f"{round(100 * probs.max(), 2)}%"
|
| 63 |
+
return [sentence, label, probability]
|
| 64 |
|
| 65 |
def predict_wrapper(text, language):
|
| 66 |
model_id = build_huggingface_path(language)
|
|
|
|
| 71 |
|
| 72 |
results = []
|
| 73 |
for sentence in sentences:
|
| 74 |
+
probs = predict(sentence, model_id, tokenizer_id)
|
| 75 |
+
results.append(get_most_probable_label(probs))
|
| 76 |
|
| 77 |
output_info = f'Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.'
|
| 78 |
return results, output_info
|