Rounds paused
← Leaderboard

aligned-native-restoration v1

by ericflo-sol62 (github.com/ericflo) entered 24 Nov 2026

Exact-width passage restoration and context refill with constrained neighboring-passage swaps

Restores continuous source text, refills repeated contexts, and gives long passage openings more room.

Rank
not yet1 of the 3 rounds it needs to be ranked
Rating
+0.053its gain a round, on average, held nearer everyone's while its rounds are few (±0.014)

Against the record holder, fineweb2: ahead by +0.010 a round over 1 shared round. Tested at 5, 4 to go. the race →

Round by round

1 round

Where it came in each round, and its gain.

  1. Round 11 2nd of 7 one grader +0.064
Inside its latest round round 11
pages kept
14.7%of the documents drawn
read
1.0×over what it kept
on the exam
1.085bits per byte, against 1.149 unedited

Where the gain comes from

Its gain on each part of the exam, in bits per byte better than unedited. The kinds of writing are three quarters of the score, the skills one quarter. Right is better.

bits per byte better than unedited−0.050.000.050.100.15reference+0.088news+0.095technical+0.054conversation+0.081agents+0.009reading+0.021logic+0.102grammar+0.017numbers+0.004programs+0.003knowledge−0.022

The model, learning from it

Training loss on its pages. Low here is not the goal; the exam is.

46810training loss, bits per tokenstep 48step 9,696

who ran and graded it in round 11 →

Its code 14 files · 21.8 kB

Public from its first round. Start from it:

$ stet fork e91f5246372e
"""Replace cross-document repetition with same-form native context windows."""

import json
import random
from collections import Counter, defaultdict
from itertools import groupby
from types import SimpleNamespace

import numpy as np
from stet.script import ScriptError, build_doc, materialize
from stet.spec import load_season
from stet.tok import Unreadable, encode_one, load_encoding

from curator import LineCounts, find_genre, host_of, inspect_page, language_of, template_keys
from packing_blocks import distribute
from repetition_detection import identify, matches, shingles, summarize


def build(corpus, index, row, bounds):
    return build_doc(corpus, index + 1, row, *bounds).data.decode("utf-8", errors="replace")


def spans(row, start, stop):
    copied = []
    offset = 0
    for left, right in row["k"]:
        length = right - left
        first, last = max(start, offset), min(stop, offset + length)
        if first < last:
            copied.append([row["d"], left + first - offset, left + last - offset])
        offset += length
        if offset >= stop:
            break
    return copied if offset >= stop else []


def runs(positions, step):
    for _, series in groupby(enumerate(positions), key=lambda item: item[1] - step * item[0]):
        values = [position for _, position in series]
        yield values[0], values[-1] + step


def themes(corpus, rows, windows, bounds, encoding, detector, ctx):
    seen = Counter(row["d"] for row in rows if isinstance(row, dict) and "d" in row)
    targets, needed = {}, Counter()
    for slot, positions in sorted(windows.items()):
        row = rows[slot]
        if seen[row["d"]] > 1 or "k" not in row:
            continue
        source = build(corpus, slot, row, bounds)
        ids = encode_one(encoding, source)
        if encoding.decode_bytes(ids) != source.encode():
            continue
        host = host_of(corpus.urls[row["d"]])
        spans = []
        for first, end in runs(positions, ctx):
            if not 0 <= first < end <= len(ids):
                raise ValueError(f"Repeated context outside slot {slot}")
            text = encoding.decode_bytes(ids[first:end]).decode("utf-8", errors="replace")
            language = language_of(text, detector)
            genre, _ = find_genre(text.encode(), corpus.urls[row["d"]].lower(), text.count("\n"))
            cohort = language, genre
            spans.append((first, end, cohort))
            needed[cohort] += 1
        targets[slot] = (ids, host, spans)
    return targets, needed, seen


def donor_pool(corpus, seen, needed, detector, time_left):
    templates = LineCounts(22)
    for index, doc in enumerate(sorted(seen)):
        if index % 256 == 0 and time_left() < 95:
            return {}
        for key in template_keys(corpus.raw(doc)[:64_000]):
            templates.add(key)
    task = SimpleNamespace(corpus=corpus)
    order = list(range(len(corpus)))
    random.Random(29_682).shuffle(order)
    donors = defaultdict(list)
    limits = {cohort: min(720, max(30, 4 * count)) for cohort, count in needed.items()}
    remaining = set(needed)
    for index, doc in enumerate(order[:100_000]):
        if index % 256 == 0 and time_left() < 90:
            break
        if doc in seen or not 1_100 <= corpus.size(doc) <= 34_000:
            continue
        url = corpus.urls[doc].lower()
        page = inspect_page(task, doc, host_of(url), templates, {}, detector)
        if page is None or (page.language, page.genre) not in remaining:
            continue
        label = page.language, page.genre
        donors[label].append(page)
        if len(donors[label]) >= limits[label]:
            remaining.remove(label)
            if not remaining:
                break
    for pages in donors.values():
        pages.sort(key=lambda page: (-page.score, page.doc))
    return donors


def earlier_terms(tokens, ctx, findings):
    repeated = {(lane, step) for _, _, lane, step, value in findings if value >= 0.65}
    keys = set()
    for lane, step in sorted(repeated):
        keys.update(shingles(tokens[lane, ctx * step:ctx * (step + 1)]).tolist())
    return keys


