Monday, November 30, 2026
HomeData ScienceWeak Supervision and Data Programming – Snorkel, Labelling Functions and Programmatic Labelling...

Weak Supervision and Data Programming – Snorkel, Labelling Functions and Programmatic Labelling at Scale

Table of Content

📋 KEY INSIGHTS

  • Weak supervision replaces expensive manual labelling with programmatic labelling functions — heuristics, distant supervision, and existing resources — that are noisy but cheap to write at scale.
  • Snorkel’s label model learns the accuracy and correlation structure of labelling functions, producing a single probabilistic label per data point that outperforms majority vote.
  • Labelling functions can encode domain expertise, regex patterns, existing knowledge bases, and crowdsourced labels — any signal that is correlated with the true label, even weakly.
  • Slicing functions identify challenging subsets of data for targeted model improvement, complementing labelling functions in the Snorkel workflow.
  • Distant supervision automatically labels data by aligning it with an external knowledge base — if an entity pair appears in Freebase as a “born in” relation, all sentences mentioning that pair are labelled as born-in.
  • Foundation models have shifted weak supervision from labelling functions to prompt-based labelling — GPT-4 as a noisy annotator at $0.01/sample vs. $1/sample for human labellers.

Labelled data is the bottleneck of supervised learning. Human annotation is expensive ($0.05–$5 per label depending on complexity), slow, and impossible to scale to billions of examples. Weak supervision sidesteps manual labelling by using programmatic labelling sources — heuristics, patterns, knowledge bases, and existing models — that are individually noisy but, when combined intelligently, produce training labels good enough to train high-quality models.

This guide covers the full weak supervision stack: labelling functions and the label model, the Snorkel framework, distant supervision, data slicing, and the latest shift towards LLM-based programmatic labelling with foundation model annotators.

Labelling Functions, the Label Model and Snorkel

A labelling function (LF) is any Python function that takes a data point as input and returns a label or ABSTAIN. LFs can encode regex patterns (“if the text matches ‘acquired by’, label as ACQUISITION”), heuristics (“if the document mentions a drug name in the first sentence, label as MEDICAL”), external knowledge bases (“if entity pair (X, Y) appears in Wikidata with relation ‘capital of’, label as CAPITAL”), crowd-sourced labels, or predictions from an existing weak model. Any single LF is likely to be noisy — it may have 60–80% accuracy rather than 95%+ — and many LFs will only fire on a subset of the data (coverage vs. accuracy trade-off).

Naive majority vote over LFs is a natural baseline but ignores two key problems: LF accuracy varies (a 90%-accurate LF should count for more than a 60%-accurate one) and LFs are often correlated (two regex LFs that both match the word “acquisition” fire together and should not count as independent votes). Snorkel’s label model (Ratner et al., 2019) addresses both by learning LF accuracies and correlations from the LF output matrix alone — without needing any ground-truth labels. The label model is a generative model: it assumes a latent true label y, and each LF output λ_i is generated from y with accuracy α_i and conditional independence (or learned correlation) with other LFs. The model parameters (accuracies and correlations) are estimated by minimising the negative log-likelihood of the observed LF output matrix using the method of moments. The connection to our Bayesian statistics guide is direct: the label model is a latent variable model — the same EM algorithm and Bayesian posterior inference described there for mixture models applies to learning LF accuracies from unlabelled data, with the latent true label playing the role of the mixture component assignment.

The Snorkel workflow has three stages: (1) write labelling functions that encode domain knowledge and existing resources; (2) train the label model on the LF output matrix to produce probabilistic labels for every data point; (3) train a discriminative end model (BERT, LightGBM, any classifier) on the probabilistically labelled dataset using the label model’s confidence weights. The end model learns to generalise beyond the patterns captured by the LFs, often exceeding the label model’s accuracy because it accesses raw features (text, images) rather than just LF outputs. On benchmark datasets (Spouse, TREC, YouTube), the Snorkel pipeline achieves within 2–5 F1 points of fully supervised models trained on 10× more hand-labelled data. The connection to our active learning guide is direct: Snorkel and active learning are complementary strategies for label-efficient learning — Snorkel uses programmatic labelling to label large amounts of data cheaply, while active learning selects the most informative examples for expensive human annotation; production systems often combine both, using Snorkel for the bulk of labelling and active learning to identify the most impactful examples for human review.

