The Stack · dataset

On this page 7

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.

StageMethodPurpose
CollectionPublic repositories from GitHub (v1) or Software Heritage (v2)Broad coverage of real-world code
License detectionAutomated license file and header analysisKeep only permissively licensed files
Exact deduplicationContent hashingRemove identical copies of files
Near-deduplicationMinHash with locality-sensitive hashingReduce memorization and wasted compute
Opt-out processingRemoval of repositories on requestRespect developer consent
Construction stages of The Stack

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.

ReleaseSource archiveApproximate sizeMain model trained on it
The Stack v1.0GitHub repositoriesAbout 3 TB, 30 languagesSantaCoder (subset)
The Stack v1.2GitHub repositoriesAbout 6 TB raw, 350+ languagesStarCoder (filtered subset)
The Stack v2Software HeritageTens of TB, 600+ languagesStarCoder2
Main releases compared

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.

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.

CorpusContentLicensing approachTypical use
The StackSource code, 300+ languagesPermissive licenses only, opt-outCode model pretraining
The PileMixed text with a GitHub sliceHeterogeneous, not license filteredGeneral language models
Common CrawlRaw web pagesNo license filteringBase material for web corpora
RedPajamaWeb, books, code, papersMixed, code from GitHub subsetOpen reproduction of LLM data mixes
The Stack and related corpora

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.

IssueCauseMitigation
Benchmark contaminationTest solutions present in public repositoriesDecontaminate against evaluation sets
Low-quality filesAutogenerated code, minified files, data blobsHeuristic quality filters
Language imbalanceLong-tail distribution of languagesPer-language sampling weights
Leaked secretsKeys and credentials committed by developersSecret and PII redaction
Common issues when training on The Stack

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.