#!/usr/bin/env python3 """Add the completed ESPnet-format preparation entry to its original data card.""" import argparse import json from pathlib import Path from huggingface_hub import CommitOperationAdd, HfApi, get_token, hf_hub_download from convert_release import RECIPES def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--dataset", choices=list(RECIPES), required=True) parser.add_argument( "--root", type=Path, default=Path("/root/bagpiper-sft-conversion") ) args = parser.parse_args() recipe = RECIPES[args.dataset] api = HfApi(token=get_token()) target_revision = api.repo_info(recipe["target"], repo_type="dataset").sha status = json.loads( Path( hf_hub_download( recipe["target"], "STATUS.json", repo_type="dataset", revision=target_revision, ) ).read_text() ) assert ( status["state"] == "complete" and status.get("validation") == "RELEASE_VALIDATION.json" ) source_revision = api.repo_info(recipe["source"], repo_type="dataset").sha card = Path( hf_hub_download( recipe["source"], "README.md", repo_type="dataset", revision=source_revision ) ).read_text() heading = "## Prepare for ESPnet training" section = f"""{heading} The complete [ESPnet-format release](https://huggingface.co/datasets/{recipe['target']}) preserves all {status['expected_rows']:,} source rows, ordered text turns, and original encoded audio bytes. It converts this Parquet schema into three-element dialogue messages and portable audio files. Source `row_id` becomes the globally unique ESPnet `example_id`; repeated training examples remain present. ```bash python -m pip install huggingface_hub zstandard hf download {recipe['target']} prepare_espnet.py --local-dir tools python tools/prepare_espnet.py \\ --repo-id {recipe['target']} --data-root /path/to/bagpiper-{args.dataset}-sft ``` The helper verifies archive/audio hashes, resolves local paths, and writes `prepared//{{all,train,valid}}.json` plus `dialogues.jsonl`. Add `--max-shards 2` for a small trial and repeat `--partition NAME` to select applications. Audio SHA256 determines the suggested 1% validation split; `all.json` retains the original training pool. The split is not the paper's official split. Prepare token-length statistics with the checkpoint-compatible configuration as shown in the converted release's README. See its [full release validation](https://huggingface.co/datasets/{recipe['target']}/blob/main/RELEASE_VALIDATION.json) and [public download/ESPnet reader checks](https://huggingface.co/datasets/{recipe['target']}/blob/main/PUBLIC_DOWNLOAD_VALIDATION.json). This conversion preserves the original source selection and applicable terms. """ if heading in card: start = card.index(heading) end = card.find("\n## ", start + len(heading)) card = card[:start] + section + (card[end + 1 :] if end >= 0 else "") else: marker = "## Loading the data" assert marker in card card = card.replace(marker, section + marker, 1) output = args.root / "releases" / args.dataset / "SOURCE_README.updated.md" output.write_text(card) commit = api.create_commit( recipe["source"], repo_type="dataset", parent_commit=source_revision, operations=[ CommitOperationAdd(path_in_repo="README.md", path_or_fileobj=output) ], commit_message="Link completed lossless ESPnet training format and preparation helper", ) print( json.dumps( dict( source=recipe["source"], commit=commit.oid, converted_revision=target_revision, ) ) ) if __name__ == "__main__": main()