Analyzing sentiment of a phone call
Once you've transcribed the text from an audio file, it's possible to perform natural language processing on the text.
In this exercise, we'll use NLTK
's VADER (Valence Aware Dictionary and sEntiment Reasoner) to analyze the sentiment of the transcribed text of call_2.wav
(file).
To transcribe the text, we'll use the transcribe_audio()
function we created earlier.
Once we have the text, we'll use NLTK
's SentimentIntensityAnalyzer()
class to obtain a sentiment polarity score.
.polarity_scores(text)
returns a value for pos (positive), neu (neutral), neg (negative) and compound. Compound is a mixture of the other three values. The higher it is, the more positive the text. Lower means more negative.
Este exercício faz parte do curso
Spoken Language Processing in Python
Instruções do exercício
- Instantiate an instance of
SentimentIntensityAnalyzer()
and save it to the variablesid
. - Transcribe the target call and save it to
call_2_text
. - Print the
polarity_scores()
ofcall_2_text
.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
from nltk.sentiment.vader import SentimentIntensityAnalyzer
# Create SentimentIntensityAnalyzer instance
sid = ____
# Let's try it on one of our phone calls
call_2_text = transcribe_audio(____)
# Display text and sentiment polarity scores
print(call_2_text)
print(sid.____(call_2_text))