SlideShare a Scribd company logo
1 of 50
Download to read offline
Sentiment Analysis
by NLTK
Wei-Ting Kuo
PyconApac2015
http://goo.gl/wJelD4
Sentiment Analysis?
Aim to determine the attitude of a
speaker/writer with respect to some text.
Amazon’s Customer Review
Twitter Follower’s replies
Positive or Negative?
This is a good book!
This is a good book!

I like it!
Positive
The first chapter is good,

but the rest is terrible
Negative
(more)

Positive
This is a bad book! Negative
How to compute it?
This is a good book!
From scouter: This is a postive review
Why is sentiment
analysis useful?
• This is a terrible book. Because it’s important, so I
mention three times, terrible, terrible, terrible!!!
Let’s begin with the
easiest way!
Sentiment Dictionary
like 1

good 2

bad -2

terrible -3
This is a good book!
Dictionary

like 1

good 2

bad -2

terrible -3
2
This is a good book!

I like it!
Positive
3
The first chapter is good,

but the rest is terrible
-1 Negative
(more)

Positive
This is a bad book! -2 Negative
AFINN-111
• http://www2.imm.dtu.dk/pubdb/
views/publication_details.php?
id=6010
• A list of words rated between

-5 (neg) to 5 (pos)
Let’s build the dictionary
in Python
Let’s split the sentence first
And compute the score
•
Recap
What if the text is long?
And have many punctuation?
• Nice book! Though it is lack of advanced topics.
It’s still good for beginners.
Doesn’t work!
NLTK to the rescue
• Natural Language ToolKit
• Works with Python3!
Tokenization
the process of breaking a stream of text up into
words, phrases, symbols, or other meaningful
elements called tokens
Word tokenize
It seems we lose some
information
• Nice book! Though it is lack of advanced
topics. It’s still good for beginners.
Positive: 3
Separate to multiple
sentences first
• Nice book!
• Though it is lack of advanced topics.
• It’s still good for beginners.
Positive
Negative
Positive
How to split the text to
sentences?
Sentence tokenize
Compute score for
each sentence
But we still miss some
information in another case
It’s a bad idea to buy this book.
Negative
Negative
The first chapter is good,

but the rest is terrible and confusing
At least the customer mentioned something good,
but it’s not recorded
Let’s count Pos & Neg
separately
The first chapter is good,

but the rest is terrible and confusing
It’s a bad idea to buy this book.
Neg: -5
Neg: -3
Pos:3
In Python
how about new words?
how about domain specific term?
Machine Learning!!!
Traing Data
(with Labels)
Model
Trained ModelReal Data Prediction
Training Data
• This is a good book! Postive
• This is a awesome book! Postive
• This is a bad book! Negative
• This is a terrible book! Negative
• This is a good book! Postive
• This is a awesome book! Postive
• This is a bad book! Negative
• This is a terrible book Negative
Model
This is a good article
This is a bad article
Trained Model
Postive
Negative
The format NLTK use
Prepare the Training Set
Build the model, and train it!
Real Case
• Movie Review Data

http://www.cs.cornell.edu/people/pabo/movie-review-data/
• 5331 positive reviews & 5331 negative reviews
labelled by human.
Positive Reviews
Negative Reviews
Read our data
Separate the data
Training Data Testing Data
Training data to train the model
Testing data to compute the accuracy
Separate our data
Train the data
Compute the accuracy
accuracy = number of correct / total
How to enhance?
• Use the most frequent 1000 words only
• Use different model, maybe SVC
• Read more paper about the latest research
Q & A

More Related Content

What's hot

Introduction to Sentiment Analysis
Introduction to Sentiment AnalysisIntroduction to Sentiment Analysis
Introduction to Sentiment AnalysisJaganadh Gopinadhan
 
Sentiment Analysis on Twitter
Sentiment Analysis on TwitterSentiment Analysis on Twitter
Sentiment Analysis on TwitterSubarno Pal
 
