On the Trade-off of Intra-/Inter-class Diversity for Supervised Pre-training

Jieyu Zhang, Bohan Wang, Zhengyu Hu, Pang Wei Koh, Alexander Ratner · OpenReview

Abstract

Pre-training datasets are critical for building state-of-the-art machine learning models, motivating rigorous study on their impact on downstream tasks. In this work, we study the impact of the trade-off between the intra-class diversity (the number of samples per class) and the inter-class diversity (the number of classes) of a supervised pre-training dataset. Empirically, we found that with the size of the pre-training dataset fixed, the best downstream performance comes with a balance on the intra-/inter-class diversity. To understand the underlying mechanism, we show theoretically that the downstream performance depends monotonically on both types of diversity. Notably, our theory reveals that the optimal class-to-sample ratio (#classes / #samples per class) is invariant to the size of the pre-training dataset, which motivates an application of predicting the optimal number of pre-training classes. We demonstrate the effectiveness of this application by an improvement of around 2 points on the downstream tasks when using ImageNet as the pre-training dataset.

Introduction

In the current deep learning paradigm, supervised pre-training serves as the foundational step for most state-of-the-art models. By training on a massive, general-purpose dataset like ImageNet and subsequently fine-tuning on specific downstream tasks, models can leverage learned features to achieve high performance even with limited task-specific data. While the community generally accepts that larger datasets lead to better performance, the internal composition of these datasets—specifically the balance between the number of categories and the number of examples per category—has remained largely unexamined.

This paper investigates a fundamental design question: Given a fixed budget for a pre-training dataset, should developers prioritize inter-class diversity (more classes) or intra-class diversity (more samples per class)? By combining empirical evidence with a novel theoretical framework, this research identifies a "Goldilocks zone" for dataset composition and introduces a method to predict this optimal balance at scale.

The Diversity Trade-off

When constructing a pre-training dataset of a fixed size $N$, designers face a direct trade-off between the number of classes ($K$) and the number of samples per class ($n$), where $N = K \times n$.

Common intuition often favors maximizing $K$ to ensure a wide variety of features. However, this research demonstrates that an extreme focus on either dimension is suboptimal:

  1. Low Inter-class Diversity (Small $K$): If the dataset contains too few classes, the model fails to learn a sufficiently diverse set of features, limiting its ability to generalize to varied downstream tasks.
  2. Low Intra-class Diversity (Small $n$): If the dataset contains too many classes with too few images per class, the model cannot effectively learn the nuances or variations within each category, leading to poor feature representation.

Theoretical Framework and the Invariance Property

To analyze this trade-off, the authors modeled dataset generation as a "two-step sampling process" where classes are sampled first, followed by individual images within those classes. This framework allowed for the derivation of an error bound formula showing that downstream performance is a convex function of the class-to-sample ratio ($K/n$).

A pivotal finding of this theoretical work is the Invariance Property. The researchers proved that the optimal $K/n$ ratio for a specific downstream task remains constant regardless of the total dataset size $N$. This suggests that the "ideal recipe" for a dataset is a characteristic of the task and the data domain itself, rather than a variable that shifts as more data is collected.

Methodology and Extrapolation Strategy

The invariance property enables a practical "Extrapolation Strategy" for dataset design. Instead of performing an expensive grid search on a massive production-scale dataset, developers can:

  1. Construct a small "pilot" dataset (e.g., 5,000 images).
  2. Test various $K/n$ ratios to find the one that yields the best downstream performance.
  3. Apply that same ratio when scaling up to the full production dataset (e.g., 100,000+ images).

This approach significantly reduces the computational cost of dataset optimization while ensuring the final model is pre-trained on a balanced distribution of data.

Empirical Results

The authors validated their findings using ResNet-18 and Vision Transformer (ViT) architectures pre-trained on ImageNet-1K and Places365. Downstream evaluation was conducted across six diverse tasks, including CIFAR10, StanfordDogs (fine-grained), and MIT67 (scenes).

Key results include:

  • Performance Gains: Using the extrapolation method to select the optimal number of classes resulted in an average improvement of approximately 2 percentage points across downstream tasks compared to the standard approach of using all available ImageNet classes.
  • Task Sensitivity: The optimal ratio varies by task. For instance, fine-grained recognition tasks (like identifying specific aircraft or dog breeds) typically require higher intra-class diversity (larger $n$) during pre-training than general object recognition.
  • Consistency: The invariance of the optimal ratio held true across different model architectures and different pre-training source domains.

Limitations and Future Work

While this study provides a rigorous foundation for dataset design, several avenues for future research remain:

  • Self-Supervised Learning (SSL): The current study focuses on supervised pre-training. As the industry shifts toward SSL, exploring whether these trade-offs and the invariance property hold in label-free environments is a critical next step.
  • Data Imbalance: The theoretical model assumes uniform sampling (equal $n$ for all $K$). Real-world datasets are often long-tailed, and the impact of class imbalance on the optimal diversity trade-off requires further investigation.
  • Model Capacity: The study primarily used fixed model sizes. Future work could examine how increasing model parameters influences the demand for inter-class versus intra-class diversity.

Conclusion

This research moves the practice of dataset curation from empirical "gut feeling" toward a predictable science. By identifying the invariance of the optimal class-to-sample ratio, the authors provide a scalable methodology for optimizing pre-training datasets, ultimately leading to more robust and high-performing downstream models.

Summary updated

BibTeX
@inproceedings{zhang2023trade,
  author = {Jieyu Zhang and Bohan Wang and Zhengyu Hu and Pang Wei Koh and Alexander Ratner},
  title = {{On the Trade-off of Intra-/Inter-class Diversity for Supervised Pre-training}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=Fe6fDq65aZ},
}
Figure