Search

Search papers and lessons

Weak Supervision

Level 3 · 14 min read

Weak supervision builds a training set from cheap, noisy rules, then estimates how reliable each rule is without any hand-labelled data.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • Learning basics
  • Losses & regularization
  • Inference
  • ReadReady to readNot yet

TL;DR

Weak supervision is a way to build a labelled training set when labels are scarce, slow or expensive. Instead of labelling each example by hand, you write many cheap labelling functions, which are rules or heuristics that vote on some examples and abstain on the rest. A label model then estimates how accurate each function is from how the functions agree and disagree, and it combines their votes into a probability for each example. Those probabilities become training targets for an ordinary classifier.

Builds on: Supervised Learning, Generative Model, Conditional Independence, Latent Variable Model, Log-Odds · Leads to: Snorkel: Rapid Training Data Creation with Weak Supervision

Where it's used

Radiology. Researchers have labelled large sets of chest X-ray images by writing rules over the text of the radiology reports that already sit in hospital records, such as phrases that say a finding is present or absent. An image model was then trained on the resulting labels. Each rule was imperfect, but there were many of them, and the image model learned from the pixels rather than from the text.

Content classification at scale. Large internet companies have described using weak supervision to build classifiers for products and web content. Engineers already had heuristics and older models that were each partly right. Google published a 2019 industrial case study, Snorkel DryBell, in which such sources were combined into training labels, which reduced the hand labelling the team needed.

Relation extraction from papers. Early Snorkel experiments extracted pairs such as which chemical is linked to which disease from biomedical articles. The labelling functions were dictionaries of known names and pattern rules over the words between two mentions, so the system labelled thousands of sentences without a person reading each one.

How it works

Take a tiny spam problem. Three emails, A, B and C, have no labels. We want a classifier that says spam (+1) or not spam (−1).

  1. Write three labelling functions. Each reads an email and votes +1, −1, or abstains (0):

    • Phrase rule: votes spam if the email contains a listed spam phrase, and abstains otherwise.
    • New-sender rule: votes spam if the sender's account is under a week old, and not spam otherwise.
    • Link rule: votes spam if the email has more than five links, not spam if it has none, and abstains otherwise.
  2. Run the three functions on every email. Each row is an email and each column is a function:

    EmailPhrase ruleNew-sender ruleLink rule
    A+1+10
    B0−1−1
    C0+1+1

    Check: no email has a true label anywhere in this table, only votes.

  3. Measure how often pairs of functions agree on a large unlabelled set. Agreement carries information about accuracy, because two accurate functions must agree often and two bad ones cannot agree consistently. The exact measurement is in the math section.

  4. From the agreement pattern, estimate how accurate each function is. The numbers are worked out in Example 2: the phrase rule is right 90 percent of the time it votes, the new-sender rule 80 percent, the link rule 75 percent. No true label was used.

  5. Turn each accuracy aa into a vote weight w=log⁡a1−aw = \log\frac{a}{1-a}, which gives 2.197, 1.386 and 1.099. For each email, add the weighted votes. That sum is the log-odds of spam, and the sigmoid turns it into a probability.

    • Email A: 2.197+1.386=3.5832.197 + 1.386 = 3.583. The probability is 36/37≈0.97336/37 \approx 0.973. The link rule abstained, so it adds nothing.
    • Email B: −1.386−1.099=−2.485-1.386 - 1.099 = -2.485. The probability is 1/13≈0.0771/13 \approx 0.077.
    • Email C: 1.386+1.099=2.4851.386 + 1.099 = 2.485. The probability is 12/13≈0.92312/13 \approx 0.923.

    Check: A and C lean spam and B leans not spam, as the votes suggested.

0.50.60.70.80.9012345accuracy avote weight w
  • vote weight w
A function that is more accurate earns a larger weight. A function that is right only half the time earns zero, and its vote is ignored. The three marked points are the accuracies from step 4.
  1. Train an ordinary classifier on the emails, using the probabilities from step 5 as targets instead of 0 or 1. The loss is cross-entropy, the same loss used by logistic regression, so the classifier is pushed toward the probabilities rather than toward hard labels.
  2. The trained classifier can now score emails that no function touched, from the words and structure of the text. The labelling functions were only the teacher.
flowchart LR
  A["Unlabelled examples"] --> B["Labelling functions vote +1, -1 or abstain"]
  B --> C["Label model estimates each accuracy from agreement"]
  C --> D["Probabilistic labels for each example"]
  D --> E["Train a classifier with cross-entropy"]

The math

Definition: Simplified weak supervision model

