llm_extract | R Documentation |
Use a Large Language Model (LLM) to extract specific entity, or entities, from the provided text
llm_extract(
.data,
col,
labels,
expand_cols = FALSE,
additional_prompt = "",
pred_name = ".extract"
)
llm_vec_extract(x, labels = c(), additional_prompt = "", preview = FALSE)
.data |
A |
col |
The name of the field to analyze, supports |
labels |
A vector with the entities to extract from the text |
expand_cols |
If multiple |
additional_prompt |
Inserts this text into the prompt sent to the LLM |
pred_name |
A character vector with the name of the new column where the prediction will be placed |
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_extract
returns a data.frame
or tbl
object.
llm_vec_extract
returns a vector that is the same length as x
.
library(mall)
data("reviews")
llm_use("ollama", "llama3.2", seed = 100, .silent = TRUE)
# Use 'labels' to let the function know what to extract
llm_extract(reviews, review, labels = "product")
# Use 'pred_name' to customize the new column's name
llm_extract(reviews, review, "product", pred_name = "prod")
# Pass a vector to request multiple things, the results will be pipe delimeted
# in a single column
llm_extract(reviews, review, c("product", "feelings"))
# To get multiple columns, use 'expand_cols'
llm_extract(reviews, review, c("product", "feelings"), expand_cols = TRUE)
# Pass a named vector to set the resulting column names
llm_extract(
.data = reviews,
col = review,
labels = c(prod = "product", feels = "feelings"),
expand_cols = TRUE
)
# For character vectors, instead of a data frame, use this function
llm_vec_extract("bob smith, 123 3rd street", c("name", "address"))
# To preview the first call that will be made to the downstream R function
llm_vec_extract(
"bob smith, 123 3rd street",
c("name", "address"),
preview = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.