edbeeching HF Staff commited on
Commit
a05c9c1
·
verified ·
1 Parent(s): 4cf5425

Publish the script that built this dataset

Browse files
Files changed (1) hide show
  1. scripts/create_dataset.py +109 -0
scripts/create_dataset.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Publish an exact, revision-pinned copy of the official single-turn IFBench data."""
2
+
3
+ import argparse
4
+ import hashlib
5
+ import json
6
+ from pathlib import Path
7
+ from urllib.request import urlopen
8
+
9
+ from datasets import Dataset, Features, Json, List, Value, load_dataset
10
+ from huggingface_hub import HfApi, hf_hub_download
11
+
12
+
13
+ def main():
14
+ parser = argparse.ArgumentParser(description=__doc__)
15
+ parser.add_argument("--output-dataset", required=True)
16
+ parser.add_argument("--source-revision", required=True)
17
+ args = parser.parse_args()
18
+ source = f"https://raw.githubusercontent.com/allenai/IFBench/{args.source_revision}/ifbench/data/IFBench_test.jsonl"
19
+ raw = urlopen(source).read()
20
+ records = [json.loads(line) for line in raw.splitlines() if line.strip()]
21
+ assert len(records) == 300 and len({row['key'] for row in records}) == 300
22
+ features = Features(
23
+ {
24
+ "key": Value("string"),
25
+ "prompt": Value("string"),
26
+ "instruction_id_list": List(Value("string")),
27
+ "kwargs": Json(),
28
+ }
29
+ )
30
+ dataset = Dataset.from_list(records, features=features)
31
+ assert list(dataset) == records
32
+ api = HfApi()
33
+ # Never replace an existing repository or its dataset card.
34
+ api.create_repo(args.output_dataset, repo_type="dataset", private=False, exist_ok=False)
35
+ dataset.push_to_hub(args.output_dataset, config_name="default", split="test")
36
+ generated_card = Path(hf_hub_download(args.output_dataset, "README.md", repo_type="dataset")).read_text()
37
+ yaml = generated_card.split("---", 2)[1].strip()
38
+ card = f"""---
39
+ license: odc-by
40
+ language:
41
+ - en
42
+ tags:
43
+ - evaluation
44
+ - instruction-following
45
+ {yaml}
46
+ ---
47
+
48
+ | subset | description | num_samples |
49
+ | --- | --- | ---: |
50
+ | `default` | Official single-turn IFBench test prompts, unchanged; `test` split | {len(dataset)} |
51
+
52
+ # IFBench
53
+
54
+ An exact mirror of the single-turn test data from [AllenAI IFBench](https://github.com/allenai/IFBench).
55
+ Credit: Valentina Pyatkin, Saumya Malik, Victoria Graf, Hamish Ivison, Shengyi Huang, Pradeep Dasigi,
56
+ Nathan Lambert, and Hannaneh Hajishirzi, [Generalizing Verifiable Instruction Following](https://huggingface.co/papers/2507.02833).
57
+
58
+ ## Provenance and license
59
+
60
+ - Source revision: `{args.source_revision}`.
61
+ - Source file: [`ifbench/data/IFBench_test.jsonl`]({source}).
62
+ - Original file SHA-256: `{hashlib.sha256(raw).hexdigest()}`.
63
+ - No filtering, prompt changes, or row reordering. All original fields and values are preserved.
64
+ - `kwargs` uses the Hugging Face Datasets JSON feature to preserve heterogeneous argument dictionaries;
65
+ use `datasets>=4.7.0` to load it as a list of dictionaries. Other fields are `key`, `prompt`, and `instruction_id_list`.
66
+ - The data is licensed under [ODC-BY-1.0](https://opendatacommons.org/licenses/by/1-0/), as stated in the
67
+ [upstream README](https://github.com/allenai/IFBench/blob/{args.source_revision}/README.md#licensing).
68
+ It is intended for research and educational use under Ai2's Responsible Use Guidelines.
69
+ It includes outputs generated by third-party models, which may be subject to separate terms.
70
+ - Verifier code is separately Apache-2.0 licensed; it is not part of this dataset release.
71
+
72
+ ## Reproducing
73
+
74
+ The builder is published at `scripts/create_dataset.py`. Exact publication invocation:
75
+
76
+ ```bash
77
+ python scripts/create_dataset.py --output-dataset {args.output_dataset} --source-revision {args.source_revision}
78
+ ```
79
+
80
+ To reproduce independently, use an unused repository name under your own namespace. The builder refuses to overwrite
81
+ an existing repository. It requires `datasets>=4.7.0` and `huggingface_hub`, and a token with write access to the destination.
82
+
83
+ ## Loading
84
+
85
+ ```python
86
+ from datasets import load_dataset
87
+
88
+ dataset = load_dataset("{args.output_dataset}", "default", split="test")
89
+ ```
90
+
91
+ Pin a Hub commit revision for reproducible evaluation. This repository contains evaluation data, not training data.
92
+ """
93
+ api.upload_file(
94
+ path_or_fileobj=card.encode(), path_in_repo="README.md", repo_id=args.output_dataset, repo_type="dataset"
95
+ )
96
+ commit = api.upload_file(
97
+ path_or_fileobj=__file__,
98
+ path_in_repo="scripts/create_dataset.py",
99
+ repo_id=args.output_dataset,
100
+ repo_type="dataset",
101
+ commit_message="Publish the script that built this dataset",
102
+ )
103
+ loaded = load_dataset(args.output_dataset, "default", split="test", revision=commit.oid)
104
+ assert list(loaded) == records
105
+ print(json.dumps({"dataset": args.output_dataset, "revision": commit.oid, "samples": len(loaded)}))
106
+
107
+
108
+ if __name__ == "__main__":
109
+ main()