Evals with related questions: cluster on the passage
The same math works on a model's test scores.
score = np.array([1, 1, 1, 0, 0, 0, 1, 1, 0,
1, 1, 1, 0, 0, 1, 0, 0, 0], float)
passage = np.repeat(np.arange(6), 3)
print(np.bincount([0, 0, 1, 2, 2], weights=[1.0, 2, 5, -1, 4]))
naive, clustered = eval_ses(score, passage)
print(f"naive {naive:.3f} clustered {clustered:.3f}")
[3. 5. 3.]
naive 0.118 clustered 0.171
An eval is an experiment too. Here a model answers 3 questions on each of 6 reading passages, scored 1 if right. When an eval asks several questions about each passage, the questions are the users and the passages are the cities. A model that misreads a passage misses several questions at once.
For one eval score, the sandwich has only an intercept. So each passage contributes its residual total, squared. np.bincount(ids, weights=w) adds up the weights that share each id: ids 0, 0, 1, 2, 2 with weights 1, 2, 5, -1, 4 give totals 3, 5 and 3. Give it the residuals as weights and it returns each passage's residual total. It needs the ids to be whole numbers, 0 or more. Neither standard error uses a small-sample correction, so the two compare fairly.
On these 18 answers, the clustered standard error is 1.45 times the naive one. Anthropic's guidance is to cluster on the unit of randomization, here the passage (1 source). In Evan Miller's paper behind that guidance, the clustered standard error on DROP, a reading-comprehension eval, came out 3.05 times the naive one. On the multilingual MGSM, where one question appears in many languages, it was 1.88 times. The paper's summary: "Analyzing the same data, clustered standard errors can be over 3X larger than naive standard errors."
To compare two models on the same questions, run it on the per-question score differences.
In the editor, write eval_ses(score, passage): the naive and the clustered standard error of an eval score.