
How to Evaluate OCR for AI Agents
Audio Summary
AI Summary
This discussion focuses on the challenges and workflows involved in processing and evaluating documents, particularly in the context of AI agents and OCR. The speaker, Isaac, emphasizes that document processing is a complex and often overlooked area, crucial for high-reliability domains like medicine, law, and finance.
**Key Challenges in Document Processing:**
* **Upstream Data Issues:** Many perceived AI hallucinations are actually errors originating from the OCR process. A single digit swapped in a financial table or a misrecognized word can lead to incorrect AI outputs, even with perfect prompting.
* **High-Stakes Domains:** Document processing is critical in fields where errors can have severe consequences. Medical, legal, and financial documents require high accuracy and reliable citations.
* **Difficulty in Comparison:** Evaluating document quality is challenging. Dense tables with many values make it hard to spot errors. Understanding the end goal is essential to determine which errors are significant.
* **Need for Bounding Boxes:** Effective annotation often requires bounding boxes to precisely link issues to specific locations in the document, rather than just textual notes.
* **Inconsistent Data Formatting:** Real-world documents are messy and inconsistent. Even seemingly simple forms can have variations in formatting, grouping of information, and inclusion of elements like underlines or specific data fields.
* **OCR Limitations:** State-of-the-art OCR models, like Shandra and Gemini Flash, still struggle with various aspects of document processing.
* **Layout Replication:** Vision models attempt to replicate the visual layout, leading to differences from the original document, such as varying underline lengths or centering of headers.
* **Semantic Grouping:** Models may fail to correctly associate headers with their corresponding data rows or cells, disrupting the intended structure.
* **Missing Information:** Crucial elements like numbers (e.g., a "1" next to a requirement) can be missed.
* **Header Handling:** Headers might be treated differently, sometimes receiving a point value when they shouldn't, or vice versa, requiring domain expertise to evaluate correctly.
* **Watermarks:** Watermarks like "example," "confidential," or "draft" are often not captured by default OCR, which can be critical for context and legal enforceability. This is a significant issue in sectors like government, legal, and finance.
* **Handwriting and Scans:** PDFs can contain a mix of text layers and scanned images, making OCR complex. Handwritten notes or scanned documents present additional challenges.
**Annotation Tools and Workflows:**
* **Custom Annotation Interface:** The speaker advocates for creating custom annotation interfaces tailored to specific data and inspection needs.
* **Iterative Development:** The annotation tool was developed iteratively. Initial versions were basic, with improvements added based on recurring annoyances during the labeling process. This included adding bounding boxes, rendered output views, and hover-over highlighting for model output inspection.
* **Bounding Boxes and Notes:** Tying bounding boxes from the original document to specific notes in the model output is crucial for efficient error analysis. This avoids constant switching between the PDF and the output.
* **Comparison Across Models:** The annotation tool allows for easy comparison of outputs from different OCR models (e.g., Shandra, Gemini Flash) on the same document.
* **Structured Data Extraction:** For some use cases, instead of extracting all text, structured data extraction (e.g., JSON output) can be more efficient, especially for search and filtering.
* **Agent Traces:** Understanding agent traces is vital for debugging. These traces show the step-by-step process an agent followed, including tool calls and retrieved information.
**Agent-Based Document Processing:**
* **Citations are Essential:** When agents process documents, reliable citations are paramount to verify the source of information.
* **Testing Post-OCR and Final Answer:** Evaluation should encompass both the quality of the OCR output and the final answer provided by the agent.
* **Root Cause Analysis:** When an agent fails, it's important to work backward from the wrong answer to identify the root cause.
* **Hallucination vs. Context:** Determine if the error is a pure hallucination or if the agent is repeating something from its context window.
* **Prompting vs. Retrieval:** If it's repeating context, investigate if the issue stems from the prompt or a retrieval error.
* **OCR vs. Source Document:** If retrieval is correct, the problem lies in either the OCR extraction or the original source document itself.
* **Iterative Improvement:** The goal is to isolate the failure point (OCR, retrieval, agent logic) to inform the next steps for improvement, whether it's prompt tuning, changing models, or fixing upstream data issues.
* **Jev for Evaluation:** Tools like Jev can assist in evaluating whether an agent's answer is supported by its citations, contradicting them, or is unsupported.
* **Comparison of OCR and Agent Setups:** The system allows for comparing different OCR models, retrieval approaches, and agent harnesses to find the optimal configuration.
**Specific Examples and Tools:**
* **Food Inspection Report:** Demonstrates issues with header grouping, missing data points (e.g., a "1"), and inconsistent formatting.
* **Medical Document:** Highlights the challenge of watermarks like "example" which, if missed, could lead to misinterpretation of data.
* **Loan Estimate:** Shows a case where an agent correctly answers a question with a citation, but the citation itself might require further validation (e.g., is an empty field correctly interpreted as zero?).
* **Tesseract OCR:** Mentioned as a simple, local OCR tool that can be used in conjunction with scripting for cropping and zooming, though it can be slow and expensive.
* **Prime Agent:** Discussed as an agent harness that uses Python as its primary tool. Evaluations showed it was less effective and more expensive than a vanilla Py agent for certain tasks.
* **Signatures:** The ambiguity of signatures, especially when scanned or partially erased, poses challenges for reliable extraction and verification.
**The "No Silver Bullet" Reality:**
The speaker strongly refutes the idea of a "silver bullet" solution for document processing. PDFs are inherently complex, combining image and text layers with intricate formatting. While AI agents are powerful, they require careful evaluation and are not a substitute for understanding the underlying data and processing pipeline.
**Recommendations:**
* **Subscribe to Updates:** The speaker maintains a blog/newsletter where he shares insights on document news, new models, and detailed evaluations.
* **Utilize Custom Tools:** Develop or adapt annotation tools to fit specific document types and evaluation needs.
* **Focus on Upstream Issues:** Prioritize identifying and fixing OCR and data extraction errors, as they are often the source of downstream AI failures.
* **Systematic Evaluation:** Implement a systematic approach to evaluate OCR models, retrieval mechanisms, and agent performance.
* **Consider Domain Expertise:** Leverage domain knowledge to interpret ambiguous data and errors correctly.
* **Courses and Resources:** The speaker co-leads an intensive course on document understanding and offers support through private forums and office hours, including OCR credits from vendors.
In essence, the presentation underscores that robust document AI requires meticulous attention to detail, iterative refinement of tools and workflows, and a deep understanding of the potential failure points, starting from the very first step of optical character recognition.