Overview

4 Diversity sampling

This chapter explains how to choose labeled data not just for uncertainty, but for diversity: finding what a model does not know, what is underrepresented, and what is missing from the real-world setting where the model will be used. The core idea is that random sampling often reinforces existing biases, so active learning should deliberately seek examples that broaden coverage of language, topics, accents, demographics, and other meaningful sources of variation.

The chapter first presents model-based outlier sampling, where unlabeled items are scored by how little activation they produce in a model layer, with rankings built from held-out validation data so the model does not simply repeat its own biases. It then covers clustering-based sampling, which groups items into clusters and samples centroids, outliers, and random members to maximize coverage of the feature space. The text also shows how to adapt PyTorch models to expose hidden layers and logits, how to rank activations robustly, and why cosine similarity and dimensionality reduction are often useful for sparse or high-dimensional data.

Next, the chapter turns to representative sampling, which seeks examples most like the target deployment domain rather than the original training distribution, while warning that this can overfit to the present and miss future variation. It then addresses real-world diversity directly by encouraging stratified sampling across demographics and evaluating performance separately across groups, with attention to intersectional bias and the difference between being representative and merely well-represented. Finally, the chapter notes that these methods generalize across model types, but their effectiveness depends on the data, the architecture, and the practical limits of available labeled examples.

Diversity sampling, showing items selected to be labeled that are maximally different from the existing training items and from one another. You want to sample items that are not like the items that are currently in your training data and are also not like one another.
Two neural architectures and how you can interpret them for outlier detection. In the top example, you can use the model scores (known as z or logits), which retain their absolute values before they are normalized via softmax. In the bottom example, you have lost the absolute values in the final layer because of the softmax function, so you can use the activation in the second-to-last layer to determine whether an item is an outlier.
Four identical probability distributions that are derived from different inputs via softmax with base e
An example clustering algorithm applied to the data, splitting it into five separate clusters. For each cluster, the most central item is known as the centroid, and the items farthest from the centers are outliers.
An example clustering algorithm using cosine similarity. For each cluster, the center is defined as a vector from 0, and the membership of that cluster is the angle between the vector representing the cluster and the vector representing the item. Note that although this example looks less like real clusters than the spheroidal clusters in figure 4.4, it is limited by being 2D. For higher-dimensional sparse data, which you are more likely to be using with your models, this kind of clustering is often better than the spheroid type shown here.
An example of representative sampling, showing that the current training data is from a different distribution of the data from the application domain. Representative sampling maximizes sampling of items that look the most like the application domain relative to the current training data.
An example of the problems that diversity sampling tries to address. Here, we have items mapped to three real-world demographics that we’re calling X, O, and Z. Demographic X looks pretty good. All the examples we have so far are within the current training data. X is not the same distribution as the training data as a whole. This problem isn’t typical of neural models, but it could be a problem with simpler models such as Naive Bayes. X is typical of a privileged demographic with a positive bias, such as standard English data within a multilingual dataset. Demographic O is partially in the training data today and partially outside it. O is distributed across the entire feature range fairly evenly. So if we can collect training data that is representative of the entire feature space, we are least worried about O. O is typical of a demographic with minimal bias (positive or negative), such as time-based demographics, in which each item was collected carefully over a certain period. By contrast, demographic Z is clustered outside the current training data. Even worse, a Z data point inside the current training data appears to be an outlier for Z. The model may not have information about Z and may actually be modeling Z incorrectly. Z is typical of an underrepresented demographic, such as an underrepresented ethnicity that does not appear in the dataset except when that person happens to share features with a more privileged demographic.
Cheat sheet for the types of diversity sampling covered in this chapter: model-based outlier sampling, cluster-based sampling, representative sampling, and sampling for real-world diversity. These four strategies ensure diversity and representation in your data—respectively, items that are unknown to your model in its current state; items that are statistically representative of the entire distribution of your data; items that are maximally representative of where you are going to deploy your model; and items that are most representative of real-world demographics.