Let Y∈{−1,+1}Y \in \{-1, +1\} be the unknown true label of an example, and let λ1,…,λm∈{−1,+1}\lambda_1, \dots, \lambda_m \in \{-1, +1\} be the votes of mm labelling functions on that example. Function jj has accuracy aj=P(λj=Y)a_j = P(\lambda_j = Y). Its signed accuracy is cj=2aj−1c_j = 2a_j - 1, a number between −1-1 and 11. The model assumes that every function votes on every example (abstentions are added back in step 5), that the two labels are equally likely (P(Y=+1)=P(Y=−1)=12P(Y = +1) = P(Y = -1) = \tfrac{1}{2}), and that the votes are conditionally independent given YY. The real systems relax all three; this is the core version.

Step 3 in symbols: agreement

Function jj outputs YY with probability aja_j and −Y-Y otherwise, so its average vote given the label is E[λj∣Y]=(2aj−1) Y=cjY\mathbb{E}[\lambda_j \mid Y] = (2a_j - 1)\,Y = c_j Y. Because the votes are independent given YY, the average product of two votes factors:

E[λiλj]=E[E[λi∣Y] E[λj∣Y]]=E[cicjY2]=cicj,i≠j.\mathbb{E}[\lambda_i \lambda_j] = \mathbb{E}\big[\mathbb{E}[\lambda_i \mid Y]\,\mathbb{E}[\lambda_j \mid Y]\big] = \mathbb{E}[c_i c_j Y^2] = c_i c_j, \qquad i \ne j.

The left side is observable on unlabelled data, because it only needs the votes. The right side is the hidden accuracy information. This is the whole idea: the pattern of agreement reveals the accuracies, and no true label is needed.

Step 4 in symbols: three functions

With three functions there are three equations, and they can be solved exactly. Multiplying the first two and dividing by the third gives

c12=(c1c2)(c1c3)c2c3.c_1^2 = \frac{(c_1 c_2)(c_1 c_3)}{c_2 c_3}.

Take the positive root, which assumes each function does better than chance, and then c2=E[λ1λ2]/c1c_2 = \mathbb{E}[\lambda_1\lambda_2]/c_1 and c3=E[λ1λ3]/c1c_3 = \mathbb{E}[\lambda_1\lambda_3]/c_1. Finally aj=(1+cj)/2a_j = (1 + c_j)/2. With more functions, the label model fits all the pairwise agreements together instead of using one triple.

Step 5 in symbols: the weighted vote

Under the assumptions, the votes given Y=+1Y = +1 have probability aja_j of matching +1+1 and 1−aj1 - a_j of not matching. The likelihood ratio for one function is therefore aj/(1−aj)a_j/(1 - a_j) when it votes +1+1 and its inverse when it votes −1-1. An abstaining function is equally likely under both labels, so its factor is 1. Taking logarithms of the product over functions gives

log⁡P(Y=+1∣λ)P(Y=−1∣λ)=∑j=1mwjλj,wj=log⁡aj1−aj.\log\frac{P(Y = +1 \mid \lambda)}{P(Y = -1 \mid \lambda)} = \sum_{j=1}^{m} w_j \lambda_j, \qquad w_j = \log\frac{a_j}{1 - a_j}.

This is the Log-Odds of the label, and the probability is its sigmoid, P(Y=+1∣λ)=σ(∑jwjλj)P(Y = +1 \mid \lambda) = \sigma\big(\sum_j w_j \lambda_j\big), the same form as logistic regression. The weights are fixed by the accuracies, so the model is a weighted vote in which accurate functions speak loudly.

Step 6 in symbols: training on soft targets

Let qθ(x)=σ(z)q_\theta(x) = \sigma(z) be the classifier's probability of spam for an input xx, and let tt be the label model's probability for that input. The cross-entropy with a soft target is

L(θ)=−[ tlog⁡qθ(x)+(1−t)log⁡(1−qθ(x)) ].L(\theta) = -\big[\, t \log q_\theta(x) + (1 - t)\log(1 - q_\theta(x)) \,\big].

Its minimum is at qθ(x)=tq_\theta(x) = t. Taking the derivative with respect to the score zz gives ∂L/∂z=σ(z)−t\partial L / \partial z = \sigma(z) - t. This is the same expression as the logistic-regression gradient, with the hard label replaced by the probability tt.

Worked examples

Example
1. Tiny: from accuracy to vote weight

