lewtun HF Staff commited on
Commit
dbda1ea
·
verified ·
1 Parent(s): 7cdfcc3

Publish the card and the script that built this dataset

Browse files
Files changed (2) hide show
  1. README.md +17 -12
  2. scripts/create_dataset.py +178 -0
README.md CHANGED
@@ -33,6 +33,7 @@ configs:
33
  data_files:
34
  - split: test
35
  path: gold/test-*
 
36
  language:
37
  - en
38
  license: apache-2.0
@@ -42,7 +43,9 @@ tags:
42
  - evaluation
43
  - alpaca-eval
44
  ---
45
- # SmolTalkBench
 
 
46
 
47
  1000 single-turn everyday chat prompts with reference replies, for AlpacaEval-style pairwise
48
  win rates. Built to compare the rule-based chatbot from the run4 agent swarm
@@ -54,26 +57,20 @@ from datasets import load_dataset
54
  ds = load_dataset("HuggingFaceSwarms/SmolTalkBench", "gold", split="test")
55
  ```
56
 
57
- ## Configs
58
-
59
- | config | reference replies (`output`) |
60
- |---|---|
61
- | `gold` (default) | the source conversations' replies, by `meta-llama/Meta-Llama-3.1-70B-Instruct` |
62
-
63
  Variants with other reference models go in their own configs, keeping the same `id`s and
64
  instructions so that results compare across them.
65
 
66
  ## Construction
67
 
68
  - Source: the `everyday-conversations` subset of [`HuggingFaceTB/smoltalk`](https://huggingface.co/datasets/HuggingFaceTB/smoltalk)
69
- at revision `5feaf2fd3ffc`, train and test splits. Each conversation was written whole by
70
- [`meta-llama/Meta-Llama-3.1-70B-Instruct`](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct).
71
  - Every source conversation opens with a bare greeting ("Hi", "Hello", ...) answered by
72
  "Hello! How can I help you today?". The greeting is dropped: `instruction` is the second
73
  user turn and `output` the assistant's reply to it.
74
  - Prompts are deduplicated (case and whitespace insensitive), leaving 2198 rows.
75
- - 1000 rows are sampled with seed 0, in proportion to each parent topic (`topic` without
76
- its last level), so every subcategory keeps its share.
77
 
78
  ## Columns
79
 
@@ -90,4 +87,12 @@ instructions so that results compare across them.
90
 
91
  Note that SmolLM and SmolLM2 Instruct models were trained on the source conversations.
92
 
93
- Built by `experiments/run4/eval/build_smoltalkbench.py` in the flock repository.
 
 
 
 
 
 
 
 
 
33
  data_files:
34
  - split: test
35
  path: gold/test-*
36
+ default: true
37
  language:
38
  - en
39
  license: apache-2.0
 
43
  - evaluation
44
  - alpaca-eval
45
  ---
46
+ | subset | description | num_samples |
47
+ | --- | --- | ---: |
48
+ | `gold` (default) | Single-turn everyday chat prompts from smoltalk's `everyday-conversations`, sampled in proportion to their parent topic, with the source conversations' replies by `meta-llama/Meta-Llama-3.1-70B-Instruct` as references | 1000 |
49
 
50
  1000 single-turn everyday chat prompts with reference replies, for AlpacaEval-style pairwise
51
  win rates. Built to compare the rule-based chatbot from the run4 agent swarm
 
57
  ds = load_dataset("HuggingFaceSwarms/SmolTalkBench", "gold", split="test")
58
  ```
59
 
 
 
 
 
 
 
60
  Variants with other reference models go in their own configs, keeping the same `id`s and
61
  instructions so that results compare across them.
62
 
63
  ## Construction
64
 
