round-paired-context v1
EttinX pairwise LoRA with matched passage replacements and a sparse ranking curriculum
A local decision model learns to recognize coherent passages and uses matched comparisons to curate each round.
- Rank
- 5of 14 on the leaderboard
- Rating
- +0.041its gain a round, on average (±0.008)
Round by round
4 rounds
Where it came in each round, and its gain.
Inside its latest round round 8
- pages kept
- 14.3%of the documents drawn
- read
- 1.0×over what it kept
- its own words
- 0%of tokens not copied
- on the exam
- 2.778bits per byte, against 2.812 unedited
Where the gain comes from
Its gain on each thing the exam tests, in bits per byte better than unedited. Each counts the same. Right is better.
The model, learning from it
Training loss on its pages. Low here is not the goal; the exam is.
Its code 4 files · 10.8 kB
Public from its first round. Start from it:
import math
import random
from collections import Counter, defaultdict
import numpy as np
GENRES = {"prose", "news", "reference"}
def pool_key(page):
return page.language, page.genre, page.tokens.bit_length()
def windows(corpus, page):
raw = corpus.raw(page.doc)
text = b"".join(raw[left:right] for left, right in page.ranges)
middle = min(max(0, len(text) - 1_160), len(text) // 2)
return [text[start:start + 1_160].decode("utf-8", errors="ignore") for start in (0, middle)]
def probability(left, right):
return sum(1 / (1 + math.exp(-1.65 * (first - second))) for first, second in zip(left, right)) / len(left)
def pairwise_ratings(pages, scores):
if len(pages) < 2:
return {page.doc: 0.5 for page in pages}, 0
cohort = sorted(pages, key=lambda page: (sum(scores[page.doc][0]), page.doc))
edges = {(index, index + distance) for distance in (1, 3, 9) for index in range(len(cohort) - distance)}
left, right = np.array(sorted(edges), dtype=np.int32).T
observations = np.array([probability(scores[cohort[a].doc][0], scores[cohort[b].doc][0]) for a, b in zip(left, right)])
degree = np.bincount(np.concatenate((left, right)), minlength=len(cohort))
strengths = np.zeros(len(cohort))
for _ in range(26):
margin = strengths[left] - strengths[right]
residual = observations - 1 / (1 + np.exp(-margin))
gradient = np.bincount(left, weights=residual, minlength=len(cohort)) - np.bincount(right, weights=residual, minlength=len(cohort))
strengths += 0.75 * (gradient - 0.08 * strengths) / degree
ranks = np.argsort(np.argsort(strengths, kind="stable"), kind="stable")
return {page.doc: float((rank + 0.5) / len(cohort)) for page, rank in zip(cohort, ranks)}, len(edges)
def eligible_pools(selected, candidates, standard):
first = int(0.56 * len(selected))
last = int(0.94 * len(selected))
current = defaultdict(list)
for slot in range(first, last):
page = selected[slot]
if page.genre in GENRES and page.tokens >= 180:
current[pool_key(page)].append((slot, page))
population = sum(map(len, current.values()))
count = 8_400 if standard else 1_050
for key, rows in current.items():
rows.sort(key=lambda item: (item[1].doc * 2246822519) & 0xFFFFFFFF)
del rows[max(4, math.ceil(count * len(rows) / max(1, population))):]
extras = defaultdict(list)
existing = {page.doc for page in selected}
for page in candidates:
key = pool_key(page)
if page.doc not in existing and key in current:
extras[key].append(page)
for key, rows in extras.items():
rows.sort(key=lambda page: (-page.score, page.doc))
del rows[max(4, len(current[key])):]
return current, extras
def replace(task, selected, groups, alternatives, scores, target):
output = list(selected)
used = {fingerprint for page in selected for fingerprint in page.fingerprints}
existing = {page.doc for page in selected}
taken = Counter()
size = count = 0
for key, items in groups.items():
if task.time_left() < 18 or size >= target * 0.014:
break
challengers = [page for page in alternatives[key] if page.doc in scores and scores[page.doc][1] < 0.60]
challengers.sort(key=lambda page: (-sum(scores[page.doc][0]), page.doc))
choices = [item for item in items if item[1].doc in scores and scores[item[1].doc][1] < 0.53]
for slot, incumbent in sorted(choices, key=lambda row: (sum(scores[row[1].doc][0]), row[0])):
if size >= target * 0.014:
break
for page in challengers[:24]:
if page.doc in existing or abs(page.tokens / incumbent.tokens - 1) > 0.10:
continue
if taken[page.host] >= max(2_000, target * 0.00025) or page.score < incumbent.score - 0.38:
continue
if probability(scores[page.doc][0], scores[incumbent.doc][0]) < 0.73:
continue
if sum(key in used for key in set(page.fingerprints)) >= min(2, len(page.fingerprints)):
continue
output[slot] = page
existing.add(page.doc)
used.update(page.fingerprints)
taken[page.host] += page.tokens
size += incumbent.tokens
count += 1
break
return output, count, size
def schedule(pages, groups, scores):
adjusted = list(pages)
all_ratings = {}
comparisons = moved = 0
for rows in groups.values():
active = [slot for slot, _ in rows if pages[slot].doc in scores and scores[pages[slot].doc][1] < 0.66]
ratings, count = pairwise_ratings([pages[slot] for slot in active], scores)
all_ratings.update(ratings)
comparisons += count
bands = defaultdict(list)
for slot in sorted(active):
bands[slot // 1_024].append(slot)
for slots in bands.values():
if len(slots) < 4:
continue
orders = sorted(range(len(slots)), key=lambda index: (index - 0.25 * len(slots) * ratings[pages[slots[index]].doc], index))
for destination, source in zip(slots, orders):
adjusted[destination] = pages[slots[source]]
moved += destination != slots[source]
return adjusted, all_ratings, comparisons, moved
def repeat_pages(pages, ratings, target):
candidates = [page for page in pages if ratings.get(page.doc, 0) >= 0.88 and page.tokens <= 4_000]
random.Random(87095).shuffle(candidates)
replay = []
added = 0
hosts = Counter()
for page in candidates:
if added + page.tokens <= target * 0.007 and hosts[page.host] < 2:
replay.append(page)
added += page.tokens
hosts[page.host] += 1
if not replay:
return pages, 0, 0
offset = int(0.80 * len(pages))
width = max(1, int(0.13 * len(pages)))
locations = defaultdict(list)
for index, page in enumerate(replay):
locations[offset + index * width // len(replay)].append(page)
output = []
for index, page in enumerate(pages):
output.append(page)
output.extend(locations.get(index, ()))
return output, len(replay), added
def edit_pages(task, selected, candidates, target, replay):
from judge import fit_and_score
if task.device() != "cuda" or task.time_left() < 58:
print("Pairwise decision model scored 0 passages within the budget", flush=True)
return None
groups, alternatives = eligible_pools(selected, candidates, task.train_tokens >= 80_000_000)
population = [page for rows in groups.values() for _, page in rows] + [page for rows in alternatives.values() for page in rows]
population.sort(key=lambda page: (page.doc * 2654435761) & 0xFFFFFFFF)
try:
scores = fit_and_score(task, candidates, population)
except (ImportError, OSError, RuntimeError, ValueError) as error:
print(f"Pairwise decision model unavailable ({error})", flush=True)
return None
edited, replacements, volume = replace(task, selected, groups, alternatives, scores, target)
edited, ratings, comparisons, moved = schedule(edited, groups, scores)
repeats = replay_tokens = 0
if replay:
edited, repeats, replay_tokens = repeat_pages(edited, ratings, target)
print(
f"Pairwise decision model scored {len(scores):,} passages from two views, made {comparisons:,} comparisons, "
f"replaced {replacements:,} pages ({volume:,} tokens), moved {moved:,} and replayed {repeats:,} ({replay_tokens:,} tokens)",
flush=True,
)
return edited if replacements or moved or repeats else None
download bundle (.tar.zst) id 5041e74d8267bb4ac4a01d1d2d79809015c4f10ac1677581e8a4f70422bb165e
Files it fetches 126.5 MB in 6 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 |
| encoder/config.json | 1.5 kB | cf463a124f08 | https://huggingface.co/dleemiller/EttinX-nli-xs/resolve/802360b6ffe6d4627f1d28fd3225522e247cd3e8/config.json |
| encoder/model.safetensors | 122.2 MB | 6916aea0615d | https://huggingface.co/dleemiller/EttinX-nli-xs/resolve/802360b6ffe6d4627f1d28fd3225522e247cd3e8/model.safetensors |
| encoder/special_tokens_map.json | 694 B | ea97ecdbcc73 | https://huggingface.co/dleemiller/EttinX-nli-xs/resolve/802360b6ffe6d4627f1d28fd3225522e247cd3e8/special_tokens_map.json |
| encoder/tokenizer.json | 3.4 MB | 2cfefe444546 | https://huggingface.co/dleemiller/EttinX-nli-xs/resolve/802360b6ffe6d4627f1d28fd3225522e247cd3e8/tokenizer.json |
| encoder/tokenizer_config.json | 20.4 kB | 1da5cf18208b | https://huggingface.co/dleemiller/EttinX-nli-xs/resolve/802360b6ffe6d4627f1d28fd3225522e247cd3e8/tokenizer_config.json |
| total | 126.5 MB |