Submits each row of data to the Databoard annotate task, which asks an
LLM to annotate the text in col using rules. The server post-processes
the answer and returns tabular output columns.
Usage
llm_annotate(data, col, rules, options = list(), wait = 0)Arguments
- data
A data frame containing the texts to be annotated, or a data frame previously returned by
llm_annotate()whose pending results should be fetched.- col
A column in
dataholding the input text. Tidy-evaluation is supported (pass the bare column name).- rules
Required in submit mode. A data frame that is converted to an array of dicts with keys
category,description, andexample. Thedescriptionis used to identify text segments. Theexampleshould contain comma-separated text segments that match the rule. Thecategoryis used as thevalueattribute in the annotation output.- options
A named list of additional options passed to the Databoard server. See the databoad server documentation for available options.
- wait
Integer. Seconds to wait server-side per case for the task to complete before returning.
0(default): submit all tasks and return immediately with statePENDING. Fetch results later by callingllm_annotate(data)again.> 0: wait up to that many seconds per case for the result.
Value
The input data frame with the columns .task_id and .task_state
added. When results are available, they are unnested into additional
result columns (e.g. llm_result). For annotation tasks, llm_annos
is added as a list-column with one data frame per case containing
value and segment.
Details
The function has two modes of operation, dispatched automatically:
Submit - if
datadoes not yet contain a.task_idcolumn, the texts incolare submitted as new annotation tasks (viada_submit()).Fetch - if
dataalready contains a.task_idcolumn (i.e. it was previously returned byllm_annotate()), the function fetches results for any tasks that are still pending (viada_fetch()). In this case, all other parameters are ignored.
To customize prompts, pass options$prompts$system and/or
options$prompts$user.
Examples
if (FALSE) { # \dontrun{
anno_rules <- tibble::tribble(
~category, ~description, ~example,
"PERSON", "Names of people", "John Doe, Jane Roe",
"PLACE", "Names of places", "Berlin, New York"
)
# Submit
results <- llm_annotate(movies, abstract, anno_rules)
# Fetch pending tasks
results <- llm_annotate(results)
# Inspect annotations
head(results$llm_result)
results$llm_annos[[1]]
} # }