LLM Learning Roadmap
✨ Awesome-Anything
🖼️ Digital Image Processing
🍃 LLM Components
🌱 LLM Pre-training
☘️ LLM Post-Training
🍀 LLM Popular Models
🪴 LLM Applications
🌿 LLM Optimization
🌾 LLM Compression
🌵 LLM Hands-on Practice
🌴 LLM Must-read Papers
🌳 LLM Q&A
🐝 VLM Image Encoders
📝 MISC.
2.2 Pre-training Data
2.2 Pre-training Data
The most critical aspect of the entire pre-training phase is data acquisition and processing. The scale of data for pre-training typically reaches 10 trillion tokens, while continued pre-training requires at least 100 billion tokens.
2.2.1 Data Source
The pre-training phase involves learning from vast amounts of data to comprehensively understand the world and its complexities. This includes not only fundamental language abilities but also advanced skills such as math, coding, and logical reasoning. Therefore, collecting large-scale, multi-domain corpora is essential. Common data sources include:
- Common Crawl: An open data-sharing platform containing massive amounts of web page data.
- GitHub: Code-related data collected from GitHub repositories.
- Web text: Text from code-related and math-related websites, such as programming forums, library documentation, and math resource sites.
- E-books, Educational Materials, and Research Papers: These resources contain rich knowledge, enhancing the model's understanding and generation capabilities across various domains.
- Internal Data: Proprietary data curated by companies developing large models, often including vertical business-critical information.
The total data volume typically reaches 10 trillion tokens. For general base models, corpora in multiple languages must be collected, primarily Chinese and English, with other languages included based on specific needs.
Some high-quality data, such as research papers and books, are often in PDF format, requiring specialized PDF parsing services. Relying on standard Python libraries for parsing is unreliable—especially for PDFs containing formulas or tables, where parsing quality is often poor. Using large models like ChatGPT/GPT-4 for parsing may be prohibitively expensive compared to dedicated PDF services. Training an OCR model is another viable option, provided there is sufficient high-quality PDF-text data pairs available.
While many open-source datasets exist (e.g., FineWeb, Pile, Skypile, RedPajama) and can serve as a starting point, it’s important to note that there’s no free lunch—all publicly released Chinese large-model datasets have some quality issues. In the opposite, high-quality English data is relatively easy to obtain.
- Open-Source General Datasets
Dataset Name | URL |
Skywork/SkyPile-150B | |
wikipedia-cn-20230720-filtered | |
C4 | |
RedPajama | |
EleutherAI/the_pile_deduplicated | |
WuDaoCorporaText | |
PRM800K | |
YeungNLP/firefly-pretrain-dataset |
- Example of Continued Pre-training:
- General data: 70B tokens
- Total continued pre-training data: 100B tokens
- Chinese Corpus
Datasets (Chinese) | Sampled Tokens (in billions) |
cc | 4.024 |
tdata | 1.6118 |
baidu_baike_v3 | 0.804 |
wiki_zw | 0.1602 |
qikan | 0.1602 |
recipe | 0.0182 |
roots_zw | 0.08 |
ch_ebooks4 | 0.1602 |
zlibrary_ch4 | 0.4002 |
novel_zw | 0.1602 |
ebook_zw | 0.2402 |
zdata | 0.1602 |
xhs | 0.08 |
cc_22_v1 | 4.8788 |
wanjuan | 1.08 |
- English Corpus
Datasets (English) | Sampled Tokens (in billions) |
c4 | 32.675 |
arxiv_v2 | 3.2652 |
se_v2 | 1.6326 |
roots_en | 1.6326 |
wiki_en | 3.6792 |
novel_en | 0.4142 |
zlibrary_en3 | 3.2652 |
reddit | 2.4364 |
- Code Corpus
Datasets (English) | Sampled Tokens (in billions) |
code | 4.9042 |
md | 0.8788 |
github70v1 | 1.2168 |
- English/Chinese/Code Percentage
- 7:2:1
- In reference to Yi’s

