Skip to content
nano-gpt-data-curation

claude-opus-4-8

nano-gpt-data-curation — graded by the task's verifier against a measured baseline.

backend
modal
variant
claude claude-opus-4-8
metric
held-out multi-domain perplexity
actions
97
duration
1h 16m
recorded
2026-08-04

run iddclm-nano-curation__xJxXGaB

Everything claude-opus-4-8 did on this task, in order.

download JSON ↗
claude-codeclaude-opus-4-897 turns57 narration97 action97 observation40 reasoning1 final
#26
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolEdit
args
{
  "replace_all": false,
  "file_path": "/workspace/submission/curate.py",
  "old_string": "# ---------- score every pool doc: length-normalised total log-odds ----------\nscores = np.empty(N, dtype=np.float32)\nfor i in range(N):\n    f = feats(texts[i])\n    scores[i] = weight[np.array(f)].sum() / len(f) if f else -1e9\n    if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)",
  "new_string": "# ---------- score every pool doc: length-normalised total log-odds ----------\nif not _HAVE_SCORES:\n    scores = np.empty(N, dtype=np.float32)\n    for i in range(N):\n        f = feats(texts[i])\n        scores[i] = weight[np.array(f)].sum() / len(f) if f else -1e9\n        if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)\n    np.save(_CACHE, scores)"
}
Edit result
The file /workspace/submission/curate.py has been updated successfully. (file state is current in your context — no need to Read it back)

[metadata] {"filePath": "/workspace/submission/curate.py", "oldString": "# ---------- score every pool doc: length-normalised total log-odds ----------\nscores = np.empty(N, dtype=np.float32)\nfor i in range(N):\n    f = feats(texts[i])\n    scores[i] = weight[np.array(f)].sum() / len(f) if f else -1e9\n    if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)", "newString": "# ---------- score every pool doc: length-normalised total log-odds ----------\nif not _HAVE_SCORES:\n    scores = np.empty(N, dtype=np.float32)\n    for i in range(N):\n        f = feats(texts[i])\n        scores[i] = weight[np.array(f)].sum() / len(f) if f else -1e9\n        if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)\n    np.save(_CACHE, scores)", "originalFile": "\"\"\"Curate a raw web pool for training a small LM whose eval target is a BROAD,\nmulti-domain high-quality English corpus (Wikipedia + general web prose + news +\ntechnical Q&A).\n\nSTATED CRITERION: a document is worth training on to the extent it *resembles the\ndisclosed target domain*, per token. We estimate target-likeness with a linear\nNaive-Bayes log-odds model over word unigrams+bigrams: positives are document\nchunks of the disclosed dev target (data/multi_dev.npy, decoded), negatives are a\nrandom sample of the raw pool. Each pool document's score is the MEAN per-token\nlog-odds of target-vs-pool (length-normalised, so long docs aren't favoured just\nfor being long). We first gate out obvious junk (too short, non-English/markup\ngibberish by low alpha ratio, degenerate line repetition), dedup near-identical\ndocs (keeping the highest-scoring copy), then emit ids in descending score\n(priority order). Deterministic; no manual id picking.\n\nPure numpy/stdlib (no sklearn) so it runs in the sandbox.\n\"\"\"\nimport json, re, sys, zlib, math\nimport numpy as np\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV  = \"/workspace/data/multi_dev.npy\"\nOUT  = \"/workspace/submission/selection.json\"\nSEED = 1337\nK    = 1 << 20                      # hashed feature buckets\nWORD = re.compile(r\"[a-z0-9']+\")\nrng  = np.random.default_rng(SEED)\n\ndef feats(text, cap=2000):\n    \"\"\"hashed unigram + bigram feature ids for a doc (first `cap` words).\"\"\"\n    w = WORD.findall(text.lower())[:cap]\n    out = [zlib.crc32(x.encode()) & (K - 1) for x in w]\n    for i in range(len(w) - 1):\n        out.append(zlib.crc32((w[i] + \" \" + w[i + 1]).encode()) & (K - 1))\n    return out\n\n# ---------- load pool ----------\nids, texts = [], []\nwith open(POOL) as f:\n    for line in f:\n        r = json.loads(line)\n        ids.append(r[\"id\"]); texts.append(r[\"text\"])\nN = len(ids)\nprint(f\"pool: {N} docs\", file=sys.stderr)\n\nimport os\n_CACHE = \"/tmp/curate_scores.npy\"\nif os.path.exists(_CACHE):\n    scores = np.load(_CACHE)\n    if len(scores) == N:\n        print(\"loaded cached scores\", file=sys.stderr)\n        _HAVE_SCORES = True\n    else:\n        _HAVE_SCORES = False\nelse:\n    _HAVE_SCORES = False\n\n# ---------- positives from disclosed dev target ----------\nfrom transformers import AutoTokenizer\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\ndev = np.load(DEV)\npos_texts, cur = [], []\nfor t in dev.tolist():\n    if t == 50256:\n        if cur: pos_texts.append(tok.decode(cur)); cur = []\n    else:\n        cur.append(t)\nif cur: pos_texts.append(tok.decode(cur))\npos_texts = [p for p in pos_texts if len(p) > 200]\nprint(f\"positives: {len(pos_texts)}\", file=sys.stderr)\n\n# ---------- negatives: random pool sample ----------\nneg_idx = rng.choice(N, size=min(6000, N), replace=False)\nneg_texts = [texts[i] for i in neg_idx]\n\n# ---------- fit Naive-Bayes log-odds weights ----------\npos_c = np.zeros(K, dtype=np.float64)\nneg_c = np.zeros(K, dtype=np.float64)\nfor p in pos_texts:\n    f = feats(p)\n    if f: np.add.at(pos_c, np.array(f), 1.0)\nfor p in neg_texts:\n    f = feats(p)\n    if f: np.add.at(neg_c, np.array(f), 1.0)\na = 1.0\nPtot, Ntot = pos_c.sum(), neg_c.sum()\nweight = (np.log(pos_c + a) - math.log(Ptot + a * K)) - \\\n         (np.log(neg_c + a) - math.log(Ntot + a * K))\n# Only trust features actually observed (>=3 times); center so a \"neutral\" seen\n# feature ~ 0 and unseen features contribute 0.  Then score = sum(weight)/n_tokens,\n# so docs padded with rare junk tokens dilute toward 0 instead of scoring high.\nc0 = math.log(Ntot + a * K) - math.log(Ptot + a * K)   # OOV/prior constant\nweight = weight - c0\nweight[(pos_c + neg_c) < 3] = 0.0\nweight = weight.astype(np.float32)\n\n# ---------- score every pool doc: length-normalised total log-odds ----------\nscores = np.empty(N, dtype=np.float32)\nfor i in range(N):\n    f = feats(texts[i])\n    scores[i] = weight[np.array(f)].sum() / len(f) if f else -1e9\n    if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)\n\n# ---------- quality gates ----------\nfrom collections import Counter\n# common English function words: prose is 30-45% these; nav/keyword-spam and\n# non-English text are near 0, so this is a strong \"is it real English prose\" gate.\nSTOP = set(\"the of and to a in is that it for on as with was are be by this at \"\n           \"from or an not but have has had he she they we you i his her their \"\n           \"which who will would can could been were said your all more one about \"\n           \"when what there if so no do does did than then them these those into \"\n           \"out up down over after also its our\".split())\ndef passes(t):\n    if len(t) < 300: return False\n    ws = WORD.findall(t.lower())\n    if len(ws) < 60: return False\n    alpha = sum(c.isalpha() or c.isspace() for c in t) / len(t)\n    if alpha < 0.70: return False\n    digit = sum(c.isdigit() for c in t) / len(t)\n    if digit > 0.15: return False                         # tables / listings\n    stopr = sum(1 for w in ws if w in STOP) / len(ws)\n    if stopr < 0.22: return False                         # non-English / nav / keyword spam / code\n    lines = [l for l in t.split(\"\\n\") if l.strip()]\n    if lines and Counter(lines).most_common(1)[0][1] / len(lines) > 0.5: return False\n    wc = Counter(ws)\n    if len(wc) / len(ws) < 0.30: return False             # low type-token ratio: repetitive\n    if wc.most_common(1)[0][1] / len(ws) > 0.10: return False  # one token dominates (spam)\n    return True\nkeep = np.array([passes(t) for t in texts], dtype=bool)\nprint(f\"passed gates: {int(keep.sum())}\", file=sys.stderr)\n\n# ---------- dedup (highest score wins) + emit priority order ----------\norder = np.argsort(-scores)\nseen, selection = set(), []\nfor i in order:\n    if not keep[i]: continue\n    sig = re.sub(r\"\\s+\", \" \", texts[i].lower()).strip()[:400]\n    h = zlib.crc32(sig.encode())\n    if h in seen: continue\n    seen.add(h); selection.append(int(ids[i]))\nselection = selection[:40000]\njson.dump(selection, open(OUT, \"w\"))\nprint(f\"wrote {len(selection)} ids -> {OUT}\", file=sys.stderr)\n", "structuredPatch": [{"oldStart": 95, "oldLines": 11, "newStart": 95, "newLines": 13, "lines": [" weight = weight.astype(np.float32)", " ", " # ---------- score every pool doc: length-normalised total log-odds ----------", "-scores = np.empty(N, dtype=np.float32)", "-for i in range(N):", "-    f = feats(texts[i])", "-    scores[i] = weight[np.array(f)].sum() / len(f) if f else -1e9", "-    if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)", "+if not _HAVE_SCORES:", "+    scores = np.empty(N, dtype=np.float32)", "+    for i in range(N):", "+        f = feats(texts[i])", "+        scores[i] = weight[np.array(f)].sum() / len(f) if f else -1e9", "+        if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)", "+    np.save(_CACHE, scores)", " ", " # ---------- quality gates ----------", " from collections import Counter"]}], "userModified": false, "replaceAll": false}
#27
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolBashRun curation with stopword gate
args
{
  "command": "cd /workspace; nohup python3 submission/curate.py > /tmp/cur3.log 2>&1 & echo \"pid $!\"",
  "description": "Run curation with stopword gate"
}
Bash result
pid 1437

[stdout]
pid 1437
[metadata] {"noOutputExpected": false}
#28
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolBashCheck time remaining
args
{
  "command": "cd /workspace; cat /workspace/.timer/remaining_secs; echo \"secs left\"",
  "description": "Check time remaining"
}
Bash result
4498
secs left

[stdout]
4498
secs left
[metadata] {"noOutputExpected": false}
#29
narration

75 min left. Let me wait for curation to finish, then inspect top docs.

toolBashInspect selection with stopword gate
args
{
  "command": "cd /workspace; sleep 150; grep -E \"wrote|passed|gates\" /tmp/cur3.log; python3 -c \"\nimport json\nsel=json.load(open('submission/selection.json'))\ntext={}\nwith open('data/pool.jsonl') as f:\n    for line in f:\n        r=json.loads(line); text[r['id']]=r['text']\nprint('total',len(sel))\nfor i in sel[:10]:\n    print('id',i,'::',text[i][:140].replace(chr(10),' '))\nprint('... rank 5000 ...')\nfor i in sel[5000:5003]:\n    print('id',i,'::',text[i][:140].replace(chr(10),' '))\n\"",
  "description": "Inspect selection with stopword gate"
}
Bash result
Command did not complete within its 120s timeout and was moved to the background (ID: bguxdeyl0). Output is being written to: /tmp/claude-0/-workspace/056a17ab-c7c2-448d-bef2-fc697ffa5283/tasks/bguxdeyl0.output. You will be notified when it completes. To check interim output, use Read on that file path.
Session cwd remains /workspace; directory changes made by the backgrounded command do not apply to subsequent commands.

[metadata] {"noOutputExpected": false, "backgroundTaskId": "bguxdeyl0", "timedOutAfterMs": 120000, "backgroundCwdHint": "Session cwd remains /workspace; directory changes made by the backgrounded command do not apply to subsequent commands."}
#30
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolBashRead inspection output
args
{
  "command": "cat /tmp/claude-0/-workspace/056a17ab-c7c2-448d-bef2-fc697ffa5283/tasks/bguxdeyl0.output",
  "description": "Read inspection output"
}
Bash result
(Bash completed with no output)

