Download make_datasheet.py from PiotrSty/code-search-net-python-permissive: direct link, hf CLI and curl.
- Browser
- Download file 5.47 kB
-
https://huggingface.co/datasets/PiotrSty/code-search-net-python-permissive/resolve/main/make_datasheet.py
- Command line
-
hf download hf://datasets/PiotrSty/code-search-net-python-permissive/make_datasheet.py
-
curl -L -o make_datasheet.py https://huggingface.co/datasets/PiotrSty/code-search-net-python-permissive/resolve/main/make_datasheet.py
5.47 kB
| #!/usr/bin/env python | |
| """Generate datasheet.md for the Python permissive dataset from build.json.""" | |
| import json | |
| from pathlib import Path | |
| HERE = Path(__file__).resolve().parent | |
| BUILD = HERE / "code_search_net_python_permissive.build.json" | |
| OUT = HERE / "datasheet.md" | |
| def main(): | |
| b = json.loads(BUILD.read_text(encoding="utf-8")) | |
| cap = json.loads((HERE / "repo_cap.json").read_text(encoding="utf-8")) | |
| rows = b["kept"] | |
| lic = sorted(b["licenses"].items(), key=lambda x: -x[1]) | |
| lic_table = "\n".join( | |
| f"| {k} | {v:,} | {100*v/rows:.1f}% |" for k, v in lic) | |
| top = "\n".join( | |
| f"{i}. `{r}` — {n:,} rows" for i, (r, n) in enumerate(b["top_repos"], 1)) | |
| splits = " · ".join(f"{k} {v:,}" for k, v in b["splits"].items()) | |
| text = f"""# code_search_net_python_permissive — CodeSearchNet Python (permissive only) | |
| Added: 2026-12-05. Release: `None` (working copy, not a release). | |
| ## What the data is | |
| Function-level Python source with its docstring, restricted to repositories whose | |
| audited licence is permissive. | |
| | | | | |
| |---|---| | |
| | Rows (functions) | **{rows:,}** | | |
| | Repositories | **{b['repos']:,}** | | |
| | Characters (`text`) | **{b['chars']:,}** | | |
| | Tokens, tiktoken `cl100k_base` | **{b['tokens']:,}** | | |
| | Parquet | **{b['bytes']:,} bytes** (zstd), 20 columns | | |
| | Splits | {splits} | | |
| | Language | Python (code) + English (docstrings) | | |
| | Not OCR, not translated | yes | | |
| `text` = docstring + `\\n\\n` + code. `id` is | |
| `sha1(repo|path|func_name|sha256(code))[:24]` and is unique. `record_sha256` is | |
| the canonical SHA-256 of the row and ships in the parquet. | |
| ## Where it comes from | |
| - Upstream: [`code-search-net/code_search_net`](https://huggingface.co/datasets/code-search-net/code_search_net), | |
| `python` configuration. | |
| - No intermediary snapshot beyond the official HF dataset; no repository | |
| contents were scraped (only the GitHub licence API was queried). | |
| ## Composition | |
| Licences (rows), from a per-repo audit against the GitHub licence API | |
| (`/repos/{{owner}}/{{repo}}/license`, 2026-12-05): | |
| | SPDX | rows | % | | |
| |---|---:|---:| | |
| {lic_table} | |
| Audit coverage: all {b['repos']:,} retained repositories carry a permissive | |
| SPDX licence; rows from repositories with no | |
| licence or a non-permissive licence were removed ({b['removed_unknown']:,} | |
| unknown, {b['removed_not_permissive']:,} non-permissive). | |
| Largest repositories by rows: | |
| {top} | |
| Row length (`token_count`): min {b['token_min']} · mean {b['token_avg']} · | |
| max {b['token_max']}. Docstrings are non-empty for {b['docstring_nonempty']:,} / | |
| {rows:,} rows. | |
| ## Schema | |
| ``` | |
| id, repo, path, func_name, url, split, language, docstring, code, text, | |
| token_count, doc_chars, code_chars, license_basis, source, added, | |
| record_sha256, license, license_class, license_source | |
| ``` | |
| ## Collection, normalization, filtering | |
| Committed scripts: `build_csn_go.py` (shards → records), `audit_licenses.py` | |
| (GitHub licence API), `join_go.py` (join + permissive filter), | |
| `finalize_go.py`, `make_datasheet.py`. | |
| - Code ≥ 20 chars; text ≥ 100 chars. | |
| - Exact-code SHA-256 dedup (global). | |
| - Keep only repositories with a detected permissive SPDX licence | |
| (`license_class == "permissive"`). | |
| - Audit cap: {cap['audited_repos']:,} repositories audited | |
| ({100*cap['audited_rows']/cap['total_rows']:.1f}% of rows); | |
| {cap['not_audited_repos']:,} selected repositories | |
| ({cap['not_audited_rows']:,} rows) were not audited before the rate-limit | |
| window closed and are dropped; the {cap['excluded_long_tail_repos']:,}-repo | |
| long tail is excluded too. | |
| - No text rewriting beyond stripping; no PII scrubbing (see Not checked). | |
| ## Rights | |
| - Every retained row has an audited permissive SPDX licence in `license` and a | |
| `license_source` URL; `license_class == "permissive"`. | |
| - No copyleft (LGPL/EPL/GPL/AGPL) and no `NOASSERTION`/`unknown` rows. | |
| - Permissive is not obligation-free: Apache-2.0 requires NOTICE/attribution and | |
| preservation of notices; MIT/BSD require the copyright notice. The parquet | |
| carries `repo` and `url` for attribution but **does not bundle licence texts | |
| or NOTICE files**. | |
| - Repo-level licence is not file-level: a repository may vendor or generate | |
| files under other terms; GitHub reports the repository licence only. | |
| ## Why include it / uses | |
| A licence-clean, function-level Python corpus with docstrings for code LLM | |
| pretraining/SFT, code–documentation retrieval, and function-level generation or | |
| summarisation. Python is under-represented relative to Java/Python code corpora. | |
| ## Limitations | |
| - Function-level only: no package context, imports, or call graph. | |
| - Licence state is a 2026-12-05 GitHub snapshot; repos can relicense later. | |
| - Domain balance follows CodeSearchNet's collection (CLI/tooling-heavy, | |
| web/scripting/data code prominent). | |
| - Docstrings are upstream quality. | |
| ## Not checked | |
| - PII in code or docstrings (author names, emails, keys): **no scrubber was run; | |
| SlayerLab/NERGAL not applied**. | |
| - Whether GitHub's LICENSE-file detection matches actual terms. | |
| - Vendored/generated files inside repos that may carry other licences. | |
| - Cross-corpus dedup against other code corpora. | |
| - Preservation of Apache NOTICE / BSD-MIT copyright notices in downstream use. | |
| ## Reproduce | |
| ```bash | |
| python build_csn_go.py | |
| python audit_licenses.py | |
| python join_go.py | |
| python make_datasheet.py | |
| python finalize_go.py | |
| ``` | |
| """ | |
| OUT.write_text(text, encoding="utf-8") | |
| print("wrote", OUT, len(text), "chars") | |
| if __name__ == "__main__": | |
| main() | |