Sentiment Analysis
Sentiment Analysis
Dr. Shylaja S S
Director of Cloud Computing & Big Data (CCBD), Centre for
Data Sciences & Applied Machine Learning (CDSAML)
Department of Computer Science and Engineering
[email protected]
Sentiment Analysis in NLP
```python
from textblob import TextBlob
```python
from nltk.sentiment import SentimentIntensityAnalyzer
sia = SentimentIntensityAnalyzer()
text = "The movie was really good, I loved it!"
sentiment = sia.polarity_scores(text)
print(sentiment)
```
Sentiment Analysis using Machine Learning (Scikit-Learn)
```python
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
texts = ["I love this!", "This is bad.", "Amazing experience!", "Not good at all."]
labels = [1, 0, 1, 0]
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(texts)
model = MultinomialNB()
model.fit(X, labels)
classifier = pipeline("sentiment-analysis")
result = classifier("I absolutely love this movie! It’s fantastic.")
print(result)
```
Challenges in Sentiment Analysis
• Sarcasm Detection – 'Oh great, another delay!' (negative meaning but positive words).
• Context Understanding – 'The movie was sick!' (positive slang vs. literal meaning).
• Domain Dependency – 'The stock is going down' (negative for holders, positive for
buyers).
• Advanced models like BERT and GPT handle complex sentiment detection.