View source: R/llm-sentiment.R
llm_sentiment | R Documentation |
Use a Large Language Model (LLM) to perform sentiment analysis from the provided text
llm_sentiment(
.data,
col,
options = c("positive", "negative", "neutral"),
pred_name = ".sentiment",
additional_prompt = ""
)
llm_vec_sentiment(
x,
options = c("positive", "negative", "neutral"),
additional_prompt = "",
preview = FALSE
)
.data |
A |
col |
The name of the field to analyze, supports |
options |
A vector with the options that the LLM should use to assign a sentiment to the text. Defaults to: 'positive', 'negative', 'neutral' |
pred_name |
A character vector with the name of the new column where the prediction will be placed |
additional_prompt |
Inserts this text into the prompt sent to the LLM |
x |
A vector that contains the text to be analyzed |
preview |
It returns the R call that would have been used to run the
prediction. It only returns the first record in |
llm_sentiment
returns a data.frame
or tbl
object.
llm_vec_sentiment
returns a vector that is the same length as x
.
library(mall)
data("reviews")
llm_use("ollama", "llama3.2", seed = 100, .silent = TRUE)
llm_sentiment(reviews, review)
# Use 'pred_name' to customize the new column's name
llm_sentiment(reviews, review, pred_name = "review_sentiment")
# Pass custom sentiment options
llm_sentiment(reviews, review, c("positive", "negative"))
# Specify values to return per sentiment
llm_sentiment(reviews, review, c("positive" ~ 1, "negative" ~ 0))
# For character vectors, instead of a data frame, use this function
llm_vec_sentiment(c("I am happy", "I am sad"))
# To preview the first call that will be made to the downstream R function
llm_vec_sentiment(c("I am happy", "I am sad"), preview = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.