sentiment-analysis_text / text_analysis.py
goatley's picture
Upload 3 files
85dd36d verified
raw
history blame contribute delete
833 Bytes
# Import necessary libraries
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")
# Create a pipeline for sentiment analysis
nlp_pipeline = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
# Example texts for analysis
texts = [
"I love using Hugging Face models!",
"This movie was terrible.",
"The weather today is nice.",
"I am feeling neutral about this.",
"The product exceeded my expectations."
"I love my life"
]
# Perform sentiment analysis for each text
for text in texts:
print(f"Text: {text}")
result = nlp_pipeline(text)
print(f"Sentiment: {result}\n")