Skip to contents

llm_predict() creates a parsnip model specification whose "dsprrr" engine predicts with a dsprrr module, for classification or regression on text columns. temperature and top_p can be marked for tuning with tune(); see temperature() and top_p().

Usage

llm_predict(
  mode = "classification",
  signature = NULL,
  temperature = NULL,
  top_p = NULL
)

Arguments

mode

"classification" (the default) or "regression".

signature

Optional signature string or signature() object for the module. NULL derives one from the data when fitting.

temperature

Sampling temperature for the module, or tune().

top_p

Nucleus sampling parameter for the module, or tune().

Value

A parsnip model specification of class llm_predict.

Details

The engine is registered automatically when parsnip is loaded (see register_dsprrr_engine()). Fitting builds a Predict module from the predictor columns and the outcome: an enum output with the outcome's levels for classification, or a number for regression, unless you give a signature. Prediction runs the module on the new data with the default chat (see dsp_configure()); a fitted model makes no model calls until it predicts.

Known issue: the engine is registered without parsnip's encoding information, so parsnip::fit() and parsnip::fit_xy() currently fail with "no applicable method for 'filter'". Until that is fixed, the specification cannot be fitted through parsnip, workflows or tune.

Examples

spec <- llm_predict(
  mode = "classification",
  signature = "text -> sentiment: enum('positive', 'negative', 'neutral')"
) |>
  parsnip::set_engine("dsprrr")
spec
#> 
#> ── LLM Predict Model Specification 
#> Mode: classification
#> Engine: dsprrr

# Mark a parameter for tuning
llm_predict(signature = "text -> sentiment", temperature = parsnip::tune())
#> 
#> ── LLM Predict Model Specification 
#> Mode: classification