-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfer.py
More file actions
29 lines (24 loc) · 804 Bytes
/
infer.py
File metadata and controls
29 lines (24 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys, pathlib
sys.path.append(pathlib.Path(__file__).parent.as_posix())
import torch
import utils.constant as constant
from transformers import (
pipeline,
AutoTokenizer,
AutoModelForSequenceClassification,
)
""" Load tokenizer and model. Setup pipeline. """
tokenizer = AutoTokenizer.from_pretrained(constant.FINETUNED_MODEL)
model = AutoModelForSequenceClassification.from_pretrained(constant.FINETUNED_MODEL)
classifier = pipeline(
"text-classification",
model=model,
tokenizer=tokenizer,
device=torch.device("cuda" if torch.cuda.is_available() else "cpu"),
)
while True:
text = input("Enter comment to classify (or 'exit' to quit): ")
if text.lower() == 'exit':
break
outputs = classifier(text, return_all_scores=True)
print(outputs)