text-classification / model /sentiment.py
manue
Refactor sentiment model initialization to use AutoTokenizer and AutoModelForSequenceClassification
2cae640
raw
history blame
521 Bytes
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
from typing import Any
class Sentiment:
def __init__(self, line: str) -> (list | list[Any] | Any | None):
tokenizer = AutoTokenizer.from_pretrained("MilaNLProc/feel-it-italian-sentiment")
model = AutoModelForSequenceClassification.from_pretrained("MilaNLProc/feel-it-italian-sentiment")
self.pipe = pipeline("text-classification", model=model, tokenizer=tokenizer)
self.result = self.pipe(line)