code-search-net-ruby-permissive / make_datasheet.py
PiotrSty's picture
CodeSearchNet Ruby permissive-only
bbfe90a verified
Raw History Blame Contribute Delete
5.01 kB
#!/usr/bin/env python
"""Generate datasheet.md for the Ruby permissive dataset from build.json."""
import json
from pathlib import Path
HERE = Path(__file__).resolve().parent
BUILD = HERE / "code_search_net_ruby_permissive.build.json"
OUT = HERE / "datasheet.md"
def main():
b = json.loads(BUILD.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_ruby_permissive — CodeSearchNet Ruby (permissive only)
Added: 2026-12-05. Release: `None` (working copy, not a release).
## What the data is
Function-level Ruby 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 | Ruby (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),
`ruby` 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"`).
- 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 Ruby corpus with docstrings for code LLM
pretraining/SFT, code–documentation retrieval, and function-level generation or
summarisation. Ruby 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,
Rails/web/SDK 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()