跳到正文
DEV Community· Ali Shoaib·· 4 小時前AI 評分37

Late Edition:以 Gemma 輔助修正 OCR 文字,並以檢查機制把關

Late Edition: Giving OCR Text a Second Look 📰

AI 導讀

Late Edition 是以 Python 建立的原型,使用 Gemma 提出 OCR 文字修正,再透過確定性檢查決定是否採納。檢查會拒絕數字有變、新增大寫字詞,或與原文相似度低於 0.80 的修正;系統亦可產生 HTML 報告,列出原文、接受的編輯和拒絕的建議。模型只接收 OCR 文字,無法查看原始頁面圖像;推理依賴託管 API。

正文

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine.

Late Edition: Giving OCR Text a Second Look 📰

What I Built

Newspaper scans can hold valuable information, but getting that information into usable text isn't always straightforward. OCR can misread characters, distort words, and turn a perfectly readable page into a messy block of text.

For Week 4, I built Late Edition, a Python prototype that explores how language models can help correct OCR text while keeping potentially risky changes in check.

The idea was to let a model suggest repairs without automatically trusting everything it produces.

Late Edition takes OCR text, splits it into chunks, and sends those chunks to a selected Gemma model. Before accepting a proposed correction, it runs a set of deterministic checks to decide whether the change is safe enough to keep.

It can also generate an HTML report showing the original text, accepted edits, and rejected suggestions.

The goal isn't to produce a verified historical transcription. It's to explore a more cautious way of using AI for text correction.

Demo

HTML report: [Add a sample report link or screenshot]

The report is designed to make the correction process easier to inspect, including changes the system chose not to accept.

Code

GitHub repository: https://github.com/ali-scribe/late-edition

The main implementation is organized around the correction checks in guard.py and the report generation in report.py.

How I Built It

Late Edition is built with Python and uses a selected Gemma model through Google's hosted Gemini API.

The workflow has three main steps:

  1. Split the OCR text. Divide the input into manageable chunks.
  2. Request corrections. Send each chunk as text to the model and receive proposed repairs.
  3. Validate the output. Run deterministic checks before accepting the proposed changes.

The validation layer checks three things:

  • Digits: If the model changes any digits, the proposed correction is rejected—even if the replacement seems plausible.
  • Capitalized words: A correction is rejected if it introduces a new capitalized word.
  • Text similarity: A correction is rejected if its similarity to the original falls below a threshold of 0.80.

These rules are intentionally cautious. A model might produce a fluent sentence while quietly changing a name, number, or other important detail. Fluency alone isn't enough to make a correction trustworthy.

There are limitations, though. The model only receives OCR text; it never sees the original page image to verify a suspected error. Inference also relies on a hosted API, so this isn't an offline or private-inference solution.

My latest test run reported 32 passing tests and 6 failures. The remaining failures involve plausible-repair behavior, retry-cap fallback, and repeated-chunk caching. The validation thresholds have also only been tested on a small sample, so they need broader evaluation.

Why Does Open Innovation Matter?

Open innovation makes it easier for developers to experiment with models, inspect their behavior, and build tools around them instead of treating AI as a black box.

For this project, working with Gemma gave me a way to explore model-assisted OCR correction while keeping the surrounding validation logic under my control.

The distinction matters: the model proposes a correction, but the application decides whether to accept it.

This project still uses a hosted API, so it isn't fully independent of a closed service. But using an open model gives the project a path toward further experimentation, including evaluating different models and exploring alternative inference setups.

For me, open innovation isn't just about making a model available. It's also about giving developers room to question its output, test its limitations, and build safeguards around it.

The Spirit of It

There's something interesting about working with text from an old newspaper.

A single character can change a name. A digit can change a date. A small correction can quietly become a new error if nobody checks it.

Late Edition doesn't solve historical OCR correction, and it can't verify a transcription against the original scan. But building it made me think more carefully about the difference between text that looks right and text that has actually been checked.

Sometimes, the most important part of an AI-assisted system Is knowing when not to make one.

Thanks to the organizers and everyone building and sharing projects through the Hacktoberfest Open-Source AI Challenge. 🚀

Hacktoberfest #OpenSource #AI #Python #Gemma

來源:DEV Community · dev.to