SentimentAnalysis / models.py
Vela
created project
726f5db
raw
history blame
664 Bytes
from transformers import pipeline
def load_model():
return pipeline("text-classification", model="tabularisai/multilingual-sentiment-analysis")
def analyze_sentiments(df, text_column, classifier):
if text_column not in df.columns:
raise ValueError(f"Column '{text_column}' not found in DataFrame.")
sentiments = []
for text in df[text_column]:
try:
sentiment = classifier(str(text))[0]['label']
sentiments.append(sentiment)
except Exception as e:
print(f"Error processing text: {text}. Error: {e}")
sentiments.append('UNKNOWN')
df['sentiment'] = sentiments
return df