aligned-native-restoration v1
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.
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.
The model, learning from it
Training loss on its pages. Low here is not the goal; the exam is.
Its code 14 files · 21.8 kB
Public from its first round. Start from it:
$ stet fork e91f5246372e
- context_refill.py9.6 kB
- continuity.py3.8 kB
- curator.py17.8 kB
- early_order.py6.4 kB
- lengths.py1.5 kB
- native_restore.py7.1 kB
- packing_blocks.py4.0 kB
- passage_order.py6.0 kB
- prose_selection.py3.9 kB
- repetition_detection.py4.9 kB
- restore_and_refill.py1.7 kB
- stet.toml1.3 kB
- teacher_rank.py3.0 kB
- technical_rehearsal.py7.4 kB
"""Plan exact-width restorations of native text on the same source page."""
import random
import re
from collections import Counter, defaultdict
from dataclasses import dataclass
from stet.script import ScriptError
from stet.tok import Unreadable, encode_one
from curator import FURNITURE, find_genre, language_of
from packing_blocks import distribute
LANGUAGE_ASSET = "8f3472cfe8738a7b6099e8e999c3cbfae0dcd15696aac7d7738a8039db603e83"
MULTILINE_NOISE = re.compile(rb"(?:https?://\S+|<[^>]{0,120}>|\x00)")
@dataclass(slots=True)
class Choice:
slot: int
context: int
step: int
language: str
genre: str
row: dict
lead: str
native: str
cut: str
recovered: int
changed_tokens: int
def clean_gap(gap):
if not 72 <= len(gap) <= 1500 or len(MULTILINE_NOISE.findall(gap)) > 2:
return False
sentences = [line for line in gap.splitlines() if line.strip()]
return bool(sentences) and any(len(line) >= 40 for line in sentences) and not FURNITURE.search(gap)
def merge_ranges(ranges):
result = []
for left, right in ranges:
if result and left < result[-1][1]:
return []
if result and left == result[-1][1]:
result[-1][1] = right
else:
result.append([left, right])
return result
def native_context(source, start, width, encoder):
try:
body = source[start:start + 9000].decode("utf-8", errors="ignore")
tokens = encode_one(encoder, body)
except Unreadable:
return None
if len(tokens) < width:
return None
sequence = tokens[:width]
raw = encoder.decode_bytes(sequence)
try:
text = raw.decode("utf-8")
except UnicodeDecodeError:
return None
if source[start:start + len(raw)] != raw:
return None
return sequence, raw, text
def try_context(common, corpus, encoder, bounds, detector, slot, row, original, before, start,
stop, step, gap_start, left_edge, right_edge):
source = corpus.raw(row["d"])
prefix = len(encoder.decode_bytes(original[:start]))
end = len(encoder.decode_bytes(original[:stop]))
if gap_start - prefix < 110 or end - gap_start < 135:
return None
first = left_edge - (gap_start - prefix)
if first < 0 or not 0 <= first < left_edge < right_edge:
return None
pieces = common["spans"](row, prefix, gap_start)
if len(pieces) != 1 or pieces[0][1:] != [first, left_edge]:
return None
option = native_context(source, first, stop - start, encoder)
if option is None:
return None
replacement, raw, fresh = option
if first + len(raw) < right_edge + 100:
return None
retained = gap_start - prefix
current = before[prefix:end]
if current == raw or not raw.startswith(current[:retained]):
return None
url = corpus.urls[row["d"]].lower()
old_genre, _ = find_genre(current, url, current.count(b"\n"))
genre, _ = find_genre(raw, url, raw.count(b"\n"))
language = language_of(fresh, detector)
if genre != old_genre or language != language_of(current.decode("utf-8", errors="replace"), detector):
return None
remaining = common["spans"](row, end, len(before))
head = common["spans"](row, 0, prefix)
if (prefix and not head) or (end < len(before) and not remaining):
return None
ranges = merge_ranges([part[1:] for part in head] + [[first, first + len(raw)]] +
[part[1:] for part in remaining])
if not ranges:
return None
revised = {"d": row["d"], "k": ranges}
try:
actual = encode_one(encoder, common["build"](corpus, slot, revised, bounds))
except (ScriptError, Unreadable):
return None
if actual != original[:start] + replacement + original[stop:]:
return None
lead = current[:retained].decode("utf-8", errors="replace")[-450:]
native = raw[retained:].decode("utf-8", errors="replace")[:450]
cut = current[retained:].decode("utf-8", errors="replace")[:450]
changed = sum(left != right for left, right in zip(original[start:stop], replacement, strict=True))
return Choice(slot, start, step, language, genre, revised, lead, native, cut, right_edge - left_edge, changed)
def collect(common, corpus, season, scale, rows, widths, encoder, detector, training_pool=False, time_left=None):
limits = season.raw["script"]
bounds = season.min_copy_bytes, int(limits["max_segments"]), int(limits["max_out_doc_bytes"])
per_doc = Counter(row["d"] for row in rows)
phase = round(scale.steps * 0.54) * scale.ctx
size = scale.ctx
options, counts = [], Counter()
if training_pool:
positions = [(slot, row["d"] % size) for slot, row in enumerate(rows)]
else:
lanes, _ = distribute(widths, scale.batch_size, scale.steps * size + 1)
if lanes is None:
return [], Counter()
positions = sorted((slot.row, slot.offset) for lane in lanes for slot in lane if slot.offset >= phase)
for index, (slot, offset) in enumerate(positions):
if index % 128 == 0 and time_left is not None and time_left() < 20:
break
row = rows[slot]
keep = row.get("k", [])
if len(keep) < 2 or widths[slot] <= size or per_doc[row["d"]] != 1:
continue
raw = corpus.raw(row["d"])
if not any(clean_gap(raw[left[1]:right[0]]) for left, right in zip(keep, keep[1:])):
continue
before = common["build"](corpus, slot, row, bounds).encode()
original = encode_one(encoder, before.decode())
if encoder.decode_bytes(original) != before:
continue
counts["pages_with_clean_gaps"] += 1
first = (-offset - 1) % size
windows = [(start, len(encoder.decode_bytes(original[:start + size])))
for start in range(first, len(original) - size + 1, size)]
cursor, choices = 0, []
for (begin, left), (right, _) in zip(keep, keep[1:]):
cursor += left - begin
if not clean_gap(raw[left:right]):
continue
for start, end in windows:
if end <= cursor:
continue
step = (offset + 1 + start) // size
if step < scale.steps:
item = try_context(common, corpus, encoder, bounds, detector, slot, row, original,
before, start, start + size, step, cursor, left, right)
if item:
choices.append(item)
break
if choices:
counts["pages_with_native_alternatives"] += 1
options.extend(choices)
return options, counts
EDIT_FRACTION = 0.0065
def sample(choices, budget):
possible = defaultdict(list)
for choice in choices:
possible[choice.slot].append(choice)
rng = random.Random(208_071)
ordered = [rng.choice(possible[slot]) for slot in sorted(possible)]
rng.shuffle(ordered)
selected, changed = [], 0
for item in ordered:
if changed + item.changed_tokens <= budget:
selected.append(item)
changed += item.changed_tokens
return selected, changed
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.
| Path | Size | sha256 | From |
|---|---|---|---|
| language/lid.176.ftz | 916.0 kB | 8f3472cfe873 | https://huggingface.co/julien-c/fasttext-language-id/resolve/9f2e94d2fd6b2615d26f5ec5b34cf7e2f38cb86e/lid.176.ftz |
| difficulty/early.safetensors | 56.0 MB | f828164714bf | https://huggingface.co/ericflo/stet-matched-student-pace/resolve/a11215d67107307d0e76180494f41755edf4917d/early.safetensors |
| difficulty/mature.safetensors | 56.0 MB | 64c2afc22042 | https://huggingface.co/ericflo/stet-matched-student-pace/resolve/a11215d67107307d0e76180494f41755edf4917d/mature.safetensors |
| difficulty/calibration.json | 170 B | 3be8effd9fd9 | https://huggingface.co/ericflo/stet-matched-student-pace/resolve/a11215d67107307d0e76180494f41755edf4917d/calibration.json |
| total | 112.9 MB |