Search

Search papers and lessons

Snorkel: Rapid Training Data Creation with Weak Supervision

Alexander Ratner, Stephen H. Bach, Henry Ehrenberg et al. · 2017

Snorkel lets experts write noisy labeling rules, learns how accurate each rule is without ground truth, and trains a model on the resulting probabilistic labels instead of hand-labeled data.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Inference
  • Linear algebra
  • Learning basics
  • ReadReady to readNot yet

TL;DR

Deep learning models need large labeled training sets, and labels from experts are slow and expensive. Snorkel asks users to write labeling functions, which are small programs that vote on a label or abstain, and then learns how accurate each function is without any ground-truth labels. It combines the votes into a probability for each example, and trains an ordinary model on those probabilities. The paper reports that this beats distant supervision and comes close to large hand-labeled training sets.

Builds on: Weak Supervision, Factor Graph, Stochastic Gradient Descent · Leads to: Generative Model

Why it mattered

The paper turned weak supervision from a research technique into a usable system with an interface for domain experts. Its deployments were with the U.S. Department of Veterans Affairs, with Stanford Hospital and Clinics, and with the U.S. Food and Drug Administration, on text and medical image tasks. Its core idea is that a probabilistic model can learn source accuracies without labels, and the paper has been cited well over a thousand times.

The problem

Modern models learn from examples, and the examples need labels. Labels from subject matter experts take time, and the paper notes that projects change their class definitions as they go, which forces re-labeling. Weak supervision is cheaper: labels from distant supervision (aligning a knowledge base to the data to make noisy labels), crowd workers, or hand-written rules. These sources are noisy and overlap, so they can disagree.

Two problems follow. First, to resolve a disagreement you need to know how accurate each source is, but there is no ground truth to measure that against. Second, the end model should know which labels are more reliable, so it can weight them. The paper's Example 1.1 shows the stakes: taking the more accurate source where it has a label and the other source elsewhere gives an expected training accuracy of 60.3%, only marginally better than the weaker source.

How it works

Snorkel has three stages, shown below.

flowchart LR
  A["Experts write labeling functions"] --> B["Apply them to unlabeled data to get a label matrix"]
  B --> C["Generative model learns accuracies and correlations"]
  C --> D["Probabilistic labels for each example"]
  D --> E["Train a discriminative model with a noise-aware loss"]

The walkthrough below traces a toy example with three examples and three labeling functions. The values are illustrative and are not from the paper.

  1. Write labeling functions. Each function takes one example and returns +1+1, −1-1, or abstains. Suppose three functions vote as follows. Example x1x_1 gets (+1,−1,+1)(+1, -1, +1), example x2x_2 gets (−1,−1,∅)(-1, -1, \emptyset), and example x3x_3 gets (∅,+1,−1)(\emptyset, +1, -1), where ∅\emptyset means the function abstained. Check: each row has one entry per function, and abstentions are allowed.
  2. Build the label matrix. Stack the votes into a matrix Λ\Lambda with one row per example and one column per function. Check: Λ\Lambda has three rows and three columns.
  3. Estimate source accuracies. Without any true labels, the generative model learns how often each function agrees with the hidden label, and how often it votes at all. Its weights capture log-odds of accuracy, the logarithm of the ratio of being right to being wrong. Suppose the model finds that function 2 is the most accurate. Check: the weights are learned from agreements and disagreements alone.
  4. Resolve the votes into probabilities. A plain majority vote would tie on x3x_3, because one function votes +1+1 and one votes −1-1. The learned weights break the tie toward +1+1, since function 2 is trusted more. The output is a probability, not a hard label. Check: each example gets a number between 0 and 1.
  5. Train the end model. A discriminative model, such as a neural network, is trained on the probabilistic labels using a loss that accounts for the uncertainty. Check: the model sees every example and is not limited to the examples the functions voted on.

Step 5 is what makes Snorkel more than a rule engine. The labeling functions usually cover a small part of the data with high precision. The end model learns features from all the data and generalises beyond the rules. In the paper's CDR example, 33 labeling functions all abstained on one candidate, yet a neural network trained on the probabilistic labels correctly identified it as a true mention.

The math

The generative model as a factor graph

Let Λi,j=λj(xi)\Lambda_{i,j} = \lambda_j(x_i) be the vote of labeling function jj on example ii, and let yiy_i be the hidden true label. The paper models the joint distribution of votes and labels with three kinds of factor:

