Practical Weak Supervision

Book description

Most data scientists and engineers today rely on quality labeled data to train machine learning models. But building a training set manually is time-consuming and expensive, leaving many companies with unfinished ML projects. There's a more practical approach. In this book, Wee Hyong Tok, Amit Bahree, and Senja Filipi show you how to create products using weakly supervised learning models.

You'll learn how to build natural language processing and computer vision projects using weakly labeled datasets from Snorkel, a spin-off from the Stanford AI Lab. Because so many companies have pursued ML projects that never go beyond their labs, this book also provides a guide on how to ship the deep learning models you build.

  • Get up to speed on the field of weak supervision, including ways to use it as part of the data science process
  • Use Snorkel AI for weak supervision and data programming
  • Get code examples for using Snorkel to label text and image datasets
  • Use a weakly labeled dataset for text and image classification
  • Learn practical considerations for using Snorkel with large datasets and using Spark clusters to scale labeling

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword by Xuedong Huang
  2. Foreword by Alex Ratner
  3. Preface
    1. Who Should Read This Book
    2. Navigating This Book
    3. Conventions Used in This Book
    4. Using Code Examples
    5. O’Reilly Online Learning
    6. How to Contact Us
    7. Acknowledgments
  4. 1. Introduction to Weak Supervision
    1. What Is Weak Supervision?
    2. Real-World Weak Supervision with Snorkel
    3. Approaches to Weak Supervision
      1. Incomplete Supervision
      2. Inexact Supervision
      3. Inaccurate Supervision
    4. Data Programming
    5. Getting Training Data
      1. How Data Programming Is Helping Accelerate Software 2.0
    6. Summary
  5. 2. Diving into Data Programming with Snorkel
    1. Snorkel, a Data Programming Framework
    2. Getting Started with Labeling Functions
      1. Applying the Labels to the Datasets
      2. Analyzing the Labeling Performance
      3. Using a Validation Set
    3. Reaching Labeling Consensus with LabelModel
      1. Intuition Behind LabelModel
      2. LabelModel Parameter Estimation
    4. Strategies to Improve the Labeling Functions
    5. Data Augmentation with Snorkel Transformers
      1. Data Augmentation Through Word Removal
      2. Snorkel Preprocessors
      3. Data Augmentation Through GPT-2 Prediction
      4. Data Augmentation Through Translation
      5. Applying the Transformation Functions to the Dataset
    6. Summary
  6. 3. Labeling in Action
    1. Labeling a Text Dataset: Identifying Fake News
      1. Exploring the Fake News Detection(FakeNewsNet) Dataset
      2. Importing Snorkel and Setting Up Representative Constants
      3. Fact-Checking Sites
      4. Is the Speaker a “Liar”?
      5. Twitter Profile and Botometer Score
      6. Generating Agreements Between Weak Classifiers
    2. Labeling an Images Dataset: Determining Indoor Versus Outdoor Images
      1. Creating a Dataset of Images from Bing
      2. Defining and Training Weak Classifiers in TensorFlow
      3. Training the Various Classifiers
      4. Weak Classifiers out of Image Tags
      5. Deploying the Computer Vision Service
      6. Interacting with the Computer Vision Service
      7. Preparing the DataFrame
      8. Learning a LabelModel
    3. Summary
  7. 4. Using the Snorkel-Labeled Dataset for Text Classification
    1. Getting Started with Natural Language Processing (NLP)
      1. Transformers
    2. Hard Versus Probabilistic Labels
    3. Using ktrain for Performing Text Classification
      1. Data Preparation
      2. Dealing with an Imbalanced Dataset
      3. Training the Model
      4. Using the Text Classification Model for Prediction
      5. Finding a Good Learning Rate
    4. Using Hugging Face and Transformers
      1. Loading the Relevant Python Packages
      2. Dataset Preparation
      3. Checking Whether GPU Hardware Is Available
      4. Performing Tokenization
      5. Model Training
      6. Testing the Fine-Tuned Model
    5. Summary
  8. 5. Using the Snorkel-Labeled Dataset for Image Classification
    1. Visual Object Recognition Overview
      1. Representing Image Features
      2. Transfer Learning for Computer Vision
    2. Using PyTorch for Image Classification
      1. Loading the Indoor/Outdoor Dataset
      2. Utility Functions
      3. Visualizing the Training Data
      4. Fine-Tuning the Pretrained Model
    3. Summary
  9. 6. Scalability and Distributed Training
    1. The Need for Scalability
    2. Distributed Training
    3. Apache Spark: An Introduction
      1. Spark Application Design
    4. Using Azure Databricks to Scale
      1. Cluster Setup for Weak Supervision
    5. Fake News Detection Dataset on Databricks
      1. Labeling Functions for Snorkel
      2. Setting Up Dependencies
      3. Loading the Data
      4. Fact-Checking Sites
      5. Transfer Learning Using the LIAR Dataset
      6. Weak Classifiers: Generating Agreement
      7. Type Conversions Needed for Spark Runtime
    6. Summary
  10. Index

Product information

  • Title: Practical Weak Supervision
  • Author(s): Wee Hyong Tok, Amit Bahree, Senja Filipi
  • Release date: October 2021
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492077060