Use w=log⁡a1−aw = \log\frac{a}{1-a} and the natural logarithm.

  1. Accuracy a=0.75a = 0.75. Then a/(1−a)=0.75/0.25=3a/(1-a) = 0.75/0.25 = 3, and w=log⁡3≈1.099w = \log 3 \approx 1.099. A reasonably accurate function counts moderately.
  2. Accuracy a=0.5a = 0.5. Then a/(1−a)=1a/(1-a) = 1, and w=log⁡1=0w = \log 1 = 0. A coin-flip function adds nothing.
  3. Accuracy a=0.25a = 0.25. Then a/(1−a)=1/3a/(1-a) = 1/3, and w=log⁡(1/3)≈−1.099w = \log(1/3) \approx -1.099. The function is worse than chance, so its votes count with the opposite sign.
  4. Interpretation: a function's weight depends on how far its accuracy sits from one half, in either direction. A function that is badly wrong is still informative, once you know it is wrong.
Example
2. Standard: recovering three accuracies from agreement

On a large unlabelled set, suppose the average products of votes are E[λ1λ2]=0.48\mathbb{E}[\lambda_1\lambda_2] = 0.48, E[λ1λ3]=0.40\mathbb{E}[\lambda_1\lambda_3] = 0.40 and E[λ2λ3]=0.30\mathbb{E}[\lambda_2\lambda_3] = 0.30.

  1. Compute the squared first signed accuracy: c12=0.48×0.400.30=0.1920.30=0.64c_1^2 = \dfrac{0.48 \times 0.40}{0.30} = \dfrac{0.192}{0.30} = 0.64.
  2. Take the positive root: c1=0.8c_1 = 0.8.
  3. Compute the second: c2=0.48/0.8=0.6c_2 = 0.48 / 0.8 = 0.6.
  4. Compute the third: c3=0.40/0.8=0.5c_3 = 0.40 / 0.8 = 0.5.
  5. Check: c2c3=0.6×0.5=0.30c_2 c_3 = 0.6 \times 0.5 = 0.30, which matches the observed agreement.
  6. Convert to accuracies with aj=(1+cj)/2a_j = (1 + c_j)/2: a1=0.9a_1 = 0.9, a2=0.8a_2 = 0.8, a3=0.75a_3 = 0.75.
  7. Interpretation: the first function is right 90 percent of the time, and no one ever checked a label. The only evidence was that the three functions agree in the pattern that accurate, roughly independent functions would produce.
Example
3. Realistic: flagging a forum post

A forum flags posts as spam. Three functions vote on one post: the phrase rule votes spam (accuracy 0.9), the new-sender rule votes not spam (accuracy 0.8), and the link rule votes not spam (accuracy 0.75).

  1. The phrase rule votes +1+1, so it adds w1=log⁡9≈2.197w_1 = \log 9 \approx 2.197.
  2. The new-sender rule votes −1-1, so it adds −w2=−log⁡4≈−1.386-w_2 = -\log 4 \approx -1.386.
  3. The link rule votes −1-1, so it adds −w3=−log⁡3≈−1.099-w_3 = -\log 3 \approx -1.099.
  4. The total log-odds is 2.197−1.386−1.099≈−0.2882.197 - 1.386 - 1.099 \approx -0.288. Exactly, this is log⁡9−log⁡4−log⁡3=log⁡(3/4)\log 9 - \log 4 - \log 3 = \log(3/4).
  5. The odds of spam are e−0.288=3/4e^{-0.288} = 3/4, so spam is less likely than not, at three to four.
  6. The probability is 3/41+3/4=37≈0.429\dfrac{3/4}{1 + 3/4} = \dfrac{3}{7} \approx 0.429.
  7. Interpretation: the single strongest vote is the phrase rule, but two weaker votes outweigh it. The label model leans not spam, with little confidence, so the post is a poor training target to treat as a hard label.

Try it: suppose the link rule had abstained instead of voting not spam. What is the probability of spam? Answer: the total is log⁡9−log⁡4=log⁡2.25≈0.811\log 9 - \log 4 = \log 2.25 \approx 0.811, the odds are 2.25=9/42.25 = 9/4, and the probability is 9/41+9/4=913≈0.692\dfrac{9/4}{1 + 9/4} = \dfrac{9}{13} \approx 0.692.

Common mistakes and tradeoffs

It is tempting to think weak labels average out to the truth. In fact they only do so when their errors are roughly independent. Two rules that both look for the same phrase make the same mistakes, so the label model counts that evidence twice and gives both rules too high an accuracy. Correlated functions are the main way this method fails, and they must be merged, modelled, or removed.