<ins/>
2.2.2 Data Crawling
Some high-quality data, such as research papers and books, are often in PDF format, requiring specialized PDF parsing services. Relying on standard Python libraries for parsing is unreliable—especially for PDFs containing formulas or tables, where parsing quality is often poor. Using large models like ChatGPT/GPT-4 for parsing may be prohibitively expensive compared to dedicated PDF services. Training an OCR model is another viable option, provided there is sufficient high-quality PDF-text data pairs available.
Crawlers can be mainly divided into: 1. Targeted website crawling; 2. Crawling from designated websites according to keywords; 3. Crawling based on search engines
Example of Targeted Website Crawling
Example of Keywords-based Crawling
Reference: MediaCrawler, a Playwright-based crawler for the Chinese community.
- Basic configuration
- Run script
<ins/>
2.2.3 Data Cleaning
Data cleaning is the most critical step in pre-training data processing. The quality and diversity of the data determine the generalization capability and effectiveness of the model.
It is recommended to study technical reports from various companies for this part, such as the technical report of deepseek-math, where the data processing pipeline is worth reading carefully.
URL Filtering (llama 3.1)
By establishing a URL blacklist (such as nsfw websites) and calculating URL scores to determine whether the content should be retained, a distinction is made between manually curated datasets and others. For example, content from sites like Arxiv and Wikipedia will be filtered out in this stage.
Regular Expression Filtering Scripts
Content Extraction
After obtaining a collection of URLs through filtering, we need to extract the “text” from these URLs and filter out irrelevant content such as “tables of contents,” “titles,” and advertisements. To do this, we use the
trafilatura library for content extraction. The usage of trafilatura is simple:- Note: you may need to install the libs first
Language Identification
- Use FastText to train a language identification model, and discard articles with a language confidence score below 0.65.
- Use langid to identify the language type.
- language identification using data-juicer. Below is the key code snippet.
Low-Quality Filtering
- Article-Level Filtering: First, remove some articles that repeatedly contain the same content or contain incorrect information (e.g., scraped content, etc.); secondly, for each article, determine the overall length, the proportion of punctuation in the article, etc., to filter out irregular articles.
- Sentence-Level Filtering: Filter out some useless sentences in the article. These types of sentences usually have no specific meaning, are conversational, and hard to classify. Therefore, use the following heuristics to filter such sentences (some rules are only applicable to English):
- Sentence is mainly composed of uppercase letters (discard)
- Sentence is composed of numbers/digits (discard)
- Contains pre-defined keywords, such as “click here,” “forward,” “like” (discard)
- If the sentence length is less than 10, and it starts or ends with the following (discard):
- Starts with “login, register”
- Ends with “more, expand”
- Use heuristic methods to perform pre-train data quality filtering, such as determining whether data length is below a certain threshold; whether the proportion of a certain token in the data exceeds a certain threshold; the proportion of Chinese, English, digits; whether it contains "http"; whether it contains low-quality keywords like COVID, "epidemic", etc.; whether it contains strong sentiment or anti-society content; whether it includes explicit words. Note that while applying these rules, do not overdo such that the data distribution is biased.
You can see that data processing is a very meticulous job: some things can be automated and fast through training models, but model outputs can easily introduce bias, so some engineers still use rule-based filtering instead of models to clean the data.
Model Scoring
Using models to score the quality of pret-rain data has become a standard practice in data cleaning, as seen in technical reports for llama3 and qwen2. Under the same size, BERT-structured models have stronger representation capabilities than transformer-decoder models, so training scoring models can choose to be BERT-type models, or use strong closed-source models for scoring training data, such as GPT4o.
The challenge of training a scorer lies in insisting on a 100% accurate scorer — actually, rough utility is enough. A weak scorer is better than none at all. If you need a month to train a scorer, you might as well skip scoring. Additionally, having 32K pre-train tokens doesn’t mean you must train a scorer using 32K; even a 4K model may suffice. Normally, Bert-base/FastText (or similar lightweight models) trained by finetuning would be enough. For detailed training workflows, refer to Deepseek-Math.

Data De-duplication
During the pre-training process, data duplication can generally be divided into three types:
- Duplication within training datasets: Refers to duplication within and between different sources of training data.
- Intra-dataset duplication: including duplication within a single document across lines, paragraphs, or n-grams (suggesting low data quality); and inter-dataset duplication, referring to overlaps between multiple documents (whether exact or fuzzy matches).
- Inter-dataset duplication: often caused when multiple datasets are derived from the same source but preprocessed differently. A typical example is LLaMA, which uses both preprocessed CommonCrawl data and previously preprocessed C4 data from CommonCrawl used in T5, where both are from CommonCrawl and may have significant overlap.
- Duplication in training configuration: Refers to redundancy caused by how many epochs (repetitions) are used to train different types, sources, or qualities of data. Usually, the number of training epochs varies across datasets.
- Duplication between training and test sets: For instance, datasets used for monitoring Language Modeling Loss during pre-training or for benchmarking should be deduplicated against the training set to avoid overlap.
Step | Focus | Description |
Step 1 | What is a Unit? | Based on the source, nature, and characteristics of the data, determine the smallest processing unit. For example: whether the dataset consists of file collections; what the unit is (line, file, book, etc.). For LLaMA, CommonCrawl is deduplicated at the line level (cc_net pipeline), Books3 at the book level (removing anything with more than 90% overlap), Github code at the file level, etc. [LLaMA] |
Step 2 | Intra-unit deduplication | After defining the Unit, analyze whether its content contains a high proportion of internal duplication (lines, paragraphs, n-grams). If so, discard this unit. (This step is more about quality filtering.) [Gopher] |
Step 3 | Inter-unit deduplication | Based on exact or fuzzy matching models, compare similarity between different documents and remove duplicates. Finally, obtain a collection of Unique Units. [Gopher] |
Step 4 | Deduplication between training and test sets (Test-set Filtering) | Remove documents in the training set that are similar to those in the test set. |
Common indicators include simhash and minhash. These techniques are used for text deduplication. First, determine how much training data is needed, then decide the deduplication granularity. For example, if 10T of training data is needed, deduplicate with a similarity threshold of around 80%.
Exploring Data Diversity
In various stages of building large models, data quality and diversity are key concerns. Data diversity has many aspects: task diversity, semantic diversity, language diversity, and source diversity, etc. During the pre-training stage, collecting data from different sources is common industry practice. At the supervised fine-tuning stage (SFT), the data used should ideally be high-quality and diverse. The paper maybe only 0.5% data is needed proposes SFT data sampling by utilizing clustering. Their method involves the three-step process of: Vectorization → Clustering → Core Sample Selection

