Swift · Choices

Choices

import UForm 4.0.0-rc.1 · 3ee5e534

textChoose scores each text’s legal choices, one byte each, through one forward of the byte decoder, a softmax over that item’s choices alone at its question type’s calibrated inverse temperature. The call appends the mask byte, and a text longer than the context loses its head, never its end. A model whose choiceTemperatureGroups is zero carries no byte decoder and refuses with unsupported.

let chosen = try model.textChoose(
    ["keep this candidate? ", "expand which neighbor? "],
    choices: [Array("yn".utf8), Array("ABCD".utf8)],
    temperatureGroups: [0, 1],
    arena: arena)
let keep = chosen.probabilities[0][0]           // one Float per choice, in the order offered

API

StructChosenWhat one choose call wrote into its arena, read in place until the arena's next call.2
Encode.swift:68 ↗
struct Chosen
probabilitiesOne probability per choice, in the order each item offered them.
Encode.swift:70 ↗
let probabilities: Tape
statsWhat the call counted on the way.
Encode.swift:72 ↗
let stats: EncodeStats
StructChoicesCalibrated choices over the byte decoder: each choice item scores the soft cross-entropy of its legal bytes' softmax, plus brierWeight times its Brier score.3
Train.swift:485 ↗
struct Choices

Mirrors uform_choices_t.

Conforms to

Sendable
weightThe loss weight; zero trains no choices.
Train.swift:487 ↗
var weight: Float
brierWeightThe Brier term's weight beside the soft cross-entropy; zero derives 0.5.
Train.swift:489 ↗
var brierWeight: Float
initTakes every field by name; a zero derives as its field documents.
Train.swift:492 ↗
init(weight: Float = 0, brierWeight: Float = 0)