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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
pretty_name: Pytorch Code 50K
|
| 6 |
+
size_categories:
|
| 7 |
+
- 10K<n<100K
|
| 8 |
+
tags:
|
| 9 |
+
- code
|
| 10 |
+
- python
|
| 11 |
+
- pytorch
|
| 12 |
+
- deep-learning
|
| 13 |
+
- beta
|
| 14 |
+
task_categories:
|
| 15 |
+
- text-generation
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# ⚠️ Pytorch-Code-50K — BETA
|
| 19 |
+
|
| 20 |
+
> **Status: BETA.** This is an early, unpolished release. The data is real but
|
| 21 |
+
> **unaudited**: it has not been manually reviewed, re-verified against upstream,
|
| 22 |
+
> or checked for toxic/low-quality content beyond the filters listed below. The
|
| 23 |
+
> sample may change between releases. **Use at your own risk and do not treat it
|
| 24 |
+
> as a benchmark.**
|
| 25 |
+
|
| 26 |
+
## Overview
|
| 27 |
+
|
| 28 |
+
**Pytorch-Code-50K** is a collection of **~50,000 Python source files that use the
|
| 29 |
+
PyTorch ecosystem**, extracted from BigCode's
|
| 30 |
+
[**The Stack**](https://huggingface.co/datasets/bigcode/the-stack)
|
| 31 |
+
(Python subset).
|
| 32 |
+
|
| 33 |
+
It is intended as a lightweight, easy-to-consume corpus for:
|
| 34 |
+
|
| 35 |
+
- fine-tuning and pre-training small code models on PyTorch idioms,
|
| 36 |
+
- studying how PyTorch APIs are actually used in the wild,
|
| 37 |
+
- retrieval / RAG over real PyTorch examples,
|
| 38 |
+
- quick prototyping where a full 3 TB dataset is overkill.
|
| 39 |
+
|
| 40 |
+
## Source
|
| 41 |
+
|
| 42 |
+
| | |
|
| 43 |
+
|---|---|
|
| 44 |
+
| **Upstream** | [bigcode/the-stack](https://huggingface.co/datasets/bigcode/the-stack) (`data/python`) |
|
| 45 |
+
| **Curated by** | Monster-Code |
|
| 46 |
+
| **Language** | Python |
|
| 47 |
+
| **Domain** | PyTorch / deep learning code |
|
| 48 |
+
| **Size** | ~50,000 files |
|
| 49 |
+
| **Format** | Parquet (one row per file) |
|
| 50 |
+
| **Release** | BETA v0.1 |
|
| 51 |
+
|
| 52 |
+
> The Stack is a collection of source code from repositories with various
|
| 53 |
+
> licenses. Any use of all or part of the code in this dataset must abide by the
|
| 54 |
+
> terms of the original licenses, including attribution clauses when relevant.
|
| 55 |
+
> Provenance (`repo`, `path`, `license`, `sha`) is preserved so you can
|
| 56 |
+
> attribute and filter correctly.
|
| 57 |
+
|
| 58 |
+
## Selection criteria
|
| 59 |
+
|
| 60 |
+
A file is included when **all** of the following hold:
|
| 61 |
+
|
| 62 |
+
1. It comes from the Python subset of The Stack.
|
| 63 |
+
2. Its source contains a top-level import from the PyTorch ecosystem, matched
|
| 64 |
+
with this regex:
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
^[ \t]*(?:import|from)[ \t]+(
|
| 68 |
+
torch(vision|audio|text|arrow|metrics|_geometric|_scatter|_sparse|
|
| 69 |
+
_cluster|_spline_conv|_xla|_cpp|_jit|_onnx|_fx)?
|
| 70 |
+
| pytorch_lightning
|
| 71 |
+
| lightning(\.pytorch)?
|
| 72 |
+
| skorch
|
| 73 |
+
)\b
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
3. Its length is between **200 and 200,000 characters**.
|
| 77 |
+
4. Its content hash is unique within the sample (exact duplicates removed).
|
| 78 |
+
|
| 79 |
+
### Sampling
|
| 80 |
+
|
| 81 |
+
The Stack stores files grouped by repository, so a naive "first 50K" pass would
|
| 82 |
+
be dominated by whichever repositories sort first. Instead, `update.py`
|
| 83 |
+
**reservoir-samples** over a randomly shuffled subset of the source shards, so
|
| 84 |
+
the sample is approximately uniform over the scanned shards rather than biased
|
| 85 |
+
toward any one repository. Pass `--seed` to reproduce or vary the sample.
|
| 86 |
+
|
| 87 |
+
## Dataset schema
|
| 88 |
+
|
| 89 |
+
| Column | Type | Description |
|
| 90 |
+
|---|---|---|
|
| 91 |
+
| `content` | `string` | The full source code of the file. |
|
| 92 |
+
| `repo` | `string` | Repository identifier (`owner/name`) when available. |
|
| 93 |
+
| `path` | `string` | File path within the repository, when available. |
|
| 94 |
+
| `license` | `string` | Detected license(s), comma-separated if multiple. |
|
| 95 |
+
| `size` | `int64` | File size in bytes. |
|
| 96 |
+
| `sha` | `string` | Content hash from the source dataset. |
|
| 97 |
+
| `lang` | `string` | Language tag (always `python` here). |
|
| 98 |
+
| `ext` | `string` | File extension (`.py`). |
|
| 99 |
+
|
| 100 |
+
> Source column names vary between The Stack releases; `update.py` maps them
|
| 101 |
+
> defensively. Columns that are missing upstream are emitted as empty strings.
|
| 102 |
+
|
| 103 |
+
## Usage
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
from datasets import load_dataset
|
| 107 |
+
|
| 108 |
+
ds = load_dataset("Monster-Code/Pytorch-Code-50K", split="train")
|
| 109 |
+
print(ds)
|
| 110 |
+
# Dataset({
|
| 111 |
+
# features: ['content', 'repo', 'path', 'license', 'size', 'sha', 'lang', 'ext'],
|
| 112 |
+
# num_rows: 50000
|
| 113 |
+
# })
|
| 114 |
+
|
| 115 |
+
# Only permissively licensed files
|
| 116 |
+
ds = ds.filter(lambda x: "mit" in x["license"].lower())
|
| 117 |
+
|
| 118 |
+
# A single training example
|
| 119 |
+
print(ds[0]["content"][:500])
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
Stream it instead of downloading everything:
|
| 123 |
+
|
| 124 |
+
```python
|
| 125 |
+
ds = load_dataset("Monster-Code/Pytorch-Code-50K", split="train", streaming=True)
|
| 126 |
+
for row in ds:
|
| 127 |
+
...
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
## How it was built
|
| 131 |
+
|
| 132 |
+
```bash
|
| 133 |
+
pip install huggingface_hub pyarrow
|
| 134 |
+
|
| 135 |
+
# accept the terms of the source dataset once:
|
| 136 |
+
# https://huggingface.co/datasets/bigcode/the-stack
|
| 137 |
+
|
| 138 |
+
python update.py # full 50K build
|
| 139 |
+
python update.py --dry-run # scan and report, push nothing
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
`update.py`:
|
| 143 |
+
|
| 144 |
+
1. lists the Python parquet shards of `bigcode/the-stack`,
|
| 145 |
+
2. shuffles them with a seed and downloads them through the HF cache
|
| 146 |
+
(re-runs are incremental),
|
| 147 |
+
3. filters by the PyTorch import regex and length bounds,
|
| 148 |
+
4. reservoir-samples 50,000 unique files,
|
| 149 |
+
5. writes local parquet shards and pushes them plus this card to the Hub.
|
| 150 |
+
|
| 151 |
+
The script is idempotent and resumable: source shards are cached under `cache/`
|
| 152 |
+
and already-downloaded shards are skipped.
|
| 153 |
+
|
| 154 |
+
## Known limitations (BETA)
|
| 155 |
+
|
| 156 |
+
- **Not exhaustively filtered.** Files may contain security-sensitive code,
|
| 157 |
+
secrets committed to version control, or license-incompatible snippets. No
|
| 158 |
+
manual review has been performed.
|
| 159 |
+
- **Import-based selection.** Files that use PyTorch only through a wrapper
|
| 160 |
+
(e.g. `transformers` without importing `torch`) are **not** included. Files
|
| 161 |
+
that mention `import torch` in a docstring/comment may be included.
|
| 162 |
+
- **Sampling bias.** The sample is uniform over a random subset of shards, not
|
| 163 |
+
over all PyTorch files on GitHub. Repositories whose code is heavily
|
| 164 |
+
duplicated may still be over-represented.
|
| 165 |
+
- **Duplicates.** The Stack is not deduplicated, so the same file can appear
|
| 166 |
+
more than once (across repositories) and very similar files are common.
|
| 167 |
+
- **License metadata is noisy.** `license` comes from upstream detection and
|
| 168 |
+
may be missing, wrong, or list several licenses.
|
| 169 |
+
- **Beta may change.** Rows and schema may change in future releases; pin a
|
| 170 |
+
revision if you need reproducibility.
|
| 171 |
+
|
| 172 |
+
## Terms of use
|
| 173 |
+
|
| 174 |
+
This dataset is distributed for research purposes. You are responsible for
|
| 175 |
+
complying with the licenses of the original repositories. By using this dataset
|
| 176 |
+
you agree to the [Terms of Use of The Stack](https://huggingface.co/datasets/bigcode/the-stack#terms-of-use-for-the-stack).
|
| 177 |
+
|
| 178 |
+
## Citation
|
| 179 |
+
|
| 180 |
+
If you use this dataset, please cite The Stack and this release:
|
| 181 |
+
|
| 182 |
+
```bibtex
|
| 183 |
+
@misc{pytorch-code-50k,
|
| 184 |
+
title = {Pytorch-Code-50K (BETA)},
|
| 185 |
+
author = {Monster-Code},
|
| 186 |
+
year = {2026},
|
| 187 |
+
howpublished = {\url{https://huggingface.co/datasets/Monster-Code/Pytorch-Code-50K}}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
@article{BigCodeTheStack,
|
| 191 |
+
title = {The Stack: 3 TB of permissively licensed source code},
|
| 192 |
+
author = {BigCode Project},
|
| 193 |
+
journal = {arXiv preprint arXiv:2211.15533},
|
| 194 |
+
year = {2022}
|
| 195 |
+
}
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
## Contact
|
| 199 |
+
|
| 200 |
+
Questions, takedown requests, or complaints about specific files:
|
| 201 |
+
open a discussion on the dataset repo or contact the Monster-Code maintainers.
|
| 202 |
+
|
| 203 |
+
---
|
| 204 |
+
|
| 205 |
+
*This is a **BETA** release. Expect rough edges. Please report issues on the
|
| 206 |
+
dataset's Hugging Face page.*
|