Fix OCR interpretation of stylistic lines - #62
Conversation
|
Thanks for tackling this — it's adjacent to something I dug into on #59, but I think the fix as written has a mechanism problem that will make it unreliable and, in some cases, silently drop legitimate output. The core issue: delta = chunk["choices"][0]["delta"].get("content", "")This is one SSE chunk from the SGLang/vLLM def is_stylistic_line(text):
return text.strip() in ('_', '-', '—')This only matches a delta whose entire stripped content is exactly one of those three single characters. Two consequences:
Suggested approach: this needs to operate on the assembled text, not per-token deltas — e.g. post-process each completed line in import re
_STYLISTIC_LINE_RE = re.compile(r'^[\s]*[_\-—―‐‑‒–]{4,}[\s]*$')
def is_stylistic_line(line: str) -> bool:
"""A full line consisting only of repeated dash/underscore/em-dash
characters (a decorative horizontal rule), not a single character."""
return bool(_STYLISTIC_LINE_RE.match(line))applied line-by-line to the final One more thing worth separating out: this PR's framing ("prevent misinterpretation as placeholders") reads as a different problem from what #59 was actually about. #59 wasn't the model transcribing a genuine decorative line in a document — it was verbatim regurgitation of eval-rubric text ("Rule 2 UNDERSCORE & LINE RULES", "Ground Truth") from what looks like training-data contamination from an LLM-as-judge pipeline. If this PR is aimed at the #59 pattern specifically, filtering standalone decorative lines from the output won't address that — the contaminated example produces a lot more than just a line of underscores (full rubric section headers, etc.), and the fix for that lives in the training data, not client-side output filtering. If this is aimed at a separate, genuine "document has a decorative rule and OCR renders it as underscores" case, that's a legitimate and different problem worth solving — just flagging so it's clear which one this patch is targeting before it merges. |
|
Thanks for the detailed review — you’re absolutely right. I was treating I’ve updated the PR to remove all per-delta filtering. The stream is now collected verbatim into STYLISTIC_LINE_RE = re.compile(r"^[\s]*[_\-—―‐‑‒–]{4,}[\s]*$")and the output file is written from that post-processed assembled text. This preserves single I also agree with your distinction from #59. This patch is only intended for the separate/client-side case where the OCR output contains a decorative horizontal rule from the source document. It is not meant to solve the rubric/training-contamination pattern from #59, which would require a different upstream/data fix. |
Updated the OCR processing logic to correctly identify and ignore stylistic lines, such as horizontal lines made of underscores or hyphens, to prevent them from being misinterpreted as placeholders. This change ensures that the OCR output is consistent with the Ground Truth by not including underscores for stylistic lines.