MediaPipeTasksDecision Framework Reference

ChoiceQuestion

struct ChoiceQuestion: Sendable, Equatable

Configuration for evaluating a mutually exclusive categorical choice menu.

  • Creates a new ChoiceQuestion instance.

    Declaration

    Swift

    init(choices: [String] = [], descriptions: [String]? = nil, temperature: Float = 0.0, instructions: String = "", scoringMode: ScoringMode = .lengthNormalizedLogProb, normalizePrior: Bool = false, examples: [[String]] = [], inputPrompt: InputPrompt = .unspecified, balanceClassWeights: Bool = true, fittedHead: Data? = nil)
  • Creates a ChoiceQuestion from ordered key-description criteria pairs (for example, ChoiceQuestion(criteria: ["billing": "Invoices or refunds", "technical": "Crashes"])).

    Declaration

    Swift

    init(criteria: KeyValuePairs<String, String>, temperature: Float = 0.0, instructions: String = "", scoringMode: ScoringMode = .lengthNormalizedLogProb, normalizePrior: Bool = false, fittedHead: Data? = nil)
  • Creates a ChoiceQuestion from ordered (key, examples) pairs, with optional descriptions.

    If descriptions is non-empty, it must provide a non-empty description for every choice key (and no unknown keys); embedding models include descriptions as one extra training point per choice while every choice has at most 6 examples, and ignore them above 6.

    Declaration

    Swift

    init(examples: [(key: String, examples: [String])], descriptions: [String: String] = [:], inputPrompt: InputPrompt = .unspecified, balanceClassWeights: Bool = true, temperature: Float = 0.0, instructions: String = "") throws
  • Declaration

    Swift

    init(options: [(key: String, description: String)], temperature: Float = 0.0, instructions: String = "", scoringMode: ScoringMode = .lengthNormalizedLogProb, normalizePrior: Bool = false)
  • Whether to weight each choice's examples by N / (K * N_c) when fitting a classifier.

    Here N is the total number of examples across all K choices, K is the number of choices, and N_c is the number of examples for choice c, so choices with fewer examples are not penalized.

    Declaration

    Swift

    var balanceClassWeights: Bool
  • Ordered list of option keys (may be empty when fittedHead is provided).

    Declaration

    Swift

    var choices: [String]
  • Optional descriptions corresponding 1:1 with choices.

    Declaration

    Swift

    var descriptions: [String]?
  • Per-choice example inputs corresponding 1:1 with choices, or [] when unused.

    When provided, every choice must have at least one non-empty example. Supported only by embedding models; other models throw DecisionMakerError.failedToEvaluate.

    Declaration

    Swift

    var examples: [[String]]
  • Optional pre-fitted FittedHead binary payload for embedding models.

    Declaration

    Swift

    var fittedHead: Data?
  • How examples and inputs are embedded when examples are provided.

    Declaration

    Swift

    var inputPrompt: InputPrompt
  • Optional task instructions prepended to the choice prompt.

    Declaration

    Swift

    var instructions: String
  • Whether to normalize option log-probabilities against the empty-context prior.

    Cannot be true when examples or fittedHead are provided (DecisionMakerError.invalidArgument).

    Declaration

    Swift

    var normalizePrior: Bool
  • Multi-token log-probability aggregation strategy.

    Declaration

    Swift

    var scoringMode: ScoringMode
  • Softmax temperature override (0.0 uses the model's calibrated default).

    Declaration

    Swift

    var temperature: Float