LLM Training Datasets: Common Corpus Types and Construction Practices
This article explains why training data determines the capability ceiling of a large language model, reviews the main corpus types used for general-purpose LLM training, and outlines key practices for licensing, data processing, deduplication, versioning, and traceability. It also describes a typical nine-stage data pipeline and includes Python examples for heuristic filtering, exact deduplication, and manifest verification.
Why Training Data Sets the Ceiling
Pretraining is fundamentally about letting a model learn statistical regularities and knowledge distributions from language, and those patterns come entirely from the training corpus. The corpus determines what the model can learn, how stable that learning is, and what biases it will carry. The industry usually evaluates training data from three dimensions:
- Scale: The total token count determines the range of linguistic phenomena the model can encounter.
- Diversity: Coverage of domains, genres, languages, and text lengths determines the model’s generalization ability.
- Quality: Noise, duplication, and low-information-density text reduce training efficiency and can introduce false facts or harmful content.
The data mix also matters. The proportion of code data affects programming performance and structured reasoning; the proportion of multilingual data affects cross-lingual transfer. A data team should therefore define target capabilities first and derive the corpus composition from those goals, rather than collect data first and decide its use later.
Common Types of General Corpora
1. Web Text
Web text has the broadest topic coverage and is the main corpus source for many general-purpose models. Its main problem is noise: pages often contain navigation bars, ad templates, copyright notices, and machine-generated low-quality content. Processing requires extracting the main body text, removing templated segments, and then stratifying by language and quality.
2. Encyclopedia and Knowledge Texts
Encyclopedia-style and knowledge-base texts have clear structure and high factual density, making them useful for supplementing common-sense and entity knowledge. Before training, check the update timestamps and revision history of entries to avoid outdated or tampered content.
3. Books and Long-Form Texts
Books and long reports provide long-distance semantic coherence and help improve long-context understanding. Licensing for this type of data is complex, so each item’s usage permission must be verified individually. It should not be assumed that all such content can be collected freely.
4. Academic and Technical Literature
Papers, technical reports, and standards documents contain specialized terminology, formulas, and rigorous reasoning chains. Because they often include formulas, tables, and reference sections, they require dedicated layout parsing and symbol normalization.
5. Open-Source Code
Code data clearly helps with programming, logical reasoning, and structured output. When using open-source repositories, review the license type of each repository and filter out files containing secrets, credentials, or personal information.
6. Dialogue and Q&A Text
Forum Q&A and dialogue records help models learn conversational tone and question formulation. This type of data tends to contain more personal information and inappropriate content, so stricter redaction and safety filtering are needed.
7. Multilingual and Parallel Corpora
Multilingual corpora support cross-lingual transfer. Training must control the proportion of each language; otherwise, resource-rich languages can crowd out the learning space of low-resource languages.
8. Synthetic and Instruction Data
Instruction data, whether manually written or generated by models, can strengthen specific task capabilities. If synthetic data accounts for too large a share, model outputs may become homogenized and source-model biases may be amplified. The ratio should therefore be controlled and continuously evaluated.
Compliance and Licensing for Data Sources
Data compliance is a prerequisite for training-data work. Common concerns include:
- Copyright and licenses: Confirm the license scope of each data batch, and distinguish commercial use, research-only use, and attribution requirements.
- Personal information: Identify and redact names, phone numbers, identity document numbers, and addresses, while following applicable local privacy regulations.
- Collection rules: Respect target sites’ access policies and rate limits, and do not bypass access controls.
- Data ledger: Record the source, license status, collection time, processing version, and owner for every data source.
The ledger is the basis for later audits, issue tracing, and compliance reporting. Without it, if a licensing problem is found in one data batch, the team may struggle to identify which training versions are affected.
Building a Training Data Pipeline
A mature data pipeline usually includes the following stages:
- Collection and extraction: Acquire raw files, extract main text, and preserve necessary metadata.
- Format normalization: Unify encoding, clean control characters, and normalize whitespace and punctuation.
- Language identification: Bucket documents by language so proportions can be controlled later.
- Heuristic filtering: Remove obvious low-quality text using rules such as minimum text length, symbol ratio, and duplicate-line ratio.
- Quality scoring: Use classifier models or rule systems to score documents and keep high-quality samples.
- Deduplication: Run exact deduplication first, then approximate deduplication, to reduce duplicate interference.
- Safety and privacy filtering: Detect and handle harmful content and personal information.
- Decontamination: Detect overlap between training data and evaluation sets to prevent inflated benchmark scores.
- Mixing and sampling: Set proportions according to target capabilities and generate the final training set.
The following example shows basic heuristic filtering and exact deduplication:
import hashlibimport redef normalize(text: str) -> str:"""Normalize case and whitespace to help detect duplicate text."""text = text.lower()return re.sub(r"\s+", " ", text).strip()def heuristic_filter(text: str, min_chars: int = 200,max_symbol_ratio: float = 0.1) -> bool:"""Remove very short texts and texts with too many symbols."""if len(text) < min_chars:return Falsesymbols = sum(1 for c in text if not (c.isalnum() or c.isspace()))return symbols / len(text) <= max_symbol_ratiodef dedup_exact(docs):"""Exact deduplication based on a hash of normalized text."""seen = set()for doc in docs:key = hashlib.sha256(normalize(doc).encode("utf-8")).hexdigest()if key not in seen:seen.add(key)yield docif __name__ == "__main__":raw = ["Sample text " * 60, "Sample text " * 60, "Too short"]kept = [d for d in dedup_exact(raw) if heuristic_filter(d)]print(len(kept)) # Output: 1
Exact deduplication only identifies identical text. Approximate deduplication commonly uses locality-sensitive hashing or MinHash to measure similarity and can find copies with only minor edits. The threshold should be tuned experimentally: too low a threshold can delete valuable text, while too high a threshold makes deduplication ineffective.
Integrity and Traceability
If training data is corrupted, tampered with, or lost during storage migration, model results may become impossible to reproduce. The solution is to establish verifiable integrity records for the data.
Common practices include:
- Compute a hash for every data file and generate a manifest file.
- Bind each training run to a unique data version, and save the manifest and configuration with that run.
- Store multiple replicas on object storage or a distributed file system, and inspect them periodically.
- Write a data card documenting data sources, processing steps, known limitations, and intended use.
The following code generates a manifest and verifies file integrity:
import hashlibimport jsonfrom pathlib import Pathdef sha256_of(path: Path) -> str:h = hashlib.sha256()with path.open("rb") as f:for chunk in iter(lambda: f.read(1 << 20), b""):h.update(chunk)return h.hexdigest()def build_manifest(data_dir: str) -> dict:root = Path(data_dir)return {str(p.relative_to(root)): sha256_of(p)for p in sorted(root.rglob("*.jsonl"))}def verify_manifest(data_dir: str, manifest_file: str) -> list:expected = json.loads(Path(manifest_file).read_text(encoding="utf-8"))actual = build_manifest(data_dir)# Return a list of files whose hash is missing or inconsistentreturn sorted(k for k in set(expected) | set(actual)if expected.get(k) != actual.get(k))
The manifest should be versioned together with the data. Running verification before training starts can catch corrupted data before it reaches the training stage.
Common Problems and Practical Recommendations
- Repeated data causing memorization: High-frequency duplicate samples can make the model memorize content verbatim. Deduplication and sampling caps reduce this risk.
- Imbalanced data mix: When one domain dominates, learning capacity for other capabilities is squeezed. Adjust the mix regularly according to target capabilities.
- Evaluation leakage: If original evaluation questions appear in the training corpus, benchmark scores lose their meaning. Perform overlap detection before model release.
- Synthetic data self-loop: Training repeatedly on model-generated data can reduce diversity. Sufficient real data should be retained.
- Missing quality evaluation: If only data volume is checked without sampling, problems may not be discovered until model behavior becomes abnormal. Each version should include sampled manual review, with findings recorded.
In summary, general corpus selection should start from target capabilities, complete licensing review first, and then use a standardized pipeline for cleaning, deduplication, and mixing. Manifests and data cards should be maintained to preserve traceability. This workflow is not expensive, but it significantly reduces downstream rework and compliance risk.
