-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdb8c55
commit 95a7ff7
Showing
3 changed files
with
1,045 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# 4.2 Rule-based Sentiment Analysis" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Textblob" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from textblob import TextBlob" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 40, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sentence_1 = \"i had a great time at the movie it was really funny\"\n", | ||
"sentence_2 = \"i had a great time at the movie but the parking was terrible\"\n", | ||
"sentence_3 = \"i had a great time at the movie but the parking wasn't great\"\n", | ||
"sentence_4 = \"i went to see a movie\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 41, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"i had a great time at the movie it was really funny\n", | ||
"0.525\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(sentence_1)\n", | ||
"sentiment_score = TextBlob(sentence_1)\n", | ||
"print(sentiment_score.sentiment.polarity)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"TextBlob returns a score between -1 and 1, where negative scores indicate negative sentiment, and positive scores indicate positive sentiment. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 42, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"i had a great time at the movie but the parking was terrible\n", | ||
"-0.09999999999999998\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(sentence_2)\n", | ||
"sentiment_score_2 = TextBlob(sentence_2)\n", | ||
"print(sentiment_score_2.sentiment.polarity)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 43, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"i had a great time at the movie but the parking wasn't great\n", | ||
"0.8\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(sentence_3)\n", | ||
"sentiment_score_3 = TextBlob(sentence_3)\n", | ||
"print(sentiment_score_3.sentiment.polarity)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 44, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"i went to see a movie\n", | ||
"0.0\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(sentence_4)\n", | ||
"sentiment_score_4 = TextBlob(sentence_4)\n", | ||
"print(sentiment_score_4.sentiment.polarity)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### VADER" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 33, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 34, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"vader_sentiment = SentimentIntensityAnalyzer()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 45, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"i had a great time at the movie it was really funny\n", | ||
"{'neg': 0.0, 'neu': 0.578, 'pos': 0.422, 'compound': 0.807}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(sentence_1)\n", | ||
"print(vader_sentiment.polarity_scores(sentence_1))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The compond score gives us the overall score for the text and is scored the same as TextBlob between -1 and 1." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 46, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"i had a great time at the movie but the parking was terrible\n", | ||
"{'neg': 0.234, 'neu': 0.621, 'pos': 0.144, 'compound': -0.3818}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(sentence_2)\n", | ||
"print(vader_sentiment.polarity_scores(sentence_2)) " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 47, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"i had a great time at the movie but the parking wasn't great\n", | ||
"{'neg': 0.247, 'neu': 0.611, 'pos': 0.142, 'compound': -0.4387}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(sentence_3)\n", | ||
"print(vader_sentiment.polarity_scores(sentence_3)) " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 48, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"i went to see a movie\n", | ||
"{'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(sentence_4)\n", | ||
"print(vader_sentiment.polarity_scores(sentence_4)) " | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.