sentiment_match: Sentiment Matching

View source: R/sentiment.R

sentiment_matchR Documentation

Sentiment Matching


Provides score and explanation, returns a single vector, and runs relatively fast.


  x = NULL,
  phrases = NULL,
  model = names(default_models),
  batch_size = 100,



A plain text vector or column name if data is supplied. If you know what you're doing, you can also pass in a 512-D numeric embedding.


A named list of examples phrases with each element of the list being words/terms that are indications of the name of that element (such as positive words/terms under the name "positive" and negative words/terms under the name "negative", all within the same list).


An embedding name from tensorflow-hub, some of which are "en" (english large or not) and "multi" (multi-lingual large or not).


Size of batches to use. Larger numbers will be faster than smaller numbers, but do not exhaust your system memory!


Additional arguments passed to conda_install() or virtualenv_install().


data.table containing text, sentiment, phrase, class, and similarity.


## Not run: 
envname   <- "r-sentiment-ai"

# make sure to install sentiment ai (
# = envname,
#                      method  = "conda")

# running the model
mod_match <- sentiment_match(x       = airline_tweets$text,
                             model   = "en.large",
                             envname = envname)

# checking performance
pos_neg <- factor(airline_tweets$airline_sentiment,
                  levels = c("negative", "neutral", "positive"))
pos_neg <- (as.numeric(pos_neg) - 1) / 2
cosine(mod_match$sentiment, pos_neg)

# you could also calculate accuracy/kappa

## End(Not run) documentation built on March 19, 2022, 2:15 a.m.