In the world of deep learning, pre-training is the bedrock of performance. We take a massive dataset like ImageNet, train a model to recognize its categories, and then "fine-tune" that model for specific tasks like identifying dog breeds or classifying aircraft. But while we know more data is generally better, we haven't spent much time asking how that data should be structured.
A new paper from researchers at the University of Washington, USTC, HKUST, and Snorkel AI, presented at NeurIPS 2023, dives into a fundamental trade-off: Is it better to have many different classes with a few examples each, or a few classes with many examples?
TL;DR
This paper identifies a critical trade-off between inter-class diversity (number of classes) and intra-class diversity (samples per class) in supervised pre-training. The authors prove—both theoretically and empirically—that there is an optimal "class-to-sample ratio" that remains constant regardless of the total dataset size, allowing researchers to predict the best dataset composition for massive scales using only a tiny fraction of the data.
What Problem Does This Paper Address?
When building a pre-training dataset of a fixed size ($N$), you face a see-saw: if you increase the number of classes ($K$), you must decrease the number of samples per class ($n$), and vice versa ($N = K \times n$).
Intuitively, both are good. More classes (inter-class diversity) help the model learn a broader range of features. More samples per class (intra-class diversity) help the model learn more robust, invariant features for those specific categories. However, because they compete for the same "budget" of total images, researchers usually just use whatever is available (like all 1,000 classes of ImageNet) without knowing if that's actually optimal for their specific downstream task.
Methods
The authors tackle this using a two-pronged approach:
- Empirical Grid Search: They pre-trained ResNet-18 models on various subsets of ImageNet, systematically varying $K$ and $n$ while keeping the total size $N$ fixed. They then evaluated these models on six different downstream tasks.
- Theoretical Modeling: They developed a "two-step sampling framework." First, you sample $K$ classes from a distribution of possible concepts, then you sample $n$ images for each. Using generalization analysis, they derived a formula for downstream test error as a function of $K$ and $n$.
The most significant theoretical breakthrough is the discovery that the optimal class-to-sample ratio ($K/n$) is invariant to the total dataset size. This means if you find the best ratio for a small dataset of 5,000 images, that same ratio will likely be the best for a dataset of 5,000,000 images.
Datasets
- Pre-training: ImageNet-1K and Places365.
- Downstream Tasks:
- Stanford40: Action recognition.
- StanfordDogs: Fine-grained object recognition.
- MIT67: Scene classification.
- CIFAR10: General image recognition.
- Flowers102: Botanical classification.
- FGVCAircraft: Aircraft variant classification.
- Backbones: ResNet-18 (primary) and ViT-B-16 (to verify architecture-agnosticism).
Key Insights and Ideas
- The Invariance Property: This is the "aha" moment. Because the optimal ratio $x^* = K/n$ is constant, the optimal number of classes $\bar{K}$ scales with the square root of the dataset size ($\bar{K} \propto \sqrt{N}$). This provides a concrete mathematical rule for dataset design.
- Standard Isn't Always Best: The "Standard" approach—using all 1,000 ImageNet classes—is often sub-optimal, especially when the total number of pre-training samples is limited.
- The "Why" Matters: The trade-off only exists if you are sampling new classes (Data Generation Process 1). If you take a fixed set of images and simply cluster them into more and more classes (Data Generation Process 2), the trade-off disappears, and more classes are almost always better. This reveals that the "cost" of inter-class diversity is actually the loss of samples per class.
Key Results
- Performance Gains: By using their "Extrapolation" method to pick the optimal $K$, the authors achieved an average improvement of 2 points on downstream tasks compared to the standard ImageNet design.
- Predictive Power: The authors showed they could accurately predict the optimal number of classes for a 100,000-sample dataset using a "pilot" study of only 5,000 samples.
- Robustness: The findings held true across different architectures (CNNs vs. Transformers) and different pre-training sources (ImageNet vs. Places365), suggesting this is a fundamental property of supervised transfer learning.
Limitations and Future Work
- Class Selection Bias: The study assumes classes are sampled i.i.d. from a distribution. In reality, some classes are more "informative" than others. The paper doesn't address which classes to pick, only how many.
- Quantity vs. Quality: The research focuses on the counts of classes and samples, but does not account for the inherent "quality" or "difficulty" of individual images.
- Supervised Focus: The work is strictly about supervised pre-training. It remains to be seen if these exact scaling laws apply to self-supervised learning (like MAE or CLIP), where the concept of a "class" is more fluid or non-existent.
This research provides a much-needed "rule of thumb" for the data-hungry era of AI: if you're building a dataset, don't just collect everything—balance your diversity.
Summary updated