Sub topic 6
Measuring coverage, overlap and conflict
This chapter assumes you can read basic NumPy and know what a labeling function and a label matrix are. In a label matrix, each row is an example, each column is a labeling function, and each cell holds a class or an abstain value. You also need accuracy and the idea of a small hand-labeled gold set.
Before you combine labeling functions with a majority vote or a label model, you should check how they behave on your data. Three numbers per function do most of that work: coverage, overlap and conflict. They need no ground truth, so you can compute them on the whole unlabeled training set and recompute them after every edit.
Why diagnostics come before combining
A label model can only use the information the votes contain. Three things go wrong silently if you skip diagnostics:
- A function that rarely fires adds almost nothing, however accurate it is.
- Examples that no function labels get no training signal.
- Functions that disagree on many examples mean at least one of them is often wrong, but the matrix alone does not say which.
Diagnostics show where to spend effort: which function to rewrite, which region of the data lacks a source, and which pairs of sources are suspiciously alike.
Definitions
Let L[i, j] be the vote of function j on example i. It is either a class or ABSTAIN. All three measures are fractions of the whole dataset, not of the examples where the function fires.
| Measure | Counts example `i` for function `j` when | What a high value suggests |
|---|---|---|
| Coverage | `j` does not abstain on `i` | The function reaches many examples |
| Overlap | `j` votes and at least one other function also votes | Redundancy, or a chance to cross-check |
| Conflict | `j` votes and at least one other function votes a different class | Noise in `j`, in the others, or an ambiguous example |
Because of how they are defined, conflict is never larger than overlap, and overlap is never larger than coverage. For each function, conflict <= overlap <= coverage. If your numbers break this rule, there is a bug.
Two dataset-level numbers matter as well:
- Total coverage is the share of examples that at least one function labels. The rest have no weak label at all.
- Mean votes per example tells you how much evidence a label model has to work with.
Computing the statistics
The code below computes all three measures from a label matrix with NumPy. It also computes the empirical accuracy of each function on a gold set. The matrix has eight examples and three functions: lf_pos (positive words), lf_neg (negative words) and lf_thanks.
import numpy as np
ABSTAIN, NEG, POS = -1, 0, 1
names = ['lf_pos', 'lf_neg', 'lf_thanks']
L = np.array([
[POS, ABSTAIN, POS],
[ABSTAIN, NEG, ABSTAIN],
[POS, NEG, POS],
[ABSTAIN, ABSTAIN, ABSTAIN],
[POS, ABSTAIN, ABSTAIN],
[ABSTAIN, NEG, ABSTAIN],
[POS, NEG, ABSTAIN],
[ABSTAIN, ABSTAIN, POS],
])
y = np.array([POS, NEG, NEG, POS, POS, NEG, NEG, POS]) # gold labels
def lf_stats(L, y=None):
voted = L != ABSTAIN
rows = []
for j in range(L.shape[1]):
v = voted[:, j]
others = voted.copy()
others[:, j] = False # ignore function j itself
has_other = others.any(axis=1)
differs = (others & (L != L[:, [j]])).any(axis=1)
row = {
'coverage': v.mean(),
'overlap': (v & has_other).mean(),
'conflict': (v & differs).mean(),
}
if y is not None and v.any():
row['accuracy'] = (L[v, j] == y[v]).mean()
row['n_votes'] = int(v.sum())
rows.append(row)
return rows
for name, r in zip(names, lf_stats(L, y)):
print(name, {k: round(float(x), 3) for k, x in r.items()})
voted = L != ABSTAIN
print('total coverage', voted.any(axis=1).mean())
print('mean votes per example', voted.sum(axis=1).mean())
conflicted = [len({v for v in row if v != ABSTAIN}) > 1 for row in L]
print('examples with a conflict', np.mean(conflicted))The others mask is what keeps abstentions from counting as disagreement. Without it, every vote would "conflict" with every abstain, because -1 differs from any class.
The output works out as follows:
| Function | Coverage | Overlap | Conflict | Empirical accuracy |
|---|---|---|---|---|
| `lf_pos` | 0.500 | 0.375 | 0.250 | 0.500 (4 votes) |
| `lf_neg` | 0.500 | 0.250 | 0.250 | 1.000 (4 votes) |
| `lf_thanks` | 0.375 | 0.250 | 0.125 | 0.667 (3 votes) |
Total coverage is 0.875, because only example 3 gets no vote. Mean votes per example is 1.375, and a quarter of the examples contain a conflict.
Reading the numbers
Look at the table with the matrix in mind. lf_pos and lf_neg conflict on examples 2 and 6, where a review contains both praise and a complaint. That is why both show 0.25. lf_thanks agrees with lf_pos on example 0 and example 2, so the two overlap often and mostly agree. You should be careful with that pattern, as the next sections explain.
Low coverage
A function with coverage of 0.02 touches 2 percent of the data. It may be precise, but it rarely changes the outcome. This is normal for high-precision rules such as a regex for "I want a refund". Keep them if they are accurate, and make sure other functions cover the remaining data. Coverage by class matters too: if every function labels only positive reviews, the label model will rarely see a negative one.
Overlap is not good or bad by itself
Overlap is the raw material for learning source accuracies. If a function never overlaps with another, no method can estimate how reliable it is without ground truth. Overlap with agreement raises confidence in the label. However, high overlap with consistent agreement can also mean two functions are near copies of each other. A label model that treats them as independent counts that evidence twice. Chapter-level failure modes come later, but the first sign is visible here: pairs with high overlap and almost no conflict.
Conflict is a signal, not a verdict
High conflict means that for many examples, some pair of functions votes differently. It does not tell you who is wrong. Check by reading about 20 conflicting examples by hand. Typical causes are:
- A word list that is too broad, such as "great" in "not great".
- A genuinely mixed example, such as the "Thank you, but it is terrible" review from the earlier code.
- A labeling function with a bug.
Conflict is also useful. A label model resolves conflicts using what it learns about each function. Little conflict across the whole set gives it little to learn from.
Empirical accuracy needs enough votes
Accuracy against a gold set is the one diagnostic that needs labels. In the table, lf_neg is 1.0 accurate, but on four votes. With so few votes, a function at 90 percent true accuracy can easily appear at 75 or 100 percent. As a rough guide, the standard error of an accuracy estimate is sqrt(p(1-p)/n). With n = 20 and p = 0.8, that is about 0.09. Treat accuracy on fewer than about 30 votes as a hint.
A triage routine
After each edit, recompute the statistics and compare them with the previous run. Keep a short log of the numbers. A change that raises coverage while conflict rises with it often means the rule became sloppy.
Using Snorkel's version
Snorkel computes the same quantities. LFAnalysis(L_train, lfs).lf_summary() returns columns Polarity, Coverage, Overlaps and Conflicts. If you pass gold labels as Y=y, it adds Correct, Incorrect and Emp. Acc.. Its definitions match the table above, so you can use your own function to cross-check it.
Common mistakes
- Counting abstain as a vote. This inflates conflict and overlap. Mask abstentions before comparing votes.
- Reading conflict as error rate. Two functions can conflict on an example that is truly mixed, and no function is wrong there.
- Ignoring uncovered examples. Total coverage below roughly 0.7 means a large part of the data will be dropped or rely on the end model's generalization alone.
- Judging a function by coverage alone. A function with coverage 0.6 and accuracy 0.55 hurts more than it helps.
Exercise
A labeling function has coverage 0.30, overlap 0.28 and conflict 0.00 on the training set. Another function in the set has coverage 0.31 and almost the same overlap. What do you check next, and why?
Show answer
Check whether the two functions fire on nearly the same examples with the same label, which would make them near duplicates (for example, two regexes built from the same word list). A label model that treats them as independent would count the same evidence twice and become overconfident. If they are duplicates, merge them or remove one. If they are different rules that happen to agree, keep both.
Exercise
In a binary task, an example receives votes [POS, ABSTAIN, NEG, NEG] from four functions. For which functions does this example add to coverage, overlap and conflict?
Show answer
All three functions that voted (the first, third and fourth) get coverage, overlap and conflict credit, since each has at least one other voter and each has another voter with a different class. The second function abstained, so it gets none of the three. The third and fourth agree with each other but still conflict with the first.