The Stack is an open dataset of permissively licensed source code released by the BigCode project, a collaboration led by Hugging Face and ServiceNow, to support the transparent pretraining of code language models. In the field of training data for artificial intelligence, it is one of the reference examples of a large, documented and governed pretraining corpus built from public software repositories.
The dataset matters because it combines scale with an explicit data governance process: license filtering, near-deduplication, an opt-out mechanism for developers and gated access with terms of use. Models such as SantaCoder, StarCoder and StarCoder2 were trained on curated subsets of it, which makes The Stack a common baseline when researchers compare code pretraining data.
How The Stack dataset was built
The Stack was assembled by collecting public repositories, detecting their licenses and keeping only files under permissive licenses such as MIT, Apache 2.0 and the BSD family. Repositories under copyleft licenses such as the GPL, or with no detectable license, were excluded, because the goal was a corpus that could be redistributed and used for training with fewer legal uncertainties.
After license filtering, the pipeline applied exact and near-deduplication. Exact duplicates were removed by hashing file contents, while near-duplicates were found with MinHash and locality-sensitive hashing, which group files whose token sets overlap strongly. The BigCode team reported that near-deduplication improved downstream model quality noticeably, a finding consistent with wider research on training data deduplication.
The following table summarizes the main stages of the construction pipeline and what each stage protects against.
| Stage | Method | Purpose |
|---|---|---|
| Collection | Public repositories from GitHub (v1) or Software Heritage (v2) | Broad coverage of real-world code |
| License detection | Automated license file and header analysis | Keep only permissively licensed files |
| Exact deduplication | Content hashing | Remove identical copies of files |
| Near-deduplication | MinHash with locality-sensitive hashing | Reduce memorization and wasted compute |
| Opt-out processing | Removal of repositories on request | Respect developer consent |
Versions and scale of The Stack
The dataset exists in several versions, and the version number matters when a paper or model card cites it. The first release in late 2022 contained about 3 TB of code in 30 programming languages; version 1.1 and later updates widened coverage to more than 300 languages and processed opt-out requests. The Stack v2, released in 2024, was rebuilt on top of the Software Heritage archive and is an order of magnitude larger.
| Release | Source archive | Approximate size | Main model trained on it |
|---|---|---|---|
| The Stack v1.0 | GitHub repositories | About 3 TB, 30 languages | SantaCoder (subset) |
| The Stack v1.2 | GitHub repositories | About 6 TB raw, 350+ languages | StarCoder (filtered subset) |
| The Stack v2 | Software Heritage | Tens of TB, 600+ languages | StarCoder2 |
Size figures differ between the raw, deduplicated and training views of each release, so they should be read as orders of magnitude. The model training sets, such as StarCoderData, are much smaller curated subsets that also add GitHub issues, Jupyter notebooks and commit messages, and apply personal data redaction.
Governance, consent and licensing
The Stack is notable for treating consent and provenance as part of the dataset design. Developers can search whether their code is included and file an opt-out request; later releases remove those repositories, and users of the dataset are asked to switch to the newest version so that opt-outs propagate to future models.
- Gated access: users accept terms of use on the hosting platform before downloading.
- License metadata: each file keeps its detected license so downstream users can honor attribution.
- Personal data handling: training subsets apply detection and redaction of emails, keys and names.
- Documentation: a datasheet describes sources, filters and known limitations.
These measures reduce risk but do not remove it. License detection is imperfect, permissive licenses still require attribution in many cases, and an opt-out only affects models trained after the removal. Teams using the dataset still need their own review of training data licensing.
How The Stack compares with other pretraining corpora
The Stack is a code-specific pretraining corpus, which distinguishes it from general web corpora that contain code only incidentally. The table below places it next to related datasets from the same field.
| Corpus | Content | Licensing approach | Typical use |
|---|---|---|---|
| The Stack | Source code, 300+ languages | Permissive licenses only, opt-out | Code model pretraining |
| The Pile | Mixed text with a GitHub slice | Heterogeneous, not license filtered | General language models |
| Common Crawl | Raw web pages | No license filtering | Base material for web corpora |
| RedPajama | Web, books, code, papers | Mixed, code from GitHub subset | Open reproduction of LLM data mixes |
In practice, general language models often mix a code corpus with web text, because code improves reasoning on structured tasks. The Stack frequently supplies that code component in open data mixtures.
Practical use and known limitations
Researchers use The Stack for pretraining code models, building evaluation contamination checks and studying language distribution in open source. Because the data is skewed toward popular languages, teams usually resample or cap high-volume languages such as JavaScript, Java and Python to protect smaller ones.
| Issue | Cause | Mitigation |
|---|---|---|
| Benchmark contamination | Test solutions present in public repositories | Decontaminate against evaluation sets |
| Low-quality files | Autogenerated code, minified files, data blobs | Heuristic quality filters |
| Language imbalance | Long-tail distribution of languages | Per-language sampling weights |
| Leaked secrets | Keys and credentials committed by developers | Secret and PII redaction |
A common misconception is that permissive licensing makes the data risk-free. The dataset still contains outdated, vulnerable or insecure code, and models trained on it can reproduce those patterns, so security review of generated code remains necessary.
Another limitation is temporal drift. A snapshot reflects the libraries, APIs and coding conventions that were common when it was collected, so a model trained only on an older release may suggest deprecated functions or outdated idioms. Teams that need current behavior usually refresh the data with a newer release or add a recent, separately licensed supplement.
Explained without jargon
The Stack is a giant library of program code. It was gathered from public projects that anyone can read online. Its builders kept only code whose owners allow reuse.
AI systems that write code need to read huge amounts of code first. The Stack is that reading material. It also removes copies of the same file and lets developers ask to have their work taken out. The key idea is simple: useful training data that is also documented and fair.
A typical use case
A university research group wants to train a small code completion model for scientific Python and Julia. Instead of scraping repositories themselves, the team requests access to The Stack v2, accepts the terms of use and downloads only the language subsets they need. They apply near-deduplication again within their selection, remove notebooks with large embedded outputs and decontaminate the data against the benchmarks they plan to report.
The resulting training set is about 40 billion tokens. Because the source, version and filters are documented, reviewers can reproduce the data pipeline and check that opted-out repositories are absent. The group publishes its model with a datasheet that names the exact release, which makes the results comparable with other models trained on the same corpus.