--- license: other language: - en pretty_name: Pytorch Code 50K size_categories: - 10K **Status: BETA.** This is an early, unpolished release. The data is real but > **unaudited**: it has not been manually reviewed, re-verified against upstream, > or checked for toxic/low-quality content beyond the filters listed below. The > sample may change between releases. **Use at your own risk and do not treat it > as a benchmark.** ## Overview **Pytorch-Code-50K** is a collection of **~50,000 Python source files that use the PyTorch ecosystem**, extracted from BigCode's [**The Stack**](https://huggingface.co/datasets/bigcode/the-stack) (Python subset). It is intended as a lightweight, easy-to-consume corpus for: - fine-tuning and pre-training small code models on PyTorch idioms, - studying how PyTorch APIs are actually used in the wild, - retrieval / RAG over real PyTorch examples, - quick prototyping where a full 3 TB dataset is overkill. ## Source | | | |---|---| | **Upstream** | [bigcode/the-stack](https://huggingface.co/datasets/bigcode/the-stack) (`data/python`) | | **Curated by** | Monster-Code | | **Language** | Python | | **Domain** | PyTorch / deep learning code | | **Size** | ~50,000 files | | **Format** | Parquet (one row per file) | | **Release** | BETA v0.1 | > The Stack is a collection of source code from repositories with various > licenses. Any use of all or part of the code in this dataset must abide by the > terms of the original licenses, including attribution clauses when relevant. > Provenance (`repo`, `path`, `license`, `sha`) is preserved so you can > attribute and filter correctly. ## Selection criteria A file is included when **all** of the following hold: 1. It comes from the Python subset of The Stack. 2. Its source contains a top-level import from the PyTorch ecosystem, matched with this regex: ```python ^[ \t]*(?:import|from)[ \t]+( torch(vision|audio|text|arrow|metrics|_geometric|_scatter|_sparse| _cluster|_spline_conv|_xla|_cpp|_jit|_onnx|_fx)? | pytorch_lightning | lightning(\.pytorch)? | skorch )\b ``` 3. Its length is between **200 and 200,000 characters**. 4. Its content hash is unique within the sample (exact duplicates removed). ### Sampling The Stack stores files grouped by repository, so a naive "first 50K" pass would be dominated by whichever repositories sort first. Instead, `update.py` **reservoir-samples** over a randomly shuffled subset of the source shards, so the sample is approximately uniform over the scanned shards rather than biased toward any one repository. Pass `--seed` to reproduce or vary the sample. ## Dataset schema | Column | Type | Description | |---|---|---| | `content` | `string` | The full source code of the file. | | `repo` | `string` | Repository identifier (`owner/name`) when available. | | `path` | `string` | File path within the repository, when available. | | `license` | `string` | Detected license(s), comma-separated if multiple. | | `size` | `int64` | File size in bytes. | | `sha` | `string` | Content hash from the source dataset. | | `lang` | `string` | Language tag (always `python` here). | | `ext` | `string` | File extension (`.py`). | > Source column names vary between The Stack releases; `update.py` maps them > defensively. Columns that are missing upstream are emitted as empty strings. ## Usage ```python from datasets import load_dataset ds = load_dataset("Monster-Code/Pytorch-Code-50K", split="train") print(ds) # Dataset({ # features: ['content', 'repo', 'path', 'license', 'size', 'sha', 'lang', 'ext'], # num_rows: 50000 # }) # Only permissively licensed files ds = ds.filter(lambda x: "mit" in x["license"].lower()) # A single training example print(ds[0]["content"][:500]) ``` Stream it instead of downloading everything: ```python ds = load_dataset("Monster-Code/Pytorch-Code-50K", split="train", streaming=True) for row in ds: ... ``` ## How it was built ```bash pip install huggingface_hub pyarrow # accept the terms of the source dataset once: # https://huggingface.co/datasets/bigcode/the-stack python update.py # full 50K build python update.py --dry-run # scan and report, push nothing ``` `update.py`: 1. lists the Python parquet shards of `bigcode/the-stack`, 2. shuffles them with a seed and downloads them through the HF cache (re-runs are incremental), 3. filters by the PyTorch import regex and length bounds, 4. reservoir-samples 50,000 unique files, 5. writes local parquet shards and pushes them plus this card to the Hub. The script is idempotent and resumable: source shards are cached under `cache/` and already-downloaded shards are skipped. ## Known limitations (BETA) - **Not exhaustively filtered.** Files may contain security-sensitive code, secrets committed to version control, or license-incompatible snippets. No manual review has been performed. - **Import-based selection.** Files that use PyTorch only through a wrapper (e.g. `transformers` without importing `torch`) are **not** included. Files that mention `import torch` in a docstring/comment may be included. - **Sampling bias.** The sample is uniform over a random subset of shards, not over all PyTorch files on GitHub. Repositories whose code is heavily duplicated may still be over-represented. - **Duplicates.** The Stack is not deduplicated, so the same file can appear more than once (across repositories) and very similar files are common. - **License metadata is noisy.** `license` comes from upstream detection and may be missing, wrong, or list several licenses. - **Beta may change.** Rows and schema may change in future releases; pin a revision if you need reproducibility. ## Terms of use This dataset is distributed for research purposes. You are responsible for complying with the licenses of the original repositories. By using this dataset you agree to the [Terms of Use of The Stack](https://huggingface.co/datasets/bigcode/the-stack#terms-of-use-for-the-stack). ## Citation If you use this dataset, please cite The Stack and this release: ```bibtex @misc{pytorch-code-50k, title = {Pytorch-Code-50K (BETA)}, author = {Monster-Code}, year = {2026}, howpublished = {\url{https://huggingface.co/datasets/Monster-Code/Pytorch-Code-50K}} } @article{BigCodeTheStack, title = {The Stack: 3 TB of permissively licensed source code}, author = {BigCode Project}, journal = {arXiv preprint arXiv:2211.15533}, year = {2022} } ``` ## Contact Questions, takedown requests, or complaints about specific files: open a discussion on the dataset repo or contact the Monster-Code maintainers. --- *This is a **BETA** release. Expect rough edges. Please report issues on the dataset's Hugging Face page.*