情緒與情感分析
在 sentiments 資料集中,字彙表 nrc 提供了單字與其對應情緒的對照字典。這個資料集包含像是 joy(喜悅)、trust(信任)、anticipation(期待)等情緒。
在你一直探索的俄羅斯推文機器人資料集中,你已經看過由傾向左派與傾向右派的推文機器人所發送的推文。請使用 nrc 字彙表,分析傾向左派(民主黨)的推文機器人所發送的推文內容。左派推文 left 已經被切成單字,並且移除了停用字。
本練習屬於課程
R 的自然語言處理入門
練習說明
- 從
nrc字彙表建立只包含 anticipation(期待)單字的 tibble。 - 從
nrc字彙表建立只包含 joy(喜悅)單字的 tibble。 - 列印在
left_tokens中出現次數最多的anticipation單字。 - 列印在
left_tokens中出現次數最多的joy單字。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
left_tokens <- left %>%
unnest_tokens(output = "word", token = "words", input = content) %>%
anti_join(stop_words)
# Dictionaries
anticipation <- ___("nrc") %>%
___(sentiment == "anticipation")
joy <- ___("nrc") %>%
___(sentiment == "joy")
# Print top words for Anticipation and Joy
left_tokens %>%
___(anticipation, by = "word") %>%
___(word, sort = TRUE)
left_tokens %>%
___(joy, by = "word") %>%
___(word, sort = TRUE)