65
  - Source: the `everyday-conversations` subset of [`HuggingFaceTB/smoltalk`](https://huggingface.co/datasets/HuggingFaceTB/smoltalk)
66
+ at revision `5feaf2fd3ffc`, train and test splits. Each conversation was
67
+ written whole by [`meta-llama/Meta-Llama-3.1-70B-Instruct`](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct).
68
  - Every source conversation opens with a bare greeting ("Hi", "Hello", ...) answered by
69
  "Hello! How can I help you today?". The greeting is dropped: `instruction` is the second
70
  user turn and `output` the assistant's reply to it.
71
  - Prompts are deduplicated (case and whitespace insensitive), leaving 2198 rows.
72
+ - 1000 rows are sampled with seed 0, in proportion to each parent topic (`topic`
73
+ without its last level), so every subcategory keeps its share.
74
 
75
  ## Columns
76
 
 
87
 
88
  Note that SmolLM and SmolLM2 Instruct models were trained on the source conversations.
89
 
90
+ ## Reproducing
91
+
92
+ [`scripts/create_dataset.py`](scripts/create_dataset.py) builds the `gold` config and pushes it with this card and itself:
93
+
94
+ ```sh
95
+ hf download HuggingFaceSwarms/SmolTalkBench scripts/create_dataset.py --repo-type dataset --local-dir .
96
+ uv run scripts/create_dataset.py --n 1000 --seed 0 \
97
+ --source_revision 5feaf2fd3ffca7c237fc38d1861bc30365d48ffa --repo HuggingFaceSwarms/SmolTalkBench --push
98
+ ```
scripts/create_dataset.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.11"
3
+ # dependencies = ["datasets>=3.0", "huggingface_hub>=0.30"]
4
+ # ///
5
+ """Build SmolTalkBench: single-turn chat prompts with reference replies, AlpacaEval style.
6
+
7
+ uv run scripts/create_dataset.py # build and print stats
8
+ uv run scripts/create_dataset.py --push # also push the data, card and this script
9
+
10
+ This builds the `gold` config, whose references come from the source conversations. Variants
11
+ with other reference models go in their own configs, keeping the same ids and instructions.
12
+
13
+ Source: the everyday-conversations subset of HuggingFaceTB/smoltalk (train + test), written
14
+ whole by Llama-3.1-70B-Instruct. Every conversation opens with a bare greeting and the same
15
+ "How can I help you today?", so the prompt is the second user turn and the reference is the
16
+ assistant's reply to it. Prompts are deduplicated, then sampled in proportion to their parent
17
+ topic (full_topic without its leaf), largest remainders rounding the allocation to exactly N.
18
+ Columns follow AlpacaEval's reference outputs (instruction, output, generator, dataset).
19
+ """
20
+
21
+ import argparse
22
+ import random
23
+ from collections import Counter, defaultdict
24
+ from pathlib import Path
25
+
26
+ from datasets import Dataset, load_dataset
27
+ from huggingface_hub import CommitOperationAdd, DatasetCard, HfApi
28
+
29
+ SOURCE = "HuggingFaceTB/smoltalk"
30
+ SUBSET = "everyday-conversations"
31
+ SOURCE_REVISION = "5feaf2fd3ffca7c237fc38d1861bc30365d48ffa"
32
+ GENERATOR = "meta-llama/Meta-Llama-3.1-70B-Instruct"
33
+ REPO = "HuggingFaceSwarms/SmolTalkBench"
34
+ CONFIG = "gold"
35
+ SCRIPT = "scripts/create_dataset.py"
36
+ META = {"license": "apache-2.0", "language": ["en"], "pretty_name": "SmolTalkBench",
37
+ "tags": ["chatbot", "evaluation", "alpaca-eval"]}
38
+
39
+
40
+ def candidates(source_revision):
41
+ """One row per distinct second user turn, first occurrence kept (train, then test)."""
42
+ ds = load_dataset(SOURCE, SUBSET, revision=source_revision)
43
+ rows, seen = [], set()
44
+ for split in ("train", "test"):
45
+ for index, record in enumerate(ds[split]):
46
+ msgs = record["messages"]
47
+ assert [m["role"] for m in msgs[:4]] == ["user", "assistant", "user", "assistant"]
48
+ prompt = msgs[2]["content"].strip()
49
+ key = " ".join(prompt.casefold().split())
50
+ if key in seen:
51
+ continue
52
+ seen.add(key)
53
+ topic = record["full_topic"]
54
+ rows.append({"id": f"{split}-{index:04d}", "instruction": prompt,
55
+ "output": msgs[3]["content"].strip(), "generator": GENERATOR,
56
+ "dataset": f"{SOURCE}/{SUBSET}", "topic": topic,
57
+ "category": topic.split("/")[0],
58
+ # Capitalised three-level topics are everyday requests; lowercase
59
+ # two-level ones are grade-school science and general knowledge.
60
+ "group": "everyday" if topic.count("/") == 2 else "school",
61
+ "source_split": split, "source_index": index})
62
+ return rows
63
+
64
+
65
+ def stratified(rows, n, seed):
66
+ """Proportional allocation over parent topics, rounded by largest remainder."""
67
+ strata = defaultdict(list)
68
+ for row in rows:
69
+ strata[row["topic"].rsplit("/", 1)[0]].append(row)
70
+ names = sorted(strata)
71
+ quotas = {s: n * len(strata[s]) / len(rows) for s in names}
72
+ alloc = {s: int(q) for s, q in quotas.items()}
73
+ for s in sorted(names, key=lambda s: (alloc[s] - quotas[s], s))[:n - sum(alloc.values())]:
74
+ alloc[s] += 1
75
+ rng = random.Random(seed)
76
+ picked = [row for s in names for row in rng.sample(strata[s], alloc[s])]
77
+ return sorted(picked, key=lambda row: (row["source_split"] != "train", row["source_index"]))
78
+
79
+
80
+ def card(args, total):
81
+ public = " --public" if args.public else ""
82
+ return f"""| subset | description | num_samples |
83
+ | --- | --- | ---: |
84
+ | `{CONFIG}` (default) | Single-turn everyday chat prompts from smoltalk's `{SUBSET}`, sampled in proportion to their parent topic, with the source conversations' replies by `{GENERATOR}` as references | {args.n} |
85
+
86
+ {args.n} single-turn everyday chat prompts with reference replies, for AlpacaEval-style pairwise
87
+ win rates. Built to compare the rule-based chatbot from the run4 agent swarm
88
+ (`cmpatino/chatbot-swarm`) at different commits, and small LMs, against one fixed reference.
89
+
90
+ ```python
91
+ from datasets import load_dataset
92
+
93
+ ds = load_dataset("{args.repo}", "{CONFIG}", split="test")
94
+ ```
95
+
96
+ Variants with other reference models go in their own configs, keeping the same `id`s and
97
+ instructions so that results compare across them.
98
+
99
+ ## Construction
100
+
101
+ - Source: the `{SUBSET}` subset of [`{SOURCE}`](https://huggingface.co/datasets/{SOURCE})
102
+ at revision `{args.source_revision[:12]}`, train and test splits. Each conversation was
103
+ written whole by [`{GENERATOR}`](https://huggingface.co/{GENERATOR}).
104
+ - Every source conversation opens with a bare greeting ("Hi", "Hello", ...) answered by
105
+ "Hello! How can I help you today?". The greeting is dropped: `instruction` is the second
106
+ user turn and `output` the assistant's reply to it.
107
+ - Prompts are deduplicated (case and whitespace insensitive), leaving {total} rows.
108
+ - {args.n} rows are sampled with seed {args.seed}, in proportion to each parent topic (`topic`
109
+ without its last level), so every subcategory keeps its share.
110
+
111
+ ## Columns
112
+
113
+ | column | description |
114
+ |---|---|
115
+ | `id` | `<source split>-<source index>` |
116
+ | `instruction` | the prompt (second user turn) |
117
+ | `output` | reference reply by `generator` |
118
+ | `generator`, `dataset` | reference model and source, as in AlpacaEval's reference outputs |
119
+ | `topic` | the source `full_topic` |
120
+ | `category` | first level of `topic` |
121
+ | `group` | `everyday` (three-level topics) or `school` (two-level grade-school knowledge topics) |
122
+ | `source_split`, `source_index` | the row in the source subset |
123
+
124
+ Note that SmolLM and SmolLM2 Instruct models were trained on the source conversations.
125
+
126
+ ## Reproducing
127
+
128
+ [`{SCRIPT}`]({SCRIPT}) builds the `{CONFIG}` config and pushes it with this card and itself:
129
+
130
+ ```sh
131
+ hf download {args.repo} {SCRIPT} --repo-type dataset --local-dir .
132
+ uv run {SCRIPT} --n {args.n} --seed {args.seed} \\
133
+ --source_revision {args.source_revision} --repo {args.repo} --push{public}
134
+ ```
135
+ """
136
+
137
+
138
+ def main():
139
+ parser = argparse.ArgumentParser(description=__doc__)
140
+ parser.add_argument("--n", type=int, default=1000)
141
+ parser.add_argument("--seed", type=int, default=0)
142
+ parser.add_argument("--source_revision", default=SOURCE_REVISION,
143
+ help=f"commit of {SOURCE}")
144
+ parser.add_argument("--repo", default=REPO)
145
+ parser.add_argument("--push", action="store_true")
146
+ parser.add_argument("--public", action="store_true", help="push as a public dataset")
147
+ args = parser.parse_args()
148
+ rows = candidates(args.source_revision)
149
+ picked = stratified(rows, args.n, args.seed)
150
+ assert len(picked) == args.n and len({r["id"] for r in picked}) == args.n
151
+ print(f"{len(rows)} distinct prompts -> {len(picked)} sampled")
152
+ print("groups:", dict(Counter(r["group"] for r in picked)))
153
+ print("categories:", dict(Counter(r["category"] for r in picked).most_common()))
154
+ if not args.push:
155
+ return
156
+ Dataset.from_list(picked).push_to_hub(args.repo, config_name=CONFIG, split="test",
157
+ private=not args.public)
158
+ # push_to_hub wrote the card's dataset_info and configs; keep them, add ours.
159
+ pushed = DatasetCard.load(args.repo, repo_type="dataset")
160
+ for key, value in META.items():
161
+ pushed.data[key] = value
162
+ # push_to_hub(set_default=True) drops or trips over the flag when re-pushing the default
163
+ # config (datasets 5.1), so make gold the default here.
164
+ for entry in pushed.data["configs"]:
165
+ if entry["config_name"] == CONFIG:
166
+ entry["default"] = True
167
+ pushed.text = card(args, len(rows))
168
+ api = HfApi()
169
+ api.create_commit(args.repo, repo_type="dataset", operations=[
170
+ CommitOperationAdd("README.md", str(pushed).encode()),
171
+ CommitOperationAdd(SCRIPT, Path(__file__).read_bytes()),
172
+ ], commit_message="Publish the card and the script that built this dataset")
173
+ print(f"pushed https://huggingface.co/datasets/{args.repo} @ "
174
+ f"{api.dataset_info(args.repo).sha}")
175
+
176
+
177
+ if __name__ == "__main__":
178
+ main()