CommencerCommencer gratuitement

Sentiment and emotion

Within the sentiments dataset, the lexicon nrc contains a dictionary of words and an emotion associated with that word. Emotions such as joy, trust, anticipation, and others are found within this dataset.

In the Russian tweet bot dataset you have been exploring, you have looked at tweets sent out by both a left- and a right-leaning tweet bot. Explore the contents of the tweets sent by the left-leaning (democratic) tweet bot by using the nrc lexicon. The left tweets, left, have been tokenized into words, with stop-words removed.

Cet exercice fait partie du cours

Introduction to Natural Language Processing in R

Afficher le cours

Instructions

  • Create a tibble of just the anticipation words from the nrc lexicon.
  • Create a tibble of just the joy words from the nrc lexicon.
  • Print the top anticipation words found in left_tokens.
  • Print the top joy words found in left_tokens.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

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)
Modifier et exécuter le code