Sub topic 13
Krippendorff's alpha for missing data and different scales
This chapter assumes you can compute Cohen's kappa and Fleiss' kappa, you know what chance agreement means, and you can read short Python functions. It covers Krippendorff's alpha, an agreement measure that handles missing labels, any number of annotators, and several label scales with one formula.
Why kappa is not always enough
Cohen's kappa needs exactly two annotators who labeled the same items. Fleiss' kappa allows more annotators, but every item must have the same number of ratings. Real annotation projects often break both rules:
- Crowd workers each label a different subset of the items.
- An annotator skips an item or marks it "cannot decide".
- Labels are ratings from 1 to 5, where a 4 versus a 5 is a smaller disagreement than a 1 versus a 5.
Krippendorff's alpha handles all three cases. It also reports agreement as a number where 1 is perfect agreement and 0 is the level expected by chance.
The core idea: observed and expected disagreement
Kappa is built from agreement. Alpha is built from disagreement:
alpha = 1 - D_o / D_eD_ois the observed disagreement, the average distance between labels given to the same item.D_eis the disagreement expected if labels were assigned to items at random, keeping each label's overall frequency.
When annotators never disagree, D_o is 0 and alpha is 1. When their labels look unrelated to the items, D_o equals D_e and alpha is 0. Alpha can go below 0 when annotators disagree systematically more than chance would.
The distance between two labels comes from a difference function δ(c, k). Changing this function is how alpha adapts to different scales.
The coincidence matrix
Alpha works from a coincidence matrix, which replaces the items-by-annotators table. Build it like this:
- Take each item (called a unit) and keep only the labels that exist.
- Drop units with fewer than two labels. They carry no information about agreement.
- For a unit with
mlabels, look at every ordered pair of labels from different positions. Add1 / (m - 1)to the cello[c][k], wherecandkare the two labels.
The weight 1 / (m - 1) makes each unit contribute a total of m, so a unit with three labels counts more than a unit with two. Missing labels need no special handling: they never enter the matrix.
Let n_c be the row total for label c, and n the grand total. The formula becomes:
alpha = 1 - (n - 1) * sum(o[c][k] * δ(c, k)) / sum(n_c * n_k * δ(c, k))Both sums run over all ordered pairs (c, k).
Implementation from scratch
The function below takes each unit as a list of labels, with None for a missing label. It takes the difference function as an argument.
from collections import defaultdict
from itertools import permutations
def krippendorff_alpha(units, delta):
o = defaultdict(float)
for unit in units:
values = [v for v in unit if v is not None]
m = len(values)
if m < 2:
continue # a single label says nothing about agreement
for i, j in permutations(range(m), 2):
o[(values[i], values[j])] += 1 / (m - 1)
n_c = defaultdict(float)
for (c, _), w in o.items():
n_c[c] += w
n = sum(n_c.values())
observed = sum(w * delta(c, k) for (c, k), w in o.items())
expected = sum(n_c[c] * n_c[k] * delta(c, k) for c in n_c for k in n_c)
if expected == 0:
raise ValueError("Only one label value was used; alpha is undefined.")
return 1 - (n - 1) * observed / expected
def nominal(c, k):
return float(c != k)
def interval(c, k):
return float((c - k) ** 2)
# Three annotators, some labels missing (None)
labels = [
["pos", "pos", "pos"],
["pos", "neg", None],
["neg", "neg", "neg"],
["neu", "neu", None],
[None, "pos", "pos"],
["neg", None, None], # one label only, ignored
]
print(round(krippendorff_alpha(labels, nominal), 3))
# 1-5 ratings from the same three annotators
ratings = [
[3, 3, None],
[4, 5, 5],
[2, None, 3],
[1, 1, 1],
[5, 5, 4],
[None, 3, None], # one label only, ignored
]
print(round(krippendorff_alpha(ratings, interval), 3))
print(round(krippendorff_alpha(ratings, nominal), 3))The three printed values are 0.75, 0.909 and 0.446. For the first dataset, the coincidence matrix has n = 12. The only off-diagonal mass is o[pos][neg] = o[neg][pos] = 1, so alpha is 1 - 11 * 2 / 88 = 0.75.
The last two lines use the same ratings with different difference functions. The disagreements are mostly 4 versus 5 and 2 versus 3, which are near misses. The interval metric forgives them and the nominal metric does not.
Choosing the difference function
The scale of your labels decides the metric. Choosing it is a modeling decision, so make it before you look at the score.
| Scale | Example | Difference `δ(c, k)` |
|---|---|---|
| Nominal | sentiment classes, entity types | 0 if equal, 1 otherwise |
| Ordinal | "bad / ok / good" | based on the number of ratings ranked between `c` and `k`, so rank order matters but spacing does not |
| Interval | 1–5 scores treated as equally spaced | `(c - k)²` |
| Ratio | counts, durations | `((c - k) / (c + k))²` |
With the nominal metric, alpha is closely related to Fleiss' kappa when every item has the same number of ratings, and for two annotators it behaves much like kappa. The interval metric with quadratic distance plays the same role as quadratically weighted kappa for ordinal ratings.
Reading alpha
Krippendorff suggests treating alpha of 0.800 or higher as reliable. Values from 0.667 to 0.800 support only tentative conclusions. Below 0.667, the labels are usually too noisy to trust for evaluation. These cutoffs are conventions, like the kappa scales, and the right bar depends on how costly label errors are. A dataset used to rank models needs a higher bar than one used for exploratory analysis.
Gotchas and failure modes
- Prevalence still matters. Alpha corrects for chance using the overall label frequencies. When one label dominates,
D_eis small, and a few disagreements can push alpha down sharply even though raw agreement is high. Always report the label distribution beside alpha. - Dropped units are silent. Units with fewer than two labels disappear from the calculation. If many items are dropped, alpha describes only the overlapping part of your data. Report how many units entered the computation.
- Sparse overlap gives unstable estimates. When each pair of annotators shares few items, alpha varies a lot. Bootstrap over units to get a confidence interval instead of a single number.
- The wrong metric changes the answer. Treating 1–5 ratings as nominal, as the example above showed, made alpha drop from 0.909 to 0.446. Treating unordered classes as interval is worse, because arbitrary integer codes invent distances.
- Only one label value is undefined. If every annotator uses the same single label,
D_eis 0 and the formula divides by zero. The function above raises an error for this case. - Spans are not covered here. Alpha needs a fixed set of units. For entity spans, use span-level F1 as in the previous chapter's approach, or a unitizing variant of alpha, which is more complex.
Practical workflow
- Store labels in one record per annotator, per item, so missing labels are simply absent records.
- Convert to a list of units and choose the difference function from the label scale.
- Compute alpha overall, then for each label or annotator pair to find where disagreement concentrates.
- Bootstrap units to get an interval, and record the number of units used.
- Use the disagreements to revise the guidelines, then re-run the pilot.
Exercise
In a unit, three annotators give the labels 2, 2 and 3. Using the nominal coincidence matrix rules, which cells receive weight from this unit, and what is the total weight added?
Show answer
The unit has m = 3 labels, so each ordered pair adds 1/(m - 1) = 0.5. The ordered pairs of the two 2s add 2 × 0.5 = 1 to o[2][2]. The pairs between each 2 and the 3 add 2 × 0.5 = 1 to o[2][3] and 1 to o[3][2]. The total weight is 3, which equals m.
Exercise
A project has 5,000 items. Each item was labeled by two to four crowd workers out of a pool of 60, using the classes spam, ham and unsure. Which measure fits, and why not Cohen's or Fleiss' kappa?
Show answer
Krippendorff's alpha with the nominal difference function. Cohen's kappa needs the same two annotators on every item. Fleiss' kappa needs the same number of ratings per item. Alpha accepts a different number and a different set of annotators per item, because it only uses the labels that exist.