lewtun HF Staff commited on
Commit
f504767
·
verified ·
1 Parent(s): c0a7d5b

Add stratified mcq_carbon_600 configuration

Browse files
README.md CHANGED
@@ -78,6 +78,28 @@ dataset_info:
78
  num_examples: 2600
79
  download_size: 11786125
80
  dataset_size: 15000459
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  - config_name: eukaryote_cls
82
  features:
83
  - name: id
@@ -245,6 +267,10 @@ configs:
245
  data_files:
246
  - split: train
247
  path: mcq_carbon/train-*
 
 
 
 
248
  - config_name: eukaryote_cls
249
  data_files:
250
  - split: train
@@ -325,6 +351,7 @@ headline score is needed.
325
  | `binary` | 2,600 | Full benchmark in binary-choice format, with two ordered options per question. |
326
  | `mcq` | 2,600 | Full benchmark in four-option multiple-choice format. |
327
  | `mcq_carbon` | 2,600 | MCQ benchmark with the 500 `3_species_cls` rows replaced by 500 stratified `eukaryote_cls` rows. |
 
328
  | `binary_600` | 600 | Lower-cost binary subset with 100 examples from each of the six subtasks. |
329
  | `mcq_600` | 600 | Lower-cost MCQ subset with 100 examples from each of the six subtasks. |
330
  | `binary_eukaryote` | 170 | Binary `3_species_cls` questions whose target organism is eukaryotic. |
@@ -338,6 +365,13 @@ original species-classification position. From source revision `ae30ecec16a7669f
338
  `basic_class`, 100 `reverse_search`, and 100 `odd_one_out` rows, sampling approximately half of each taxon label
339
  within each question type. See [`scripts/create_mcq_carbon.py`](scripts/create_mcq_carbon.py).
340
 
 
 
 
 
 
 
 
341
  The `eukaryote_cls` configuration uses the `mcq` feature schema, including JSON-serialized `metadata`.
342
 
343
  The `binary_600` and `mcq_600` configurations were sampled without replacement using seed 42 from source revision
@@ -407,3 +441,13 @@ python scripts/create_mcq_carbon.py --source-revision ae30ecec16a7669f342f7d8743
407
  ```
408
 
409
  The script publishes the Parquet file, this card, and the builder script together.
 
 
 
 
 
 
 
 
 
 
 
78
  num_examples: 2600
79
  download_size: 11786125
80
  dataset_size: 15000459
81
+ - config_name: mcq_carbon_600
82
+ features:
83
+ - name: id
84
+ dtype: int64
85
+ - name: subtask
86
+ dtype: string
87
+ - name: question
88
+ dtype: string
89
+ - name: options
90
+ list: string
91
+ - name: answer_index
92
+ dtype: int64
93
+ - name: answer_text
94
+ dtype: string
95
+ - name: metadata
96
+ dtype: string
97
+ splits:
98
+ - name: train
99
+ num_bytes: 3012902
100
+ num_examples: 600
101
+ download_size: 2377835
102
+ dataset_size: 3012902
103
  - config_name: eukaryote_cls
104
  features:
105
  - name: id
 
267
  data_files:
268
  - split: train
269
  path: mcq_carbon/train-*
270
+ - config_name: mcq_carbon_600
271
+ data_files:
272
+ - split: train
273
+ path: mcq_carbon_600/train-*
274
  - config_name: eukaryote_cls
275
  data_files:
276
  - split: train
 
351
  | `binary` | 2,600 | Full benchmark in binary-choice format, with two ordered options per question. |
352
  | `mcq` | 2,600 | Full benchmark in four-option multiple-choice format. |
353
  | `mcq_carbon` | 2,600 | MCQ benchmark with the 500 `3_species_cls` rows replaced by 500 stratified `eukaryote_cls` rows. |
354
+ | `mcq_carbon_600` | 600 | Stratified 100-row sample from each `mcq_carbon` subtask. |
355
  | `binary_600` | 600 | Lower-cost binary subset with 100 examples from each of the six subtasks. |
356
  | `mcq_600` | 600 | Lower-cost MCQ subset with 100 examples from each of the six subtasks. |
357
  | `binary_eukaryote` | 170 | Binary `3_species_cls` questions whose target organism is eukaryotic. |
 
365
  `basic_class`, 100 `reverse_search`, and 100 `odd_one_out` rows, sampling approximately half of each taxon label
366
  within each question type. See [`scripts/create_mcq_carbon.py`](scripts/create_mcq_carbon.py).
367
 
