made some changes 2
Browse files
Components/model_Responce.py
CHANGED
@@ -54,15 +54,9 @@ def model_prediction(text, model=model, tokenizer=tokenizer, labels=outcome_labe
|
|
54 |
# Hugging face model
|
55 |
# Tokenize the text
|
56 |
inputs = tokenizer(text, return_tensors="pt")
|
57 |
-
|
58 |
-
with torch.no_grad():
|
59 |
-
outputs = model(**inputs)
|
60 |
|
61 |
# Get the predicted class probabilities
|
62 |
-
|
63 |
-
# Get predicted probabilities and labels
|
64 |
-
probabilities = torch.nn.functional.softmax(outputs.logits, dim=1).numpy()[0]
|
65 |
-
predicted_label_index = np.argmax(probabilities)
|
66 |
-
predicted_label = labels[predicted_label_index]
|
67 |
|
68 |
-
return
|
|
|
54 |
# Hugging face model
|
55 |
# Tokenize the text
|
56 |
inputs = tokenizer(text, return_tensors="pt")
|
57 |
+
outputs = model(inputs)
|
|
|
|
|
58 |
|
59 |
# Get the predicted class probabilities
|
60 |
+
probs = outputs.logits.softmax(dim=-1)
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
return labels[torch.argmax(probs)]
|