Skip to contents

In-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"
)

Arguments

model

function(prompt, candidate) -> log-probability.

examples

List of (x,y) pairs.

query

Query input.

candidates

Optional label set.

template, separator

Prompt assembly.

Value

List with prediction, prompt, log_probs, posterior, n_shot, candidates, estimate, n, method.

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"
#>