In the rapidly evolving landscape of Large Language Models (LLMs), the "data recipe"—the specific mixture of text used during pre-training—is often as critical as the model architecture itself. Traditionally, researchers have curated pre-training data by focusing on either quality (using LLM classifiers or heuristic rules to find the best text) or diversity (using embeddings to ensure a broad coverage of topics).
However, a recent paper introduces a compelling argument: focusing on just one of these metrics in isolation limits a model's potential. To solve this, researchers have developed DATAMASK, a novel framework that leverages reinforcement learning techniques to jointly optimize for both quality and diversity at a massive, trillion-token scale.
TL;DR
DATAMASK treats pre-training data selection as a "mask learning" problem. By utilizing policy gradients to simultaneously optimize for data quality and diversity, it achieves a staggering 98.9% speedup over traditional greedy selection algorithms. This efficiency allowed the authors to curate FineWeb-Mask, a 1.5-trillion-token subset of the FineWeb dataset that outperforms state-of-the-art baselines by up to 3.2% on downstream tasks.
The Core Problem: Quality vs. Diversity
Selecting the optimal subset from a massive data pool like the 15-trillion-token FineWeb dataset is a combinatorial nightmare. Current approaches generally fall into two distinct camps, both with significant drawbacks:
- Quality-Aware Selection: This method uses a "judge" model to score every document. While effective initially, it inevitably leads to semantic redundancy. The model repeatedly sees the same "high-quality" structural patterns, resulting in diminishing returns during long-term pre-training.
- Diversity-Aware Selection: This approach uses embeddings to identify unique samples. The flaw here is that diversity metrics often ignore quality entirely, accidentally discarding highly informative (but common) samples in favor of unique "trash" data.
Attempting to optimize both simultaneously has historically been computationally prohibitive. Standard diversity algorithms, such as Facility Location, are "greedy"—they pick one sample at a time—making them impossible to scale to trillions of tokens.
The DATAMASK Method
To overcome these scaling limitations, the authors propose DATAMASK, which reframes data selection as a Mask Learning problem.
- Probabilistic Relaxation: Instead of making a hard, binary "yes/no" choice for each document, DATAMASK assigns a learnable "logit" (probability) to every sample in the dataset.
- Policy Gradient Estimation (PGE): Because the act of sampling data is non-differentiable, the authors employ Policy Gradients—a foundational technique in Reinforcement Learning. They treat the selection of a data batch as an "action" and the resulting combined quality/diversity score as the "reward."
- Group Relative Advantage: To stabilize the training process, the framework uses a technique similar to RLHF (PPO/GRPO). It samples multiple "masks" (subsets), calculates their scores, and updates the logits based on how much better or worse a specific mask performed compared to the group average.
- Acceleration: By implementing batch updating and quality-aware pruning (filtering out the bottom 40% of low-quality data before starting), the team reduced the selection time for 100,000 samples from 78 hours (using a greedy approach) to just 50 minutes.
Key Insights: The Quality-Diversity Conflict
The authors empirically demonstrate that high-quality data tends to cluster tightly in embedding space. If you only select for quality, you end up with a highly redundant dataset. Conversely, selecting solely for diversity yields unique but often low-quality data.
They also observed a fascinating "Short-Long-Short" phenomenon regarding document length and quality. Very low-quality samples (like ads or headers) are typically short. Mid-to-high quality samples tend to be long and detailed. However, the absolute highest-quality samples (such as concise summaries or clear instructions) become short again. Including a balanced mix allows the model to learn novel information it wouldn't find in a narrow, high-quality-only slice.
Key Results and Performance
To validate their curated data, the authors pre-trained a 1.5B dense model and a 7B Mixture-of-Experts (MoE) model.
- Performance Boost: The resulting 1.5-trillion-token subset, FineWeb-Mask, achieved a 3.2% improvement over the raw FineWeb dataset on the 1.5B model, and a 1.9% improvement on the 7B MoE model across 12 diverse tasks (including Reading Comprehension, World Knowledge, and Reasoning).
- Superiority over Baselines: FineWeb-Mask consistently outperformed other popular curated datasets, including FineWeb-Edu, UltraFineWeb, and FineWeb-DCLM, particularly shining in world knowledge and reasoning benchmarks.
Limitations and Future Work
While DATAMASK represents a significant leap forward, it has a few limitations:
- Embedding Dependency: The diversity metric relies heavily on the quality of the underlying embedding model (E5-base-v2 was used here). If the embeddings fail to capture certain semantic nuances, the selection quality will degrade.
- Fixed Budget: The current framework requires a predefined selection budget (e.g., "select exactly 10%"). Future iterations could involve learning the optimal dataset size dynamically.
- Metric Weighting: Finding the perfect hyperparameter ($\lambda$) to balance quality and diversity for different model sizes remains an open area for exploration.
Source Code: https://github.com/ByteDance-Seed/DATAMASK
Summary updated