Delete test.py
Browse files
test.py
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 1 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 2 |
-
import torch
|
| 3 |
-
|
| 4 |
-
MODEL_PATH = "model.safetensors" # папка с model.safetensors + config.json
|
| 5 |
-
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
| 7 |
-
model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH)
|
| 8 |
-
|
| 9 |
-
def predict(text: str):
|
| 10 |
-
inputs = tokenizer(
|
| 11 |
-
text,
|
| 12 |
-
return_tensors="pt",
|
| 13 |
-
truncation=True,
|
| 14 |
-
padding=True,
|
| 15 |
-
max_length=512
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
with torch.no_grad():
|
| 19 |
-
outputs = model(**inputs)
|
| 20 |
-
|
| 21 |
-
logits = outputs.logits
|
| 22 |
-
probs = torch.softmax(logits, dim=-1)
|
| 23 |
-
|
| 24 |
-
pred_id = torch.argmax(probs, dim=-1).item()
|
| 25 |
-
confidence = probs[0, pred_id].item()
|
| 26 |
-
|
| 27 |
-
return {
|
| 28 |
-
"label_id": pred_id,
|
| 29 |
-
"confidence": confidence
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
print(predict("Салем калын калай?"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|