Sub topic 11
Evaluating with a small hand-labeled gold set
This chapter assumes you can write basic Python, know precision, recall and F1, and have read the earlier chapters on labeling functions, the label matrix, label models and training the end model. Weak labels are noisy, and the label model's own confidence is an estimate built from those same noisy votes. A small set of labels checked by a person is the only independent evidence that the pipeline works.
Why you still need hand labels
Weak supervision removes most hand labeling from training. It cannot remove it from evaluation. Three things in the pipeline cannot grade themselves:
- The label model estimates source accuracies from agreement between sources. If several sources share the same blind spot, the estimate is confidently wrong.
- The end model trains on weak labels. Its training loss measures how well it imitates them, not how well it matches the truth.
- LLM labels and synthetic text come from a model with its own biases. Agreement between runs of the same model is not accuracy.
A gold set is a sample of real, unlabeled-pool-style examples that a person labels carefully, ideally with a written guideline and a second annotator on a subset. Typical sizes are a few hundred examples, which is small enough to label in an afternoon.
Splitting the gold set
Split the gold set into two parts, and keep the roles separate.
- Dev split. Use it while building. You inspect errors here, rewrite labeling functions, choose the label model settings and pick thresholds.
- Test split. Use it for the final number only. Once you tune against it, it becomes a second dev set and the reported score is optimistic.
Both splits must be disjoint from anything the labeling functions were written from. If you wrote a regex after reading an example, that example belongs in dev or in the unlabeled pool, never in test.
Sampling the gold set
The gold set should look like the data the model will see in use. Draw it at random from the unlabeled pool. Two traps are common:
- Sampling from covered examples only. If you label only examples where some labeling function fired, you never measure the examples the functions miss, and coverage gaps become invisible.
- Class imbalance. With 5% positives, a random sample of 200 has about 10 positives. Recall on 10 examples is nearly meaningless. Either label more, or stratify: sample extra from likely positives and reweight when computing the final metrics.
Record how you sampled, because reweighting depends on it.
What to evaluate
Score every stage against the same gold labels. The comparison shows where quality is gained or lost.
| System | Question it answers |
|---|---|
| Each labeling function alone | Is this source better than chance, and on how many examples does it fire? |
| Majority vote | What is the baseline with no learned weights? |
| Label model | Does learning source accuracies help over voting? |
| End model | Does the classifier generalize beyond the rules that labeled its training data? |
| End model trained on gold only | How much did weak labels actually buy you? |
For a labeling function, report accuracy only on the examples where it does not abstain, next to its coverage. A function that is 95% accurate on 2% of the data and one that is 70% accurate on 60% of the data are different tools.
The label model and majority vote may abstain or output ties. Decide how to score those rows before you compare. A simple choice is to treat an abstention as a wrong prediction for the full-data score, and also report accuracy on the covered subset.
Uncertainty on a small set
A gold set of 200 gives noisy scores. For an accuracy of 0.80 the standard error is sqrt(0.8 × 0.2 / 200), about 0.028, so a 95% interval is roughly plus or minus 5.6 points. A 2-point gain from a new labeling function is inside that noise.
Two habits help:
- Report an interval, not a single number. The bootstrap works for F1, where no simple formula exists.
- Compare systems on the same examples with a paired bootstrap. Resample example indices once, score both systems on that resample, and look at the distribution of the difference. This is tighter than comparing two separate intervals.
import random
ABSTAIN, NEG, POS = -1, 0, 1
def f1_score(y_true, y_pred, positive=POS):
tp = sum(t == positive and p == positive for t, p in zip(y_true, y_pred))
fp = sum(t != positive and p == positive for t, p in zip(y_true, y_pred))
fn = sum(t == positive and p != positive for t, p in zip(y_true, y_pred))
if tp == 0:
return 0.0
precision = tp / (tp + fp)
recall = tp / (tp + fn)
return 2 * precision * recall / (precision + recall)
def lf_report(y_true, votes):
"""Coverage and accuracy on covered examples for one labeling function."""
covered = [(t, v) for t, v in zip(y_true, votes) if v != ABSTAIN]
coverage = len(covered) / len(y_true)
accuracy = sum(t == v for t, v in covered) / len(covered) if covered else 0.0
return coverage, accuracy
def paired_bootstrap_diff(y_true, pred_a, pred_b, n_boot=2000, seed=0):
"""95% interval for F1(b) - F1(a), resampling examples jointly."""
rng = random.Random(seed)
n = len(y_true)
diffs = []
for _ in range(n_boot):
idx = [rng.randrange(n) for _ in range(n)]
yt = [y_true[i] for i in idx]
diffs.append(
f1_score(yt, [pred_b[i] for i in idx]) - f1_score(yt, [pred_a[i] for i in idx])
)
diffs.sort()
return diffs[int(0.025 * n_boot)], diffs[int(0.975 * n_boot)]
# Simulated gold labels and two systems of different quality.
rng = random.Random(42)
gold = [rng.choice([NEG, POS]) for _ in range(200)]
def noisy(labels, p_correct):
return [y if rng.random() < p_correct else 1 - y for y in labels]
majority = noisy(gold, 0.75)
label_model = noisy(gold, 0.82)
# A labeling function that abstains on about 60% of examples.
lf_votes = [
(y if rng.random() < 0.9 else 1 - y) if rng.random() < 0.4 else ABSTAIN
for y in gold
]
print("LF coverage, accuracy:", lf_report(gold, lf_votes))
print("Majority F1:", round(f1_score(gold, majority), 3))
print("Label model F1:", round(f1_score(gold, label_model), 3))
print("95% interval for difference:", paired_bootstrap_diff(gold, majority, label_model))If the interval for the difference contains zero, the gold set cannot tell the two systems apart. Either gather more gold labels or treat them as equal and choose the simpler one.
Reading the results
The pattern of scores across stages points to the problem:
- Label model no better than majority vote. Sources may be too few, too similar or too inaccurate for learned weights to matter. Check the diagnostics from the earlier chapter.
- End model below the label model. The classifier is underfitting the weak labels. Check features, class balance and whether soft labels are used correctly.
- End model above the label model. This is the healthy case. The classifier is using features the rules never saw, so it generalizes past them.
- Great dev score, worse test score. You overfit the dev split by tuning labeling functions to it. Rotate in fresh gold examples or shrink the amount of tuning.
Keeping the gold set useful
Gold labels are expensive, so manage them.
- Write annotation guidelines first. Have a second person label 50 to 100 examples and compute agreement. Low agreement means the task is ambiguous, and no model can be scored reliably on it.
- Freeze the test split in a separate file and record a checksum so nobody edits it by accident.
- Spend extra gold labels where they help most: on classes with few examples, and on slices where the weak sources disagree.
- When the data changes, for example a new product line or a new language, sample a new gold slice. Old scores do not transfer.
Exercise
A gold test split has 100 examples and your end model gets 0.80 accuracy on it. Roughly what is the 95% interval, and can you conclude it beats a baseline at 0.75?
Show answer
The standard error is sqrt(0.8 × 0.2 / 100) = 0.04, so the interval is about 0.80 ± 0.078, or 0.72 to 0.88. The baseline of 0.75 lies inside it, so you cannot conclude the model is better. A paired comparison on the same examples would be tighter, but with 100 examples it would still likely be inconclusive.
Exercise
You tuned three labeling functions by looking at errors on the whole gold set, then reported F1 on that same set. What is wrong, and how do you fix it?
Show answer
The same examples guided the tuning and measured the result, so the F1 is optimistic. Split the gold set into dev and test before tuning, tune on dev only, and report F1 on test once. If the test split is already burned, label a fresh sample and use that as the new test set.