Skip to content

Commit 2374634

Browse files
committed
added sentiment analysis using vader tutorial
1 parent 67b14ec commit 2374634

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
3535
- [How to Build a Spam Classifier using Keras in Python](https://www.thepythoncode.com/article/build-spam-classifier-keras-python). ([code](machine-learning/nlp/spam-classifier))
3636
- [How to Build a Text Generator using TensorFlow and Keras in Python](https://www.thepythoncode.com/article/text-generation-keras-python). ([code](machine-learning/nlp/text-generator))
3737
- [How to Perform Text Classification in Python using Tensorflow 2 and Keras](https://www.thepythoncode.com/article/text-classification-using-tensorflow-2-and-keras-in-python). ([code](machine-learning/nlp/text-classification))
38+
- [Sentiment Analysis using Vader in Python](https://www.thepythoncode.com/article/vaderSentiment-tool-to-extract-sentimental-values-in-texts-using-python). ([code](machine-learning/nlp/sentiment-analysis-vader))
3839
- ### [Computer Vision](https://www.thepythoncode.com/topic/computer-vision)
3940
- [How to Detect Human Faces in Python using OpenCV](https://www.thepythoncode.com/article/detect-faces-opencv-python). ([code](machine-learning/face_detection))
4041
- [How to Make an Image Classifier in Python using TensorFlow and Keras](https://www.thepythoncode.com/article/image-classification-keras-python). ([code](machine-learning/image-classifier))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# [Sentiment Analysis using Vader in Python](https://www.thepythoncode.com/article/vaderSentiment-tool-to-extract-sentimental-values-in-texts-using-python)
2+
- `pip3 install -r requirements.txt`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vaderSentiment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
2+
3+
# init the sentiment analyzer
4+
sia = SentimentIntensityAnalyzer()
5+
6+
sentences = [
7+
"This food is amazing and tasty !",
8+
"Exoplanets are planets outside the solar system",
9+
"This is sad to see such bad behavior"
10+
]
11+
12+
for sentence in sentences:
13+
score = sia.polarity_scores(sentence)["compound"]
14+
print(f'The sentiment value of the sentence :"{sentence}" is : {score}')
15+
16+
for sentence in sentences:
17+
print(f'For the sentence "{sentence}"')
18+
polarity = sia.polarity_scores(sentence)
19+
pos = polarity["pos"]
20+
neu = polarity["neu"]
21+
neg = polarity["neg"]
22+
print(f'The percententage of positive sentiment in :"{sentence}" is : {round(pos*100,2)} %')
23+
print(f'The percententage of neutral sentiment in :"{sentence}" is : {round(neu*100,2)} %')
24+
print(f'The percententage of negative sentiment in :"{sentence}" is : {round(neg*100,2)} %')
25+
print("="*50)

0 commit comments

Comments
 (0)