Summary

  • This chapter covered four common approaches to diversity sampling: model-based outlier sampling, cluster-based sampling, representative sampling, and sampling for real-world diversity. These techniques can help you understand the kinds of “unknown unknowns” in your models.
  • Model-based outlier sampling allows you to sample items that are unknown to your model in its current state, helping you expand your model’s knowledge where there are currently gaps.
  • Cluster-based sampling allows you to sample items that are statistically representative of the entire distribution of your data, helping you expand your model’s knowledge to capture all the meaningful trends in your data, including the rarer ones that would likely be missed with random sampling.
  • Representative sampling can be used to sample items that are maximally representative of where you are going to deploy your model, helping you adapt your model to domains that are different from your current training data, which is a common problem in real-world machine learning.
  • To support real-world diversity, you need to deploy all your techniques from uncertainty sampling and diversity sampling to make your applications more accurate across a diverse set of users and, therefore, more fair.
  • Accuracy metrics such as micro and macro F-score can be applied across real-world demographics as one way to measure potential biases in a model.
  • Interpreting the layers of a neural model for diversity sampling lets you access as much information as possible for active learning, giving you more options for calculating model outliers and providing a building block for advanced transfer learning techniques.
  • The strategies for deciding how many items should be reviewed by humans when implementing diversity sampling is different from uncertainty sampling, because in some cases, they can be adaptive within each iteration of active learning. Adaptive sampling methods allow you to make the human-in-the-loop machine learning feedback loop more efficient because you don’t have to wait for your model to retrain.
  • Implementing diversity sampling is possible with any supervised machine learning algorithm, including neural models, Bayesian models, SVMs, and decision trees. You can implement active learning with any type of machine learning algorithm that you are currently using; you don’t need to switch to the neural models that are the focus of the examples in this book. You might even decide to try some of these additional algorithms for active learning to take advantage of their unique properties.

FAQ

What is the main goal of diversity sampling in active learning?

Diversity sampling aims to select unlabeled items that expand what the model knows, especially items that are unlike the current training data or reveal gaps in the model’s knowledge. It helps address “unknown unknowns” and improves coverage beyond simple uncertainty sampling.

How is model-based outlier sampling different from uncertainty sampling?

Uncertainty sampling focuses on items near the decision boundary, while model-based outlier sampling looks for items with the lowest activation in a model layer—items the model has little information about. These are often far from the decision boundary and may represent unknown or rare cases.

Why does the chapter recommend using validation data to rank activations for outlier detection?

Validation data is drawn from the same distribution as the training data, so it provides a better reference for ranking neuron activations. Using training data directly can bias the rankings because the model has already overfit to it.

Why are logits often preferred over softmax probabilities for model-based outlier sampling?

Softmax compresses different input patterns into similar probability distributions, which can hide important differences. Logits retain more information about the raw output scores, making them more useful for distinguishing true lack of information from conflicting confident signals.

What is cluster-based sampling, and why is it useful?

Cluster-based sampling groups similar unlabeled items together and samples from each cluster to increase diversity. It is useful because it avoids spending too many annotations on redundant items and helps surface rare but meaningful patterns in the data.

Why does the chapter suggest cosine similarity for clustering text data?

Cosine similarity works well for sparse, high-dimensional text features because it compares direction rather than magnitude. That makes it more suitable than Euclidean distance for text representations such as word counts or embeddings.

What is representative sampling trying to do?

Representative sampling seeks unlabeled items that are most like the target deployment domain relative to the current training data. It is especially useful for domain adaptation, where the model needs to better match the real-world data it will face in production.

Why is representative sampling rarely used alone?

Because it can be overly sensitive to noise and can overfit to the current unlabeled pool. It is often combined with uncertainty sampling or other methods so the model improves both on domain fit and on informative examples.

How does the chapter recommend improving real-world demographic diversity?

The chapter recommends stratified sampling across demographics such as language, geography, gender, socioeconomic status, race and ethnicity, and time. The idea is to ensure each demographic is sufficiently represented so the model performs more fairly across real-world groups.

What are the main limitations of diversity sampling?

Diversity sampling cannot guarantee perfect fairness or complete coverage, especially when there is not enough data from certain groups or domains. It can reduce bias and improve representativeness, but it cannot fully solve data scarcity or underlying structural bias on its own.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Human-in-the-Loop Machine Learning Human-in-the-Loop Machine Learning ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Human-in-the-Loop Machine Learning Human-in-the-Loop Machine Learning ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Human-in-the-Loop Machine Learning Human-in-the-Loop Machine Learning ebook for free