Large Language Model Training Datasets: A Complete Guide to General Corpus Composition and Engineering Practices
This article breaks down the datasets used to train large language models across four dimensions: training stages, general corpus types, processing workflows, and data mixing strategies. It explains why pre-training, supervised fine-tuning, preference alignment, and evaluation each require different data, surveys six major sources of general-purpose text, and outlines seven essential steps for turning raw data into trainable corpora. Readers will also find practical guidance on data ratios, compliance controls, and reproducible pipeline design.
When people discuss large language model capabilities, they tend to focus on parameter counts and compute budgets. Yet what truly sets the ceiling for a model is often the data. An experience repeatedly validated in the industry is that a model’s knowledge boundaries, language style, reasoning habits, and even value tendencies can almost always be traced back to its training corpus. Understanding “which datasets are needed to train an LLM” is therefore essentially about understanding a layered data engineering system. The discussion below covers four dimensions: stage separation, corpus types, processing workflows, and mixing strategies.
1. Separate the Stages First: Different Training Stages Need Completely Different Data
LLM training does not feed all text in at once. It advances in stages, and the data objective differs at each stage.
- Pre-training: The goal is to learn the statistical regularities of language and world knowledge. This stage uses the largest volume of data, typically on the order of trillions of tokens, and emphasizes breadth and diversity while only requiring overall quality to meet a baseline.
- Supervised fine-tuning: The goal is to teach the model to “answer by instruction.” Data volume typically ranges from tens of thousands to millions of examples, with emphasis on accurate instruction-response correspondence and well-formed formatting.
- Preference alignment: The goal is to make outputs better match human preferences and safety requirements. The data format is “multiple candidate responses to the same question plus a preference ranking or score.”
- Evaluation: The goal is to quantify capability. Evaluation data must be strictly isolated from the training set to avoid data leakage that inflates metrics.
A common misconception is treating fine-tuning data as a scaled-down version of pre-training data. In reality, the two differ enormously in structure, length distribution, and annotation methods, and mixing them will noticeably slow convergence.
2. Six Major Sources of General-Purpose Corpus
2.1 Web Text
Web pages are the largest share of pre-training corpus, covering encyclopedias, news, forums, Q&A sites, and technical blogs. Their value lies in timeliness and topical breadth, but raw web pages contain heavy noise and require handling of boilerplate text, navigation bars, ads, and repeated passages.
2.2 Books and Long-Form Text
Books provide structurally complete long-range narrative and rigorous argumentation, and are key to improving long-context understanding and logical coherence. Because of copyright constraints, practice typically relies on works already in the public domain or corpora for which authorization has been obtained.
2.3 Code Corpus
Code data yields clear gains in reasoning ability, structured output, and tool-calling capability. Typical content includes source code in mainstream programming languages, comments, configuration files, and natural-language descriptions of command lines. License identification is required during use to avoid introducing code under restrictive licenses.
2.4 Multilingual and Cross-Lingual Corpus
Multilingual capability depends on the coverage and quality of non-target-language corpora. When low-resource languages lack sufficient data, language confusion and degradation are likely, so language identification is needed for precise routing, along with a guaranteed proportion for high-priority languages such as Chinese.
2.5 Academic and Professional Text
Papers, patents, standards documents, and textbooks are high-density knowledge corpora that significantly help with professional Q&A and terminology accuracy. Their formats are complex (formulas, tables, references), and parsing quality directly determines usability.
2.6 Multimodal Corpus
Image-text pairs, video subtitles, and transcribed audio are used to build vision-language or speech capabilities. The key metric for image-text pairs is how faithfully the description relates to the image; noisy pairings induce hallucination.
3. From Raw Data to Trainable Corpus: Seven Essential Steps
- Extraction and main-text detection: Extract the main body text from raw markup files and remove boilerplate and repeated blocks.
- Quality filtering: Combine rules (length, symbol ratio, stopword ratio) with a lightweight classifier score, and discard low-information text.
- Deduplication: Includes document-level exact deduplication, paragraph-level near deduplication, and cross-source comparison. Duplicate data causes memorization and amplifies privacy and copyright risk.
- Sensitive and harmful content filtering: Combine keywords, classification models, and manual spot checks to handle pornographic, violent, privacy-invasive, and illegal content.
- Privacy desensitization: Identify and replace phone numbers, ID numbers, emails, addresses, and similar items.
- Tokenization and packing: Use a unified tokenizer, pack text into training samples of fixed length, and record document boundaries to support attention isolation.
- Version and lineage management: Record the source, processing operators, version number, and checksum for every batch of data to ensure experiments are reproducible.
A schematic processing pipeline can be abstracted as:
def build_corpus(raw_docs):docs = [extract_main_text(d) for d in raw_docs] # Main-text extractiondocs = [d for d in docs if quality_score(d) > 0.6] # Quality filteringdocs = dedup(docs, method="minhash", threshold=0.8) # Near deduplicationdocs = [desensitize(d) for d in docs] # Privacy desensitizationreturn tokenize_and_pack(docs, seq_len=4096) # Tokenization and packing
4. Data Mixing and Scheduling: The Variables That Decide Results
There is no universal answer for data mixing, but several widely accepted principles apply. First, high-quality sources need to be sampled repeatedly for several rounds; too many repetitions trigger overfitting and memorization, so the inflection point in validation loss should be monitored. Second, a moderate amount of code and math corpus improves general reasoning performance, but too high a proportion squeezes out the natural-language distribution. Third, gradually raising the proportion of high-quality and instruction-style data in the later stage of training is usually more stable than uniform sampling throughout. Fourth, Chinese corpus must be guaranteed a sufficient proportion and adequate cleaning intensity, otherwise mixed Chinese-English output is likely.
From an engineering standpoint, it is advisable to maintain a “data recipe” configuration that explicitly declares each source’s proportion, sampling weights, and repetition rounds, and binds it to the model version for traceability and ablation experiments.
5. Compliance and Risk Control
Data compliance must be designed up front rather than patched afterward. Key points include: prioritize corpora with clear authorization or in the public domain; respect site terms and access-rate limits when crawling; maintain a ledger of data sources and retain authorization records; apply minimal collection and desensitization for personal information; and run leakage checks on evaluation sets. For enterprise deployment, object storage can archive raw data, message queues can decouple processing tasks, container platforms can host cleaning and training workloads, and logging, monitoring, and alerting services can track pipeline health. General-purpose capabilities from cloud providers such as Baidu AI Cloud typically cover these areas.
6. Conclusion
Building datasets for large language models is a systems engineering effort: stage objectives determine data shape, source diversity determines breadth of capability, cleaning and deduplication set the quality floor, mixing strategy determines final results, and the compliance system determines whether the effort can be sustained long term. Make this chain solid, and improvements in model capability become predictable and reproducible.
