This function takes in texts and their associated document IDs to predict sentiments using the flair Python library.
Usage
get_sentiments(
texts,
doc_ids,
tagger = NULL,
...,
language = NULL,
show.text_id = FALSE,
gc.active = FALSE
)
Arguments
- texts
A list or vector of texts for which sentiment prediction is to be made.
- doc_ids
A list or vector of document IDs corresponding to the texts.
- tagger
An optional flair sentiment model. If NULL (default), the function loads the default model based on the language.
- ...
Additional arguments passed to next.
- language
A character string indicating the language of the texts. Currently supports "sentiment" (English), "sentiment-fast" (English), and "de-offensive-language" (German)
- show.text_id
A logical value. If TRUE, includes the actual text from which the sentiment was predicted. Default is FALSE.
- gc.active
A logical value. If TRUE, runs the garbage collector after processing all texts. This can help in freeing up memory by releasing unused memory space, especially when processing a large number of texts. Default is FALSE.
Value
A data.table
containing three columns:
doc_id
: The document ID from the input.sentiment
: Predicted sentiment for the text.score
: Score for the sentiment prediction.
Examples
if (FALSE) { # \dontrun{
library(flaiR)
texts <- c("UCD is one of the best universities in Ireland.",
"UCD has a good campus but is very far from my apartment in Dublin.",
"Essex is famous for social science research.",
"Essex is not in the Russell Group, but it is famous for political science research.",
"TCD is the oldest university in Ireland.",
"TCD is similar to Oxford.")
doc_ids <- c("doc1", "doc2", "doc3", "doc4", "doc5", "doc6")
# Load re-trained sentiment ("sentiment") model
tagger_sent <- load_tagger_sentiments('sentiment')
results <- get_sentiments(texts, doc_ids, tagger_sent)
print(results)
} # }