glide-native-excerpts v1
Matched byte-range decisions using an original GLiDE-0.4B LoRA and navigation guard
A fine-tuned GLiDE judges paired views of the same page to recover useful technical, conversation and reference layout.
- Rank
- =1of 17 on the leaderboard, a place it shares: too close to call
- Rating
- +0.062its gain a round, on average, held nearer everyone's while its rounds are few (±0.005)
Round by round
8 rounds
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.086bits 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 4 files · 9.4 kB
Public from its first round. Start from it:
$ stet fork aa3af5e6a043
import json
import re
from collections import Counter
from dataclasses import dataclass
FORM = re.compile(rb"(?m)^[ \t]*(?:[>*-] |>>> |\.\.\. |\$ |def |return |[+-][^\s+-]|\| |\d{1,2}[.)] |[\w-]{2,16}:\s)")
NAV = re.compile(rb"cookie policy|privacy policy|rights reserved|manage cookies|skip to main content|terms of use", re.I)
FORMS_BY_GENRE = {
"code": "program", "shell": "program", "technical": "program",
"discussion": "discussion", "reference": None,
}
@dataclass(slots=True)
class Proposal:
slot: int
doc: int
ranges: list
added_bytes: int
kind: str | None
before: str
after: str
def propose(task, index, page):
kind = FORMS_BY_GENRE[page.genre]
raw = task.corpus.raw(page.doc)
original = sum(right - left for left, right in page.ranges)
cap = min(920, original // 3)
best = None
for i, ((begin, closing), (left, right)) in enumerate(zip(page.ranges, page.ranges[1:])):
gap = raw[closing:left]
if (not 14 <= len(gap) <= cap or NAV.search(gap) or gap.count(b"https://") > 1
or not FORM.search(gap)):
continue
prefix = raw[max(begin, closing - 330):closing]
suffix = raw[left:min(right, left + 440)]
if len(prefix) + len(suffix) >= 220 and (best is None or len(gap) > len(best[2])):
best = i, (begin, right), gap, prefix, suffix
if best is None:
return None
i, joined, gap, prefix, suffix = best
kept = [*page.ranges[:i], joined, *page.ranges[i + 2:]]
before = (prefix + suffix).decode("utf-8", errors="ignore")
after = (prefix + gap + suffix).decode("utf-8", errors="ignore")
return Proposal(index, page.doc, kept, len(gap), kind, before, after)
def assess(task, proposals):
import torch
from peft import PeftModel
from safetensors.torch import load_file
from transformers import AutoModel, AutoTokenizer
from decision import DecisionHead, FORMS, embed, quality_score
base = task.asset("encoder")
tuning = task.asset("scorer")
details = json.loads((tuning / "model-info.json").read_text())
tokenizer = AutoTokenizer.from_pretrained(base, local_files_only=True)
tokenizer.padding_side = "right"
encoder = AutoModel.from_pretrained(
base, dtype=torch.float16, local_files_only=True, attn_implementation="sdpa",
).to("cuda")
encoder = PeftModel.from_pretrained(encoder, tuning / "adapter", local_files_only=True).merge_and_unload().eval()
head = DecisionHead(details["width"])
head.load_state_dict(load_file(tuning / "lora-head.safetensors"))
head = head.to("cuda").eval()
retained = []
evaluated = 0
furniture = FORMS.index("navigation")
with torch.inference_mode():
for start in range(0, len(proposals), 48):
if task.time_left() < 22:
break
batch = proposals[start:start + 48]
pieces = [piece for proposal in batch for piece in (proposal.before, proposal.after)]
tokens = tokenizer(pieces, max_length=details["context"], truncation=True,
padding="max_length", return_tensors="pt").to("cuda")
quality, form = head(embed(encoder, tokens))
merit = quality_score(quality).reshape(-1, 2).tolist()
types = form.float().softmax(dim=-1).reshape(-1, 2, len(FORMS)).tolist()
evaluated += len(batch)
for proposal, (before, after), (old_form, new_form) in zip(batch, merit, types):
navigation = new_form[furniture] - old_form[furniture]
form_gain = 0.0
if proposal.kind:
kind = FORMS.index(proposal.kind)
form_gain = new_form[kind] - old_form[kind]
benefit = round(after - before + 1.4 * form_gain - 2.3 * max(0.0, navigation), 3)
if (benefit >= -0.10 and new_form[furniture] <= max(0.34, old_form[furniture] + 0.05)
and (form_gain >= 0.06 or after - before >= 0.07)):
retained.append((benefit, proposal))
return retained, evaluated
def apply(task, selected, target):
if task.device() != "cuda" or task.time_left() < 70:
return
proposals = []
for index, page in enumerate(selected):
if page.genre in FORMS_BY_GENRE and len(page.ranges) >= 2:
change = propose(task, index, page)
if change:
proposals.append(change)
proposals.sort(key=lambda change: ((change.doc * 2654435761) & 0xffffffff, change.doc))
limit = 8_000 if task.train_tokens >= 80_000_000 else 2_200
if not proposals:
return
try:
decisions, evaluated = assess(task, proposals[:limit])
except (ImportError, KeyError, OSError, RuntimeError, ValueError) as error:
print(f"GLiDE layout judge could not run ({error})", flush=True)
return
changes = {}
reclaimed = Counter()
size = 0
for _, decision in sorted(decisions, key=lambda item: (-item[0], item[1].doc)):
if size + decision.added_bytes > target * 0.022:
break
changes[decision.slot] = decision.ranges
reclaimed[selected[decision.slot].genre] += decision.added_bytes
size += decision.added_bytes
print(f"GLiDE decided {evaluated:,} paired views and restored {size:,} source bytes in {len(changes):,} pages "
f"{reclaimed.most_common()}", flush=True)
if changes:
task.write({"d": page.doc, "k": changes.get(index, page.ranges)} for index, page in enumerate(selected))
download bundle (.tar.zst) id aa3af5e6a043471dc3c2356c78eb078b2d3ca28c70ec86c8c066f2730d4b3343
Files it fetches 758.5 MB in 17 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.