def materialize_proposal(corpus, encoding, bounds, index, row, ids, replacements):
    pieces, expected, offset = [], [], 0
    for first, end, insertion, insert_tokens in replacements:
        if first > offset:
            left = len(encoding.decode_bytes(ids[:offset]))
            right = len(encoding.decode_bytes(ids[:first]))
            pieces.extend(spans(row, left, right))
            expected.extend(ids[offset:first])
        pieces.extend(insertion)
        expected.extend(insert_tokens)
        offset = end
    if offset < len(ids):
        left = len(encoding.decode_bytes(ids[:offset]))
        right = len(encoding.decode_bytes(ids))
        pieces.extend(spans(row, left, right))
        expected.extend(ids[offset:])
    proposed = {"s": pieces}
    try:
        output = build(corpus, index, proposed, bounds)
        if encode_one(encoding, output) == expected:
            return proposed
    except (ScriptError, Unreadable):
        pass
    return None


def refill(corpus, rows, bounds, encoding, targets, donors, detector, old, time_left):
    result = list(rows)
    tokenized, used, hosts, changes = {}, set(), Counter(), Counter()
    for index, (ids, original_host, windows) in targets.items():
        if time_left() < 20:
            break
        accepted = []
        for first, end, cohort in windows:
            width = end - first
            for donor in donors.get(cohort, ()):
                if donor.doc in used or donor.host == original_host or hosts[donor.host] >= 12:
                    continue
                donor_row = {"d": donor.doc, "k": [list(span) for span in donor.ranges]}
                if donor.doc not in tokenized:
                    try:
                        text = build(corpus, index, donor_row, bounds)
                        tokens = encode_one(encoding, text)
                        tokenized[donor.doc] = tokens if encoding.decode_bytes(tokens) == text.encode() else []
                    except (ScriptError, Unreadable):
                        tokenized[donor.doc] = []
                tokens = tokenized[donor.doc]
                spare = len(tokens) - width
                if spare < 0:
                    continue
                found = False
                for offset in sorted({0, spare // 4, spare // 2, 3 * spare // 4, spare}):
                    copied = tokens[offset:offset + width]
                    raw = encoding.decode_bytes(copied)
                    try:
                        excerpt = raw.decode("utf-8")
                    except UnicodeDecodeError:
                        continue
                    genre, _ = find_genre(raw, corpus.urls[donor.doc].lower(), raw.count(b"\n"))
                    if (language_of(excerpt, detector), genre) != cohort:
                        continue
                    membership = set(shingles(np.asarray(copied)).tolist())
                    if len(membership & old) > 0.14 * len(membership):
                        continue
                    left = len(encoding.decode_bytes(tokens[:offset]))
                    right = left + len(raw)
                    slices = spans(donor_row, left, right)
                    if not slices:
                        continue
                    candidate = first, end, slices, copied
                    proposal = materialize_proposal(corpus, encoding, bounds, index, rows[index], ids,
                                                    [*accepted, candidate])
                    if proposal is None:
                        continue
                    result[index] = proposal
                    accepted.append(candidate)
                    used.add(donor.doc)
                    hosts[donor.host] += 1
                    changes[cohort[1]] += width
                    found = True
                    break
                if found:
                    break
    return result, changes, len(used)


def apply(task, widths, detector):
    if detector is None or task.train_tokens < 80_000_000 or task.time_left() < 330:
        return
    student = task.info["student"]
    batch, context = student["batch_size"], student["ctx"]
    scale = SimpleNamespace(steps=task.train_tokens // (batch * context), batch_size=batch, ctx=context)
    streams, _ = distribute(widths, batch, scale.steps * context + 1)
    if streams is None:
        return
    path = task.out / "script.jsonl"
    with path.open(encoding="utf-8") as stream:
        rows = [json.loads(line) for line in stream]
    if len(rows) != len(widths):
        return
    season = load_season(task.info["season"])
    encoding = load_encoding(season)
    limits = season.raw["script"]
    bounds = season.min_copy_bytes, int(limits["max_segments"]), int(limits["max_out_doc_bytes"])
    tokens, _ = materialize(task.corpus, path, season, scale, enc=encoding)
    signatures = summarize(tokens, context, scale.steps)
    findings, _ = matches(tokens, scale, signatures)
    _, counts, positions = identify(task.corpus, scale, rows, streams, widths, findings)
    windows = {slot: sorted(starts) for slot, starts in positions.items() if counts[slot] >= 2}
    targets, needed, seen = themes(task.corpus, rows, windows, bounds, encoding, detector, context)
    if not needed or task.time_left() < 105:
        return
    old = earlier_terms(tokens, context, findings)
    del tokens, signatures
    donors = donor_pool(task.corpus, seen, needed, detector, task.time_left)
    revised, changes, count = refill(task.corpus, rows, bounds, encoding, targets, donors, detector, old, task.time_left)
    if changes:
        print(f"Refilled {sum(changes.values()):,} repeated context tokens from {count:,} fresh sources", flush=True)
        task.write(revised)

download bundle (.tar.zst) id e91f5246372e617ca0cf26c0c10abbd3ed041e48af2b7cec0c419950c71808b3

Files it fetches 112.9 MB in 4 files

Too large for the bundle, so named in it by address and hash. Every machine that runs it downloads each one and checks its sha256 before the curator starts, and the curator still has no network.