3. Natural language processing with Python 5-2. Emotion intensity analysis tool VADER

⑴ Usage / Overview of VADER Sentiment Analysis Tool

import nltk

#➊ Download dictionary
nltk.download('vader_lexicon')
#➋ Import emotion intensity analysis class
from nltk.sentiment.vader import SentimentIntensityAnalyzer

#➌ Instance generation
vader_analyzer = SentimentIntensityAnalyzer()

⑵ Emotional polarity output format

text = "I am happy."

result = vader_analyzer.polarity_scores(text)
print(text + "\n", result)

image.png

⑶ Emotional polarity scoring

import pandas as pd

sentences = ["I am happy.", "I am sad.", "I am angry."]

#Get score
result = []
for s in sentences:
    score = vader_analyzer.polarity_scores(s)
    result.append(score)

#Convert from dictionary type to data frame
i = 0
df = pd.DataFrame()
for i in range(3):
    x = pd.DataFrame.from_dict(result[i], orient='index').T
    df = pd.concat([df,x], ignore_index=True)
df.index = sentences

print(df)

image.png

sentences = ["That's fantastic.", "That's wonderful.", "That's great."]

image.png

⑷ Negative / abbreviated and compound sentences

sentences = ["I was not happy.", "I wasn't happy.", "I'm rich but unhappy."]

result = []
for s in sentences:
    score = vader_analyzer.polarity_scores(s)
    result.append(score)

i = 0
df = pd.DataFrame()
for i in range(3):
    x = pd.DataFrame.from_dict(result[i], orient='index').T
    df = pd.concat([df,x], ignore_index=True)
df.index = sentences

print(df)

image.png

⑸ Exclamation mark ・ Strength expression by capital letters

sentences = ["I am happy.", "I am happy!", "I am happy!!", "I am happy!!!", "I am HAPPY."]

result = []
for s in sentences:
    score = vader_analyzer.polarity_scores(s)
    result.append(score)

i = 0
df = pd.DataFrame()
for i in range(5):
    x = pd.DataFrame.from_dict(result[i], orient='index').T
    df = pd.concat([df,x], ignore_index=True)
df.index = sentences

print(df)

image.png

import matplotlib.pyplot as plt
from matplotlib import pyplot as pyplot

x = (df.index.values.tolist())[0:4]
y = df.iloc[0:4, 3]
plt.plot(x, y, marker="o")

plt.axhline(y=df.iloc[4, 3], color='r', linestyle='-')

plt.ylabel("compound score")
plt.legend(['number of "!"','uppercase notation'])
plt.grid()

image.png

⑹ Emotional expression by emoticons

sentences = ["I love you.", "I love you :-*","I love you <3"]

result = []
for s in sentences:
    score = vader_analyzer.polarity_scores(s)
    result.append(score)

i = 0
df = pd.DataFrame()
for i in range(3):
    x = pd.DataFrame.from_dict(result[i], orient='index').T
    df = pd.concat([df,x], ignore_index=True)
df.index = sentences

print(df)

image.png

sentences = ["I am happy.", "I am happy :-)", "I am happy (^^)"]

image.png


Recommended Posts

3. Natural language processing with Python 5-2. Emotion intensity analysis tool VADER
3. Natural language processing with Python 4-1. Analysis for words with KWIC
3. Natural language processing with Python 3-1. Important word extraction tool TF-IDF analysis [original definition]
3. Natural language processing with Python 5-1. Concept of sentiment analysis [AFINN-111]
3. Natural language processing with Python 2-1. Co-occurrence network
3. Natural language processing with Python 1-1. Word N-gram
Python: Natural language processing
3. Natural language processing with Python 5-3. Emotion value analysis of Japanese sentences [Word emotion polarity value correspondence table]
3. Natural language processing with Python 2-2. Co-occurrence network [mecab-ipadic-NEologd]
[Python] I played with natural language processing ~ transformers ~
3. Natural language processing with Python 5-4. Emotion value analysis of Japanese sentences [Japanese evaluation polarity dictionary (noun edition)]
100 Language Processing with Python Knock 2015
Natural language processing 1 Morphological analysis
Building an environment for natural language processing with Python
Study natural language processing with Kikagaku
100 Language Processing Knock with Python (Chapter 1)
[Natural language processing] Preprocessing with Japanese
100 Language Processing Knock with Python (Chapter 3)
Japanese Natural Language Processing Using Python3 (4) Sentiment Analysis by Logistic Regression
Dockerfile with the necessary libraries for natural language processing in python
100 Language Processing Knock with Python (Chapter 2, Part 2)
100 Language Processing Knock with Python (Chapter 2, Part 1)
I tried natural language processing with transformers.
Getting started with Python with 100 knocks on language processing
Python: Deep Learning in Natural Language Processing: Basics
Let's enjoy natural language processing with COTOHA API
3. Natural language processing with Python 3-3. A year of corona looking back at TF-IDF
Data analysis with python 2
RNN_LSTM2 Natural language processing
Image processing with Python
Voice analysis with python
Data analysis with Python
100 natural language processing knocks Chapter 4 Morphological analysis (first half)
100 natural language processing knocks Chapter 4 Morphological analysis (second half)
[Chapter 5] Introduction to Python with 100 knocks of language processing
[Chapter 3] Introduction to Python with 100 knocks of language processing
[Chapter 2] Introduction to Python with 100 knocks of language processing
100 natural language processing knocks Chapter 5 Dependency analysis (second half)
100 natural language processing knocks Chapter 5 Dependency analysis (first half)
[Chapter 4] Introduction to Python with 100 knocks of language processing
[For beginners] Language analysis using the natural language processing tool "GiNZA" (from morphological analysis to vectorization)
The first artificial intelligence. I wanted to try natural language processing, so I will try morphological analysis using MeCab with python3.
Image processing with Python (Part 2)
[Practice] Make a Watson app with Python! # 3 [Natural language classification]
[Python] Morphological analysis with MeCab
[Co-occurrence analysis] Easy co-occurrence analysis with Python! [Python]
100 Language Processing Knock-57: Dependency Analysis
Acoustic signal processing with Python (2)
Sentiment analysis with Python (word2vec)
Acoustic signal processing with Python
100 Language Processing Knock Chapter 1 (Python)
100 Language Processing Knock Chapter 2 (Python)
Image processing with Python (Part 1)
[Python] Try to classify ramen shops by natural language processing
Sentiment analysis with natural language processing! I tried to predict the evaluation from the review text
Planar skeleton analysis with Python
Create a simple video analysis tool with python wxpython + openCV
Natural language processing 3 Word continuity
Japanese morphological analysis with Python
Image processing with Python (Part 3)
100 language processing knock-56: co-reference analysis