368
+ The `mcq_carbon_600` configuration samples without replacement from `mcq_carbon` at revision
369
+ `c0a7d5b8ccfe4c0d64bc3ff5dd171ff4365c16f6` using seed 42. It retains 100 rows per subtask and preserves the mix of question
370
+ dimensions within each subtask. Within dimensions, it samples proportionally by target label where available; eukaryote odd-one-out
371
+ questions are also stratified by majority taxon, and answer position is the final stratum. The 100 motif rows are all
372
+ retained. See
373
+ [`scripts/create_mcq_carbon_600.py`](scripts/create_mcq_carbon_600.py).
374
+
375
  The `eukaryote_cls` configuration uses the `mcq` feature schema, including JSON-serialized `metadata`.
376
 
377
  The `binary_600` and `mcq_600` configurations were sampled without replacement using seed 42 from source revision
 
441
  ```
442
 
443
  The script publishes the Parquet file, this card, and the builder script together.
444
+
445
+ ### mcq_carbon_600
446
+
447
+ To rebuild and publish `mcq_carbon_600` from the pinned source revision, run:
448
+
449
+ ```bash
450
+ python scripts/create_mcq_carbon_600.py --source-revision c0a7d5b8ccfe4c0d64bc3ff5dd171ff4365c16f6 --output-dataset HuggingFaceBio/genomeqa --seed 42 --publish
451
+ ```
452
+
453
+ The script publishes the Parquet file, this card, and the builder script together.
mcq_carbon_600/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:817ef1644008538bb435decfc8b25d342a677745c131f6c42a6393b318368889
3
+ size 2377835
scripts/create_mcq_carbon_600.py ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Create a 600-row, stratified subset of GenomeQA mcq_carbon."""
2
+
3
+ import argparse
4
+ import json
5
+ import random
6
+ import re
7
+ from collections import Counter, defaultdict
8
+ from pathlib import Path
9
+
10
+ from datasets import Dataset, load_dataset
11
+ from huggingface_hub import CommitOperationAdd, HfApi, hf_hub_download
12
+
13
+
14
+ DATASET_ID = "HuggingFaceBio/genomeqa"
15
+ PARQUET_PATH = "mcq_carbon_600/train-00000-of-00001.parquet"
16
+ QUOTAS = {
17
+ "1_enhancer_vs_promoter": {"basic_class": 34, "selection": 33, "outlier": 33},
18
+ "2_splice_sites": {"fine_grained_class": 34, "generalized_selection": 33, "find_shuffled_outlier": 33},
19
+ "eukaryote_cls": {"basic_class": 60, "reverse_search": 20, "odd_one_out": 20},
20
+ "4_histone_marks": {
21
+ "seq_to_label": 25,
22
+ "label_to_seq": 25,
23
+ "odd_one_out": 25,
24
+ "chromatin_classify": 14,
25
+ "chromatin_select_seq": 11,
26
+ },
27
+ "5_tfbs": {"forward_classify": 34, "reverse_select": 33, "3d_structure_select": 33},
28
+ "6_motif": {"seq_to_motif": 50, "motif_to_seq": 50},
29
+ }
30
+ MARK = re.compile(r"\b(?:H2AFZ|H3K\d+(?:me\d|ac)|H4K\d+me\d)\b")
31
+ ENHANCER_OUTLIER_PATTERNS = (
32
+ r"Find the one containing a (enhancer|promoter)",
33
+ r"specific sequence that contains a (enhancer|promoter)",
34
+ r"sequence that includes a (enhancer|promoter)",
35
+ r"one actually harbors a (enhancer|promoter)",
36
+ r"sequence holds a (enhancer|promoter)",
37
+ )
38
+
39
+
40
+ def label_for_row(row: dict, metadata: dict) -> tuple[str, ...]:
41
+ subtask, dimension = row["subtask"], metadata["dim"]
42
+ if subtask == "1_enhancer_vs_promoter":
43
+ if dimension == "basic_class":
44
+ return (row["answer_text"].lower(),)
45
+ if dimension == "selection":
46
+ labels = set(re.findall(r"\b(?:enhancer|promoter)\b", row["question"].lower()))
47
+ if len(labels) != 1:
48
+ raise ValueError(f"Cannot identify enhancer selection target: {row['id']}")
49
+ return (labels.pop(),)
50
+ for pattern in ENHANCER_OUTLIER_PATTERNS:
51
+ match = re.search(pattern, row["question"], flags=re.IGNORECASE)
52
+ if match:
53
+ return (match.group(1).lower(),)
54
+ raise ValueError(f"Cannot identify enhancer outlier target: {row['id']}")
55
+ if subtask == "2_splice_sites":
56
+ if dimension == "fine_grained_class":
57
+ return (metadata["true_type"],)
58
+ if dimension == "generalized_selection":
59
+ return (metadata["target"],)
60
+ return ()
61
+ if subtask == "eukaryote_cls":
62
+ if dimension == "basic_class":
63
+ return (metadata["true"],)
64
+ if dimension == "reverse_search":
65
+ return (metadata["target"],)
66
+ return (metadata["minority"], metadata["majority"])
67
+ if subtask == "4_histone_marks":
68
+ if dimension == "seq_to_label":
69
+ return (row["answer_text"],)
70
+ if dimension in {"label_to_seq", "odd_one_out"}:
71
+ marks = MARK.findall(row["question"])
72
+ if not marks:
73
+ raise ValueError(f"Cannot identify histone mark: {row['id']}")
74
+ target = marks[1] if dimension == "odd_one_out" and "while one contains" in row["question"] else marks[0]
75
+ return (target,)
76
+ if dimension == "chromatin_classify":
77
+ return (metadata["truth"].lower(),)
78
+ return (metadata["target_state"].lower(),)
79
+ if subtask == "5_tfbs":
80
+ if dimension == "forward_classify":
81
+ return (row["answer_text"],)
82
+ if dimension == "reverse_select":
83
+ return (metadata["target"],)
84
+ return ()
85
+
86
+
87
+ def stratified_sample(
88
+ indices: list[int], quota: int, labels: dict[int, tuple[str, ...]], rng: random.Random, depth: int = 0
89
+ ) -> list[int]:
90
+ if quota == len(indices):
91
+ return indices.copy()
92
+ groups = defaultdict(list)
93
+ for index in indices:
94
+ label = labels[index][depth] if depth < len(labels[index]) else None
95
+ groups[label].append(index)
96
+ if list(groups) == [None]:
97
+ return rng.sample(indices, quota)
98
+
99
+ total = len(indices)
100
+ take = {label: quota * len(group) // total for label, group in groups.items()}
101
+ order = sorted(groups)
102
+ rng.shuffle(order)
103
+ order.sort(key=lambda label: quota * len(groups[label]) % total, reverse=True)
104
+ for label in order[: quota - sum(take.values())]:
105
+ take[label] += 1
106
+
107
+ selected = []
108
+ for label in sorted(groups):
109
+ if take[label]:
110
+ selected.extend(stratified_sample(groups[label], take[label], labels, rng, depth + 1))
111
+ return selected
112
+
113
+
114
+ def main() -> None:
115
+ parser = argparse.ArgumentParser()
116
+ parser.add_argument("--source-revision", required=True)
117
+ parser.add_argument("--output-dataset", default=DATASET_ID)
118
+ parser.add_argument("--output-dir", type=Path, default=Path.cwd())
119
+ parser.add_argument("--seed", type=int, default=42)
120
+ parser.add_argument("--publish", action="store_true")
121
+ args = parser.parse_args()
122
+
123
+ source = load_dataset(DATASET_ID, "mcq_carbon", split="train", revision=args.source_revision)
124
+ groups = defaultdict(list)
125
+ labels = {}
126
+ for index, row in enumerate(source):
127
+ metadata = json.loads(row["metadata"])
128
+ groups[(row["subtask"], metadata["dim"])].append(index)
129
+ labels[index] = label_for_row(row, metadata) + (str(row["answer_index"]),)
130
+ expected = {(subtask, dimension) for subtask, quotas in QUOTAS.items() for dimension in quotas}
131
+ if set(groups) != expected:
132
+ raise ValueError(f"Unexpected source subtasks or dimensions: {set(groups) ^ expected}")
133
+
134
+ rng = random.Random(args.seed)
135
+ selected = []
136
+ for subtask, dimensions in QUOTAS.items():
137
+ for dimension, quota in dimensions.items():
138
+ candidates = groups[(subtask, dimension)]
139
+ if len(candidates) < quota:
140
+ raise ValueError(f"Only {len(candidates)} {subtask}/{dimension} rows for quota {quota}")
141
+ selected.extend(stratified_sample(candidates, quota, labels, rng))
142
+ rng.shuffle(selected)
143
+ subset = source.select(selected)
144
+ if len(selected) != 600 or len(set(selected)) != 600 or Counter(subset["subtask"]) != dict.fromkeys(QUOTAS, 100):
145
+ raise RuntimeError("The subset must contain 100 distinct rows per subtask")
146
+
147
+ parquet_path = args.output_dir / PARQUET_PATH
148
+ parquet_path.parent.mkdir(parents=True, exist_ok=True)
149
+ subset.to_parquet(parquet_path)
150
+ materialized = Dataset.from_parquet(str(parquet_path))
151
+
152
+ api = HfApi()
153
+ head = api.repo_info(args.output_dataset, repo_type="dataset").sha
154
+ card = Path(hf_hub_download(args.output_dataset, "README.md", repo_type="dataset", revision=head)).read_text()
155
+ info = f"""- config_name: mcq_carbon_600
156
+ features:
157
+ - name: id
158
+ dtype: int64
159
+ - name: subtask
160
+ dtype: string
161
+ - name: question
162
+ dtype: string
163
+ - name: options
164
+ list: string
165
+ - name: answer_index
166
+ dtype: int64
167
+ - name: answer_text
168
+ dtype: string
169
+ - name: metadata
170
+ dtype: string
171
+ splits:
172
+ - name: train
173
+ num_bytes: {materialized.info.splits['train'].num_bytes}
174
+ num_examples: {len(materialized)}
175
+ download_size: {parquet_path.stat().st_size}
176
+ dataset_size: {materialized.info.dataset_size}
177
+ """
178
+ marker = "- config_name: eukaryote_cls\n features:"
179
+ existing = "- config_name: mcq_carbon_600\n features:"
180
+ if existing in card:
181
+ start = card.index(existing)
182
+ end = card.index(marker, start)
183
+ card = card[:start] + info + card[end:]
184
+ else:
185
+ if marker not in card:
186
+ raise ValueError("Cannot find dataset_info insertion point in card")
187
+ card = card.replace(marker, info + marker, 1)
188
+ config = """- config_name: mcq_carbon_600
189
+ data_files:
190
+ - split: train
191
+ path: mcq_carbon_600/train-*
192
+ """
193
+ card = card.replace(
194
+ "- config_name: eukaryote_cls\n data_files:", config + "- config_name: eukaryote_cls\n data_files:", 1
195
+ )
196
+ row = (
197
+ "| `mcq_carbon` | 2,600 | MCQ benchmark with the 500 `3_species_cls` rows replaced by 500 stratified "
198
+ "`eukaryote_cls` rows. |\n"
199
+ )
200
+ new_row = "| `mcq_carbon_600` | 600 | Stratified 100-row sample from each `mcq_carbon` subtask. |\n"
201
+ card = card.replace(row, row + new_row, 1)
202
+ note = f"""The `mcq_carbon_600` configuration samples without replacement from `mcq_carbon` at revision
203
+ `{args.source_revision}` using seed {args.seed}. It retains 100 rows per subtask and preserves the mix of question
204
+ dimensions within each subtask. Within dimensions, it samples proportionally by target label where available; eukaryote odd-one-out
205
+ questions are also stratified by majority taxon, and answer position is the final stratum. The 100 motif rows are all
206
+ retained. See
207
+ [`scripts/create_mcq_carbon_600.py`](scripts/create_mcq_carbon_600.py).
208
+
209
+ """
210
+ card = card.replace(
211
+ "The `eukaryote_cls` configuration uses", note + "The `eukaryote_cls` configuration uses", 1
212
+ )
213
+
214
+ if "### mcq_carbon_600" not in card:
215
+ card += f"""
216
+ ### mcq_carbon_600
217
+
218
+ To rebuild and publish `mcq_carbon_600` from the pinned source revision, run:
219
+
220
+ ```bash
221
+ python scripts/create_mcq_carbon_600.py --source-revision {args.source_revision} --output-dataset {args.output_dataset} --seed {args.seed} --publish
222
+ ```
223
+
224
+ The script publishes the Parquet file, this card, and the builder script together.
225
+ """
226
+
227
+ card_path = args.output_dir / "README.md"
228
+ card_path.write_text(card)
229
+ print(f"Prepared {len(subset)} rows at {parquet_path}")
230
+ for subtask, dimensions in QUOTAS.items():
231
+ counts = Counter(json.loads(row["metadata"])["dim"] for row in subset if row["subtask"] == subtask)
232
+ positions = Counter(row["answer_index"] for row in subset if row["subtask"] == subtask)
233
+ print(subtask, dict(counts), "answer positions", dict(positions))
234
+ if args.publish:
235
+ commit = api.create_commit(
236
+ repo_id=args.output_dataset,
237
+ repo_type="dataset",
238
+ parent_commit=head,
239
+ commit_message="Add stratified mcq_carbon_600 configuration",
240
+ operations=[
241
+ CommitOperationAdd(path_in_repo=PARQUET_PATH, path_or_fileobj=parquet_path),
242
+ CommitOperationAdd(path_in_repo="README.md", path_or_fileobj=card_path),
243
+ CommitOperationAdd(path_in_repo="scripts/create_mcq_carbon_600.py", path_or_fileobj=__file__),
244
+ ],
245
+ )
246
+ print(f"Published {commit.commit_url}")
247
+
248
+
249
+ if __name__ == "__main__":
250
+ main()