ϕi,jLab=1{Λi,j≠∅},ϕi,jAcc=1{Λi,j=yi},ϕi,j,kCorr=1{Λi,j=Λi,k} for (j,k)∈C.\phi^{\text{Lab}}_{i,j} = \mathbb{1}\{\Lambda_{i,j} \neq \emptyset\}, \qquad \phi^{\text{Acc}}_{i,j} = \mathbb{1}\{\Lambda_{i,j} = y_i\}, \qquad \phi^{\text{Corr}}_{i,j,k} = \mathbb{1}\{\Lambda_{i,j} = \Lambda_{i,k}\} \text{ for } (j,k) \in C.

The first factor says whether function jj votes at all (its labeling propensity). The second says whether its vote matches the true label (its accuracy). The third says whether two functions agree, for each pair (j,k)(j, k) in a chosen set CC of correlated pairs. These factors are gathered in a vector ϕi\phi_i with parameters ww, and the model is

pw(Λ,Y)=Zw−1exp⁡(∑i=1mw⊤ϕi(Λ,yi)),p_w(\Lambda, Y) = Z_w^{-1} \exp\left( \sum_{i=1}^{m} w^{\top} \phi_i(\Lambda, y_i) \right),

where ZwZ_w is a normaliser that makes the probabilities sum to one. This is the step 3 idea in symbols: the weights ww hold how accurate and how correlated the functions are.

Learning without labels

The true labels YY are unknown, so the model is fitted by minimising the negative marginal likelihood of the observed votes,

w^=arg⁡min⁡w  −log⁡∑Ypw(Λ,Y).\hat{w} = \arg\min_{w} \; -\log \sum_{Y} p_w(\Lambda, Y).

The paper optimises this by interleaving stochastic gradient descent steps with Gibbs sampling steps, similar to contrastive divergence. The sum over YY is what allows labels to stay unknown. Gibbs sampling is a standard way to draw approximate samples from a model like this one (see Markov Chain Monte Carlo).

The accuracy weight has a closed form in the independent case. In the appendix, the paper shows that when a function has accuracy αj\alpha_j on the examples it votes on, its weight is

wj=12log⁡(αj1−αj).w_j = \tfrac{1}{2} \log\left( \frac{\alpha_j}{1 - \alpha_j} \right).

So a function that is right 75% of the time gets a weight of about 0.55 on this scale, and a function that is right 50% of the time gets weight zero and carries no information. Check: α=0.5\alpha = 0.5 gives log⁡1=0\log 1 = 0, so w=0w = 0.

Probabilistic labels and the noise-aware loss

After learning w^\hat{w}, the paper computes probabilistic labels Y~=pw^(Y∣Λ)\tilde{Y} = p_{\hat{w}}(Y \mid \Lambda), one probability per example. The discriminative model hθh_\theta is then trained with the expected loss under these labels,

θ^=arg⁡min⁡θ∑i=1mEy∼Y~[ℓ(hθ(xi),y)].\hat{\theta} = \arg\min_{\theta} \sum_{i=1}^{m} \mathbb{E}_{y \sim \tilde{Y}}\left[ \ell(h_\theta(x_i), y) \right].

This is the noise-aware variant: each example contributes its loss averaged over the label distribution, so an uncertain example pulls less hard than a confident one. The paper's formal analysis says that as the amount of unlabeled data grows, the error of such a model falls at the same asymptotic rate as with hand-labeled data.

When does modeling accuracy help?

The paper defines the modeling advantage of the learned weights over a plain majority vote as

Aw(Λ,y)=1m∑i=1m(1{yifw(Λi)>0∧yif1(Λi)≤0}−1{yifw(Λi)≤0∧yif1(Λi)>0}),A_w(\Lambda, y) = \frac{1}{m} \sum_{i=1}^{m} \left( \mathbb{1}\{ y_i f_w(\Lambda_i) > 0 \wedge y_i f_1(\Lambda_i) \leq 0 \} - \mathbb{1}\{ y_i f_w(\Lambda_i) \leq 0 \wedge y_i f_1(\Lambda_i) > 0 \} \right),

where fwf_w is the weighted vote and f1f_1 the unweighted one. The advantage is the number of examples the weighted vote gets right and the majority vote gets wrong, minus the reverse. The paper shows that the advantage is small when label density is low, because few examples have conflicting votes, and when label density is high, because the majority vote converges. The advantage is largest in the middle. A computable upper bound A~∗\tilde{A}^* lets the optimiser decide, from the label matrix alone, whether to skip learning weights and use a majority vote.

