edbeeching's picture
edbeeching HF Staff
Publish dataset builder
cda20b5 verified
Raw History Blame Contribute Delete
5.77 kB
#!/usr/bin/env python
"""Publish the 20-example Kimi K3 visible-reasoning pilot."""
import argparse
import json
from pathlib import Path
from datasets import Dataset, load_dataset
from huggingface_hub import DatasetCard, HfApi
CONFIG_NAME = "low_visible_cot_20"
SOURCE_DATASET = "HuggingFaceBio/basic-dna-sft-data"
SOURCE_CONFIG = "all_decontaminated"
SOURCE_REVISION = "be1e789606e41af5c2b92d450223b994386b9ed8"
MODEL = "moonshotai/Kimi-K3:fireworks-ai"
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--input-jsonl", type=Path, required=True)
parser.add_argument("--output-dir", type=Path, required=True)
parser.add_argument("--output-dataset")
parser.add_argument("--config-name", default=CONFIG_NAME)
args = parser.parse_args()
with args.input_jsonl.open() as file:
rows = [json.loads(line) for line in file]
if len(rows) != 20 or len({row["id"] for row in rows}) != 20:
raise ValueError("Expected exactly 20 unique outputs")
if any(row["model"] != MODEL or row["reasoning_effort"] != "low" for row in rows):
raise ValueError("Every row must be a Kimi K3 low-reasoning output")
for row in rows:
row["source_dataset"] = SOURCE_DATASET
row["source_config"] = SOURCE_CONFIG
row["source_revision"] = SOURCE_REVISION
dataset = Dataset.from_list(rows)
args.output_dir.mkdir(parents=True, exist_ok=True)
dataset.to_parquet(args.output_dir / "train.parquet")
summary = {
"config": args.config_name,
"num_samples": len(dataset),
"model": MODEL,
"reasoning_effort": "low",
"source_dataset": SOURCE_DATASET,
"source_config": SOURCE_CONFIG,
"source_revision": SOURCE_REVISION,
"selection_seed": 42,
"track_sizes": {"computational": 10, "dashfirst": 5, "knowledge": 5},
}
summary_path = args.output_dir / "summary.json"
summary_path.write_text(json.dumps(summary, indent=2, sort_keys=True) + "\n")
if not args.output_dataset:
return
api = HfApi()
api.create_repo(args.output_dataset, repo_type="dataset", private=False, exist_ok=True)
dataset.push_to_hub(args.output_dataset, config_name=args.config_name, split="train")
api.upload_file(
path_or_fileobj=args.input_jsonl,
path_in_repo="raw/kimi_k3_low_visible_cot_20.jsonl",
repo_id=args.output_dataset,
repo_type="dataset",
commit_message="Publish raw Kimi outputs",
)
api.upload_file(
path_or_fileobj=__file__,
path_in_repo="scripts/create_dataset.py",
repo_id=args.output_dataset,
repo_type="dataset",
commit_message="Publish dataset builder",
)
api.upload_file(
path_or_fileobj=Path(__file__).with_name("run_pilot.py"),
path_in_repo="scripts/generate_outputs.py",
repo_id=args.output_dataset,
repo_type="dataset",
commit_message="Publish generation script",
)
api.upload_file(
path_or_fileobj=summary_path,
path_in_repo="provenance/summary.json",
repo_id=args.output_dataset,
repo_type="dataset",
commit_message="Publish provenance summary",
)
card = DatasetCard(
f"""---
configs:
- config_name: {args.config_name}
data_files:
- split: train
path: {args.config_name}/train-*
---
| subset | description | num_samples |
| --- | --- | ---: |
| `{args.config_name}` | Kimi K3 low-effort outputs explicitly prompted to include concise reasoning in the visible answer | {len(dataset)} |
# Basic DNA Kimi K3 visible-reasoning pilot
These outputs test whether `{MODEL}` with `reasoning_effort="low"` includes a concise, self-contained explanation in
the visible answer when explicitly requested. The dataset retains both the visible `content` and the separate
`reasoning_content` returned by the API, along with the corresponding response from the earlier answer-only run.
The 20 prompts are selected deterministically with seed 42: 10 from the `computational` track, 5 from `dashfirst`, and
5 from `knowledge`. The source is `{SOURCE_DATASET}`, config `{SOURCE_CONFIG}`, revision `{SOURCE_REVISION}`.
## Generation settings
- Model: `{MODEL}` through the Hugging Face inference router and Fireworks
- Reasoning effort: `low`
- Maximum completion tokens: 8,192
- Visible-answer instruction: recorded verbatim in every row's `instruction` field
## Reproducing
The exact published responses are retained under `raw/`. Rebuild and optionally republish the dataset with:
```bash
hf download edbeeching/basic-dna-kimi-k3-outputs-261006 \\
--repo-type dataset \\
--include 'raw/*' 'scripts/create_dataset.py' \\
--local-dir basic-dna-kimi-k3-outputs-261006
python basic-dna-kimi-k3-outputs-261006/scripts/create_dataset.py \\
--input-jsonl basic-dna-kimi-k3-outputs-261006/raw/kimi_k3_low_visible_cot_20.jsonl \\
--output-dir basic-dna-kimi-k3-outputs-261006/rebuilt
```
The original API generation implementation is published as `scripts/generate_outputs.py`. It uses the pinned source
revision above and requires `HF_TOKEN` to issue new requests.
"""
)
card.push_to_hub(args.output_dataset, repo_type="dataset", commit_message="Document dataset provenance")
revision = api.dataset_info(args.output_dataset).sha
published = load_dataset(
args.output_dataset,
args.config_name,
split="train",
revision=revision,
)
if len(published) != len(dataset) or set(published["id"]) != set(dataset["id"]):
raise ValueError("Published dataset does not match the local dataset")
print(f"Verified {len(published)} rows at revision {revision}")
if __name__ == "__main__":
main()