Sentiment analysis using ml
Sentiment analysis using mlSentiment analysis using ml
Sentiment analysis using mlPravin Katiyar
 
Twitter sentiment analysis
Twitter sentiment analysisTwitter sentiment analysis
Twitter sentiment analysisSunil Kandari
 
Amazon sentimental analysis
Amazon sentimental analysisAmazon sentimental analysis
Amazon sentimental analysisAkhila
 
Social Media Sentiments Analysis
Social Media Sentiments AnalysisSocial Media Sentiments Analysis
Social Media Sentiments AnalysisPratisthaSingh5
 
Text classification & sentiment analysis
Text classification & sentiment analysisText classification & sentiment analysis
Text classification & sentiment analysisM. Atif Qureshi
 
Sentiment analysis
Sentiment analysisSentiment analysis
Sentiment analysisAmenda Joy
 
Sentiment analysis - Our approach and use cases
Sentiment analysis - Our approach and use casesSentiment analysis - Our approach and use cases
Sentiment analysis - Our approach and use casesKarol Chlasta
 
Sentiment Analysis using Twitter Data
Sentiment Analysis using Twitter DataSentiment Analysis using Twitter Data
Sentiment Analysis using Twitter DataHari Prasad
 
Ire project presentation
Ire project presentationIre project presentation
Ire project presentationAkshita Jha
 
project sentiment analysis
project sentiment analysisproject sentiment analysis
project sentiment analysissneha penmetsa
 
Presentation on supervised learning
Presentation on supervised learningPresentation on supervised learning
Presentation on supervised learningTonmoy Bhagawati
 
Twitter sentiment-analysis Jiit2013-14
Twitter sentiment-analysis Jiit2013-14Twitter sentiment-analysis Jiit2013-14
Twitter sentiment-analysis Jiit2013-14Rachit Goel
 
Sentiment analysis presentation
Sentiment analysis presentationSentiment analysis presentation
Sentiment analysis presentationGunjanSrivastava23
 
Sentiment analysis
Sentiment analysisSentiment analysis
Sentiment analysisSeher Can
 
Sentiment Analaysis on Twitter
Sentiment Analaysis on TwitterSentiment Analaysis on Twitter
Sentiment Analaysis on TwitterNitish J Prabhu
 
social network analysis project twitter sentimental analysis
social network analysis project twitter sentimental analysissocial network analysis project twitter sentimental analysis
social network analysis project twitter sentimental analysisAshish Mundra
 
Sentiment analysis of tweets
Sentiment analysis of tweetsSentiment analysis of tweets
Sentiment analysis of tweetsVasu Jain
 

What's hot (20)

Introduction to Sentiment Analysis
Introduction to Sentiment AnalysisIntroduction to Sentiment Analysis
Introduction to Sentiment Analysis
 
Sentiment Analysis on Twitter
Sentiment Analysis on TwitterSentiment Analysis on Twitter
Sentiment Analysis on Twitter
 
Sentiment analysis using ml
Sentiment analysis using mlSentiment analysis using ml
Sentiment analysis using ml
 
Twitter sentiment analysis
Twitter sentiment analysisTwitter sentiment analysis
Twitter sentiment analysis
 
Amazon sentimental analysis
Amazon sentimental analysisAmazon sentimental analysis
Amazon sentimental analysis
 
Social Media Sentiments Analysis
Social Media Sentiments AnalysisSocial Media Sentiments Analysis
Social Media Sentiments Analysis
 
Text classification & sentiment analysis
Text classification & sentiment analysisText classification & sentiment analysis
Text classification & sentiment analysis
 
Sentiment analysis
Sentiment analysisSentiment analysis
Sentiment analysis
 
Sentiment analysis - Our approach and use cases
Sentiment analysis - Our approach and use casesSentiment analysis - Our approach and use cases
Sentiment analysis - Our approach and use cases
 
Sentiment Analysis using Twitter Data
Sentiment Analysis using Twitter DataSentiment Analysis using Twitter Data
Sentiment Analysis using Twitter Data
 
