Sub topic 8
Label Models: Learning Source Accuracies Without Ground Truth
Assume you know Python, supervised text classification, precision, recall, F1, basic probability, and regular expressions. This chapter focuses on combining noisy labeling functions (LFs), which are rules or models that assign a class or abstain.
Why majority vote is limited
A label matrix records each LF's output for each example. Suppose three LFs vote on sentiment:
| Text | Positive words | Negative words | Exclamation mark |
|---|---|---|---|
| “Great service!” | POS | ABSTAIN | POS |
A simple majority vote treats every source as equally accurate. That can fail when one source is much more reliable than another. It also fails when sources are correlated. For example, two LFs may both detect the same word and therefore provide only one piece of evidence.
A label model estimates how useful each source is from the agreement patterns in the label matrix. It does not directly observe the correct label. Instead, it assumes that the observed votes were generated from an unobserved, or latent, true label.
What the label model estimates
For each LF, the model can estimate:
- Accuracy: how often its non-abstaining vote matches the latent label.
- Coverage: how often it produces a vote.
- Class bias: whether it favors one class.
- Dependence: whether agreement may come from correlated sources.
The central assumption is that sources are sufficiently independent after accounting for the true class. If two LFs use the same keyword, their agreement can make a weak signal appear strong. A label model may then become overconfident.
The output is usually a probability vector, such as:
positive: 0.92
negative: 0.08This is a soft label. You can keep the probabilities, or convert them to hard labels by selecting the most likely class.
Fitting a label model
The Snorkel library provides a label model for this task. The following example applies LFs, trains the model without hand labels, and prints probabilities.
import pandas as pd
from snorkel.labeling import labeling_function, PandasLFApplier
from snorkel.labeling.model import LabelModel
ABSTAIN, NEG, POS = -1, 0, 1
@labeling_function()
def lf_positive(x):
return POS if "great" in x.text.lower() else ABSTAIN
@labeling_function()
def lf_negative(x):
return NEG if "broken" in x.text.lower() else ABSTAIN
lfs = [lf_positive, lf_negative]
data = pd.DataFrame({
"text": ["Great battery", "Broken screen", "Works normally"]
})
L = PandasLFApplier(lfs).apply(data)
model = LabelModel(cardinality=2, verbose=False)
model.fit(L_train=L, n_epochs=200, seed=123)
probabilities = model.predict_proba(L)
print(probabilities)The cardinality=2 argument specifies two possible classes. Training uses only the label matrix. The model's probabilities are useful for confidence filtering and for training an end classifier.
Exercise
Exercise
Why can three agreeing labeling functions still produce an overconfident label?
Show answer
They may be correlated and repeat the same evidence, so their votes are not independent.