Skip to content

feat(crossposting): OCR text length in the channel model; describe crosspost candidates first - #411

Merged
ohld merged 3 commits into
productionfrom
feat/crosspost-ocr-text
Nov 30, 2026
Merged

ohld merged 3 commits into
productionfrom
feat/crosspost-ocr-text

Conversation

@sebastianwall

@sebastianwall sebastianwall commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

What

  1. Features. model.FEATURES gains log_text = log1p(len(meme.ocr_result.text)) and text_missing (no ocr_result → log_text 0, text_missing 1; empty text → 0, 0, as in the lab). The one static-inputs query (_MODEL_STATIC_QUERY) now returns ocr_text_len, so:
    • posting reads it from meme.ocr_result at decision time and logs ocr_text_len in each candidate's JSON;
    • the nightly refit (training_rows) reads it from meme.ocr_result as it is at refit time. It never uses the logged value.
  2. Coverage. describe_memes_flow now fills up to a third of each batch with undescribed memes from crosspost top-N logs of the last 3 days. These are status ok, pool samples excluded, best policy_rank first (get_crosspost_candidates_to_describe). The rest of the batch goes through the existing tiers unchanged. Spend is unchanged: it uses the same per-run attempt cap and the same per-account daily budget. The batch stays 18 per 15 min, of which at most 6 are candidates.

Why

Walk-forward results (channel lab, model.walk_forward/compare, 2026-11-30). Each line compares 11 features + log_text + text_missing against the 11 features alone:

EN Δρ EN thirds RU Δρ
trained & tested on OCR as it is now (post-hoc, allowed for training) +0.042 (Sep+ +0.039) +0.064 / +0.040 / +0.017 (3/3) +0.001 (1/3, no gain)
decision-time-known text only −0.017 −0.011
trained post-hoc, predicted with today's live coverage −0.029 (1/3)

The last row is why the coverage fix exists. In training, "missing" means "never OCR'd". Live, it means "not OCR'd yet". The feature only helps once candidates are described before they can be picked.

Coverage at decision time (decision log since 2026-11-27):

  • RU top-20: 100%
  • EN top-20: 69% (top-3: 80%)
  • the 5 random pool samples: 48% EN, 36% RU

The missing memes are old (median 219 days EN, 289 RU) and were never OCR'd. That is a backlog, not a race. The top-N moves by about one meme per post. A meme logged in a recent top-N is therefore likely to be picked in a later decision, and this tier describes it within about 15 minutes of its first appearance. Two gaps remain:

  • A meme can be picked at its very first appearance in the top-5. This is rare for old memes, which climb gradually.
  • Pool samples are not backfilled. They are random draws from about 130k memes and are picked only through ε.

Old model rows

Model.predict reads only the features stored on the row, and load_model accepts any subset of FEATURES. The active RU v1 row (11 features) therefore loads and predicts exactly as before. test_eleven_feature_rows_load_and_predict_unchanged checks this bit for bit, with OCR missing, empty and present.

What activates: nothing automatically

  • The nightly refit never adds the text features. It keeps the active row's spec. With no usable active row, it falls back to model_loop.REFIT_FEATURES, which is the old 11 features without log_text/text_missing. This holds for both channels. Promotion is unchanged: PROMOTION_RULE = "wins>=2/3 and delta>=0", the cooldowns and the control-arm rollback all stay as they were. So the nightly job cannot promote a text-feature model on either channel.
  • Rows with text features are registered by hand once live candidate coverage is confirmed (lab/cand_ocr_coverage.py a few days after deploy). The offline gain uses post-hoc OCR. At today's EN live coverage the same model loses (−0.029). FEATURES and model.features() already compute the two text features, so such a row loads and predicts. After that, the nightly refit keeps that row's spec.

Untouched: label definition, control arm, ε/N caps, rollback rule. Nothing writes to crossposting, crossposting_snapshots or crossposting_decision_log. The new OCR tier only reads the decision log. One repository test inserts and deletes its own rows in the CI test database.

Tests

  • tests/crossposting/test_model.py: the nightly refit spec excludes the text features; feature definitions (missing, empty, present text); 11-feature rows predict unchanged; candidate log carries ocr_text_len; training rows read refit-time text, not the logged value.
  • tests/storage/test_describe_memes_repository.py: candidate tier ranking and exclusions (pool sample, stale log, described, published). Needs the DB, runs in CI.
  • tests/storage/test_describe_memes_flow.py: candidates go first, are capped at a third, and are deduplicated against the regular tiers.
  • ruff check and ruff format are clean. Locally all non-DB tests pass. The DB tests (Postgres) run in CI.

🤖 Generated with Claude Code

sebastianwall and others added 3 commits November 30, 2026 12:30
…osspost candidates first

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ure rows are registered by hand

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…result without text)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@ohld ohld left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed (Claude): live behaviour unchanged (11-feature RU v1 predicts identically, nightly spec excludes text features); candidate OCR tier stays within the same budget cap. Pushed a small fix: text_missing=1 when ocr_result has no text key (failed describes). Merging.

@ohld
ohld merged commit 339bf2e into production Nov 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants