Sub topic 6
Observed agreement and why it is not enough
This chapter assumes you can write short Python functions over lists and dictionaries, and that you know what a proportion is. It also assumes you know common labeling tasks such as sentiment classification. The previous chapters covered the task, schema, guidelines and pilot round. Here you compute the first number you will get from a pilot round, and see why you should not trust it on its own.
What observed agreement is
Observed agreement, also called percent agreement, is the fraction of items on which two annotators gave the same label. If they label N items and agree on M of them, the observed agreement is M / N. Statisticians usually write it as p_o.
It is the natural first number because it is easy to compute and easy to explain. It also points you straight at the items that need discussion.
The code below uses the pilot data from this tutorial: ten items labeled pos, neg or neu by two annotators.
def observed_agreement(a, b):
if len(a) != len(b):
raise ValueError("both annotators must label the same items")
if not a:
raise ValueError("no items to compare")
return sum(x == y for x, y in zip(a, b)) / len(a)
ann1 = ["pos", "pos", "neg", "neg", "pos", "neu", "neg", "pos", "neu", "neg"]
ann2 = ["pos", "neg", "neg", "neg", "pos", "neu", "neg", "pos", "pos", "neg"]
print(observed_agreement(ann1, ann2))This prints 0.8. The annotators disagree on item 1 (pos against neg) and item 8 (neu against pos), so 8 of 10 items match.
Edge cases to handle
Real pilot data is messier than the example. Decide these points before you compute anything.
- Alignment. The two lists must refer to the same items in the same order. Join on an item ID, not on row position. A silently shifted list gives a plausible but wrong number.
- Missing labels. An annotator may skip an item. The usual choice is to compare only items that both labeled, and to report how many items that leaves. Counting a skip as a disagreement mixes "did not label" with "labeled differently".
- More than two annotators. Compute observed agreement for each annotator pair and average the results. Fleiss' kappa, covered later in this tutorial, handles this case in one formula.
- Small samples. With 10 items, one changed label moves the score by 0.1. Treat a pilot score as a rough signal, not a measurement.
- Exact match only. The measure counts near misses as full disagreements. On a 1 to 5 rating scale, 4 against 5 counts the same as 1 against 5. The weighted kappa chapter addresses this.
The next example handles missing labels by dropping those items and reporting coverage.
def agreement_with_missing(a, b):
pairs = [(x, y) for x, y in zip(a, b) if x is not None and y is not None]
if not pairs:
raise ValueError("no items labeled by both annotators")
agreed = sum(x == y for x, y in pairs)
return agreed / len(pairs), len(pairs) / len(a)
a = ["pos", None, "neg", "neg", "pos"]
b = ["pos", "neg", "neg", None, "neg"]
score, coverage = agreement_with_missing(a, b)
print(score, coverage)This prints 0.6666666666666666 0.6. Two of the three jointly labeled items match, and 60% of items were labeled by both.
Where agreement hides in the confusion matrix
A single number does not say which labels cause the trouble. Cross-tabulate the two annotators' labels to see this. In the pilot data, annotator 1 labeled 4 items pos, and annotator 2 agreed on 3 of them. Annotator 1 labeled 2 items neu, and annotator 2 agreed on 1. All 4 of annotator 1's neg items matched.
So the disagreements are pos against neg once and neu against pos once. A pattern like this often points to a guideline gap, such as how to treat mild or mixed sentiment. The disagreement analysis chapter develops this idea.
Why 0.8 may mean less than it seems
Two annotators who label at random will still agree on some items. Observed agreement counts that accidental overlap as if it were skill. Two factors decide how large the overlap is.
Number of labels
With k equally likely labels and two annotators who guess independently, they match with probability 1/k.
| Labels (k) | Agreement from random guessing |
|---|---|
| 2 | 0.50 |
| 3 | 0.33 |
| 5 | 0.20 |
| 10 | 0.10 |
A score of 0.7 on a two-label task is a weaker result than 0.7 on a ten-label task. The raw numbers cannot be compared across tasks.
Label prevalence
Prevalence is how common each label is. When one label dominates, agreement by chance rises. Suppose 95% of comments are neg (not toxic) and each annotator says neg about 95% of the time, independently of the other. The chance that both say neg is 0.95 × 0.95 = 0.9025. The chance that both say pos is 0.05 × 0.05 = 0.0025. So they agree about 90.5% of the time without reading a single comment.
The next code shows the extreme case, an annotator who always outputs the majority label.
from collections import Counter
def expected_by_chance(a, b):
n = len(a)
ca, cb = Counter(a), Counter(b)
return sum(ca[label] * cb[label] for label in ca) / n ** 2
gold = ["neg"] * 95 + ["pos"] * 5
always_neg = ["neg"] * 100
print(observed_agreement(gold, always_neg))
print(expected_by_chance(gold, always_neg))
print(expected_by_chance(ann1, ann2))This prints 0.95, 0.95 and 0.38. The constant annotator reaches 95% agreement and has detected no positive item. The chance estimate also reaches 0.95, which shows that the agreement is fully explained by label frequencies. For the pilot data, chance accounts for 0.38 of the 0.8.
expected_by_chance multiplies, for each label, the share of items annotator A gave that label by the share annotator B gave it, then sums over labels. It uses each annotator's own label frequencies. The next chapter turns this quantity into a correction.
Common mistakes
- Reporting only percent agreement. Readers cannot tell whether the score reflects skill or skewed labels. Report it alongside a chance-corrected measure and the label distribution.
- Comparing scores across tasks. The chance floor differs with the number and balance of labels.
- Averaging over the wrong items. Include or exclude missing items consistently, and say which.
- Treating one pilot score as stable. Use enough items that the rare labels appear several times.
- Confusing agreement with correctness. Two annotators can share the same misreading of an ambiguous guideline. High agreement shows consistency, not truth.
What observed agreement is still good for
Despite its weakness, keep computing it. It is the numerator of every chance-corrected measure in this tutorial. It is also the easiest figure to explain to project stakeholders. Per-label and per-item agreement tell you where to look first when you revise guidelines. Treat it as a diagnostic, and pair it with a measure that accounts for chance.
Exercise
A toxicity task has 90% non-toxic items. Two annotators each label an item non-toxic 90% of the time, independently of each other. What observed agreement would you expect from guessing alone, and why is a reported 0.85 not impressive?
Show answer
Both say non-toxic with probability 0.9 × 0.9 = 0.81, and both say toxic with probability 0.1 × 0.1 = 0.01, so expected agreement is 0.82. An observed agreement of 0.85 is only 0.03 above what label frequencies alone produce, so it shows almost no agreement beyond chance.
Exercise
Two annotators labeled 8 items. Annotator A gave ["x", "y", "x", None, "x", "y", "y", "x"] and annotator B gave ["x", "y", "y", "x", "x", None, "y", "x"]. Using only items both labeled, what is the observed agreement and the coverage?
Show answer
Items 3 and 5 (zero-indexed) have a missing label, so 6 items remain. Of these, only item 2 disagrees (x against y), so 5 of 6 match. The observed agreement is about 0.833 and the coverage is 6/8 = 0.75.