Ire project presentation
Ire project presentationIre project presentation
Ire project presentation
 
project sentiment analysis
project sentiment analysisproject sentiment analysis
project sentiment analysis
 
Presentation on supervised learning
Presentation on supervised learningPresentation on supervised learning
Presentation on supervised learning
 
Sentiment Analysis
Sentiment AnalysisSentiment Analysis
Sentiment Analysis
 
Twitter sentiment-analysis Jiit2013-14
Twitter sentiment-analysis Jiit2013-14Twitter sentiment-analysis Jiit2013-14
Twitter sentiment-analysis Jiit2013-14
 
Sentiment analysis presentation
Sentiment analysis presentationSentiment analysis presentation
Sentiment analysis presentation
 
Sentiment analysis
Sentiment analysisSentiment analysis
Sentiment analysis
 
Sentiment Analaysis on Twitter
Sentiment Analaysis on TwitterSentiment Analaysis on Twitter
Sentiment Analaysis on Twitter
 
social network analysis project twitter sentimental analysis
social network analysis project twitter sentimental analysissocial network analysis project twitter sentimental analysis
social network analysis project twitter sentimental analysis
 
Sentiment analysis of tweets
Sentiment analysis of tweetsSentiment analysis of tweets
Sentiment analysis of tweets
 

Similar to Sentiment analysis-by-nltk

Achieving an a in the reading section
Achieving an a in the reading sectionAchieving an a in the reading section
Achieving an a in the reading sectionmrhoward12
 
ER: Extensive Reading/Effective Reading
ER: Extensive Reading/Effective ReadingER: Extensive Reading/Effective Reading
ER: Extensive Reading/Effective ReadingMarc Helgesen
 
November 5 --28. future and modals of probability and advice
November 5 --28. future and modals of probability and adviceNovember 5 --28. future and modals of probability and advice
November 5 --28. future and modals of probability and adviceIECP
 
Peer review clickbait
Peer review clickbaitPeer review clickbait
Peer review clickbaitHollyClayBuck
 
7 Tips for Writing a Film Review
7 Tips for Writing a Film Review7 Tips for Writing a Film Review
7 Tips for Writing a Film ReviewSteve Sorensen
 
Skellig STAR Lesson
Skellig STAR LessonSkellig STAR Lesson
Skellig STAR Lessonjulier3846
 
Types of Paragraph.pptx
Types of Paragraph.pptxTypes of Paragraph.pptx
Types of Paragraph.pptxJaneSumalinog
 

Similar to Sentiment analysis-by-nltk (12)

Analogy
AnalogyAnalogy
Analogy
 
Achieving an a in the reading section
Achieving an a in the reading sectionAchieving an a in the reading section
Achieving an a in the reading section
 
ER: Extensive Reading/Effective Reading
ER: Extensive Reading/Effective ReadingER: Extensive Reading/Effective Reading
ER: Extensive Reading/Effective Reading
 
Book Reviews and You!
Book Reviews and You!Book Reviews and You!
Book Reviews and You!
 
Feature writing
Feature writingFeature writing
Feature writing
 
November 5 --28. future and modals of probability and advice
November 5 --28. future and modals of probability and adviceNovember 5 --28. future and modals of probability and advice
November 5 --28. future and modals of probability and advice
 
D38-CREM
D38-CREMD38-CREM
D38-CREM
 
U72 lesson 09
U72 lesson 09U72 lesson 09
U72 lesson 09
 
Peer review clickbait
Peer review clickbaitPeer review clickbait
Peer review clickbait
 
7 Tips for Writing a Film Review
7 Tips for Writing a Film Review7 Tips for Writing a Film Review
7 Tips for Writing a Film Review
 
Skellig STAR Lesson
Skellig STAR LessonSkellig STAR Lesson
Skellig STAR Lesson
 
Types of Paragraph.pptx
Types of Paragraph.pptxTypes of Paragraph.pptx
Types of Paragraph.pptx
 

Sentiment analysis-by-nltk