|
--- |
|
library_name: transformers |
|
tags: [] |
|
--- |
|
|
|
## Inference |
|
```python |
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification |
|
import time |
|
import torch |
|
import re |
|
|
|
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") |
|
model = AutoModelForSequenceClassification.from_pretrained("Mr-Vicky-01/TP-FP").to(device) |
|
tokenizer = AutoTokenizer.from_pretrained("Mr-Vicky-01/TP-FP") |
|
|
|
|
|
start = time.time() |
|
|
|
question = "give me a scan result" |
|
question = re.sub(r'[,?.]', '', question) |
|
inputs = tokenizer(question, return_tensors="pt").to(device) |
|
with torch.no_grad(): |
|
logits = model(**inputs).logits |
|
predicted_class_id = logits.argmax().item() |
|
predicted_class = model.config.id2label[predicted_class_id] |
|
|
|
print(predicted_class) |
|
print(time.time() - start) |
|
``` |