Skip to contents

Coordinate-wise search over the vocabulary for every NULL slot. Without grad_fn the loss is MINIMISED by brute force; with one, the gradient score is MAXIMISED, exactly as in Python.

Usage

morie_kamath_autoprompt_gradient_search(
  template,
  dataset,
  model,
  vocab = NULL,
  grad_fn = NULL,
  passes = 1
)

Arguments

template

List of tokens with NULL trigger slots.

dataset

Passed through to model.

model

Loss function.

vocab

Candidate tokens.

grad_fn

Optional gradient scorer.

passes

Sweeps over the slots.

Value

List with estimate, trigger_tokens, prompt, positions.

Examples

morie_kamath_autoprompt_gradient_search(list(NULL, "x", NULL),
    "D", function(t, d) sum(nchar(unlist(t))), vocab = list("aa",
        "b"))
#> $estimate
#> [1] 3
#> 
#> $loss
#> [1] 3
#> 
#> $trigger_tokens
#> [1] "b" "b"
#> 
#> $prompt
#> $prompt[[1]]
#> [1] "b"
#> 
#> $prompt[[2]]
#> [1] "x"
#> 
#> $prompt[[3]]
#> [1] "b"
#> 
#> 
#> $positions
#> [1] 0 2
#> 
#> $history
#> $history[[1]]
#> $history[[1]][[1]]
#> [1] 0
#> 
#> $history[[1]][[2]]
#> [1] "b"
#> 
#> 
#> $history[[2]]
#> $history[[2]][[1]]
#> [1] 2
#> 
#> $history[[2]][[2]]
#> [1] "b"
#> 
#> 
#> 
#> $n
#> [1] 2
#> 
#> $method
#> [1] "AutoPrompt trigger search (Kamath Ch 3)"
#>