Results

Snorkel against distant supervision on relation extraction. The paper reports F1 for four text tasks. Distant supervision is the baseline; the Snorkel discriminative model is the end model:

TaskDistant supervision F1Snorkel discriminative F1Hand-supervision F1
Chem17.654.1not available
EHR72.281.4not available
CDR29.445.347.3
Spouses15.454.254.2

The paper's summary is that Snorkel exceeds distant supervision by an average of 132%, and comes within an average 3.60% of the predictive performance of large hand-curated training sets across all tasks.

Cross-modal tasks. Labeling functions written on text, or on crowd votes, produce labels for an image model or a tweet classifier. On the radiology task (AUC) Snorkel reaches 72.0 against 76.2 for hand supervision, and on the crowd sentiment task (accuracy) it reaches 65.6 against 68.8.

The generative stage helps. Training the end model on the learned probabilistic labels, rather than on an unweighted average of the functions, improves the result on every task in the paper's table. The gains are +5.5 on Chem, +0.5 on EHR, +3.3 on CDR, +1.4 on Spouses, +3.1 on Crowd and +5.0 on Radiology. The paper reports an average improvement of 5.81%.

User study. Fifteen researchers were invited to a two-day workshop, and the paper reports the average user scored 30.4 F1 with labeling functions, against 20.9 F1 for the model trained on seven hours of hand labels. The best user reached 48.7 F1.

Limits. The gains depend on the labeling functions being reasonably accurate and not too redundant. Modeling correlations is expensive: the paper says that with all pairwise correlations, 100 functions on 10,000 examples takes about 45 minutes, and the cheaper selection method still needs a threshold that trades accuracy for time. On the Chem task the modeling advantage is only 0.1 points in Table 1, so the optimiser chooses a majority vote there and saves time on each pipeline run.

Reading guide

Check yourself

QuestionWhy can Snorkel learn how accurate a labeling function is without any hand-labeled data? What does it use instead?Show answer

It uses the pattern of agreements and disagreements among the functions. When several functions with independent errors mostly agree, the model infers that each is probably accurate. It fits these agreement patterns through a generative model with a marginal likelihood over the unknown true labels, so no ground truth is needed.

QuestionA labeling function has accuracy α=0.75\alpha = 0.75 on the examples it votes on. Compute its weight in the independent model, w=12log⁡(α/(1−α))w = \tfrac{1}{2} \log(\alpha / (1 - \alpha)), to two decimal places. What would a function with α=0.5\alpha = 0.5 get?Show answer

For α=0.75\alpha = 0.75, α/(1−α)=0.75/0.25=3\alpha / (1 - \alpha) = 0.75 / 0.25 = 3, so w=12log⁡3≈12×1.0986=0.549w = \tfrac{1}{2} \log 3 \approx \tfrac{1}{2} \times 1.0986 = 0.549, which rounds to 0.55. A function with α=0.5\alpha = 0.5 has α/(1−α)=1\alpha / (1 - \alpha) = 1, so log⁡1=0\log 1 = 0 and its weight is zero: its votes carry no information about the label.

QuestionTwo examples get the same probabilistic label of 0.5 from the generative model. Why does the noise-aware loss treat them the same, and what would be lost by replacing them with hard labels of 1 and 0?Show answer

Each example contributes its expected loss under the label distribution, so an example with probability 0.5 contributes equally whichever way the label goes. The noise-aware loss does not pretend to know the label. Hard labels would force a confident guess, which would teach the model a wrong answer half the time and remove the information about how uncertain the rules were.

QuestionA team writes 100 labeling functions, and the average label density is very low. They are told that a learned generative model should always beat a majority vote. Using the paper's analysis, is that right, and what should they do?Show answer

Not always. The paper shows the advantage of learned weights over majority vote is small at low label density, because few examples have conflicting votes, so a weighted vote rarely disagrees with the unweighted one. The team should estimate the modeling advantage with the optimiser's upper bound, and use a majority vote when the bound is small, which saves the cost of fitting the generative model.

Sources

Read the full paper

Alexander Ratner, Stephen H. Bach, Henry Ehrenberg et al., 2017. arXiv:1711.10160