It is tempting to think that without true labels there is nothing to check. In fact a small hand-labelled development set is still needed. It shows whether the estimated accuracies are close to real ones, and it tests the final classifier. The agreement method also assumes each function beats chance, which fixes the sign of each weight; if that assumption is wrong for a function, its contribution is reversed.

It is tempting to think the label model's output is the final classifier. In fact its probabilities are training targets. The classifier trained on them can score examples that no rule covers, and it often generalises beyond the rules it learned from. That is the reason to train one at all.

It is tempting to think any cheap rule helps. In fact a rule near chance gets a weight near zero and does nothing. A rule that is worse than chance is useful once its sign is known. The costly rules are the correlated ones, because they look like independent evidence while carrying the same error.

When to use it. Use weak supervision when domain experts can write many imperfect rules, labels are the bottleneck, and you need a usable training set quickly. It fits text, images with associated text, and any setting with many cheap signals.

When not to use it. When a few thousand hand labels are cheap, the simpler route is better. When no sensible rule can be written, the method has nothing to combine. When the functions' errors are strongly correlated and you cannot find out why, the label model will be overconfident.

ApproachNeedsStrengthWeakness
Hand labellingexpert time per examplehighest qualityslow, costly to scale
Weak supervisionrules plus a small check setthousands of labels in minutesdepends on rules being roughly independent
Semi-supervised learninga small labelled set plus unlabelled datauses unlabelled data directlyassumes the shape of the data holds

History

In 2009 Mintz and colleagues labelled sentences for relation extraction by matching known pairs from a knowledge base against text. This was called distant supervision. It was noisy, since a sentence can contain a pair without expressing the relation, but it produced labels at a scale no person could match. It is the direct ancestor of weak supervision.

In 2016 Alexander Ratner and colleagues at Stanford published data programming, which treated labelling rules as functions and fitted a generative model that learned their accuracies from their agreement. This is the agreement method in this lesson.

In 2017 the Snorkel system and paper packaged this approach into an open toolkit, and it spread into both research and industry. A 2019 industrial case study from Google described the same approach at production scale.

It caught on because labels were the bottleneck. Experts could encode what they knew as rules, instead of labelling thousands of examples one at a time.

Recap

  • A labelling function is a cheap rule that votes +1+1, −1-1, or abstains.
  • Under conditional independence given the true label, the agreement between functions reveals their accuracies, with no labels needed.
  • Each function gets a weight log⁡a1−a\log\frac{a}{1-a}, and the combined log-odds of an example is a weighted vote, passed through a sigmoid.
  • The resulting probabilities are soft labels. A classifier trained with cross-entropy on them generalises beyond the rules.
  • Read next: Snorkel: Rapid Training Data Creation with Weak Supervision for the full system, and Semi-Supervised Learning for another way to use unlabelled data.

Check yourself

QuestionRecall: what does a labelling function output, and what does abstaining mean?Show answer

A labelling function outputs +1+1 (spam), −1-1 (not spam), or abstains. Abstaining means the function has no opinion on that example, and it contributes nothing to the combined score. Abstaining is not the same as voting not spam.

QuestionComputation: function 1 has accuracy 0.90.9 and votes +1+1 on an example. Function 2 has accuracy 0.750.75 and votes −1-1 on the same example. What is the probability that the example is spam?Show answer

The weights are w1=log⁡9w_1 = \log 9 and w2=log⁡3w_2 = \log 3. The total log-odds is w1⋅(+1)+w2⋅(−1)=log⁡9−log⁡3=log⁡3w_1 \cdot (+1) + w_2 \cdot (-1) = \log 9 - \log 3 = \log 3. The odds are 33, so the probability is 3/(1+3)=0.753/(1 + 3) = 0.75.

QuestionWhy: why does the agreement between two functions reveal their accuracies, even though no true label is used?Show answer

If the two functions are conditionally independent given the true label, then the average product of their votes equals the product of their signed accuracies, E[λiλj]=cicj\mathbb{E}[\lambda_i\lambda_j] = c_i c_j. The observed agreement is therefore a product of two hidden numbers, and with three functions those numbers can be solved for. The true label only sets the sign of each vote, and the assumption that each function beats chance fixes that sign.

QuestionApplied: a team writes forty labelling functions, nearly all keyed on the same two phrases. The label model reports that every function has accuracy 0.95. What is wrong, and what would you do?Show answer

The functions are strongly correlated, so they do not satisfy conditional independence. Their agreement comes from shared phrases and shared errors, not from independent evidence, which makes the estimated accuracies too high. Check the pairwise correlations between functions, merge or drop the near-duplicates, and then measure the accuracies on a small hand-labelled development set before trusting the probabilities.

Sources