"""Prompt construction. One context, N typed questions, N answer slots. All N decisions are read from a single forward pass: the logits at each "Answer k: (" slot are restricted to the option-letter tokens. No answer letters are ever inserted, so slot k sees the context and all questions but no earlier answers (the decisions are conditionally independent given input). """ import random LETTERS = "ABCDEFGHIJ" NARROW = len(LETTERS) # <= NARROW options: the original "(A) .. (J)" rendering, tokenized as a string (unchanged since v1) MAX_OPTIONS = 255 # width of the label head. > NARROW options: "wide" rendering, one label token per option: # A..Z then the first 229 two-letter upper-case strings that are single tokens (AA, AB, ...) ABSTAIN_PREFIXES = ("none of the above", "none of these", "not listed", "no suitable", "does not apply", "cannot tell") ABSTAIN_EXACT = ("other", "unsure", "something else", "neither of these", "other / not covered") def is_abstain_option(o): o = o.strip().lower() return o.startswith(ABSTAIN_PREFIXES) or o in ABSTAIN_EXACT _LABELS = {} _OPT_CACHE = {} def _enc_opt(tok, text): """Token ids of ")