#!/bin/bash
# Reproduce every scan in this submission. Requires: Python >= 3.11, pyarrow (tested 26.0.1, Python 3.13), curl, ~50 GB free disk.
# S = working dir containing scripts/ (this folder) ; data/ and out/ are created.
set -euo pipefail
export S=${S:-$(cd "$(dirname "$0")/.." && pwd)}; PY=${PY:-python3}; H=https://huggingface.co/datasets
mkdir -p $S/data/{gsm8k,metamath,mathinstruct,orca,omi2,fineweb} $S/out
g(){ [ -s "$S/data/$2" ] || curl -sL --retry 4 -o "$S/data/$2" "$H/$1"; }
g openai/gsm8k/resolve/740312add88f781978c0658806c59bc2815b9866/main/test-00000-of-00001.parquet gsm8k/test.parquet
g openai/gsm8k/resolve/740312add88f781978c0658806c59bc2815b9866/main/train-00000-of-00001.parquet gsm8k/train.parquet
g meta-math/MetaMathQA/resolve/aa4f34d3d2d3231299b5b03d9b3e5a20da45aa18/MetaMathQA-395K.json metamath/MetaMathQA-395K.json
g TIGER-Lab/MathInstruct/resolve/b4fdc323a7be1379c9c7c0b67b1de72dfee2111a/MathInstruct.json mathinstruct/MathInstruct.json
g microsoft/orca-math-word-problems-200k/resolve/29255d1770cc4eac66e5e7fa378cba542c026350/data/train-00000-of-00001.parquet orca/train.parquet
for i in $(seq -f "%05g" 0 31); do g nvidia/OpenMathInstruct-2/resolve/469216e3f46f4dacf476b382e192485ea51a143e/data/train-$i-of-00032.parquet omi2/train-$i.parquet; done
export GSM8K_TEST=$S/data/gsm8k/test.parquet; cd $S/out; D=$S/data
C="$PY -I $S/scripts/contam.py"; P="$PY -I $S/scripts/para.py"
OMI=$(for p in $D/omi2/*.parquet; do printf "parquet:%s:problem " $p; done)
# n-gram + exact
$C ctrl_test_self ng_ctrl_self.jsonl parquet:$D/gsm8k/test.parquet:question,answer
$C gsm8k_train ng_gsm8k_train.jsonl parquet:$D/gsm8k/train.parquet:question,answer
$C metamathqa ng_metamathqa.jsonl json:$D/metamath/MetaMathQA-395K.json:original_question,query,response
$C mathinstruct ng_mathinstruct.jsonl json:$D/mathinstruct/MathInstruct.json:instruction,output
$C orca_math_200k ng_orca.jsonl parquet:$D/orca/train.parquet:question,answer
$C openmathinstruct2 ng_omi2.jsonl $OMI
# paraphrase
$P ctrl_test_self para_ctrl_self.jsonl parquet:$D/gsm8k/test.parquet:question
$P gsm8k_train para_gsm8k_train.jsonl parquet:$D/gsm8k/train.parquet:question
$P metamathqa para_metamathqa.jsonl json:$D/metamath/MetaMathQA-395K.json:original_question,query
$P mathinstruct para_mathinstruct.jsonl json:$D/mathinstruct/MathInstruct.json:instruction
$P orca_math_200k para_orca.jsonl parquet:$D/orca/train.parquet:question
$P openmathinstruct2 para_omi2.jsonl $OMI
$PY -I $S/scripts/para_recall.py $D/metamath/MetaMathQA-395K.json
# FineWeb sample-10BT (15 shards; each downloaded, hashed, scanned, deleted)
for i in $(seq -f "%03g" 0 14); do echo ${i}_00000; done | xargs -P4 -I{} $S/scripts/fineweb_shard.sh {}
# injection positive control (needs shard 001 present again)
g HuggingFaceFW/fineweb/resolve/9bb295ddab0e05d785b879661af7260fed5140fc/sample/10BT/001_00000.parquet fineweb/001_00000.parquet
mkdir -p inject; $PY -I $S/scripts/inject.py $GSM8K_TEST $D/fineweb/001_00000.parquet inject
$C inject_full inject/full.jsonl parquet:inject/full.parquet:text
$C inject_half inject/half.jsonl parquet:inject/half.parquet:text
