
Nucleus (top-p) truncation (Kamath Ch 8)
Source:R/kamath_llm2_native.R
morie_kamath_nucleus_sampling.RdTemperature-scaled softmax truncated to the smallest set with cumulative
mass >= p, then renormalised. kept is 0-BASED.
Examples
morie_kamath_nucleus_sampling(logits = c(1, 2, 3, 4, 5, 6, 7, 8), p = 0.5)
#> $probabilities
#> [1] 0 0 0 0 0 0 0 1
#>
#> $kept
#> [1] 7
#>
#> $n_kept
#> [1] 1
#>
#> $kept_mass
#> [1] 0.6323327
#>
#> $estimate
#> [1] 1
#>
#> $p
#> [1] 0.5
#>
#> $temperature
#> [1] 1
#>
#> $n
#> [1] 8
#>
#> $method
#> [1] "Nucleus (top-p) truncation"
#>