Answer-token readout¶
An answer-token readout reuses a language model's output projection and reads scores for a finite set of answer codes. MetisCraft uses this path for noul, choice and score, including the Tev1 recipe.
Question¶
Which part of a vocabulary distribution corresponds to an application's answer space? The critical distinction is between a candidate index \(k\), a candidate ID such as security, and a vocabulary index \(\ell_{b,k}\) for its answer code. They are connected by an explicit codebook.
Tensors and semantics¶
| Tensor | Shape | Meaning |
|---|---|---|
| \(H\) | \([B,T,d]\) | Contextualized input tokens |
| \(h\) | \([B,d]\) | Hidden state at the final prompt position |
| \(W_{\mathrm{lm}}\) | \([V,d]\) | Vocabulary projection, stored in PyTorch orientation |
| \(Z\) | \([B,V]\) | Full-vocabulary next-token logits |
| \(\ell\) | \([B,K_{\mathrm{code},\max}]\) | Vocabulary indices for each question's answer codes |
| \(S\) | \([B,K_{\max}]\) | Task scores after code selection and binary conversion |
The plain prompt uses single-token letter codes for choices and zero-based numeric codes for score levels. chat_json uses letters for both and preserves the supplied JSON payload in the tokenizer's non-thinking chat template. noul uses yes and no codes with a plain prompt. A tokenizer must provide the required codes as distinct single tokens.
Operator chain¶
- Render state, question and candidate definitions, then left-pad the batch.
- Read
H[:, -1]. Left padding makes the last column a valid prompt position for every row. - Apply the LM output projection, then
gatherthe code columns independently for each question. - For choice and score, normalize only valid candidate scores. For noul, subtract the no logit from the yes logit and apply sigmoid to that single difference.
h = H[:, -1] # [B, d]
Z = lm_head(h) # [B, V]
S_codes = Z.gather(1, codes) # [B, K_code_max]
S_noul = S_codes[noul_rows, 0] - S_codes[noul_rows, 1]
The last operation is categorical code selection, not generated text parsing. MetisCraft's inference path does not need to sample an answer string.
Equations¶
For a bias-free LM head, the projected matrix product contracts the hidden axis:
For choice or score:
For noul, two vocabulary scores become one binary logit:
At unit temperature, this equals a two-code softmax's yes probability. In general it differs from the yes token's probability normalized over the entire vocabulary.
Small example¶
Suppose the selected code logits are \([0,1,2]\). Their candidate-normalized probabilities are \([0.090031,0.244728,0.665241]\), regardless of logits in unselected vocabulary columns. If the yes/no logits are \([2,0]\), the binary logit is \(2\) and the yes probability is \(0.880797\).
These are constructed values. The CPU verification script checks the gather and logit-difference identities against a randomly initialized transformer; it does not measure model quality.
Source map¶
build_codebook,level_codes,yes_no_codes: valid single-token codes.answer_tokenandchat_json: codebook-to-prompt alignment.Collator: per-row code-index tensor.DecisionModel.forward: LM projection, gather and noul conversion.- Tev1 4B recipe:
chat_jsonwith full-vocabulary completion training.
Scope¶
An autoregressive prompt exposes preceding options to later positions; this is directional causal visibility, not bidirectional interaction. Code choice, option order and truncation can affect results. The plain prompt truncates only state; chat_json rejects an overlong complete prompt.
Completion training adds a separate \([B,2,V]\) training path for predicting the answer code and EOS. It should not be confused with candidate-only CE or reasoning-token generation; see training and calibration. This readout does not support multi_label, and the package does not claim external inference-engine or prefix-cache integration.