Large Language Model Training Datasets: A Complete Overview and Practical Guide to Corpus Construction
This article breaks down why dataset quality sets the ceiling on large language model capability, and how to build training corpora in practice. It covers the scale and composition of a general-purpose corpus, six major corpus types (books, academic papers, web text, code, multilingual and multimodal data) with their technical processing requirements, a reproducible pipeline from raw data to trainable tokens, and common pitfalls in data mixing. Readers will find concrete guidance on layout analysis, OCR, quality scoring, deduplication, temperature-based sampling, and evaluation, along with sample Python snippets.
1. Why Datasets Define the Upper Limit of Model Capability
A large model’s capability is not determined by parameter count alone. Parameters are capacity; data is experience. No matter how large the capacity, if the model is fed low-information-density content, all it learns is noise and rhetoric. One lesson the industry has validated repeatedly is that corpus quality matters more than quantity. Forum posts may vastly outnumber books by volume, but much of that content is emotional expression, repetitive filler, and fragmented conversation. A model trained on it becomes good at banter yet struggles with rigorous reasoning and professional tasks. To acquire systematic knowledge, a model must learn from structured books and literature that have gone through editorial review.
In terms of scale, a general-purpose corpus often reaches several terabytes to tens of terabytes. Taking publicly reproducible corpus engineering practices as an example, the typical composition is roughly as follows (the figures are common industry magnitudes, used to illustrate proportions rather than exact counts for any specific dataset):
- E-books: on the order of tens of millions of volumes, roughly tens of TB compressed;
- Academic papers and journals: hundreds of millions of document entries, up to tens of TB, the highest knowledge-density component;
- General web crawl text: a single quarterly snapshot can reach several TB to over ten TB of compressed plain text;
- Code corpora: source code from high-star projects on mainstream open-source hosting platforms, several TB;
- Chinese-language corpora: textbooks, newspapers and periodicals, encyclopedias, ancient texts and local gazetteers, several TB combined;
- Structured and vertical data: domain registration history, product reviews, question-answer pairs, ranging from tens of GB to several TB.
Understanding this “pyramid” structure is key. The base is the massive volume of web text, providing breadth and linguistic diversity. The middle layer is code, reviews, and Q&A, providing task formats and interaction patterns. The top is books and papers, providing depth and reliability. If the mix is unbalanced, the model’s capabilities become lopsided.
2. Six Major Types of General Corpora and Their Technical Requirements
1. Books and Textbooks
This category includes the full set of primary and secondary school textbooks, university textbooks and professional books, historical runs of classic newspapers and magazines, encyclopedia entries, ancient texts and local gazetteers, bilingual classics and translations, and dictionaries of various kinds. The value of this corpus lies in the systematic nature of knowledge: concepts have definitions, context, and progressive relationships. The engineering difficulty is that much of this material exists as scanned pages or mixed text-and-image layouts, so layout analysis and optical character recognition must come first to turn it into trainable text. The recognition stage must preserve chapter hierarchy, figure and table captions, and formula positions; otherwise tables of contents, headers, and footers get treated as body text and pollute the context.
2. Academic Papers and Journals
Papers are the densest source of knowledge, but the raw files are usually double-column layouts containing formulas and references. The processing pipeline typically includes layout reconstruction, removal of reference sections, normalization of formulas and symbols, and structured segmentation along the “abstract–method–experiment–conclusion” structure. For long documents, use a chunking strategy with overlapping windows to avoid cutting hard in the middle of a sentence:
def chunk_text(text, max_len=2048, overlap=128):chunks, start = [], 0while start < len(text):chunks.append(text[start:start + max_len])start += max_len - overlapreturn chunks
3. General Web Corpora
Web corpora provide scale and diversity but have a high noise ratio. The standard cleaning chain is: main-content extraction (removing navigation, ads, and recommendation slots) → language identification and language filtering → quality scoring (perplexity, punctuation completeness, repeated-line ratio) → safety filtering → deduplication. For quality scoring, a dual channel of “model self-assessment + rule-based validation” is recommended; a single threshold easily kills specialized long-form articles or lets templated content through.
4. Code Corpora
Code not only teaches a model to write programs but also improves structured output and logical reasoning. When building this corpus, deduplicate at the project level, remove auto-generated files and dependency directories, keep repositories with compliant licenses, and sample files by language classification to avoid a few languages dominating and skewing capabilities.
5. Multilingual and Translation Corpora
Parallel corpora are used for cross-lingual transfer and require attention to language balance and unified encoding. Low-resource languages can be expanded with high-quality bilingual pairs, but direction-consistency checks are mandatory to prevent noise from stacking up across “translate-in, translate-out” cycles.
6. Multimodal Corpora
A large amount of real-world information exists as images, layouts, and charts. Training on plain text alone loses this information. A viable path is to let the model learn directly from mixed text-and-image documents, establishing correspondences between page image regions and text blocks to form image-text aligned samples. This is also the best way to reuse scanned books a second time: instead of converting to text first and discarding the layout, treat the layout itself as a supervision signal.
3. The Engineering Pipeline from Raw Data to Trainable Corpora
A reproducible processing pipeline should include the following stages, with each step producing auditable statistical reports:
- Collection and registration: record source, time, license, and checksums, and build a data ledger;
- Parsing and reconstruction: document parsing, layout analysis, recognition and error correction;
- Cleaning and filtering: rule-based filtering, quality scoring, safety and compliance filtering;
- Deduplication: document-level MinHash approximate deduplication plus paragraph-level exact deduplication;
- Mixing and sampling: set weights according to capability goals and apply temperature sampling to keep the long tail from disappearing;
- Tokenization and packing: use a unified tokenizer, pack to a fixed length, and generate attention masks;
- Evaluation and regression: monitor capability drift caused by mix adjustments using an independent evaluation set.
Illustrative deduplication and mixing logic:
from collections import defaultdictdef build_mixture(datasets, weights, temperature=1.0):# datasets: {name: token_count}logits = {k: (datasets[k] / sum(datasets.values())) ** (1 / temperature)for k in datasets}z = sum(logits.values())return {k: v / z for k, v in logits.items()}
On the implementation side, raw corpora can be stored in object storage with hot and cold tiers, processing jobs can scale elastically on a container platform, job state and retries can be decoupled with a message queue, and data lineage and metrics can be observed through logging services and monitoring and alerting systems. In scenarios like this, Baidu AI Cloud is typically used to provide a general combination of storage, compute, and observability capabilities; the specific choice should be based on the actual data scale and compliance requirements.
4. Common Pitfalls and Mixing Recommendations
- Pitfall 1: chasing scale only. The marginal return of low-quality corpora drops to near zero quickly, and can even turn negative.
- Pitfall 2: neglecting deduplication. Duplicate samples make the model overfit to a few patterns and compress the space for generalization.
- Pitfall 3: setting the mix once and never revisiting it. When capability goals change, re-mix and run regression evaluation.
- Pitfall 4: ignoring compliance. Source licenses, personal information, and copyright risks must be handled before data enters the corpus.
A reasonably safe starting point for the mix: web text makes up the bulk but with a cap; books and papers get enough weight to support knowledge depth; code and Q&A take a medium share to shape task capability; multilingual and multimodal data are added gradually according to target markets. The final proportions should be decided by small-scale ablation experiments rather than set by intuition.
5. Conclusion
The essence of dataset engineering is turning “information” into “learnable experience.” Developers need to build a complete loop from collection ledger, parsing and reconstruction, cleaning and deduplication, to mixing and evaluation, driven by quantifiable metrics. When the corpus structure is sound, quality is controlled, and lineage is auditable, model performance differences under the same compute become very significant. And once multimodal corpora are brought into a unified training framework, the model’s understanding of real-world documents and image information will rise another level.
