For the complete documentation index, see llms.txt. This page is also available as Markdown.

Data Programming

Examples of how Data Programming can automate labeling using rules, patterns, and keyword-based logic.

Overview

Data programming feature helps automate labeling for large datasets using user-defined rules. You can create labeling rules in Python, called labeling functions, to automatically predict labels based on patterns in the data.

You can start by using the provided template to create and test labeling functions. Labeling functions must be written in Python, and several libraries are supported by default.

After configuring your labeling functions, click Predict labels to run them and generate predicted labels. The system will also provide labeling function analysis to help you evaluate performance.

If multiple labeling functions are used, you can also view the inter-annotator agreement between them.

Use cases

Data programming works best for datasets with consistent patterns, formats, or keywords.

Examples include:

  • Structured reports.

  • Repeated text formats.

  • Keyword-based classification.

  • Rule-based categorization.

Sales report satisfaction scores

In this example, labeling functions are used to classify customer satisfaction results in sales reports.

Each row contains recurring information such as:

  • Overall satisfaction.

  • Net Promoter Score (NPS).

  • Product quality feedback.

  • Customer support feedback.

Create the labeling function

A labeling function can scan for keywords like “satisfaction” and predefined score ranges. For example:

  • Satisfaction scores of 4/5 or higher with increased NPS can be labeled as success.

  • Lower scores or negative feedback can be labeled as unsuccess.

This logic can be implemented directly in a labeling function:

Slang and abbreviation replacement

Many datasets, especially from social media or informal conversations, contain slang words and abbreviations. These can be automatically detected and replaced with their full meanings.

A labeling function can use regex patterns to identify slang or abbreviations and replace them with predefined full forms. For example:

  • cuzbecause

  • nglnot going to lie

Create the labeling function

First, define the slang words or abbreviations and their replacements.

Then scan the text for slang words or abbreviations, collect the matches, and assign labels based on the context and specific prefixes in the text.

Extracting predefine keywords from text

Labeling functions can automatically identify and label specific keywords in text to simplify data extraction. For example:

  • Apply the LOC label to terms such as New York, New Jersey, and Connecticut

  • Apply the Person label to terms such as Meteorologists, and Residents

This behavior can be customized by modifying the DICT_KEYWORDS function.

Create the labeling function

  1. Enable the Multiple-label template option to allow multiple labels in a single labeling function.

  2. Leave the @target_label() empty since the function will handle multiple labels.

  3. Define the DICT_KEYWORDS. For example:

    • LABELS['loc']New York, New Jersey, and Connecticut

    • LABELS['person']Meteorologists, and Residents

    • LABELS['time']morning, and tomorrow

  4. Add the loop logic. The labeling function should:

    • Iterate through each label and its associated keywords in DICT_KEYWORDS.

    • For each keyword, use re.finditer to find all occurrences in the text (ignoring case).

    • Collect all matches in a list called match_list.

    • Store the match_list in the PREDICTED_LABEL_COLLECTION dictionary under the corresponding label.

    • Finally, return PREDICTED_LABEL_COLLECTION.

Labeling functions:

For further details, see Assisted Labeling - Data Programming.

Last updated