Judge Calibration and Meta-Evaluation › Agreement Metrics

Michael BrenndoerferDecember 1, 20263 min read
Language AI HandbookAll chapters
Part 57 of 67Dynamic, Interactive, and Agentic Evaluation
Chapter 438Judge Calibration and Meta-Evaluation › Agreement Metrics
Reading section 10 of 20 · Agreement Metrics · 3 minSection 10 of 20 · 3 min

Section 10 of 20 · 3 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

We compute raw pairwise agreement, Cohen's κ\kappa, and Krippendorff's α\alpha. Cohen defined kappa for agreement on nominal scales. Krippendorff’s nominal alpha uses coincidence counts for pairs of comparable ratings. Cohen, 1960 Cohen’s retrospective Krippendorff

PythonIn [8]
CollapseExpand
def percent_agreement(a, b):
    m = a.notna() & b.notna()
    if m.sum() == 0:
        return float("nan")
    return float((a[m] == b[m]).mean())


def cohen_kappa(a, b):
    m = a.notna() & b.notna()
    a, b = a[m].astype(int), b[m].astype(int)
    n = len(a)
    if n == 0:
        return float("nan")
    labels = [0, 1]
    po = (a == b).mean()
    pe = sum((a == k).mean() * (b == k).mean() for k in labels)
    if pe >= 1 - 1e-9:
        return float("nan")
    return float((po - pe) / (1 - pe))


def krippendorff_alpha_nominal(labels_matrix):
    """
    labels_matrix: shape (n_items, n_raters), NaN for missing.
    Nominal difference. Implements the standard coincidence-matrix form.
    """
    data = np.asarray(labels_matrix, dtype=float)
    n_items, n_raters = data.shape
    # Build coincidence matrix over all distinct labels
    distinct = sorted({x for x in data.flatten() if not np.isnan(x)})
    idx = {v: i for i, v in enumerate(distinct)}
    K = len(distinct)
    if K == 0:
        return float("nan")
    coinc = np.zeros((K, K))
    for i in range(n_items):
        row = data[i]
        valid = [x for x in row if not np.isnan(x)]
        m_i = len(valid)
        if m_i < 2:
            continue
        for a_idx in range(m_i):
            for b_idx in range(m_i):
                if a_idx == b_idx:
                    continue
                ca, cb = idx[valid[a_idx]], idx[valid[b_idx]]
                coinc[ca, cb] += 1.0 / (m_i - 1)
    N_c = coinc.sum()
    if N_c == 0:
        return float("nan")
    # Observed disagreement: (1/N_c) * sum_{c,k} coinc[c,k] * delta^2(c,k)
    delta = np.ones((K, K)) - np.eye(K)
    D_o = (coinc * delta).sum() / N_c
    # Expected disagreement: marginals
    marg = coinc.sum(axis=0)
    e = np.outer(marg, marg) - np.diag(marg * (marg - 1))
    D_e = (e * delta).sum() / (marg.sum() * (marg.sum() - 1))
    if D_e == 0:
        return float("nan")
    return float(1 - D_o / D_e)


# Human-human reliability across the three panel annotators
alpha_human = krippendorff_alpha_nominal(
    fixture[["panel_a1", "panel_a2", "panel_a3"]].values
)

# Append each judge to the three individual panel-vote columns.
agreement_rows = []
for j in ["A", "B", "C"]:
    pa = percent_agreement(fixture["ref_majority"], fixture[f"judge_{j}"])
    kp = cohen_kappa(fixture["ref_majority"], fixture[f"judge_{j}"])
    al = krippendorff_alpha_nominal(
        np.column_stack(
            [
                fixture["panel_a1"],
                fixture["panel_a2"],
                fixture["panel_a3"],
                fixture[f"judge_{j}"],
            ]
        ).astype(float)
    )
    agreement_rows.append(
        {"judge": j, "pct_agree": pa, "kappa": kp, "alpha_vs_panel": al}
    )

agreement_df = pd.DataFrame(agreement_rows)
agreement_df
ConsoleOut [9]
CollapseExpand
Human-human Krippendorff's alpha (panel): 0.212

Judge-reference agreement:
judge  pct_agree  kappa  alpha_vs_panel
    A      0.795  0.591           0.315
    B      0.770  0.535           0.292
    C      0.680  0.361           0.230

Read panel-only alpha separately from panel-plus-judge alpha. The latter includes panel-member pairs and judge-to-member pairs. Kappa compares the judge with the majority on common decided items.

Report the measured panel-only alpha and the judge-to-majority agreement as different comparisons. Agreement against the latent label in the panel-size simulation is a third comparison with its own assumptions.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy