Skip to contents

best_params() returns the winning parameter values recorded by compile() or optimize_grid(), such as the best temperature of a grid search or the number of demonstrations chosen by LabeledFewShot(). It reads optimization_result(module)$best_params.

Usage

best_params(module, flatten = TRUE)

Arguments

module

A module returned by compile() or modified by optimize_grid().

flatten

If TRUE (the default), length-one list elements are unwrapped to plain values. If FALSE, the parameters are returned as stored.

Value

A named list of parameters. For a module that has not been optimized, NULL with a warning.

Examples

classifier <- module(signature("text -> sentiment"))
trainset <- data.frame(
  text = c("I love it!", "Terrible experience", "It's okay"),
  sentiment = c("positive", "negative", "neutral")
)
compiled <- compile(classifier, LabeledFewShot(k = 2L), trainset)
best_params(compiled)
#> $k
#> [1] 2
#>