When building a massive pre-training dataset like ImageNet, researchers usually face a fundamental choice: do you want more classes (inter-class diversity) or more examples per class (intra-class diversity)? If your total data budget is fixed, you can’t have both.
In their NeurIPS 2023 paper, "On the Trade-off of Intra-/Inter-class Diversity for Supervised Pre-training," Jieyu Zhang and colleagues provide both empirical proof and a theoretical framework to navigate this "Goldilocks" problem. Their most striking finding? The optimal balance between classes and samples is a constant ratio that stays the same even as you scale up your dataset.
TL;DR
Supervised pre-training requires a careful balance between the number of classes and the number of samples per class to maximize downstream performance. The authors demonstrate that the optimal class-to-sample ratio is invariant to the total dataset size, allowing researchers to predict the best dataset composition using only a small fraction of the total data budget.
What Problem Does This Paper Address?
Deep learning thrives on scale, but not all data is created equal. While we know that larger pre-training datasets generally lead to better downstream performance, the composition of that data is often decided by intuition or historical standards (like using all 1,000 classes of ImageNet).
The authors identify a critical trade-off:
- Inter-class diversity ($K$): The number of different categories.
- Intra-class diversity ($n$): The number of samples per category.
If you have a fixed budget of $N$ total samples, then $N = K \times n$. Increasing $K$ forces you to decrease $n$. The authors set out to find if there is an optimal "sweet spot" for this ratio and how it behaves as the total budget $N$ grows.
Methods
The researchers combined extensive empirical sweeps with new theoretical modeling:
- Empirical Sweeps: They pre-trained ResNet-18 and ViT models on various subsets of ImageNet and Places365, systematically varying $K$ and $n$ while keeping the total size $N$ fixed.
- Theoretical Framework: They modeled the dataset generation as a two-step sampling process (first sample classes from a distribution of concepts, then sample images from those concept distributions). They derived a generalization bound for downstream tasks that explicitly accounts for $K$ and $n$.
- The Extrapolation Strategy: Based on their theory that the optimal ratio $x = K/n$ is invariant to $N$, they proposed a method to estimate this ratio using a tiny "pilot" dataset (e.g., 5,000 samples) and then use that ratio to build the full-scale dataset (e.g., 100,000 samples).
Datasets
- Pre-training: ImageNet-1K and Places365.
- Downstream Evaluation: A diverse suite including Stanford40 (actions), StanfordDogs (fine-grained), MIT67 (scenes), CIFAR10 (general), Flowers102, FGVCAircraft, and DomainNet (cross-domain).
Key Insights and Ideas
- The "Goldilocks" Zone: Downstream performance follows a U-shaped curve (when looking at error). Too few classes lead to poor feature representation; too few samples per class lead to noisy, poorly learned features. You can see this trade-off clearly in the contour plots of Figure 1.
- The Invariance Property: This is the paper's "aha moment." The theory predicts—and experiments confirm—that the optimal class-to-sample ratio for a specific task doesn't change as you add more data. If a 1:10 ratio is best for a 10k dataset, it’s likely best for a 1M dataset.
- Collection vs. Clustering: The trade-off only exists because of how we collect data. If you have a fixed pool of images and just change how you cluster/label them, more classes are almost always better. The trade-off emerges when you have to choose between spending your "sampling budget" on a new concept or a new instance of an existing concept.
Key Results
- Predictive Power: The "Extrapolation" method (predicting the best $K$ from a small sample) performed as well as an exhaustive Grid Search but required significantly less data and compute.
- Performance Gains: By choosing the optimal $K$ rather than the "standard" 1,000 classes, the authors achieved an average improvement of 2 percentage points on downstream tasks when pre-training on ImageNet.
- Consistency: The U-shaped relationship between the class-to-sample ratio and test error was consistent across different model architectures (ResNet vs. ViT) and different pre-training domains (ImageNet vs. Places365).
Limitations and Future Work
- Class Selection: The study focuses on the number of classes, not which classes are most relevant. Future work could combine this ratio-based approach with active learning or concept selection.
- Uniformity Assumption: The theory assumes an equal number of samples per class ($n$). In reality, most large-scale datasets are "long-tailed," with some classes having far more data than others.
- Social Bias: The authors acknowledge that their method doesn't account for how classes are defined, which could potentially amplify existing societal biases if the concept distributions themselves are biased.
By turning dataset design from a "black art" into a predictable engineering problem, this work provides a practical roadmap for anyone building the next generation of foundation models.
Summary updated