
In-context learning by prompt-conditioned scoring (Geron Ch 15, morie.fn hmicl)
Source:R/geron_w4b_native.R
morie_geron_in_context_learning_hmicl.RdIn-context learning by prompt-conditioned scoring (Geron Ch 15, morie.fn hmicl)
Usage
morie_geron_in_context_learning_hmicl(
model,
examples,
query,
candidates = NULL,
template = "{x} -> {y}",
separator = "\n"
)Examples
scorer <- function(prompt, cand) as.numeric(lengths(regmatches(prompt,
gregexpr(as.character(cand), prompt, fixed = TRUE))))
ex <- list(list("a", "pos"), list("b", "pos"), list("c", "neg"))
morie_geron_in_context_learning_hmicl(scorer, ex, "d")
#> $prediction
#> [1] "pos"
#>
#> $prompt
#> [1] "a -> pos\nb -> pos\nc -> neg\nd ->"
#>
#> $log_probs
#> [1] 2 1
#>
#> $posterior
#> [1] 0.7310586 0.2689414
#>
#> $n_shot
#> [1] 3
#>
#> $candidates
#> [1] "pos" "neg"
#>
#> $estimate
#> [1] 0.7310586
#>
#> $n
#> [1] 3
#>
#> $method
#> [1] "In-context learning by prompt-conditioned scoring"
#>