Score multiple-choice answers by log-likelihood
Why it matters Log-likelihood scoring is how base models are evaluated on multiple-choice benchmarks, and the normalisation choice is reported as acc versus acc_norm.
Benchmarks like HellaSwag are run on base models by scoring each answer option's continuation under the model and picking the most likely one. How you normalise by length changes the result.
Write mc_predict(questions, mode). Each question is a dict with "choices", a list of (logits, token_ids, n_chars), and "gold", the correct index. logits is (n, V): row t holds the model's next-token logits before continuation token t, and token_ids has length n. A choice's log-likelihood is the sum over t of log_softmax(logits[t])[token_ids[t]]. Score each choice by:
- "sum": the log-likelihood
- "token": log-likelihood / n
- "char": log-likelihood / n_chars
Predict the highest score (lowest index on ties). Return (preds, accuracy) with preds a list of ints.
def mc_predict(questions, mode)Example
one question whose two choices both have zero logits over V = 2, with 1 and 2 tokens, gives sums -0.6931 and -1.3863, so mc_predict(..., "sum") predicts 0; with gold 1 the result is ([0], 0.0).
Understand the idea
A base model cannot "choose option B", but it can tell you how likely each option's text is as a continuation of the question. The most likely continuation is its answer, like judging which ending to a story sounds most natural.
Example: option 1 is one token with probability 0.5: log-likelihood ln 0.5 = -0.693. Option 2 is two tokens, each 0.5: -1.386. By sum, option 1 wins, simply because it is shorter. Per token both score -0.693 (a tie, so the lower index wins). Per character, a long option is divided by a bigger number and penalised less.
Rule: LL = sum_t log_softmax(logits_t)[token_t]; score = LL, LL / n_tokens or LL / n_chars; prediction = argmax.
Sum favours short answers; dividing by length removes most of that bias. Evaluation harnesses usually report both the raw and the length-normalised accuracy, and the character-normalised version does not depend on the tokenizer.
Shapes and data flow
per choice: logits (n, V) -> log_softmax (n, V) -> gathered (n,) -> scalar score