Archangel-system commited on
Commit
10032a9
·
verified ·
1 Parent(s): 6a483b5

Publish deterministic OpenAI-native decontaminated dataset

Browse files
Files changed (2) hide show
  1. build.py +7 -1
  2. verify.py +90 -0
build.py CHANGED
@@ -32,6 +32,7 @@ SOURCE_URL = (
32
  SOURCE_REPO = "sahil2801/CodeAlpaca-20k"
33
  SOURCE_REVISION = "152bb5e9a29651266b018106053980070a0521a1"
34
  SOURCE_LICENSE = "CC-BY-4.0"
 
35
  HUMANEVAL_REPO = "openai/openai_humaneval"
36
  HUMANEVAL_REVISION = "7dce6050a7d6d172f3cc5c32aa97f52fa1a2e544"
37
  MBPP_REPO = "google-research-datasets/mbpp"
@@ -448,6 +449,11 @@ def build(root: Path) -> dict[str, Any]:
448
  data_dir.mkdir(parents=True, exist_ok=True)
449
  source_path = cache_dir / "codealpaca-source.parquet"
450
  download(SOURCE_URL, source_path)
 
 
 
 
 
451
  source = load_dataset("parquet", data_files=str(source_path), split="train")
452
  required = {"instruction", "input", "output"}
453
  if set(source.column_names) != required:
@@ -592,7 +598,7 @@ def build(root: Path) -> dict[str, Any]:
592
  "revision": SOURCE_REVISION,
593
  "url": SOURCE_URL,
594
  "license": SOURCE_LICENSE,
595
- "sha256": sha256_file(source_path),
596
  },
597
  "benchmarks": {
598
  "HumanEval": {
 
32
  SOURCE_REPO = "sahil2801/CodeAlpaca-20k"
33
  SOURCE_REVISION = "152bb5e9a29651266b018106053980070a0521a1"
34
  SOURCE_LICENSE = "CC-BY-4.0"
35
+ SOURCE_SHA256 = "5a2fa0c510d42843292c583f357086abb59f95796e0f55727b97e449aa93bed9"
36
  HUMANEVAL_REPO = "openai/openai_humaneval"
37
  HUMANEVAL_REVISION = "7dce6050a7d6d172f3cc5c32aa97f52fa1a2e544"
38
  MBPP_REPO = "google-research-datasets/mbpp"
 
449
  data_dir.mkdir(parents=True, exist_ok=True)
450
  source_path = cache_dir / "codealpaca-source.parquet"
451
  download(SOURCE_URL, source_path)
452
+ source_sha256 = sha256_file(source_path)
453
+ if source_sha256 != SOURCE_SHA256:
454
+ raise AssertionError(
455
+ f"Source checksum changed: expected {SOURCE_SHA256}, got {source_sha256}"
456
+ )
457
  source = load_dataset("parquet", data_files=str(source_path), split="train")
458
  required = {"instruction", "input", "output"}
459
  if set(source.column_names) != required:
 
598
  "revision": SOURCE_REVISION,
599
  "url": SOURCE_URL,
600
  "license": SOURCE_LICENSE,
601
+ "sha256": source_sha256,
602
  },
603
  "benchmarks": {
604
  "HumanEval": {
verify.py CHANGED
@@ -8,6 +8,8 @@ import hashlib
8
  import json
9
  import re
10
  import shutil
 
 
11
  from collections import Counter
12
  from pathlib import Path
13
  from typing import Any
@@ -22,7 +24,11 @@ from build import (
22
  MBPP_REPO,
23
  MBPP_REVISION,
24
  REPO_ID,
 
 
25
  contamination_hits,
 
 
26
  load_token,
27
  make_benchmark_indexes,
28
  normalize_text,
@@ -154,6 +160,18 @@ def verify(repo_id: str) -> dict[str, Any]:
154
  }
155
  train_test_overlap = train_signatures & test_signatures
156
  assert not train_test_overlap, "aggressive train/test overlap is not zero"
 
 
 
 
 
 
 
 
 
 
 
 
157
  all_rows = list(train) + list(test)
158
  assert len(train_signatures) == len(train)
159
  assert len(test_signatures) == len(test)
@@ -193,6 +211,59 @@ def verify(repo_id: str) -> dict[str, Any]:
193
  )
194
  assert not residual_hits, f"benchmark contamination remains: {residual_hits[:3]}"
195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  rejection_lines = [
197
  json.loads(line)
198
  for line in remote_paths["rejections.jsonl"].read_text(encoding="utf-8").splitlines()
@@ -213,6 +284,13 @@ def verify(repo_id: str) -> dict[str, Any]:
213
  == stats["rejections"]["train_test_overlap_from_train"]
214
  )
215
  assert len(rejection_lines) == stats["rejections"]["total"]
 
 
 
 
 
 
 
216
 
217
  assert stats["diversity"]["rows_with_nonempty_input"] == sum(
218
  bool(row["input"].strip()) for row in all_rows
@@ -229,6 +307,13 @@ def verify(repo_id: str) -> dict[str, Any]:
229
  for row in all_rows
230
  }
231
  )
 
 
 
 
 
 
 
232
 
233
  for filename in ("data/train.parquet", "data/test.parquet", "rejections.jsonl"):
234
  assert sha256(remote_paths[filename]) == stats["files"][filename]["sha256"]
@@ -249,6 +334,9 @@ def verify(repo_id: str) -> dict[str, Any]:
249
  "fresh_dataset_cache_removed": True,
250
  "splits": {"train": len(train), "test": len(test)},
251
  "train_test_aggressive_overlap": len(train_test_overlap),
 
 
 
252
  "benchmark_overlap_after_filtering": {
253
  "HumanEval": {"exact_normalized_rows": 0, "13gram_rows": 0},
254
  "MBPP": {"exact_normalized_rows": 0, "13gram_rows": 0},
@@ -257,6 +345,8 @@ def verify(repo_id: str) -> dict[str, Any]:
257
  "strict_user_assistant_alternation": True,
258
  "nonempty_outputs": True,
259
  "card_counts_match_remote_data": True,
 
 
260
  "remote_hashes_match_stats": True,
261
  }
262
  print(json.dumps(result, indent=2))
 
8
  import json
9
  import re
10
  import shutil
11
+ import tempfile
12
+ import urllib.request
13
  from collections import Counter
14
  from pathlib import Path
15
  from typing import Any
 
24
  MBPP_REPO,
25
  MBPP_REVISION,
26
  REPO_ID,
27
+ SOURCE_SHA256,
28
+ SOURCE_URL,
29
  contamination_hits,
30
+ distribution,
31
+ lexical_tokens,
32
  load_token,
33
  make_benchmark_indexes,
34
  normalize_text,
 
160
  }
