Artificial Intelligence project 17
AI OCR Text Cleanup Assistant Project
Build a complete ocr text cleanup assistant workflow with reproducible Python code, transparent inputs, reviewable output, and responsible-use limits.
Explore AI training in VizagView all project ideas
AI objective
Correct common character confusions and close vocabulary matches while keeping every rule inspectable.
Data or knowledge source
Noisy synthetic OCR text plus a small approved vocabulary.
Requirements
- Python 3.10 or later
- A terminal or command prompt
No third-party packages required- About 45-60 minutes to build and review
How the system works
Tokenise while preserving punctuation, replace common OCR confusions in word-like tokens, use conservative dictionary similarity, and reassemble text.
Validation checklist
- Numbers without letters are preserved
- Corrections come only from the visible vocabulary
- Punctuation and spacing remain in place
- Manual comparison with the source image is required
Complete Python code
Save the program as ai_ocr_text_cleanup_assistant.py. The code runs locally and requires no paid API key or model download.
"""Clean common OCR character errors with an auditable vocabulary."""
from __future__ import annotations
from difflib import get_close_matches
import re
VOCABULARY = {"artificial", "intelligence", "project", "document", "learning", "model", "training", "data", "analysis", "python", "quality", "review", "invoice", "amount", "date", "total"}
def normalize_ocr_token(token: str) -> str:
if not re.search(r"[A-Za-z]", token):
return token
candidate = token.lower().replace("0", "o").replace("1", "l").replace("|", "l")
candidate = candidate.replace("rn", "m") if candidate not in VOCABULARY else candidate
if candidate in VOCABULARY:
return candidate
matches = get_close_matches(candidate, VOCABULARY, n=1, cutoff=0.78)
return matches[0] if matches else candidate
def clean_text(text: str) -> str:
pieces = re.findall(r"[A-Za-z0-9|]+|[^A-Za-z0-9|]+", text)
return "".join(normalize_ocr_token(piece) if re.fullmatch(r"[A-Za-z0-9|]+", piece) else piece for piece in pieces)
def main() -> None:
noisy = "Artificia1 inte11igence rnodel training docurnent qua1ity review."
print("Input: ", noisy)
print("Cleaned:", clean_text(noisy))
print("Review every correction against the source image; OCR cleanup can change meaning.")
if __name__ == "__main__":
main()
Run the project
- Create and activate a virtual environment.
- Install dependencies with
No third-party packages requiredwhen packages are required. - Run
python ai_ocr_text_cleanup_assistant.py. - Review confidence, fallbacks, sources, or error metrics rather than accepting output automatically.
- Test additional normal, edge, unsupported, and adversarial inputs.
Expected output
Cleaned text suitable for review alongside the original OCR result.
Accuracy, privacy, and responsible-use limits
Automated cleanup can silently change names, amounts, dates, legal terms, and meaning. Preserve the original image and OCR, log edits, and require review for important documents.
Ways to extend the project
Add confidence per edit, domain dictionaries, layout-aware OCR, amount reconciliation, language detection, and side-by-side approval.
Continue learning Artificial Intelligence
Try the next project, return to the Softenant project library, or explore the AI training in Vizag for guided NLP, retrieval, evaluation, automation, and responsible AI practice.