Labelling SourceExampleAccuracy RangeCoverage
Regex / keywordPattern match for relation keywords60–85%Low–medium
Distant supervisionFreebase entity pair alignment55–75%Medium–high
Existing weak modelPredictions from prior model version70–85%High
CrowdsourcingMajority vote from MTurk workers75–90%Chosen subset
LLM annotator (GPT-4)Zero-shot or few-shot prompting80–95%High (costly)

Distant Supervision, Slicing Functions and LLM Annotators

a white board with writing written on it
Photo by Bernd 📷 Dittrich on Unsplash

Distant supervision (Mintz et al., 2009) generates training labels by aligning text with an external knowledge base. For relation extraction: if Freebase says (Barack Obama, born in, Hawaii), then every sentence in a large corpus that mentions both “Barack Obama” and “Hawaii” is labelled as expressing the born-in relation. This generates millions of labelled training examples automatically — but with significant noise (a sentence mentioning both entities may express a different relation, or no relation at all). The noise is handled by the label model or by sentence-level attention mechanisms (PCNN with selective attention) that down-weight noisy instances at training time. The connection to our knowledge graphs guide is direct: distant supervision uses knowledge graphs (Freebase, Wikidata, DBpedia) as the labelling resource — the entity and relation structure described there provides the supervision signal that makes distant supervision possible at web scale.

Slicing functions (SFs) are the complement to labelling functions: rather than generating labels, they identify challenging or important subsets of the data that the model should perform well on. A slicing function might flag: “examples where both entities are pronouns” (coreference-heavy, harder), “medical documents from ICU patients” (high-stakes subgroup), or “short documents under 50 tokens” (low-context, harder). The Slice-based Learning (SBL) framework trains the base model jointly with slice-specific expert heads: each slice has a dedicated prediction head that is trained on that slice’s examples, and the final prediction is a weighted combination of the base head and all slice heads. This prevents the model from averaging over slices and ignoring hard subgroups. The connection to our imbalanced learning guide is direct: slicing functions identify the rare, hard subgroups described there — the same philosophy of treating subgroup performance as a first-class metric applies, with slicing functions providing an explicit mechanism for defining and monitoring those subgroups.

LLM-based programmatic labelling has become the dominant weak supervision approach since GPT-4’s release. Rather than writing regex patterns, practitioners prompt an LLM with the labelling criteria and a few examples, then run the LLM over the unlabelled dataset at scale. GPT-4 Turbo achieves 85–95% agreement with expert human annotators on complex NLP tasks (relation extraction, slot filling, clinical note classification) at $0.01–$0.10 per example — 10–100× cheaper than expert human annotation. The key challenge is calibration: LLMs are often overconfident, assigning high probability to incorrect labels. The connection to our prompt engineering guide is direct: effective LLM-based labelling requires careful prompt design — the same chain-of-thought, structured output, and few-shot prompting techniques described there determine whether the LLM’s labels are reliable, and multiple sampling with majority vote (using the LLM as multiple “experts” with different temperature or prompt variants) further reduces label noise.

Data programming at scale is now a standard step in production ML pipelines at large technology companies. Google’s production NLU systems (used in Gmail Smart Compose, Search intent classification) use Snorkel-inspired programmatic labelling for initial training data generation, with active learning cycles to selectively add human labels for the highest-uncertainty and highest-impact examples. The connection to our MLOps CI/CD guide is direct: programmatic labelling pipelines are part of the continuous training infrastructure described there — the labelling functions are version-controlled alongside the model code, the label model is retrained whenever new LFs are added, and the end model is automatically retrained and evaluated in the CI/CD pipeline whenever the labelling strategy changes.

✦ SUMMARIZE THIS ARTICLE WITH AI

Active learning (complement to weak supervision; selective human annotation for highest-value examples) is in our Active Learning guide. Knowledge graphs (distant supervision using Wikidata and Freebase as labelling resources) are in our Knowledge Graphs guide. Bayesian statistics (label model as a latent variable model for LF accuracy estimation) is in our Bayesian Statistics guide. Prompt engineering (LLM-based programmatic labelling with chain-of-thought) is in our Prompt Engineering guide. Imbalanced learning (slicing functions for hard subgroup identification) is in our Imbalanced Learning guide. MLOps CI/CD (programmatic labelling in continuous training pipelines) is in our MLOps guide. Data quality (label quality monitoring and LF performance tracking) is in our Data Quality guide.

Leave feedback about this

  • Rating

Durgesh Kekare
Durgesh Kekarehttps://www.dataexpertise.in
Durgesh Kekare is a data science educator and founder of DataExpertise.in. With expertise in Python, machine learning, and analytics, he helps 10,000+ learners break into data careers.

Latest Posts

List of Categories