Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
parquet
Languages:
English
Size:
10K - 100K
ArXiv:
License:
File size: 6,965 Bytes
f8f1f72 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | ---
license: other
language:
- en
pretty_name: Pytorch Code 50K
size_categories:
- 10K<n<100K
tags:
- code
- python
- pytorch
- deep-learning
- beta
task_categories:
- text-generation
---
# ⚠️ Pytorch-Code-50K — BETA
> **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.*
|