[metadata] {"noOutputExpected": false}
#31
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolBashInspect selection top docs
args
{
  "command": "cd /workspace; grep -E \"wrote|passed\" /tmp/cur3.log; echo \"===\"; python3 -c \"\nimport json\nsel=json.load(open('submission/selection.json'))\ntext={}\nwith open('data/pool.jsonl') as f:\n    for line in f:\n        r=json.loads(line); text[r['id']]=r['text']\nprint('total',len(sel))\nfor i in sel[:10]:\n    print('id',i,'::',text[i][:130].replace(chr(10),' '))\n\"",
  "description": "Inspect selection top docs"
}
Bash result
===
total 40000
id 163054 :: .<|endoftext|>Per offrire informazioni e servizi nel miglior modo possibile,questo sito utilizza cookie tecnici e analitici. Per m
id 146338 :: ? #debill What Digital Economy Bill? #debill Links @doc1online has declared that they do not recognise the Digital Economy Bill I 
id 123682 ::  Blogger.<|endoftext|>What Digital Economy Bill? #debill What Digital Economy Bill? #debill Links @doc1online has declared that th
id 169616 :: ancel Success OK<|endoftext|>FloraPix Tropical Plant Picture Gallery (15497) FloraPix all >Home >Info >Guestbook >New (recently up
id 161670 :: �站地圖<|endoftext|>BidiFormatter.Builder | Android Developers Platform Android Studio Google Play Android Jetpack Docs News Language
id 144641 :: Serializable RemObjects Elements Elements Docs RemObjects Oxygene RemObjects C# RemObjects Silver (Swift Language) RemObjects Iodi
id 153363 :: <|endoftext|>Moths June Photo Gallery by Tom Murray at pbase.com Tom Murray | profile | all galleries >> Arthropods - Arthropoda >
id 159028 ::  Dubai<|endoftext|>ZelCash (ZEL) waarde is nu €0.1927. cryptomuntenindex.nl Beste cryptocurrencies om vandaag in te investeren Exc
id 108673 :: Here are the list of players included in each of the eight playing team in IPL 2007-08. The tournament will begin on April 18, whe
id 141997 ::  LastFm - User - GetTopTags API :: Temboo Sorry, Temboo requires JavaScript! Please enable it in your browser and try again. PRODU

[stdout]
===
total 40000
id 163054 :: .<|endoftext|>Per offrire informazioni e servizi nel miglior modo possibile,questo sito utilizza cookie tecnici e analitici. Per m
id 146338 :: ? #debill What Digital Economy Bill? #debill Links @doc1online has declared that they do not recognise the Digital Economy Bill I 
id 123682 ::  Blogger.<|endoftext|>What Digital Economy Bill? #debill What Digital Economy Bill? #debill Links @doc1online has declared that th
id 169616 :: ancel Success OK<|endoftext|>FloraPix Tropical Plant Picture Gallery (15497) FloraPix all >Home >Info >Guestbook >New (recently up
id 161670 :: �站地圖<|endoftext|>BidiFormatter.Builder | Android Developers Platform Android Studio Google Play Android Jetpack Docs News Language
id 144641 :: Serializable RemObjects Elements Elements Docs RemObjects Oxygene RemObjects C# RemObjects Silver (Swift Language) RemObjects Iodi
id 153363 :: <|endoftext|>Moths June Photo Gallery by Tom Murray at pbase.com Tom Murray | profile | all galleries >> Arthropods - Arthropoda >
id 159028 ::  Dubai<|endoftext|>ZelCash (ZEL) waarde is nu €0.1927. cryptomuntenindex.nl Beste cryptocurrencies om vandaag in te investeren Exc
id 108673 :: Here are the list of players included in each of the eight playing team in IPL 2007-08. The tournament will begin on April 18, whe
id 141997 ::  LastFm - User - GetTopTags API :: Temboo Sorry, Temboo requires JavaScript! Please enable it in your browser and try again. PRODU
[metadata] {"noOutputExpected": false}
#32
narration

cur3 is still running — I'm reading stale output again. Let me check its actual progress.

toolBashCheck cur3 log progress
args
{
  "command": "cd /workspace; tail -6 /tmp/cur3.log; ls -la /tmp/curate_scores.npy 2>/dev/null",
  "description": "Check cur3 log progress"
}
Bash result
positives: 2557
scored 0
scored 40000
scored 80000
scored 120000
scored 160000
-rw-r--r-- 1 root root 728192 Aug  4 03:38 /tmp/curate_scores.npy

[stdout]
positives: 2557
scored 0
scored 40000
scored 80000
scored 120000
scored 160000
-rw-r--r-- 1 root root 728192 Aug  4 03:38 /tmp/curate_scores.npy
[metadata] {"noOutputExpected": false}
#33
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolBashInspect final selection top docs
args
{
  "command": "cd /workspace; sleep 25; grep -E \"wrote|passed\" /tmp/cur3.log; echo \"===\"; python3 -c \"\nimport json\nsel=json.load(open('submission/selection.json'))\ntext={}\nwith open('data/pool.jsonl') as f:\n    for line in f:\n        r=json.loads(line); text[r['id']]=r['text']\nprint('total',len(sel))\nfor i in sel[:12]:\n    print('id',i,'::',text[i][:120].replace(chr(10),' '))\n\"",
  "description": "Inspect final selection top docs"
}
Bash result
passed gates: 126814
wrote 40000 ids -> /workspace/submission/selection.json
===
total 40000
id 23673 :: Lahore:In the prospects of stoned to death incident of a Khanewal Woman, Inspector General of Police Punjab, Mohammad Ha
id 58452 :: <|endoftext|>New Delhi: Five new Supreme Court judges were today sworn in, taking the top court’s strength to 28, includ
id 73993 :: |PREDECESSORS AND SHORT HISTORY: in the 16th century by Rao Gopalji fl.1550, 4th son of Raja Prithviraj Singhji I of Jai
id 18830 :: Archaeological dating methods Futilities must undress thitherward convened dismissively towerish tomato. Possessory tong
id 41186 :: Amarnath Yatra 2017 Amarnath Yatra 2017 News Jammu and Kashmir police said three people, alleged conspirators in the 10 
id 76107 :: Major Bhupinder Singh In sept. 1965, Major Bhupinder Singh commanded the "B" squadron of the 4 Horse against Pakistani f
id 43758 :: vel (Maharashtra), June 14 (ANI): A magistrate's court in Panvel, Maharashtra, on Sunday extended suspended senior Natio
id 37064 :: The Bharatiya Janata Party (BJP) leaders of the West Bengal unit will meet Union Home Minister Rajnath Singh on Thursday
id 79735 :: <|endoftext|>India’s PM Narendra Modi has tweeted pictures of his mother’s first visit to his official residence in Delh
id 37522 :: Prime Minister Imran Khan on Thursday congratulated India’s premier Narendra Modi on his victory in the country's nation
id 38702 :: <|endoftext|>|HOME | NEWS | REPORT| |November 6, 1998|| Akalis drop out of Delhi, Rajasthan race The Shiromani Akali Dal
id 113946 ::  Below.<|endoftext|>Dhaka yesterday protested the "derogatory and provocative" remarks of Myanmar Religious Affairs Mini

[stdout]
passed gates: 126814
wrote 40000 ids -> /workspace/submission/selection.json
===
total 40000
id 23673 :: Lahore:In the prospects of stoned to death incident of a Khanewal Woman, Inspector General of Police Punjab, Mohammad Ha
id 58452 :: <|endoftext|>New Delhi: Five new Supreme Court judges were today sworn in, taking the top court’s strength to 28, includ
id 73993 :: |PREDECESSORS AND SHORT HISTORY: in the 16th century by Rao Gopalji fl.1550, 4th son of Raja Prithviraj Singhji I of Jai
id 18830 :: Archaeological dating methods Futilities must undress thitherward convened dismissively towerish tomato. Possessory tong
id 41186 :: Amarnath Yatra 2017 Amarnath Yatra 2017 News Jammu and Kashmir police said three people, alleged conspirators in the 10 
id 76107 :: Major Bhupinder Singh In sept. 1965, Major Bhupinder Singh commanded the "B" squadron of the 4 Horse against Pakistani f
id 43758 :: vel (Maharashtra), June 14 (ANI): A magistrate's court in Panvel, Maharashtra, on Sunday extended suspended senior Natio
id 37064 :: The Bharatiya Janata Party (BJP) leaders of the West Bengal unit will meet Union Home Minister Rajnath Singh on Thursday
id 79735 :: <|endoftext|>India’s PM Narendra Modi has tweeted pictures of his mother’s first visit to his official residence in Delh
id 37522 :: Prime Minister Imran Khan on Thursday congratulated India’s premier Narendra Modi on his victory in the country's nation
id 38702 :: <|endoftext|>|HOME | NEWS | REPORT| |November 6, 1998|| Akalis drop out of Delhi, Rajasthan race The Shiromani Akali Dal
id 113946 ::  Below.<|endoftext|>Dhaka yesterday protested the "derogatory and provocative" remarks of Myanmar Religious Affairs Mini
[metadata] {"noOutputExpected": false}
#34
narration

The stopword gate worked — top docs are now clean English news prose. Gates pass 126,814 docs. The selection skews heavily toward news though; the target wants equal parts wiki/web/news/QA. Let me get a real perplexity number now to ground myself, then consider balancing. Starting a dev eval.

toolBashRun dev eval on current selection
args
{
  "command": "cd /workspace; nohup bash dev_eval.sh > /tmp/eval1.log 2>&1 & echo \"eval pid $!\"",
  "description": "Run dev eval on current selection"
}
Bash result
eval pid 1695

[stdout]
eval pid 1695
[metadata] {"noOutputExpected": false}
#35
narration

While the eval trains, let me check its progress and think about a balanced (stratified) variant.

toolBashCheck eval1 progress
args
{
  "command": "cd /workspace; sleep 60; cat /tmp/eval1.log",
  "description": "Check eval1 progress"
}
Bash result
Token indices sequence length is longer than the specified maximum sequence length for this model (2170 > 1024). Running this sequence through the model will result in indexing errors
packed 12000000 tokens from 40000 ids -> /tmp/dev_train.npy

[stdout]
Token indices sequence length is longer than the specified maximum sequence length for this model (2170 > 1024). Running this sequence through the model will result in indexing errors
packed 12000000 tokens from 40000 ids -> /tmp/dev_train.npy
[metadata] {"noOutputExpected": false}
#36
narration

Packing worked (12M tokens). Training now. Let me wait for the perplexity result.

toolBashGet eval1 perplexity
args
{
  "command": "cd /workspace; sleep 70; cat /tmp/eval1.log | grep -E \"HELDOUT|PPL|dev\"",
  "description": "Get eval1 perplexity"
}
Bash result
packed 12000000 tokens from 40000 ids -> /tmp/dev_train.npy
HELDOUT_PPL 343.702  loss 5.8398  train_s 51  /tmp/dev_train.npy
(dev PPL on multi_dev; official uses a hidden disjoint sample of the same HQ domain)

[stdout]
packed 12000000 tokens from 40000 ids -> /tmp/dev_train.npy
HELDOUT_PPL 343.702  loss 5.8398  train_s 51  /tmp/dev_train.npy
(dev PPL on multi_dev; official uses a hidden disjoint sample of the same HQ domain)
[metadata] {"noOutputExpected": false}
#37
narration

Dev PPL = 343.7 with my classifier selection. Now the key improvement: the target is equal parts 4 registers, but my selection is news-dominated. The dev target is structured in positional quartiles (wiki → technical prose → news → Q&A). I'll train 4 register-specific scorers and round-robin select to guarantee balanced coverage. Let me rewrite curate.py for register-balanced selection.

toolWrite
args
{
  "file_path": "/workspace/submission/curate.py",
  "content": "\"\"\"Curate a raw web pool for a small LM whose eval target is a BROAD, EQUAL-PARTS\nmulti-domain high-quality English corpus: encyclopedic (Wikipedia), general\nhigh-quality web prose, news, and technical Q&A.\n\nSTATED CRITERION\n----------------\nTwo ideas, composed:\n\n1. Clean-English-prose gate. Keep only documents that read like real English\n   prose: long enough, mostly alphabetic, not table/listing/code, a healthy\n   function-word (stopword) ratio (nav menus, keyword spam, and non-English text\n   fail this), no degenerate line/token repetition. This removes the bulk of raw\n   web junk regardless of topic.\n\n2. Register-balanced target-likeness. The disclosed target is EQUAL parts of four\n   registers, and the dev target stream (data/multi_dev.npy) is laid out in four\n   positional blocks (wiki -> technical/web prose -> news -> Q&A). We split it into\n   four register corpora and fit one linear Naive-Bayes log-odds model per register\n   (register chunks = positive, a random pool sample = negative). Every surviving\n   pool doc gets four per-token log-odds scores. We then fill the priority list by\n   ROUND-ROBIN across the four registers, each round taking the next highest-scoring\n   unused doc for that register. The 12M-token budget is therefore split ~evenly\n   across the four target registers instead of collapsing onto the most abundant one\n   (news), matching the eval's equal-parts composition.\n\nReproducible, deterministic, pure numpy/stdlib (no sklearn). No hand-picked ids.\n\"\"\"\nimport json, re, sys, zlib, math, os\nimport numpy as np\nfrom collections import Counter\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV  = \"/workspace/data/multi_dev.npy\"\nOUT  = \"/workspace/submission/selection.json\"\nSEED = 1337\nK    = 1 << 20\nNREG = 4\nWORD = re.compile(r\"[a-z0-9']+\")\nrng  = np.random.default_rng(SEED)\n\ndef feats(text, cap=2000):\n    w = WORD.findall(text.lower())[:cap]\n    out = [zlib.crc32(x.encode()) & (K - 1) for x in w]\n    for i in range(len(w) - 1):\n        out.append(zlib.crc32((w[i] + \" \" + w[i + 1]).encode()) & (K - 1))\n    return out\n\n# ---------- load pool ----------\nids, texts = [], []\nwith open(POOL) as f:\n    for line in f:\n        r = json.loads(line)\n        ids.append(r[\"id\"]); texts.append(r[\"text\"])\nN = len(ids)\nids = np.array(ids)\nprint(f\"pool: {N} docs\", file=sys.stderr)\n\n# ---------- register positives from the disclosed dev target ----------\nfrom transformers import AutoTokenizer\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\ndev = np.load(DEV)\nchunks, cur = [], []\nfor t in dev.tolist():\n    if t == 50256:\n        if cur: chunks.append(tok.decode(cur)); cur = []\n    else:\n        cur.append(t)\nif cur: chunks.append(tok.decode(cur))\nchunks = [c for c in chunks if len(c) > 200]\n# four positional register groups (dev is laid out wiki|prose|news|qa)\nper = len(chunks) / NREG\nreg_pos = [chunks[int(k * per):int((k + 1) * per)] for k in range(NREG)]\nprint(\"register sizes:\", [len(r) for r in reg_pos], file=sys.stderr)\n\n# ---------- negatives: random pool sample ----------\nneg_idx = rng.choice(N, size=min(6000, N), replace=False)\nneg_texts = [texts[i] for i in neg_idx]\nneg_c = np.zeros(K, dtype=np.float64)\nfor p in neg_texts:\n    fe = feats(p)\n    if fe: np.add.at(neg_c, np.array(fe), 1.0)\nNtot = neg_c.sum()\n\n# ---------- one NB log-odds weight vector per register ----------\nweights = np.zeros((NREG, K), dtype=np.float32)\na = 1.0\nfor k in range(NREG):\n    pos_c = np.zeros(K, dtype=np.float64)\n    for p in reg_pos[k]:\n        fe = feats(p)\n        if fe: np.add.at(pos_c, np.array(fe), 1.0)\n    Ptot = pos_c.sum()\n    w = (np.log(pos_c + a) - math.log(Ptot + a * K)) - \\\n        (np.log(neg_c + a) - math.log(Ntot + a * K))\n    c0 = math.log(Ntot + a * K) - math.log(Ptot + a * K)   # center: neutral seen feature ~ 0\n    w = w - c0\n    w[(pos_c + neg_c) < 3] = 0.0                            # trust only observed features\n    weights[k] = w.astype(np.float32)\n\n# ---------- score every pool doc against all four registers ----------\n_CACHE = \"/tmp/curate_scores4.npy\"\nif os.path.exists(_CACHE) and np.load(_CACHE).shape == (N, NREG):\n    S = np.load(_CACHE)\n    print(\"loaded cached scores\", file=sys.stderr)\nelse:\n    S = np.full((N, NREG), -1e9, dtype=np.float32)\n    for i in range(N):\n        fe = feats(texts[i])\n        if fe:\n            idx = np.array(fe)\n            n = len(fe)\n            for k in range(NREG):\n                S[i, k] = weights[k][idx].sum() / n\n        if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)\n    np.save(_CACHE, S)\n\n# ---------- clean-English-prose gate ----------\nSTOP = set(\"the of and to a in is that it for on as with was are be by this at \"\n           \"from or an not but have has had he she they we you i his her their \"\n           \"which who will would can could been were said your all more one about \"\n           \"when what there if so no do does did than then them these those into \"\n           \"out up down over after also its our\".split())\ndef passes(t):\n    if len(t) < 300: return False\n    ws = WORD.findall(t.lower())\n    if len(ws) < 60: return False\n    if sum(c.isalpha() or c.isspace() for c in t) / len(t) < 0.70: return False\n    if sum(c.isdigit() for c in t) / len(t) > 0.15: return False\n    if sum(1 for w in ws if w in STOP) / len(ws) < 0.22: return False   # non-English/nav/code\n    lines = [l for l in t.split(\"\\n\") if l.strip()]\n    if lines and Counter(lines).most_common(1)[0][1] / len(lines) > 0.5: return False\n    wc = Counter(ws)\n    if len(wc) / len(ws) < 0.30: return False\n    if wc.most_common(1)[0][1] / len(ws) > 0.10: return False\n    return True\nkeep = np.array([passes(t) for t in texts], dtype=bool)\nprint(f\"passed gates: {int(keep.sum())}\", file=sys.stderr)\n\n# ---------- per-register ranked candidate lists (gated) ----------\nkept = np.where(keep)[0]\nranked = []\nfor k in range(NREG):\n    o = kept[np.argsort(-S[kept, k])]\n    ranked.append(list(o))\n\n# ---------- round-robin fill -> balanced priority order, with dedup ----------\nseen, selection, ptr = set(), [], [0, 0, 0, 0]\nTARGET = 40000\nwhile len(selection) < TARGET:\n    progressed = False\n    for k in range(NREG):\n        while ptr[k] < len(ranked[k]):\n            i = ranked[k][ptr[k]]; ptr[k] += 1\n            sig = re.sub(r\"\\s+\", \" \", texts[i].lower()).strip()[:400]\n            h = zlib.crc32(sig.encode())\n            if h in seen: continue\n            seen.add(h); selection.append(int(ids[i])); progressed = True\n            break\n        if len(selection) >= TARGET: break\n    if not progressed: break\n\njson.dump(selection, open(OUT, \"w\"))\nprint(f\"wrote {len(selection)} ids -> {OUT}\", file=sys.stderr)\n"
}
Write result
The file /workspace/submission/curate.py has been updated successfully. (file state is current in your context — no need to Read it back)

[metadata] {"type": "update", "filePath": "/workspace/submission/curate.py", "content": "\"\"\"Curate a raw web pool for a small LM whose eval target is a BROAD, EQUAL-PARTS\nmulti-domain high-quality English corpus: encyclopedic (Wikipedia), general\nhigh-quality web prose, news, and technical Q&A.\n\nSTATED CRITERION\n----------------\nTwo ideas, composed:\n\n1. Clean-English-prose gate. Keep only documents that read like real English\n   prose: long enough, mostly alphabetic, not table/listing/code, a healthy\n   function-word (stopword) ratio (nav menus, keyword spam, and non-English text\n   fail this), no degenerate line/token repetition. This removes the bulk of raw\n   web junk regardless of topic.\n\n2. Register-balanced target-likeness. The disclosed target is EQUAL parts of four\n   registers, and the dev target stream (data/multi_dev.npy) is laid out in four\n   positional blocks (wiki -> technical/web prose -> news -> Q&A). We split it into\n   four register corpora and fit one linear Naive-Bayes log-odds model per register\n   (register chunks = positive, a random pool sample = negative). Every surviving\n   pool doc gets four per-token log-odds scores. We then fill the priority list by\n   ROUND-ROBIN across the four registers, each round taking the next highest-scoring\n   unused doc for that register. The 12M-token budget is therefore split ~evenly\n   across the four target registers instead of collapsing onto the most abundant one\n   (news), matching the eval's equal-parts composition.\n\nReproducible, deterministic, pure numpy/stdlib (no sklearn). No hand-picked ids.\n\"\"\"\nimport json, re, sys, zlib, math, os\nimport numpy as np\nfrom collections import Counter\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV  = \"/workspace/data/multi_dev.npy\"\nOUT  = \"/workspace/submission/selection.json\"\nSEED = 1337\nK    = 1 << 20\nNREG = 4\nWORD = re.compile(r\"[a-z0-9']+\")\nrng  = np.random.default_rng(SEED)\n\ndef feats(text, cap=2000):\n    w = WORD.findall(text.lower())[:cap]\n    out = [zlib.crc32(x.encode()) & (K - 1) for x in w]\n    for i in range(len(w) - 1):\n        out.append(zlib.crc32((w[i] + \" \" + w[i + 1]).encode()) & (K - 1))\n    return out\n\n# ---------- load pool ----------\nids, texts = [], []\nwith open(POOL) as f:\n    for line in f:\n        r = json.loads(line)\n        ids.append(r[\"id\"]); texts.append(r[\"text\"])\nN = len(ids)\nids = np.array(ids)\nprint(f\"pool: {N} docs\", file=sys.stderr)\n\n# ---------- register positives from the disclosed dev target ----------\nfrom transformers import AutoTokenizer\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\ndev = np.load(DEV)\nchunks, cur = [], []\nfor t in dev.tolist():\n    if t == 50256:\n        if cur: chunks.append(tok.decode(cur)); cur = []\n    else:\n        cur.append(t)\nif cur: chunks.append(tok.decode(cur))\nchunks = [c for c in chunks if len(c) > 200]\n# four positional register groups (dev is laid out wiki|prose|news|qa)\nper = len(chunks) / NREG\nreg_pos = [chunks[int(k * per):int((k + 1) * per)] for k in range(NREG)]\nprint(\"register sizes:\", [len(r) for r in reg_pos], file=sys.stderr)\n\n# ---------- negatives: random pool sample ----------\nneg_idx = rng.choice(N, size=min(6000, N), replace=False)\nneg_texts = [texts[i] for i in neg_idx]\nneg_c = np.zeros(K, dtype=np.float64)\nfor p in neg_texts:\n    fe = feats(p)\n    if fe: np.add.at(neg_c, np.array(fe), 1.0)\nNtot = neg_c.sum()\n\n# ---------- one NB log-odds weight vector per register ----------\nweights = np.zeros((NREG, K), dtype=np.float32)\na = 1.0\nfor k in range(NREG):\n    pos_c = np.zeros(K, dtype=np.float64)\n    for p in reg_pos[k]:\n        fe = feats(p)\n        if fe: np.add.at(pos_c, np.array(fe), 1.0)\n    Ptot = pos_c.sum()\n    w = (np.log(pos_c + a) - math.log(Ptot + a * K)) - \\\n        (np.log(neg_c + a) - math.log(Ntot + a * K))\n    c0 = math.log(Ntot + a * K) - math.log(Ptot + a * K)   # center: neutral seen feature ~ 0\n    w = w - c0\n    w[(pos_c + neg_c) < 3] = 0.0                            # trust only observed features\n    weights[k] = w.astype(np.float32)\n\n# ---------- score every pool doc against all four registers ----------\n_CACHE = \"/tmp/curate_scores4.npy\"\nif os.path.exists(_CACHE) and np.load(_CACHE).shape == (N, NREG):\n    S = np.load(_CACHE)\n    print(\"loaded cached scores\", file=sys.stderr)\nelse:\n    S = np.full((N, NREG), -1e9, dtype=np.float32)\n    for i in range(N):\n        fe = feats(texts[i])\n        if fe:\n            idx = np.array(fe)\n            n = len(fe)\n            for k in range(NREG):\n                S[i, k] = weights[k][idx].sum() / n\n        if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)\n    np.save(_CACHE, S)\n\n# ---------- clean-English-prose gate ----------\nSTOP = set(\"the of and to a in is that it for on as with was are be by this at \"\n           \"from or an not but have has had he she they we you i his her their \"\n           \"which who will would can could been were said your all more one about \"\n           \"when what there if so no do does did than then them these those into \"\n           \"out up down over after also its our\".split())\ndef passes(t):\n    if len(t) < 300: return False\n    ws = WORD.findall(t.lower())\n    if len(ws) < 60: return False\n    if sum(c.isalpha() or c.isspace() for c in t) / len(t) < 0.70: return False\n    if sum(c.isdigit() for c in t) / len(t) > 0.15: return False\n    if sum(1 for w in ws if w in STOP) / len(ws) < 0.22: return False   # non-English/nav/code\n    lines = [l for l in t.split(\"\\n\") if l.strip()]\n    if lines and Counter(lines).most_common(1)[0][1] / len(lines) > 0.5: return False\n    wc = Counter(ws)\n    if len(wc) / len(ws) < 0.30: return False\n    if wc.most_common(1)[0][1] / len(ws) > 0.10: return False\n    return True\nkeep = np.array([passes(t) for t in texts], dtype=bool)\nprint(f\"passed gates: {int(keep.sum())}\", file=sys.stderr)\n\n# ---------- per-register ranked candidate lists (gated) ----------\nkept = np.where(keep)[0]\nranked = []\nfor k in range(NREG):\n    o = kept[np.argsort(-S[kept, k])]\n    ranked.append(list(o))\n\n# ---------- round-robin fill -> balanced priority order, with dedup ----------\nseen, selection, ptr = set(), [], [0, 0, 0, 0]\nTARGET = 40000\nwhile len(selection) < TARGET:\n    progressed = False\n    for k in range(NREG):\n        while ptr[k] < len(ranked[k]):\n            i = ranked[k][ptr[k]]; ptr[k] += 1\n            sig = re.sub(r\"\\s+\", \" \", texts[i].lower()).strip()[:400]\n            h = zlib.crc32(sig.encode())\n            if h in seen: continue\n            seen.add(h); selection.append(int(ids[i])); progressed = True\n            break\n        if len(selection) >= TARGET: break\n    if not progressed: break\n\njson.dump(selection, open(OUT, \"w\"))\nprint(f\"wrote {len(selection)} ids -> {OUT}\", file=sys.stderr)\n", "structuredPatch": [{"oldStart": 1, "oldLines": 33, "newStart": 1, "newLines": 44, "lines": ["-\"\"\"Curate a raw web pool for training a small LM whose eval target is a BROAD,", "-multi-domain high-quality English corpus (Wikipedia + general web prose + news +", "-technical Q&A).", "+\"\"\"Curate a raw web pool for a small LM whose eval target is a BROAD, EQUAL-PARTS", "+multi-domain high-quality English corpus: encyclopedic (Wikipedia), general", "+high-quality web prose, news, and technical Q&A.", " ", "-STATED CRITERION: a document is worth training on to the extent it *resembles the", "-disclosed target domain*, per token. We estimate target-likeness with a linear", "-Naive-Bayes log-odds model over word unigrams+bigrams: positives are document", "-chunks of the disclosed dev target (data/multi_dev.npy, decoded), negatives are a", "-random sample of the raw pool. Each pool document's score is the MEAN per-token", "-log-odds of target-vs-pool (length-normalised, so long docs aren't favoured just", "-for being long). We first gate out obvious junk (too short, non-English/markup", "-gibberish by low alpha ratio, degenerate line repetition), dedup near-identical", "-docs (keeping the highest-scoring copy), then emit ids in descending score", "-(priority order). Deterministic; no manual id picking.", "+STATED CRITERION", "+----------------", "+Two ideas, composed:", " ", "-Pure numpy/stdlib (no sklearn) so it runs in the sandbox.", "+1. Clean-English-prose gate. Keep only documents that read like real English", "+   prose: long enough, mostly alphabetic, not table/listing/code, a healthy", "+   function-word (stopword) ratio (nav menus, keyword spam, and non-English text", "+   fail this), no degenerate line/token repetition. This removes the bulk of raw", "+   web junk regardless of topic.", "+", "+2. Register-balanced target-likeness. The disclosed target is EQUAL parts of four", "+   registers, and the dev target stream (data/multi_dev.npy) is laid out in four", "+   positional blocks (wiki -> technical/web prose -> news -> Q&A). We split it into", "+   four register corpora and fit one linear Naive-Bayes log-odds model per register", "+   (register chunks = positive, a random pool sample = negative). Every surviving", "+   pool doc gets four per-token log-odds scores. We then fill the priority list by", "+   ROUND-ROBIN across the four registers, each round taking the next highest-scoring", "+   unused doc for that register. The 12M-token budget is therefore split ~evenly", "+   across the four target registers instead of collapsing onto the most abundant one", "+   (news), matching the eval's equal-parts composition.", "+", "+Reproducible, deterministic, pure numpy/stdlib (no sklearn). No hand-picked ids.", " \"\"\"", "-import json, re, sys, zlib, math", "+import json, re, sys, zlib, math, os", " import numpy as np", "+from collections import Counter", " ", " POOL = \"/workspace/data/pool.jsonl\"", " DEV  = \"/workspace/data/multi_dev.npy\"", " OUT  = \"/workspace/submission/selection.json\"", " SEED = 1337", "-K    = 1 << 20                      # hashed feature buckets", "+K    = 1 << 20", "+NREG = 4", " WORD = re.compile(r\"[a-z0-9']+\")", " rng  = np.random.default_rng(SEED)", " ", " def feats(text, cap=2000):", "-    \"\"\"hashed unigram + bigram feature ids for a doc (first `cap` words).\"\"\"", "     w = WORD.findall(text.lower())[:cap]", "     out = [zlib.crc32(x.encode()) & (K - 1) for x in w]", "     for i in range(len(w) - 1):"]}, {"oldStart": 41, "oldLines": 72, "newStart": 52, "newLines": 69, "lines": ["         r = json.loads(line)", "         ids.append(r[\"id\"]); texts.append(r[\"text\"])", " N = len(ids)", "+ids = np.array(ids)", " print(f\"pool: {N} docs\", file=sys.stderr)", " ", "-import os", "-_CACHE = \"/tmp/curate_scores.npy\"", "-if os.path.exists(_CACHE):", "-    scores = np.load(_CACHE)", "-    if len(scores) == N:", "-        print(\"loaded cached scores\", file=sys.stderr)", "-        _HAVE_SCORES = True", "-    else:", "-        _HAVE_SCORES = False", "-else:", "-    _HAVE_SCORES = False", "-", "-# ---------- positives from disclosed dev target ----------", "+# ---------- register positives from the disclosed dev target ----------", " from transformers import AutoTokenizer", " tok = AutoTokenizer.from_pretrained(\"gpt2\")", " dev = np.load(DEV)", "-pos_texts, cur = [], []", "+chunks, cur = [], []", " for t in dev.tolist():", "     if t == 50256:", "-        if cur: pos_texts.append(tok.decode(cur)); cur = []", "+        if cur: chunks.append(tok.decode(cur)); cur = []", "     else:", "         cur.append(t)", "-if cur: pos_texts.append(tok.decode(cur))", "-pos_texts = [p for p in pos_texts if len(p) > 200]", "-print(f\"positives: {len(pos_texts)}\", file=sys.stderr)", "+if cur: chunks.append(tok.decode(cur))", "+chunks = [c for c in chunks if len(c) > 200]", "+# four positional register groups (dev is laid out wiki|prose|news|qa)", "+per = len(chunks) / NREG", "+reg_pos = [chunks[int(k * per):int((k + 1) * per)] for k in range(NREG)]", "+print(\"register sizes:\", [len(r) for r in reg_pos], file=sys.stderr)", " ", " # ---------- negatives: random pool sample ----------", " neg_idx = rng.choice(N, size=min(6000, N), replace=False)", " neg_texts = [texts[i] for i in neg_idx]", "-", "-# ---------- fit Naive-Bayes log-odds weights ----------", "-pos_c = np.zeros(K, dtype=np.float64)", " neg_c = np.zeros(K, dtype=np.float64)", "-for p in pos_texts:", "-    f = feats(p)", "-    if f: np.add.at(pos_c, np.array(f), 1.0)", " for p in neg_texts:", "-    f = feats(p)", "-    if f: np.add.at(neg_c, np.array(f), 1.0)", "+    fe = feats(p)", "+    if fe: np.add.at(neg_c, np.array(fe), 1.0)", "+Ntot = neg_c.sum()", "+", "+# ---------- one NB log-odds weight vector per register ----------", "+weights = np.zeros((NREG, K), dtype=np.float32)", " a = 1.0", "-Ptot, Ntot = pos_c.sum(), neg_c.sum()", "-weight = (np.log(pos_c + a) - math.log(Ptot + a * K)) - \\", "-         (np.log(neg_c + a) - math.log(Ntot + a * K))", "-# Only trust features actually observed (>=3 times); center so a \"neutral\" seen", "-# feature ~ 0 and unseen features contribute 0.  Then score = sum(weight)/n_tokens,", "-# so docs padded with rare junk tokens dilute toward 0 instead of scoring high.", "-c0 = math.log(Ntot + a * K) - math.log(Ptot + a * K)   # OOV/prior constant", "-weight = weight - c0", "-weight[(pos_c + neg_c) < 3] = 0.0", "-weight = weight.astype(np.float32)", "+for k in range(NREG):", "+    pos_c = np.zeros(K, dtype=np.float64)", "+    for p in reg_pos[k]:", "+        fe = feats(p)", "+        if fe: np.add.at(pos_c, np.array(fe), 1.0)", "+    Ptot = pos_c.sum()", "+    w = (np.log(pos_c + a) - math.log(Ptot + a * K)) - \\", "+        (np.log(neg_c + a) - math.log(Ntot + a * K))", "+    c0 = math.log(Ntot + a * K) - math.log(Ptot + a * K)   # center: neutral seen feature ~ 0", "+    w = w - c0", "+    w[(pos_c + neg_c) < 3] = 0.0                            # trust only observed features", "+    weights[k] = w.astype(np.float32)", " ", "-# ---------- score every pool doc: length-normalised total log-odds ----------", "-if not _HAVE_SCORES:", "-    scores = np.empty(N, dtype=np.float32)", "+# ---------- score every pool doc against all four registers ----------", "+_CACHE = \"/tmp/curate_scores4.npy\"", "+if os.path.exists(_CACHE) and np.load(_CACHE).shape == (N, NREG):", "+    S = np.load(_CACHE)", "+    print(\"loaded cached scores\", file=sys.stderr)", "+else:", "+    S = np.full((N, NREG), -1e9, dtype=np.float32)", "     for i in range(N):", "-        f = feats(texts[i])", "-        scores[i] = weight[np.array(f)].sum() / len(f) if f else -1e9", "+        fe = feats(texts[i])", "+        if fe:", "+            idx = np.array(fe)", "+            n = len(fe)", "+            for k in range(NREG):", "+                S[i, k] = weights[k][idx].sum() / n", "         if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)", "-    np.save(_CACHE, scores)", "+    np.save(_CACHE, S)", " ", "-# ---------- quality gates ----------", "-from collections import Counter", "-# common English function words: prose is 30-45% these; nav/keyword-spam and", "-# non-English text are near 0, so this is a strong \"is it real English prose\" gate.", "+# ---------- clean-English-prose gate ----------", " STOP = set(\"the of and to a in is that it for on as with was are be by this at \"", "            \"from or an not but have has had he she they we you i his her their \"", "            \"which who will would can could been were said your all more one about \""]}, {"oldStart": 116, "oldLines": 30, "newStart": 124, "newLines": 40, "lines": ["     if len(t) < 300: return False", "     ws = WORD.findall(t.lower())", "     if len(ws) < 60: return False", "-    alpha = sum(c.isalpha() or c.isspace() for c in t) / len(t)", "-    if alpha < 0.70: return False", "-    digit = sum(c.isdigit() for c in t) / len(t)", "-    if digit > 0.15: return False                         # tables / listings", "-    stopr = sum(1 for w in ws if w in STOP) / len(ws)", "-    if stopr < 0.22: return False                         # non-English / nav / keyword spam / code", "+    if sum(c.isalpha() or c.isspace() for c in t) / len(t) < 0.70: return False", "+    if sum(c.isdigit() for c in t) / len(t) > 0.15: return False", "+    if sum(1 for w in ws if w in STOP) / len(ws) < 0.22: return False   # non-English/nav/code", "     lines = [l for l in t.split(\"\\n\") if l.strip()]", "     if lines and Counter(lines).most_common(1)[0][1] / len(lines) > 0.5: return False", "     wc = Counter(ws)", "-    if len(wc) / len(ws) < 0.30: return False             # low type-token ratio: repetitive", "-    if wc.most_common(1)[0][1] / len(ws) > 0.10: return False  # one token dominates (spam)", "+    if len(wc) / len(ws) < 0.30: return False", "+    if wc.most_common(1)[0][1] / len(ws) > 0.10: return False", "     return True", " keep = np.array([passes(t) for t in texts], dtype=bool)", " print(f\"passed gates: {int(keep.sum())}\", file=sys.stderr)", " ", "-# ---------- dedup (highest score wins) + emit priority order ----------", "-order = np.argsort(-scores)", "-seen, selection = set(), []", "-for i in order:", "-    if not keep[i]: continue", "-    sig = re.sub(r\"\\s+\", \" \", texts[i].lower()).strip()[:400]", "-    h = zlib.crc32(sig.encode())", "-    if h in seen: continue", "-    seen.add(h); selection.append(int(ids[i]))", "-selection = selection[:40000]", "+# ---------- per-register ranked candidate lists (gated) ----------", "+kept = np.where(keep)[0]", "+ranked = []", "+for k in range(NREG):", "+    o = kept[np.argsort(-S[kept, k])]", "+    ranked.append(list(o))", "+", "+# ---------- round-robin fill -> balanced priority order, with dedup ----------", "+seen, selection, ptr = set(), [], [0, 0, 0, 0]", "+TARGET = 40000", "+while len(selection) < TARGET:", "+    progressed = False", "+    for k in range(NREG):", "+        while ptr[k] < len(ranked[k]):", "+            i = ranked[k][ptr[k]]; ptr[k] += 1", "+            sig = re.sub(r\"\\s+\", \" \", texts[i].lower()).strip()[:400]", "+            h = zlib.crc32(sig.encode())", "+            if h in seen: continue", "+            seen.add(h); selection.append(int(ids[i])); progressed = True", "+            break", "+        if len(selection) >= TARGET: break", "+    if not progressed: break", "+", " json.dump(selection, open(OUT, \"w\"))", " print(f\"wrote {len(selection)} ids -> {OUT}\", file=sys.stderr)"]}], "originalFile": "\"\"\"Curate a raw web pool for training a small LM whose eval target is a BROAD,\nmulti-domain high-quality English corpus (Wikipedia + general web prose + news +\ntechnical Q&A).\n\nSTATED CRITERION: a document is worth training on to the extent it *resembles the\ndisclosed target domain*, per token. We estimate target-likeness with a linear\nNaive-Bayes log-odds model over word unigrams+bigrams: positives are document\nchunks of the disclosed dev target (data/multi_dev.npy, decoded), negatives are a\nrandom sample of the raw pool. Each pool document's score is the MEAN per-token\nlog-odds of target-vs-pool (length-normalised, so long docs aren't favoured just\nfor being long). We first gate out obvious junk (too short, non-English/markup\ngibberish by low alpha ratio, degenerate line repetition), dedup near-identical\ndocs (keeping the highest-scoring copy), then emit ids in descending score\n(priority order). Deterministic; no manual id picking.\n\nPure numpy/stdlib (no sklearn) so it runs in the sandbox.\n\"\"\"\nimport json, re, sys, zlib, math\nimport numpy as np\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV  = \"/workspace/data/multi_dev.npy\"\nOUT  = \"/workspace/submission/selection.json\"\nSEED = 1337\nK    = 1 << 20                      # hashed feature buckets\nWORD = re.compile(r\"[a-z0-9']+\")\nrng  = np.random.default_rng(SEED)\n\ndef feats(text, cap=2000):\n    \"\"\"hashed unigram + bigram feature ids for a doc (first `cap` words).\"\"\"\n    w = WORD.findall(text.lower())[:cap]\n    out = [zlib.crc32(x.encode()) & (K - 1) for x in w]\n    for i in range(len(w) - 1):\n        out.append(zlib.crc32((w[i] + \" \" + w[i + 1]).encode()) & (K - 1))\n    return out\n\n# ---------- load pool ----------\nids, texts = [], []\nwith open(POOL) as f:\n    for line in f:\n        r = json.loads(line)\n        ids.append(r[\"id\"]); texts.append(r[\"text\"])\nN = len(ids)\nprint(f\"pool: {N} docs\", file=sys.stderr)\n\nimport os\n_CACHE = \"/tmp/curate_scores.npy\"\nif os.path.exists(_CACHE):\n    scores = np.load(_CACHE)\n    if len(scores) == N:\n        print(\"loaded cached scores\", file=sys.stderr)\n        _HAVE_SCORES = True\n    else:\n        _HAVE_SCORES = False\nelse:\n    _HAVE_SCORES = False\n\n# ---------- positives from disclosed dev target ----------\nfrom transformers import AutoTokenizer\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\ndev = np.load(DEV)\npos_texts, cur = [], []\nfor t in dev.tolist():\n    if t == 50256:\n        if cur: pos_texts.append(tok.decode(cur)); cur = []\n    else:\n        cur.append(t)\nif cur: pos_texts.append(tok.decode(cur))\npos_texts = [p for p in pos_texts if len(p) > 200]\nprint(f\"positives: {len(pos_texts)}\", file=sys.stderr)\n\n# ---------- negatives: random pool sample ----------\nneg_idx = rng.choice(N, size=min(6000, N), replace=False)\nneg_texts = [texts[i] for i in neg_idx]\n\n# ---------- fit Naive-Bayes log-odds weights ----------\npos_c = np.zeros(K, dtype=np.float64)\nneg_c = np.zeros(K, dtype=np.float64)\nfor p in pos_texts:\n    f = feats(p)\n    if f: np.add.at(pos_c, np.array(f), 1.0)\nfor p in neg_texts:\n    f = feats(p)\n    if f: np.add.at(neg_c, np.array(f), 1.0)\na = 1.0\nPtot, Ntot = pos_c.sum(), neg_c.sum()\nweight = (np.log(pos_c + a) - math.log(Ptot + a * K)) - \\\n         (np.log(neg_c + a) - math.log(Ntot + a * K))\n# Only trust features actually observed (>=3 times); center so a \"neutral\" seen\n# feature ~ 0 and unseen features contribute 0.  Then score = sum(weight)/n_tokens,\n# so docs padded with rare junk tokens dilute toward 0 instead of scoring high.\nc0 = math.log(Ntot + a * K) - math.log(Ptot + a * K)   # OOV/prior constant\nweight = weight - c0\nweight[(pos_c + neg_c) < 3] = 0.0\nweight = weight.astype(np.float32)\n\n# ---------- score every pool doc: length-normalised total log-odds ----------\nif not _HAVE_SCORES:\n    scores = np.empty(N, dtype=np.float32)\n    for i in range(N):\n        f = feats(texts[i])\n        scores[i] = weight[np.array(f)].sum() / len(f) if f else -1e9\n        if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)\n    np.save(_CACHE, scores)\n\n# ---------- quality gates ----------\nfrom collections import Counter\n# common English function words: prose is 30-45% these; nav/keyword-spam and\n# non-English text are near 0, so this is a strong \"is it real English prose\" gate.\nSTOP = set(\"the of and to a in is that it for on as with was are be by this at \"\n           \"from or an not but have has had he she they we you i his her their \"\n           \"which who will would can could been were said your all more one about \"\n           \"when what there if so no do does did than then them these those into \"\n           \"out up down over after also its our\".split())\ndef passes(t):\n    if len(t) < 300: return False\n    ws = WORD.findall(t.lower())\n    if len(ws) < 60: return False\n    alpha = sum(c.isalpha() or c.isspace() for c in t) / len(t)\n    if alpha < 0.70: return False\n    digit = sum(c.isdigit() for c in t) / len(t)\n    if digit > 0.15: return False                         # tables / listings\n    stopr = sum(1 for w in ws if w in STOP) / len(ws)\n    if stopr < 0.22: return False                         # non-English / nav / keyword spam / code\n    lines = [l for l in t.split(\"\\n\") if l.strip()]\n    if lines and Counter(lines).most_common(1)[0][1] / len(lines) > 0.5: return False\n    wc = Counter(ws)\n    if len(wc) / len(ws) < 0.30: return False             # low type-token ratio: repetitive\n    if wc.most_common(1)[0][1] / len(ws) > 0.10: return False  # one token dominates (spam)\n    return True\nkeep = np.array([passes(t) for t in texts], dtype=bool)\nprint(f\"passed gates: {int(keep.sum())}\", file=sys.stderr)\n\n# ---------- dedup (highest score wins) + emit priority order ----------\norder = np.argsort(-scores)\nseen, selection = set(), []\nfor i in order:\n    if not keep[i]: continue\n    sig = re.sub(r\"\\s+\", \" \", texts[i].lower()).strip()[:400]\n    h = zlib.crc32(sig.encode())\n    if h in seen: continue\n    seen.add(h); selection.append(int(ids[i]))\nselection = selection[:40000]\njson.dump(selection, open(OUT, \"w\"))\nprint(f\"wrote {len(selection)} ids -> {OUT}\", file=sys.stderr)\n", "userModified": false}
#38
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolBashRun register-balanced curation
args
{
  "command": "cd /workspace; rm -f /tmp/curate_scores4.npy; nohup python3 submission/curate.py > /tmp/cur4.log 2>&1 & echo \"pid $!\"",
  "description": "Run register-balanced curation"
}
Bash result
pid 2020

[stdout]
pid 2020
[metadata] {"noOutputExpected": false}
#39
narration

While the balanced curation runs on CPU, let me use the idle GPU to get a random baseline for calibration.

toolBashCreate and eval random baseline
args
{
  "command": "cd /workspace; python3 -c \"\nimport json,numpy as np\nrng=np.random.default_rng(0)\nids=[]\nwith open('data/pool.jsonl') as f:\n    for line in f: ids.append(json.loads(line)['id'])\nsel=list(rng.choice(len(ids),size=40000,replace=False))\njson.dump([int(ids[i]) for i in sel],open('/tmp/random_sel.json','w'))\nprint('random selection written',len(sel))\n\"\nnohup bash dev_eval.sh /tmp/random_sel.json > /tmp/eval_rand.log 2>&1 & echo \"rand eval pid $!\"",
  "description": "Create and eval random baseline"
}
Bash result
random selection written 40000
rand eval pid 2065

[stdout]
random selection written 40000
rand eval pid 2065
[metadata] {"noOutputExpected": false}
#40
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolBashCheck curation and random eval progress
args
{
  "command": "cd /workspace; sleep 120; echo \"=== cur4 ===\"; tail -4 /tmp/cur4.log; echo \"=== rand eval ===\"; grep HELDOUT /tmp/eval_rand.log || tail -2 /tmp/eval_rand.log",
  "description": "Check curation and random eval progress"
}
Bash result
=== cur4 ===
scored 40000
scored 80000
scored 120000
scored 160000
=== rand eval ===
HELDOUT_PPL 438.495  loss 6.0833  train_s 51  /tmp/dev_train.npy

[stdout]
=== cur4 ===
scored 40000
scored 80000
scored 120000
scored 160000
=== rand eval ===
HELDOUT_PPL 438.495  loss 6.0833  train_s 51  /tmp/dev_train.npy
[metadata] {"noOutputExpected": false}
#41
narration

Random baseline = 438.5, my classifier selection = 343.7 — already 22% better. Let me wait for the balanced curation to finish and eval it.

toolBashCheck balanced selection
args
{
  "command": "cd /workspace; sleep 25; grep -E \"wrote|passed|register\" /tmp/cur4.log; echo \"=== top balanced docs ===\"; python3 -c \"\nimport json\nsel=json.load(open('submission/selection.json'))\ntext={}\nwith open('data/pool.jsonl') as f:\n    for line in f:\n        r=json.loads(line); text[r['id']]=r['text']\nprint('total',len(sel))\nfor i in sel[:8]:\n    print('id',i,'::',text[i][:110].replace(chr(10),' '))\n\"",
  "description": "Check balanced selection"
}
Bash result
register sizes: [639, 639, 639, 640]
=== top balanced docs ===
total 40000
id 23673 :: Lahore:In the prospects of stoned to death incident of a Khanewal Woman, Inspector General of Police Punjab, M
id 58452 :: <|endoftext|>New Delhi: Five new Supreme Court judges were today sworn in, taking the top court’s strength to 
id 73993 :: |PREDECESSORS AND SHORT HISTORY: in the 16th century by Rao Gopalji fl.1550, 4th son of Raja Prithviraj Singhj
id 18830 :: Archaeological dating methods Futilities must undress thitherward convened dismissively towerish tomato. Posse
id 41186 :: Amarnath Yatra 2017 Amarnath Yatra 2017 News Jammu and Kashmir police said three people, alleged conspirators 
id 76107 :: Major Bhupinder Singh In sept. 1965, Major Bhupinder Singh commanded the "B" squadron of the 4 Horse against P
id 43758 :: vel (Maharashtra), June 14 (ANI): A magistrate's court in Panvel, Maharashtra, on Sunday extended suspended se
id 37064 :: The Bharatiya Janata Party (BJP) leaders of the West Bengal unit will meet Union Home Minister Rajnath Singh o

[stdout]
register sizes: [639, 639, 639, 640]
=== top balanced docs ===
total 40000
id 23673 :: Lahore:In the prospects of stoned to death incident of a Khanewal Woman, Inspector General of Police Punjab, M
id 58452 :: <|endoftext|>New Delhi: Five new Supreme Court judges were today sworn in, taking the top court’s strength to 
id 73993 :: |PREDECESSORS AND SHORT HISTORY: in the 16th century by Rao Gopalji fl.1550, 4th son of Raja Prithviraj Singhj
id 18830 :: Archaeological dating methods Futilities must undress thitherward convened dismissively towerish tomato. Posse
id 41186 :: Amarnath Yatra 2017 Amarnath Yatra 2017 News Jammu and Kashmir police said three people, alleged conspirators 
id 76107 :: Major Bhupinder Singh In sept. 1965, Major Bhupinder Singh commanded the "B" squadron of the 4 Horse against P
id 43758 :: vel (Maharashtra), June 14 (ANI): A magistrate's court in Panvel, Maharashtra, on Sunday extended suspended se
id 37064 :: The Bharatiya Janata Party (BJP) leaders of the West Bengal unit will meet Union Home Minister Rajnath Singh o
[metadata] {"noOutputExpected": false}
#42
narration

Balanced curation done (round-robin across 4 register scorers). Let me eval it.

toolBashEval balanced selection
args
{
  "command": "cd /workspace; cp submission/selection.json /tmp/balanced_sel.json; nohup bash dev_eval.sh > /tmp/eval2.log 2>&1 & echo \"eval2 pid $!\"; cat /workspace/.timer/remaining_secs",
  "description": "Eval balanced selection"
}
Bash result
eval2 pid 2319
3897

[stdout]
eval2 pid 2319
3897
[metadata] {"noOutputExpected": false}
#43
narration

65 min left. Waiting for the balanced eval result.

toolBashGet balanced eval perplexity
args
{
  "command": "cd /workspace; sleep 140; grep HELDOUT /tmp/eval2.log || tail -3 /tmp/eval2.log",
  "description": "Get balanced eval perplexity"
}
Bash result
Command did not complete within its 120s timeout and was moved to the background (ID: bbbyq9y21). Output is being written to: /tmp/claude-0/-workspace/056a17ab-c7c2-448d-bef2-fc697ffa5283/tasks/bbbyq9y21.output. You will be notified when it completes. To check interim output, use Read on that file path.
Session cwd remains /workspace; directory changes made by the backgrounded command do not apply to subsequent commands.

[metadata] {"noOutputExpected": false, "backgroundTaskId": "bbbyq9y21", "timedOutAfterMs": 120000, "backgroundCwdHint": "Session cwd remains /workspace; directory changes made by the backgrounded command do not apply to subsequent commands."}
#44
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolBashGet balanced eval perplexity
args
{
  "command": "cd /workspace; sleep 20; grep HELDOUT /tmp/eval2.log || tail -3 /tmp/eval2.log",
  "description": "Get balanced eval perplexity"
}
Bash result
HELDOUT_PPL 326.943  loss 5.7898  train_s 51  /tmp/dev_train.npy

[stdout]
HELDOUT_PPL 326.943  loss 5.7898  train_s 51  /tmp/dev_train.npy
[metadata] {"noOutputExpected": false}
#45
narration

Balanced = 326.9 vs single-score 343.7 vs random 438.5. Register balancing helped (~5% further). This is my current submission. Let me verify the register split is meaningful and check selection diversity before trying more.

toolBashVerify register split content
args
{
  "command": "cd /workspace; python3 -c \"\nimport json,re,numpy as np\nfrom collections import Counter\nfrom transformers import AutoTokenizer\ntok=AutoTokenizer.from_pretrained('gpt2')\ndev=np.load('data/multi_dev.npy')\nchunks,cur=[],[]\nfor t in dev.tolist():\n    if t==50256:\n        if cur: chunks.append(tok.decode(cur)); cur=[]\n    else: cur.append(t)\nchunks=[c for c in chunks if len(c)>200]\nper=len(chunks)/4\nfor k in range(4):\n    grp=chunks[int(k*per):int((k+1)*per)]\n    print('REG',k,'sample:',grp[len(grp)//2][:120].replace(chr(10),' '))\n\" 2>/dev/null",
  "description": "Verify register split content"
}
Bash result
REG 0 sample:  On September 7 , 2011 , Rapzilla announced that Lecrae would be featured on the BET Hip Hop Awards Cypher on October 11
REG 1 sample:  Ned 's store " The Leftorium " first appeared in " When Flanders Failed " . It was suggested by George Meyer , who had 
REG 2 sample: While they weren't expected to contend in the midst of a rebuild, the Phils were expected to take a step forward this ye
REG 3 sample: <p>Having something like this this :</p>  <pre><code>public abstract class AAA {   protected abstract virtual string ToS

[stdout]
REG 0 sample:  On September 7 , 2011 , Rapzilla announced that Lecrae would be featured on the BET Hip Hop Awards Cypher on October 11
REG 1 sample:  Ned 's store " The Leftorium " first appeared in " When Flanders Failed " . It was suggested by George Meyer , who had 
REG 2 sample: While they weren't expected to contend in the midst of a rebuild, the Phils were expected to take a step forward this ye
REG 3 sample: <p>Having something like this this :</p>  <pre><code>public abstract class AAA {   protected abstract virtual string ToS
[metadata] {"noOutputExpected": false}
#46
narration

Register split is clean: REG0/1 = encyclopedic (WikiText style), REG2 = news, REG3 = technical Q&A with <code>. But my prose gate may filter out code-heavy Q&A. Let me check what the QA register (every 4th pick) actually selects.

toolBashInspect QA and wiki register picks
args
{
  "command": "cd /workspace; python3 -c \"\nimport json\nsel=json.load(open('/tmp/balanced_sel.json'))\ntext={}\nwith open('data/pool.jsonl') as f:\n    for line in f:\n        r=json.loads(line); text[r['id']]=r['text']\nprint('=== REG3 (QA) picks: selection[3::4] ===')\nfor j in range(3,40,4):\n    i=sel[j]; print('id',i,'::',text[i][:110].replace(chr(10),' '))\nprint()\nprint('=== REG0 (wiki) picks: selection[0::4] ===')\nfor j in range(0,20,4):\n    i=sel[j]; print('id',i,'::',text[i][:110].replace(chr(10),' '))\n\"",
  "description": "Inspect QA and wiki register picks"
}
Bash result
=== REG3 (QA) picks: selection[3::4] ===
id 23673 :: Lahore:In the prospects of stoned to death incident of a Khanewal Woman, Inspector General of Police Punjab, M
id 64048 :: <|endoftext|>Sometimes it's not enough for Publising features to be enabled. Deployment Manifest generated fro
id 153492 ::  rights reserved<|endoftext|>Graphics.UI.Gtk.Layout.Expander Source Contents Index gtk-0.12.5.0: Binding to th
id 12485 :: Disable the server cache In order to disable the cache in the server and let the files be served each time, di
id 42329 :: AndroChef Java Decompiler is Windows decompiler for class, jar, apk and dex files. It reconstructs the origina
id 88237 :: <|endoftext|>Public Member Functions |deterministic phase in radians | |void||resetEnvelopes (const Breakpoint
id 143542 :: inkIndia.NET<|endoftext|>GWT Declarative Layout with UiBinder Your web browser must have JavaScript enabled in
id 24738 :: Can you help me with this query? It's pulling the most recent answer date in the campaigns table for each user
id 63063 :: Re: Yellow belt requirments 5th kyu is representitave of yellow in our org. It comprises of: Mae ukemi, Ushiro
id 46916 :: camlp5o.opt [--] [ other-options ] camlp5r.opt [--] [ other-options ] camlp5o, camlp5r and camlp5sch are versi

=== REG0 (wiki) picks: selection[0::4] ===
id 18830 :: Archaeological dating methods Futilities must undress thitherward convened dismissively towerish tomato. Posse
id 132935 :: 236.14<|endoftext|>Shoulder Arthroscopy Cost in India | Shoulder Arthroscopy in India × Help Us With Your Deta
id 98806 ::  hesiall, Loo. Micks. The ness arou shis. I therrying ot! Mmmend bou. Mays 14 he sairry, by norms nexpren I at
id 34104 :: <|endoftext|>Stanleigh Encounters Stanleigh, his five-way excommunicated with his head uncovered? The employee
id 73087 ::  isolative that reived discordantly? Gil Gil schizophà © tico undoing it in a carved it might be you piano let

[stdout]
=== REG3 (QA) picks: selection[3::4] ===
id 23673 :: Lahore:In the prospects of stoned to death incident of a Khanewal Woman, Inspector General of Police Punjab, M
id 64048 :: <|endoftext|>Sometimes it's not enough for Publising features to be enabled. Deployment Manifest generated fro
id 153492 ::  rights reserved<|endoftext|>Graphics.UI.Gtk.Layout.Expander Source Contents Index gtk-0.12.5.0: Binding to th
id 12485 :: Disable the server cache In order to disable the cache in the server and let the files be served each time, di
id 42329 :: AndroChef Java Decompiler is Windows decompiler for class, jar, apk and dex files. It reconstructs the origina
id 88237 :: <|endoftext|>Public Member Functions |deterministic phase in radians | |void||resetEnvelopes (const Breakpoint
id 143542 :: inkIndia.NET<|endoftext|>GWT Declarative Layout with UiBinder Your web browser must have JavaScript enabled in
id 24738 :: Can you help me with this query? It's pulling the most recent answer date in the campaigns table for each user
id 63063 :: Re: Yellow belt requirments 5th kyu is representitave of yellow in our org. It comprises of: Mae ukemi, Ushiro
id 46916 :: camlp5o.opt [--] [ other-options ] camlp5r.opt [--] [ other-options ] camlp5o, camlp5r and camlp5sch are versi

=== REG0 (wiki) picks: selection[0::4] ===
id 18830 :: Archaeological dating methods Futilities must undress thitherward convened dismissively towerish tomato. Posse
id 132935 :: 236.14<|endoftext|>Shoulder Arthroscopy Cost in India | Shoulder Arthroscopy in India × Help Us With Your Deta
id 98806 ::  hesiall, Loo. Micks. The ness arou shis. I therrying ot! Mmmend bou. Mays 14 he sairry, by norms nexpren I at
id 34104 :: <|endoftext|>Stanleigh Encounters Stanleigh, his five-way excommunicated with his head uncovered? The employee
id 73087 ::  isolative that reived discordantly? Gil Gil schizophà © tico undoing it in a carved it might be you piano let
[metadata] {"noOutputExpected": false}
#47
narration

Critical bug found: the wiki register scorer (REG0) is pulling gibberish/word-salad SEO spam to the top (e.g. "Futilities must undress thitherward convened dismissively towerish tomato"). WikiText's diverse rare vocabulary makes the scorer reward rare-word junk. A full quarter of my budget is polluted. I need a gibberish filter. Let me build a "fraction of common English words" signal from the reference corpus and calibrate a threshold.

toolBashCalibrate common-word fraction gate
args
{
  "command": "cd /workspace; python3 -c \"\nimport json,re,numpy as np\nfrom collections import Counter\nfrom transformers import AutoTokenizer\nWORD=re.compile(r\\\"[a-z0-9']+\\\")\ntok=AutoTokenizer.from_pretrained('gpt2')\ndev=np.load('data/multi_dev.npy')\n# build ref vocab from dev positives + pool negative sample\nchunks,cur=[],[]\nfor t in dev.tolist():\n    if t==50256:\n        if cur: chunks.append(tok.decode(cur)); cur=[]\n    else: cur.append(t)\nref=Counter()\nfor c in chunks: ref.update(WORD.findall(c.lower()))\nrng=np.random.default_rng(1337)\ntext={}\nwith open('data/pool.jsonl') as f:\n    for line in f:\n        r=json.loads(line); text[r['id']]=r['text']\nids=list(text); neg=rng.choice(len(ids),4000,replace=False)\nfor j in neg: ref.update(WORD.findall(text[ids[j]].lower()))\ncommon={w for w,c in ref.items() if c>=5}\nprint('common vocab size',len(common))\ndef fc(i):\n    ws=WORD.findall(text[i].lower())\n    return sum(1 for w in ws if w in common)/len(ws)\nprint('--- gibberish/spam (want LOW) ---')\nfor i in [18830,98806,34104,73087,132935]: print(i,'%.2f'%fc(i))\nprint('--- good news/QA/wiki (want HIGH) ---')\nfor i in [58452,23673,24738,46916,37064,88237,153492]: print(i,'%.2f'%fc(i))\n\"",
  "description": "Calibrate common-word fraction gate"
}
Bash result
common vocab size 33531
--- gibberish/spam (want LOW) ---
18830 0.51
98806 0.56
34104 0.66
73087 0.65
132935 0.76
--- good news/QA/wiki (want HIGH) ---
58452 0.94
23673 0.75
24738 0.84
46916 0.77
37064 0.92
88237 0.80
153492 0.74

[stdout]
common vocab size 33531
--- gibberish/spam (want LOW) ---
18830 0.51
98806 0.56
34104 0.66
73087 0.65
132935 0.76
--- good news/QA/wiki (want HIGH) ---
58452 0.94
23673 0.75
24738 0.84
46916 0.77
37064 0.92
88237 0.80
153492 0.74
[metadata] {"noOutputExpected": false}
#48
narration

The common-word fraction separates gibberish (≤0.66) from good prose (≥0.74). A 0.70 threshold cleanly cuts the word-salad. Let me add this gate to curate.py.

toolEdit
args
{
  "replace_all": false,
  "file_path": "/workspace/submission/curate.py",
  "old_string": "# ---------- negatives: random pool sample ----------\nneg_idx = rng.choice(N, size=min(6000, N), replace=False)\nneg_texts = [texts[i] for i in neg_idx]",
  "new_string": "# ---------- negatives: random pool sample ----------\nneg_idx = rng.choice(N, size=min(6000, N), replace=False)\nneg_texts = [texts[i] for i in neg_idx]\n\n# reference \"common English words\" (proxy dictionary) from positives + negatives.\n# Used to reject gibberish / word-salad SEO spam whose tokens are mostly rare:\n# such docs otherwise score HIGH on the encyclopedic register (WikiText's diverse\n# rare vocabulary), polluting a whole quarter of the budget.\n_ref = Counter()\nfor c in [x for g in reg_pos for x in g] + neg_texts:\n    _ref.update(WORD.findall(c.lower()))\nCOMMON = frozenset(w for w, cnt in _ref.items() if cnt >= 5)\nprint(f\"common vocab: {len(COMMON)}\", file=sys.stderr)"
}
Edit result
The file /workspace/submission/curate.py has been updated successfully. (file state is current in your context — no need to Read it back)

[metadata] {"filePath": "/workspace/submission/curate.py", "oldString": "# ---------- negatives: random pool sample ----------\nneg_idx = rng.choice(N, size=min(6000, N), replace=False)\nneg_texts = [texts[i] for i in neg_idx]", "newString": "# ---------- negatives: random pool sample ----------\nneg_idx = rng.choice(N, size=min(6000, N), replace=False)\nneg_texts = [texts[i] for i in neg_idx]\n\n# reference \"common English words\" (proxy dictionary) from positives + negatives.\n# Used to reject gibberish / word-salad SEO spam whose tokens are mostly rare:\n# such docs otherwise score HIGH on the encyclopedic register (WikiText's diverse\n# rare vocabulary), polluting a whole quarter of the budget.\n_ref = Counter()\nfor c in [x for g in reg_pos for x in g] + neg_texts:\n    _ref.update(WORD.findall(c.lower()))\nCOMMON = frozenset(w for w, cnt in _ref.items() if cnt >= 5)\nprint(f\"common vocab: {len(COMMON)}\", file=sys.stderr)", "originalFile": "\"\"\"Curate a raw web pool for a small LM whose eval target is a BROAD, EQUAL-PARTS\nmulti-domain high-quality English corpus: encyclopedic (Wikipedia), general\nhigh-quality web prose, news, and technical Q&A.\n\nSTATED CRITERION\n----------------\nTwo ideas, composed:\n\n1. Clean-English-prose gate. Keep only documents that read like real English\n   prose: long enough, mostly alphabetic, not table/listing/code, a healthy\n   function-word (stopword) ratio (nav menus, keyword spam, and non-English text\n   fail this), no degenerate line/token repetition. This removes the bulk of raw\n   web junk regardless of topic.\n\n2. Register-balanced target-likeness. The disclosed target is EQUAL parts of four\n   registers, and the dev target stream (data/multi_dev.npy) is laid out in four\n   positional blocks (wiki -> technical/web prose -> news -> Q&A). We split it into\n   four register corpora and fit one linear Naive-Bayes log-odds model per register\n   (register chunks = positive, a random pool sample = negative). Every surviving\n   pool doc gets four per-token log-odds scores. We then fill the priority list by\n   ROUND-ROBIN across the four registers, each round taking the next highest-scoring\n   unused doc for that register. The 12M-token budget is therefore split ~evenly\n   across the four target registers instead of collapsing onto the most abundant one\n   (news), matching the eval's equal-parts composition.\n\nReproducible, deterministic, pure numpy/stdlib (no sklearn). No hand-picked ids.\n\"\"\"\nimport json, re, sys, zlib, math, os\nimport numpy as np\nfrom collections import Counter\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV  = \"/workspace/data/multi_dev.npy\"\nOUT  = \"/workspace/submission/selection.json\"\nSEED = 1337\nK    = 1 << 20\nNREG = 4\nWORD = re.compile(r\"[a-z0-9']+\")\nrng  = np.random.default_rng(SEED)\n\ndef feats(text, cap=2000):\n    w = WORD.findall(text.lower())[:cap]\n    out = [zlib.crc32(x.encode()) & (K - 1) for x in w]\n    for i in range(len(w) - 1):\n        out.append(zlib.crc32((w[i] + \" \" + w[i + 1]).encode()) & (K - 1))\n    return out\n\n# ---------- load pool ----------\nids, texts = [], []\nwith open(POOL) as f:\n    for line in f:\n        r = json.loads(line)\n        ids.append(r[\"id\"]); texts.append(r[\"text\"])\nN = len(ids)\nids = np.array(ids)\nprint(f\"pool: {N} docs\", file=sys.stderr)\n\n# ---------- register positives from the disclosed dev target ----------\nfrom transformers import AutoTokenizer\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\ndev = np.load(DEV)\nchunks, cur = [], []\nfor t in dev.tolist():\n    if t == 50256:\n        if cur: chunks.append(tok.decode(cur)); cur = []\n    else:\n        cur.append(t)\nif cur: chunks.append(tok.decode(cur))\nchunks = [c for c in chunks if len(c) > 200]\n# four positional register groups (dev is laid out wiki|prose|news|qa)\nper = len(chunks) / NREG\nreg_pos = [chunks[int(k * per):int((k + 1) * per)] for k in range(NREG)]\nprint(\"register sizes:\", [len(r) for r in reg_pos], file=sys.stderr)\n\n# ---------- negatives: random pool sample ----------\nneg_idx = rng.choice(N, size=min(6000, N), replace=False)\nneg_texts = [texts[i] for i in neg_idx]\nneg_c = np.zeros(K, dtype=np.float64)\nfor p in neg_texts:\n    fe = feats(p)\n    if fe: np.add.at(neg_c, np.array(fe), 1.0)\nNtot = neg_c.sum()\n\n# ---------- one NB log-odds weight vector per register ----------\nweights = np.zeros((NREG, K), dtype=np.float32)\na = 1.0\nfor k in range(NREG):\n    pos_c = np.zeros(K, dtype=np.float64)\n    for p in reg_pos[k]:\n        fe = feats(p)\n        if fe: np.add.at(pos_c, np.array(fe), 1.0)\n    Ptot = pos_c.sum()\n    w = (np.log(pos_c + a) - math.log(Ptot + a * K)) - \\\n        (np.log(neg_c + a) - math.log(Ntot + a * K))\n    c0 = math.log(Ntot + a * K) - math.log(Ptot + a * K)   # center: neutral seen feature ~ 0\n    w = w - c0\n    w[(pos_c + neg_c) < 3] = 0.0                            # trust only observed features\n    weights[k] = w.astype(np.float32)\n\n# ---------- score every pool doc against all four registers ----------\n_CACHE = \"/tmp/curate_scores4.npy\"\nif os.path.exists(_CACHE) and np.load(_CACHE).shape == (N, NREG):\n    S = np.load(_CACHE)\n    print(\"loaded cached scores\", file=sys.stderr)\nelse:\n    S = np.full((N, NREG), -1e9, dtype=np.float32)\n    for i in range(N):\n        fe = feats(texts[i])\n        if fe:\n            idx = np.array(fe)\n            n = len(fe)\n            for k in range(NREG):\n                S[i, k] = weights[k][idx].sum() / n\n        if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)\n    np.save(_CACHE, S)\n\n# ---------- clean-English-prose gate ----------\nSTOP = set(\"the of and to a in is that it for on as with was are be by this at \"\n           \"from or an not but have has had he she they we you i his her their \"\n           \"which who will would can could been were said your all more one about \"\n           \"when what there if so no do does did than then them these those into \"\n           \"out up down over after also its our\".split())\ndef passes(t):\n    if len(t) < 300: return False\n    ws = WORD.findall(t.lower())\n    if len(ws) < 60: return False\n    if sum(c.isalpha() or c.isspace() for c in t) / len(t) < 0.70: return False\n    if sum(c.isdigit() for c in t) / len(t) > 0.15: return False\n    if sum(1 for w in ws if w in STOP) / len(ws) < 0.22: return False   # non-English/nav/code\n    lines = [l for l in t.split(\"\\n\") if l.strip()]\n    if lines and Counter(lines).most_common(1)[0][1] / len(lines) > 0.5: return False\n    wc = Counter(ws)\n    if len(wc) / len(ws) < 0.30: return False\n    if wc.most_common(1)[0][1] / len(ws) > 0.10: return False\n    return True\nkeep = np.array([passes(t) for t in texts], dtype=bool)\nprint(f\"passed gates: {int(keep.sum())}\", file=sys.stderr)\n\n# ---------- per-register ranked candidate lists (gated) ----------\nkept = np.where(keep)[0]\nranked = []\nfor k in range(NREG):\n    o = kept[np.argsort(-S[kept, k])]\n    ranked.append(list(o))\n\n# ---------- round-robin fill -> balanced priority order, with dedup ----------\nseen, selection, ptr = set(), [], [0, 0, 0, 0]\nTARGET = 40000\nwhile len(selection) < TARGET:\n    progressed = False\n    for k in range(NREG):\n        while ptr[k] < len(ranked[k]):\n            i = ranked[k][ptr[k]]; ptr[k] += 1\n            sig = re.sub(r\"\\s+\", \" \", texts[i].lower()).strip()[:400]\n            h = zlib.crc32(sig.encode())\n            if h in seen: continue\n            seen.add(h); selection.append(int(ids[i])); progressed = True\n            break\n        if len(selection) >= TARGET: break\n    if not progressed: break\n\njson.dump(selection, open(OUT, \"w\"))\nprint(f\"wrote {len(selection)} ids -> {OUT}\", file=sys.stderr)\n", "structuredPatch": [{"oldStart": 75, "oldLines": 6, "newStart": 75, "newLines": 16, "lines": [" # ---------- negatives: random pool sample ----------", " neg_idx = rng.choice(N, size=min(6000, N), replace=False)", " neg_texts = [texts[i] for i in neg_idx]", "+", "+# reference \"common English words\" (proxy dictionary) from positives + negatives.", "+# Used to reject gibberish / word-salad SEO spam whose tokens are mostly rare:", "+# such docs otherwise score HIGH on the encyclopedic register (WikiText's diverse", "+# rare vocabulary), polluting a whole quarter of the budget.", "+_ref = Counter()", "+for c in [x for g in reg_pos for x in g] + neg_texts:", "+    _ref.update(WORD.findall(c.lower()))", "+COMMON = frozenset(w for w, cnt in _ref.items() if cnt >= 5)", "+print(f\"common vocab: {len(COMMON)}\", file=sys.stderr)", " neg_c = np.zeros(K, dtype=np.float64)", " for p in neg_texts:", "     fe = feats(p)"]}], "userModified": false, "replaceAll": false}
#49
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolEdit
args
{
  "replace_all": false,
  "file_path": "/workspace/submission/curate.py",
  "old_string": "    if sum(1 for w in ws if w in STOP) / len(ws) < 0.22: return False   # non-English/nav/code\n    lines = [l for l in t.split(\"\\n\") if l.strip()]",
  "new_string": "    if sum(1 for w in ws if w in STOP) / len(ws) < 0.22: return False   # non-English/nav/code\n    if sum(1 for w in ws if w in COMMON) / len(ws) < 0.70: return False  # gibberish / word-salad spam\n    lines = [l for l in t.split(\"\\n\") if l.strip()]"
}
Edit result
The file /workspace/submission/curate.py has been updated successfully. (file state is current in your context — no need to Read it back)

[metadata] {"filePath": "/workspace/submission/curate.py", "oldString": "    if sum(1 for w in ws if w in STOP) / len(ws) < 0.22: return False   # non-English/nav/code\n    lines = [l for l in t.split(\"\\n\") if l.strip()]", "newString": "    if sum(1 for w in ws if w in STOP) / len(ws) < 0.22: return False   # non-English/nav/code\n    if sum(1 for w in ws if w in COMMON) / len(ws) < 0.70: return False  # gibberish / word-salad spam\n    lines = [l for l in t.split(\"\\n\") if l.strip()]", "originalFile": "\"\"\"Curate a raw web pool for a small LM whose eval target is a BROAD, EQUAL-PARTS\nmulti-domain high-quality English corpus: encyclopedic (Wikipedia), general\nhigh-quality web prose, news, and technical Q&A.\n\nSTATED CRITERION\n----------------\nTwo ideas, composed:\n\n1. Clean-English-prose gate. Keep only documents that read like real English\n   prose: long enough, mostly alphabetic, not table/listing/code, a healthy\n   function-word (stopword) ratio (nav menus, keyword spam, and non-English text\n   fail this), no degenerate line/token repetition. This removes the bulk of raw\n   web junk regardless of topic.\n\n2. Register-balanced target-likeness. The disclosed target is EQUAL parts of four\n   registers, and the dev target stream (data/multi_dev.npy) is laid out in four\n   positional blocks (wiki -> technical/web prose -> news -> Q&A). We split it into\n   four register corpora and fit one linear Naive-Bayes log-odds model per register\n   (register chunks = positive, a random pool sample = negative). Every surviving\n   pool doc gets four per-token log-odds scores. We then fill the priority list by\n   ROUND-ROBIN across the four registers, each round taking the next highest-scoring\n   unused doc for that register. The 12M-token budget is therefore split ~evenly\n   across the four target registers instead of collapsing onto the most abundant one\n   (news), matching the eval's equal-parts composition.\n\nReproducible, deterministic, pure numpy/stdlib (no sklearn). No hand-picked ids.\n\"\"\"\nimport json, re, sys, zlib, math, os\nimport numpy as np\nfrom collections import Counter\n\nPOOL = \"/workspace/data/pool.jsonl\"\nDEV  = \"/workspace/data/multi_dev.npy\"\nOUT  = \"/workspace/submission/selection.json\"\nSEED = 1337\nK    = 1 << 20\nNREG = 4\nWORD = re.compile(r\"[a-z0-9']+\")\nrng  = np.random.default_rng(SEED)\n\ndef feats(text, cap=2000):\n    w = WORD.findall(text.lower())[:cap]\n    out = [zlib.crc32(x.encode()) & (K - 1) for x in w]\n    for i in range(len(w) - 1):\n        out.append(zlib.crc32((w[i] + \" \" + w[i + 1]).encode()) & (K - 1))\n    return out\n\n# ---------- load pool ----------\nids, texts = [], []\nwith open(POOL) as f:\n    for line in f:\n        r = json.loads(line)\n        ids.append(r[\"id\"]); texts.append(r[\"text\"])\nN = len(ids)\nids = np.array(ids)\nprint(f\"pool: {N} docs\", file=sys.stderr)\n\n# ---------- register positives from the disclosed dev target ----------\nfrom transformers import AutoTokenizer\ntok = AutoTokenizer.from_pretrained(\"gpt2\")\ndev = np.load(DEV)\nchunks, cur = [], []\nfor t in dev.tolist():\n    if t == 50256:\n        if cur: chunks.append(tok.decode(cur)); cur = []\n    else:\n        cur.append(t)\nif cur: chunks.append(tok.decode(cur))\nchunks = [c for c in chunks if len(c) > 200]\n# four positional register groups (dev is laid out wiki|prose|news|qa)\nper = len(chunks) / NREG\nreg_pos = [chunks[int(k * per):int((k + 1) * per)] for k in range(NREG)]\nprint(\"register sizes:\", [len(r) for r in reg_pos], file=sys.stderr)\n\n# ---------- negatives: random pool sample ----------\nneg_idx = rng.choice(N, size=min(6000, N), replace=False)\nneg_texts = [texts[i] for i in neg_idx]\n\n# reference \"common English words\" (proxy dictionary) from positives + negatives.\n# Used to reject gibberish / word-salad SEO spam whose tokens are mostly rare:\n# such docs otherwise score HIGH on the encyclopedic register (WikiText's diverse\n# rare vocabulary), polluting a whole quarter of the budget.\n_ref = Counter()\nfor c in [x for g in reg_pos for x in g] + neg_texts:\n    _ref.update(WORD.findall(c.lower()))\nCOMMON = frozenset(w for w, cnt in _ref.items() if cnt >= 5)\nprint(f\"common vocab: {len(COMMON)}\", file=sys.stderr)\nneg_c = np.zeros(K, dtype=np.float64)\nfor p in neg_texts:\n    fe = feats(p)\n    if fe: np.add.at(neg_c, np.array(fe), 1.0)\nNtot = neg_c.sum()\n\n# ---------- one NB log-odds weight vector per register ----------\nweights = np.zeros((NREG, K), dtype=np.float32)\na = 1.0\nfor k in range(NREG):\n    pos_c = np.zeros(K, dtype=np.float64)\n    for p in reg_pos[k]:\n        fe = feats(p)\n        if fe: np.add.at(pos_c, np.array(fe), 1.0)\n    Ptot = pos_c.sum()\n    w = (np.log(pos_c + a) - math.log(Ptot + a * K)) - \\\n        (np.log(neg_c + a) - math.log(Ntot + a * K))\n    c0 = math.log(Ntot + a * K) - math.log(Ptot + a * K)   # center: neutral seen feature ~ 0\n    w = w - c0\n    w[(pos_c + neg_c) < 3] = 0.0                            # trust only observed features\n    weights[k] = w.astype(np.float32)\n\n# ---------- score every pool doc against all four registers ----------\n_CACHE = \"/tmp/curate_scores4.npy\"\nif os.path.exists(_CACHE) and np.load(_CACHE).shape == (N, NREG):\n    S = np.load(_CACHE)\n    print(\"loaded cached scores\", file=sys.stderr)\nelse:\n    S = np.full((N, NREG), -1e9, dtype=np.float32)\n    for i in range(N):\n        fe = feats(texts[i])\n        if fe:\n            idx = np.array(fe)\n            n = len(fe)\n            for k in range(NREG):\n                S[i, k] = weights[k][idx].sum() / n\n        if i % 40000 == 0: print(f\"scored {i}\", file=sys.stderr)\n    np.save(_CACHE, S)\n\n# ---------- clean-English-prose gate ----------\nSTOP = set(\"the of and to a in is that it for on as with was are be by this at \"\n           \"from or an not but have has had he she they we you i his her their \"\n           \"which who will would can could been were said your all more one about \"\n           \"when what there if so no do does did than then them these those into \"\n           \"out up down over after also its our\".split())\ndef passes(t):\n    if len(t) < 300: return False\n    ws = WORD.findall(t.lower())\n    if len(ws) < 60: return False\n    if sum(c.isalpha() or c.isspace() for c in t) / len(t) < 0.70: return False\n    if sum(c.isdigit() for c in t) / len(t) > 0.15: return False\n    if sum(1 for w in ws if w in STOP) / len(ws) < 0.22: return False   # non-English/nav/code\n    lines = [l for l in t.split(\"\\n\") if l.strip()]\n    if lines and Counter(lines).most_common(1)[0][1] / len(lines) > 0.5: return False\n    wc = Counter(ws)\n    if len(wc) / len(ws) < 0.30: return False\n    if wc.most_common(1)[0][1] / len(ws) > 0.10: return False\n    return True\nkeep = np.array([passes(t) for t in texts], dtype=bool)\nprint(f\"passed gates: {int(keep.sum())}\", file=sys.stderr)\n\n# ---------- per-register ranked candidate lists (gated) ----------\nkept = np.where(keep)[0]\nranked = []\nfor k in range(NREG):\n    o = kept[np.argsort(-S[kept, k])]\n    ranked.append(list(o))\n\n# ---------- round-robin fill -> balanced priority order, with dedup ----------\nseen, selection, ptr = set(), [], [0, 0, 0, 0]\nTARGET = 40000\nwhile len(selection) < TARGET:\n    progressed = False\n    for k in range(NREG):\n        while ptr[k] < len(ranked[k]):\n            i = ranked[k][ptr[k]]; ptr[k] += 1\n            sig = re.sub(r\"\\s+\", \" \", texts[i].lower()).strip()[:400]\n            h = zlib.crc32(sig.encode())\n            if h in seen: continue\n            seen.add(h); selection.append(int(ids[i])); progressed = True\n            break\n        if len(selection) >= TARGET: break\n    if not progressed: break\n\njson.dump(selection, open(OUT, \"w\"))\nprint(f\"wrote {len(selection)} ids -> {OUT}\", file=sys.stderr)\n", "structuredPatch": [{"oldStart": 137, "oldLines": 6, "newStart": 137, "newLines": 7, "lines": ["     if sum(c.isalpha() or c.isspace() for c in t) / len(t) < 0.70: return False", "     if sum(c.isdigit() for c in t) / len(t) > 0.15: return False", "     if sum(1 for w in ws if w in STOP) / len(ws) < 0.22: return False   # non-English/nav/code", "+    if sum(1 for w in ws if w in COMMON) / len(ws) < 0.70: return False  # gibberish / word-salad spam", "     lines = [l for l in t.split(\"\\n\") if l.strip()]", "     if lines and Counter(lines).most_common(1)[0][1] / len(lines) > 0.5: return False", "     wc = Counter(ws)"]}], "userModified": false, "replaceAll": false}
#50
reasoning (redacted)

encrypted chain-of-thought — recorded, not exposed

toolBashRe-run curation with gibberish gate (scores cached)
args
{
  "command": "cd /workspace; nohup python3 submission/curate.py > /tmp/cur5.log 2>&1 & echo \"pid $!\"; cat /workspace/.timer/remaining_secs",
  "description": "Re-run curation with gibberish gate (scores cached)"
}
Bash result
pid 2772
3597

[stdout]
pid 2772
3597
[metadata] {"noOutputExpected": false}