分析電話通話的情緒傾向
當你把音訊檔轉成文字之後,就可以在文字上執行自然語言處理。
在這個練習中,我們會使用 NLTK 的 VADER(Valence Aware Dictionary and sEntiment Reasoner)來分析 call_2.wav 的轉錄文字(檔案)。
要進行轉錄,我們會使用先前建立的 transcribe_audio() 函式。
取得文字後,我們會使用 NLTK 的 SentimentIntensityAnalyzer() 類別來計算情緒極性分數。
.polarity_scores(text) 會回傳 pos(正向)、neu(中性)、neg(負向)以及 compound。compound 是前三者的綜合分數。分數越高代表文字越正向,越低則代表越負向。
本練習屬於課程
Python 的口語語言處理
練習說明
- 建立
SentimentIntensityAnalyzer()的實例,並將其存為變數sid。 - 轉錄目標通話,將結果存為
call_2_text。 - 列印
call_2_text的polarity_scores()。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
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))