161
  train_test_overlap = train_signatures & test_signatures
162
  assert not train_test_overlap, "aggressive train/test overlap is not zero"
163
+ train_instruction_signatures = {
164
+ normalize_text(row["instruction"]) for row in train
165
+ }
166
+ test_instruction_signatures = {
167
+ normalize_text(row["instruction"]) for row in test
168
+ }
169
+ train_test_instruction_overlap = (
170
+ train_instruction_signatures & test_instruction_signatures
171
+ )
172
+ assert not train_test_instruction_overlap, (
173
+ "aggressively normalized instruction overlap across train/test is not zero"
174
+ )
175
  all_rows = list(train) + list(test)
176
  assert len(train_signatures) == len(train)
177
  assert len(test_signatures) == len(test)
 
211
  )
212
  assert not residual_hits, f"benchmark contamination remains: {residual_hits[:3]}"
213
 
214
+ with tempfile.TemporaryDirectory(prefix="codealpaca-verify-source-") as temporary:
215
+ source_path = Path(temporary) / "source.parquet"
216
+ with urllib.request.urlopen(SOURCE_URL) as response, source_path.open("wb") as handle:
217
+ shutil.copyfileobj(response, handle)
218
+ source = load_dataset(
219
+ "parquet",
220
+ data_files=str(source_path),
221
+ split="train",
222
+ download_mode=DownloadMode.FORCE_REDOWNLOAD,
223
+ )
224
+ assert sha256(source_path) == SOURCE_SHA256 == stats["source"]["sha256"]
225
+ source_instructions = list(source["instruction"])
226
+ source_inputs = list(source["input"])
227
+ source_outputs = list(source["output"])
228
+ measured_source_audit = {
229
+ "rows": len(source),
230
+ "input_nonempty": sum(bool(value.strip()) for value in source_inputs),
231
+ "output_empty": sum(not bool(value.strip()) for value in source_outputs),
232
+ "duplicate_instruction_rows_exact": len(source_instructions)
233
+ - len(set(source_instructions)),
234
+ "duplicate_instruction_rows_normalized": len(source_instructions)
235
+ - len({normalize_text(value) for value in source_instructions}),
236
+ "output_equals_instruction_exact": sum(
237
+ output == instruction
238
+ for instruction, output in zip(source_instructions, source_outputs)
239
+ ),
240
+ "output_equals_instruction_normalized": sum(
241
+ normalize_text(output) == normalize_text(instruction)
242
+ for instruction, output in zip(source_instructions, source_outputs)
243
+ ),
244
+ }
245
+ assert measured_source_audit == stats["source_audit"]
246
+ assert len(humaneval) == stats["benchmarks"]["HumanEval"]["test_items"]
247
+ assert len(mbpp) == stats["benchmarks"]["MBPP"]["test_items"]
248
+
249
+ measured_before_filtering: dict[str, dict[str, set[int]]] = {
250
+ benchmark: {"exact_normalized": set(), "13gram": set()}
251
+ for benchmark in ("HumanEval", "MBPP")
252
+ }
253
+ for source_index, instruction in enumerate(source_instructions):
254
+ for hit in contamination_hits(instruction, exact_index, ngram_index):
255
+ measured_before_filtering[hit["benchmark"]][hit["criterion"]].add(
256
+ source_index
257
+ )
258
+ for benchmark in ("HumanEval", "MBPP"):
259
+ exact_rows = measured_before_filtering[benchmark]["exact_normalized"]
260
+ gram_rows = measured_before_filtering[benchmark]["13gram"]
261
+ assert stats["benchmark_overlap_before_filtering"][benchmark] == {
262
+ "exact_normalized_rows": len(exact_rows),
263
+ "13gram_rows": len(gram_rows),
264
+ "union_rows": len(exact_rows | gram_rows),
265
+ }
266
+
267
  rejection_lines = [
268
  json.loads(line)
269
  for line in remote_paths["rejections.jsonl"].read_text(encoding="utf-8").splitlines()
 
284
  == stats["rejections"]["train_test_overlap_from_train"]
285
  )
