Snorkel AI triples valuation to $3.5B as demand for AI training data booms
Back to Tutorials
aiTutorialbeginner

Snorkel AI triples valuation to $3.5B as demand for AI training data booms

September 22, 202631 views4 min read

Learn how to create labeled training datasets using Snorkel AI's data labeling approach, a key component of their data-as-a-service platform that's driving their $3.5B valuation.

Introduction

In this tutorial, you'll learn how to work with Snorkel AI's data labeling platform to create high-quality training datasets for machine learning models. As companies like Snorkel AI see massive demand for AI training data, understanding how to efficiently label and organize data becomes crucial. This hands-on guide will walk you through creating a simple text classification dataset using Snorkel's approach, which is essential for training AI models to understand and categorize information.

Prerequisites

  • Basic understanding of machine learning concepts
  • Python installed on your computer
  • Access to a computer with internet connection
  • Basic knowledge of data structures and programming concepts

Step-by-step Instructions

Step 1: Install Required Libraries

Why this matters

We need to install the Snorkel library and other supporting packages to create our data labeling system. Snorkel provides tools for creating and managing training datasets that are essential for machine learning projects.

pip install snorkel
pip install pandas
pip install numpy

Step 2: Create Sample Data

Why this matters

Before we can label data, we need a dataset to work with. In this example, we'll create a simple dataset of movie reviews that we'll later classify as positive or negative.

import pandas as pd

data = {
    'review': [
        'This movie was absolutely fantastic and I loved every minute of it',
        'Terrible film, waste of time and money',
        'Great acting and wonderful story',
        'Boring and predictable plot',
        'Amazing cinematography and brilliant performances',
        'Not worth watching, very disappointing'
    ],
    'sentiment': ['positive', 'negative', 'positive', 'negative', 'positive', 'negative']
}

df = pd.DataFrame(data)
print(df)

Step 3: Set Up Snorkel Labeling Functions

Why this matters

Snorkel uses labeling functions to automatically annotate data. These functions define rules that help identify patterns in your data, making it easier to create large, high-quality training sets without manual labeling.

from snorkel.labeling.model import MajorityLabelVoter
from snorkel.labeling import labeling_function
from snorkel.labeling.model import LabelModel

# Define labeling functions that identify sentiment patterns
@labeling_function()
def lf_positive_words(x):
    return 1 if 'fantastic' in x.review.lower() or 'wonderful' in x.review.lower() else -1

@labeling_function()
def lf_negative_words(x):
    return 0 if 'terrible' in x.review.lower() or 'disappointing' in x.review.lower() else -1

@labeling_function()
def lf_positive_words_2(x):
    return 1 if 'great' in x.review.lower() or 'amazing' in x.review.lower() else -1

@labeling_function()
def lf_negative_words_2(x):
    return 0 if 'boring' in x.review.lower() or 'waste' in x.review.lower() else -1

Step 4: Apply Labeling Functions to Your Dataset

Why this matters

Here we apply our labeling functions to the dataset. This simulates how Snorkel AI would automatically label your data, which is a key part of their data-as-a-service approach. The system creates labels based on rules rather than manual annotation.

from snorkel.labeling.model import LabelModel
from snorkel.labeling import LFAnalysis

# Apply labeling functions to the dataset
lfs = [lf_positive_words, lf_negative_words, lf_positive_words_2, lf_negative_words_2]

# Create a label matrix
Y = labeling_function.apply(lfs, df)

# Analyze the labeling function performance
lf_analysis = LFAnalysis(lfs, Y)
lf_analysis.lf_summary()

Step 5: Train a Label Model

Why this matters

Snorkel AI's approach involves training a model to combine the outputs of multiple labeling functions. This helps improve accuracy by considering multiple perspectives on the same data, which is why their valuation has grown as demand for quality training data increases.

# Train a label model to combine the labeling functions
label_model = LabelModel(cardinality=2, verbose=True)
label_model.fit(L_train=Y, n_epochs=500, log_freq=100)

# Get predictions from the label model
preds = label_model.predict(Y)
print('Predictions:', preds)

Step 6: Evaluate Your Results

Why this matters

After creating our labeled dataset, we should evaluate how well our approach worked. This evaluation is crucial for understanding the quality of training data, which is what makes platforms like Snorkel AI valuable in the current market.

# Compare predictions with actual labels
results = pd.DataFrame({'review': df.review, 'actual': df.sentiment, 'predicted': preds})
print(results)

# Calculate accuracy
from sklearn.metrics import accuracy_score
accuracy = accuracy_score(df.sentiment, ["positive" if pred == 1 else "negative" for pred in preds])
print(f'Accuracy: {accuracy:.2f}')

Step 7: Export Your Labeled Dataset

Why this matters

Once we've created our labeled dataset, we need to save it for use in training machine learning models. This represents the final step in the data preparation process that companies like Snorkel AI help automate.

# Export the labeled dataset
results['label'] = [1 if pred == 1 else 0 for pred in preds]
results.to_csv('labeled_movie_reviews.csv', index=False)
print('Dataset exported successfully!')

Summary

In this tutorial, you've learned how to use Snorkel AI's approach to create labeled training datasets for machine learning. You've created sample data, defined labeling functions, applied them to your dataset, trained a label model, evaluated the results, and exported your labeled dataset. This hands-on experience demonstrates the core concepts behind Snorkel AI's data-as-a-service platform, which is helping companies scale their machine learning efforts by providing efficient, high-quality training data solutions. As demand for AI training data continues to grow, understanding these tools becomes increasingly valuable for anyone working with machine learning projects.

Related Articles