Use SimBERT for embedding — quality weights can be obtained through independent quality scoring models.
- Plan 1: Diversity sampling based on k-means clustering.
- Drawback: High sampling probability for low-quality samples.
- Plan 2: Weighted sampling combining diversity from clustering and quality weights.
- Drawback: Similarity between samples from different clusters may even be higher than within-cluster similarity.
- Plan 3: KNN clustering, using average similarity between a sample and its neighbors as the diversity weight, combined with quality weights. Final sampling is based on the combined weights.
During pretraining, knowledge injection is important, where similar sentences are often different expressions of the same knowledge.
Practical Vertical Domain Experience
The main reference is the approach used by DeepseekMath.
- Acquire as many data documents as possible to serve as the initial seed data corpus.
- Use clustering methods to filter domain-related data from the Chinese text corpus. Retrieve relevant domain documents from the internet (encyclopedias, web data, books, etc.) to expand the seed data.
- Keyword filtering of general data
- First, preprocess the initial seed data corpus to preserve paragraph structure, segment content by heading, and split knowledge document data.
- Use Jieba to extract keywords.
- Filter mined keywords manually and compile a final keyword list.
- From the retrieved general data from the internet, filter documents that contain N keywords.
- Retrieve top 10 data most similar to the initial seed data corpus
- Use the first 512 tokens of the general document to compute similarity.
- Human filtering
- Manually review the general data to select domain-related documents to expand the initial seed data.
Pipeline: Keyword filtering of general data → Retrieve top 10 most similar domain documents → Human filtering
- Train a Chinese domain data classifier
- Training data: Use vertical domain initial seed data and expanded seed documents from step 2 (each with first 1k tokens) as positive samples. Negative samples are "non-vertical-domain" documents.
- Model: A BERT model with 1024 hidden dimensions.
- Model performance: Acquire a high precision (95%) trained classifier to classify domain-relevant text from the Chinese corpus, extracting 0.5 B of vertical data (B = billion).
<ins/>
2.2.4 Data Ratio and Order
- Guiding Principle: Classify according to task type — the finer the classification, the better. For example: Chinese, English, and code. Each document should be classified (e.g., into Wikipedia, code, markdown, etc.). You can still choose to use BERT-like models for classification.
- In many open-source LLM tech reports, the training data is often divided into Knowledge + Code + Reasoning. Among them, knowledge data is mostly Chinese and English, reasoning data includes math and chain-of-thought (CoT) mixed data. In general, Chinese model data proportions are often about: Chinese : English : Code = 4 : 4 : 2. Chinese LLMs should not rely too heavily on Chinese (half or more), and English should not be too little either. If you want strong reasoning capabilities, you must add as much math and code data as possible.
- Best Practice: If you're doing domain-specific model pretraining, consider a more refined domain data ratio for better continue pre-training. If you want the model to retain general capabilities (like summarization or QA), then:
- Domain data should not exceed 15% of total data. If you exceed this, model generalization may drop. This threshold depends on the base model's size, e.g., llama may need a smaller ratio. Empirically — recommended range: 10%-15%. Practice is required for different vertical domains, LLM models, etc.
- In SFT, then Domain : General = 1 : 1 is also okay. If SFT data is too few, you may not have to mix them with general data at all.
- The above data ratios are usually verified with small-scale pretraining experiments, then scaled up using scaling laws, so small models are typically used for ablation and performance validation.
- Most large-scale models usually rely on classes, i.e. what to learn first and what to learn next. Pay attention to the training data order during this stage to prevent performance degradation caused by catastrophic forgetting. This part should also be experimented on small models first.
Prev
2.1 Pre-training Definition
Next
2.3 Pre-training Workflow
Loading...