Sub topic 11
Evaluating with a Small Hand-Labeled Gold Set
Assume you know basic Python, supervised text classification, precision, recall, F1, and regular expressions. You should also understand that a weak label is an uncertain signal, not a trusted answer.
A gold set is a small collection of examples labeled by people using a written labeling policy. It is the reference set for evaluation. The gold set must remain separate from the weak-labeling rules and from model training.
Why a gold set matters
Weak supervision can label thousands of examples, but its sources may share the same mistakes. Measuring agreement between labeling functions does not prove that their labels are correct. A small, carefully reviewed gold set gives you an external check.
Keep the gold set representative of the data the model will classify. Include difficult cases, neutral wording, spelling errors, and both classes. Do not select only examples that are easy for your rules.
Use the gold set only after training. If you inspect the same examples while writing labeling functions, they are no longer an unbiased test set.
What to measure
For a binary classifier, report metrics for each class. Precision is the fraction of predicted positives that are correct. Recall is the fraction of actual positives that the model finds. F1 is the harmonic mean of precision and recall.
| Metric | Question it answers |
|---|---|
| Precision | When the model predicts a class, how often is it right? |
| Recall | How many items of that class does the model find? |
| F1 | How well does it balance precision and recall? |
Accuracy can hide a weak minority class. Report the confusion matrix as well. It shows how many gold examples from each class were predicted as each other class.
Evaluate a model trained on weak labels
The example below treats weak labels as ordinary training labels. In a real pipeline, a label model can instead provide class probabilities. You can use those probabilities as soft targets or as example weights. Neither choice removes the need for gold evaluation.
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix
weak_texts = [
"great battery and bright screen",
"excellent phone for the price",
"broken after one day",
"terrible support and slow refund",
"love the camera",
"the charger stopped working",
]
weak_labels = [1, 1, 0, 0, 1, 0] # produced by weak supervision
gold_texts = [
"the battery lasts all day",
"I am happy with this purchase",
"the screen cracked immediately",
"support never answered my request",
"it is an ordinary phone",
"the camera is disappointing",
]
gold_labels = [1, 1, 0, 0, 1, 0] # reviewed by people
vectorizer = TfidfVectorizer(ngram_range=(1, 2))
X_weak = vectorizer.fit_transform(weak_texts)
X_gold = vectorizer.transform(gold_texts)
model = LogisticRegression(max_iter=1000)
model.fit(X_weak, weak_labels)
predictions = model.predict(X_gold)
print(classification_report(
gold_labels,
predictions,
target_names=["negative", "positive"],
zero_division=0,
))
print(confusion_matrix(gold_labels, predictions))A small test set produces noisy metrics. For example, one error can change recall substantially when a class has only ten examples. Record the number of gold examples per class and add more reviewed examples when a metric drives an important decision.
Inspect errors, not only scores
Read false positives and false negatives. Look for systematic problems:
- Negation, such as “not great”
- Sarcasm or indirect wording
- A class missing from the labeling policy
- Duplicate or near-duplicate examples
- Data leakage from terms that reveal the answer
Exercise
A model has 95% accuracy, but recall for the positive class is 40%. What should you inspect first?
Show answer
Inspect class balance and the confusion matrix. The model may predict the majority class most of the time while missing positive examples.