Abstract
Weak supervision is a popular framework for overcoming the labeled data bottleneck: the need to obtain labels for training data. In weak supervision, multiple noisy-but-cheap sources are used to provide guesses of the label and are aggregated to produce high-quality pseudolabels. These sources are often expressed as small programs written by domain experts -- and so are expensive to obtain. Instead, we argue for using code-generation models to act as coding assistants for crafting weak supervision sources. We study prompting strategies to maximize the quality of the generated sources, settling on a multi-tier strategy that incorporates multiple types of information. We explore how to best combine hand-written and generated sources. Using these insights, we introduce ScriptoriumWS, a weak supervision system that, when compared to hand-crafted sources, maintains accuracy and greatly improves coverage.
Introduction
Machine learning models are increasingly data-hungry, yet obtaining high-quality labeled datasets remains a significant bottleneck. Programmatic Weak Supervision (PWS) has emerged as a powerful paradigm to address this by allowing domain experts to write Labeling Functions (LFs)—simple scripts or heuristics that provide noisy labels for unlabeled data. However, the process of writing these LFs is often painstaking, requiring experts to iterate on regular expressions, thresholds, and logic.
While Large Language Models (LLMs) can be prompted to label data directly, this approach is often prohibitively expensive at scale and lacks the transparency and auditability of programmatic code. ScriptoriumWS proposes a middle ground: using LLMs as coding assistants to automatically synthesize LFs from natural language prompts.
The ScriptoriumWS Framework
ScriptoriumWS integrates code-generation models into the standard weak supervision pipeline. The system takes natural language prompts as input and uses an LLM (such as OpenAI’s Codex) to generate Python-based LFs. These synthesized LFs are then applied to unlabeled data points.
The outputs of these functions are aggregated by a Label Model (e.g., Snorkel) which produces probabilistic "pseudolabels." These pseudolabels are subsequently used to train a final "End Model," such as a neural network, which generalizes beyond the specific heuristics captured in the LFs.
Prompting Strategies
The effectiveness of ScriptoriumWS hinges on the quality of the generated code, which is highly sensitive to the input prompt. The authors explored five distinct prompting strategies to guide the LLM:
- General Prompts: Basic task instructions and function signatures.
- Mission Statements: High-level context about the problem domain.
- Human Heuristics: Specific domain knowledge (e.g., "look for keywords like 'buy'") provided in natural language.
- LF Exemplars: Few-shot examples of existing code snippets to serve as templates.
- Data Exemplars: A small set of labeled examples to help the model infer the underlying logic.
Experimental Results
The system was evaluated on the WRENCH benchmark across six text classification tasks, including sentiment analysis (IMDb, Yelp), spam detection (YouTube, SMS), and relation extraction (Spouse).
Coverage and Performance
A key finding was the massive gain in data coverage. Human-written LFs are often precise but narrow, leaving large portions of the dataset unlabeled. In contrast, synthesized LFs are more comprehensive. For instance, on the SMS dataset, coverage increased from 40.5% with human LFs to 100% with ScriptoriumWS. Similarly, the Spouse dataset saw coverage jump from 25.8% to 100%.
These coverage gains translated directly into improved downstream performance. ScriptoriumWS achieved a 4.0-point F1-score improvement on SMS and a 5.0-point improvement on the Spouse dataset compared to traditional human-only weak supervision.
Discussion and Conclusion
ScriptoriumWS demonstrates that LLMs can effectively serve as assistants in the weak supervision process, offering the power of LLM-based reasoning during the design phase and the efficiency of programmatic inference during the labeling phase. While the system significantly improves coverage, it also highlights the importance of human-in-the-loop guidance, as different tasks respond better to different prompting strategies. Future work will focus on automating the selection of these strategies and extending the framework to non-textual domains.
Summary updated