286
  assert len(rejection_lines) == stats["rejections"]["total"]
287
+ assert len(source) - len(all_rows) == stats["rejections"]["total"]
288
+ measured_rejection_rate = round(
289
+ 100 * stats["rejections"]["total"] / len(source), 6
290
+ )
291
+ assert measured_rejection_rate == stats["rejection_rate_percent"]
292
+ measured_test_fraction = round(100 * len(test) / len(all_rows), 6)
293
+ assert measured_test_fraction == stats["splits"]["test_fraction_percent"]
294
 
295
  assert stats["diversity"]["rows_with_nonempty_input"] == sum(
296
  bool(row["input"].strip()) for row in all_rows
 
307
  for row in all_rows
308
  }
309
  )
310
+ assert stats["lengths"]["user_tokens"] == distribution(
311
+ [len(lexical_tokens(row["messages"][0]["content"])) for row in all_rows]
312
+ )
313
+ assert stats["lengths"]["assistant_tokens"] == distribution(
314
+ [len(lexical_tokens(row["messages"][1]["content"])) for row in all_rows]
315
+ )
316
+ assert stats["post_build_checks"]["train_test_normalized_pair_overlap"] == 0
317
 
318
  for filename in ("data/train.parquet", "data/test.parquet", "rejections.jsonl"):
319
  assert sha256(remote_paths[filename]) == stats["files"][filename]["sha256"]
 
334
  "fresh_dataset_cache_removed": True,
335
  "splits": {"train": len(train), "test": len(test)},
336
  "train_test_aggressive_overlap": len(train_test_overlap),
337
+ "train_test_normalized_instruction_overlap": len(
338
+ train_test_instruction_overlap
339
+ ),
340
  "benchmark_overlap_after_filtering": {
341
  "HumanEval": {"exact_normalized_rows": 0, "13gram_rows": 0},
342
  "MBPP": {"exact_normalized_rows": 0, "13gram_rows": 0},
 
345
  "strict_user_assistant_alternation": True,
346
  "nonempty_outputs": True,
347
  "card_counts_match_remote_data": True,
348
+ "source_audit_matches_fresh_source": True,
349
+ "prefilter_overlap_counts_match_fresh_source": True,
350
  "remote_hashes_match_stats": True,
351
  }
352
  print(json.dumps(result, indent=2))