Measure rater agreement with Cohen's kappa
Why it matters Human preference datasets for RLHF report kappa to show the labels are not noise.
When two annotators label data for an eval set, raw agreement overstates quality because some agreement happens by chance.
Write cohens_kappa(a, b) for two equal-length label lists. p_o is the fraction where they agree. p_e = sum over labels c of (fraction of a equal to c) * (fraction of b equal to c). Return (p_o - p_e) / (1 - p_e), or 1.0 if p_e == 1.
def cohens_kappa(a, b)Example
cohens_kappa([1, 1, 0, 0], [1, 0, 0, 0]) gives p_o 0.75, p_e 0.5 * 0.25 + 0.5 * 0.75 = 0.5, kappa 0.5.
Understand the idea
If two annotators label data, some agreement happens just by luck. Cohen's kappa removes that luck: it compares the observed agreement p_o with the agreement p_e you would expect if both labelled at random using their own label rates. Worked example: a = [1, 1, 1, 1, 0], b = [1, 1, 1, 0, 0]. They agree on 4 of 5, so p_o = 0.8. Rater a uses label 1 at rate 0.8 and label 0 at 0.2; rater b uses 1 at 0.6 and 0 at 0.4. p_e = 0.8 * 0.6 + 0.2 * 0.4 = 0.48 + 0.08 = 0.56. Kappa = (0.8 - 0.56) / (1 - 0.56) = 0.24 / 0.44 = about 0.545. Rule: p_o = fraction of positions where a equals b; p_e = sum over labels c of rate_a(c) * rate_b(c); kappa = (p_o - p_e) / (1 - p_e), and return 1.0 when p_e is 1. Each rater's own rates are used, not one rater's rate squared. Used in: checking label quality for eval sets, LLM-as-judge versus human agreement, and annotation guidelines.