Complex Table Recognition: How GLM-OCR Handles Merged Cells
Learn how GLM-OCR excels at recognizing complex tables with merged cells, multi-level headers, and diverse layouts commonly found in business documents.
Introduction
Table recognition is one of the most challenging tasks in document understanding. GLM-OCR achieves state-of-the-art performance in table recognition, handling complex structures that traditional OCR solutions struggle with.
Challenges in Table Recognition
Traditional OCR systems often fail with:
- Merged cells: Cells spanning multiple rows or columns
- Multi-level headers: Nested header structures
- Borderless tables: Tables without visible grid lines
- Complex layouts: Mixed text and numerical data
- Rotated tables: Tables at various angles
GLM-OCR Table Recognition Capabilities
GLM-OCR excels at all these scenarios thanks to its:
- CogViT Visual Encoder: Understands spatial relationships
- Deep Scene Optimization: Trained on real-world table data
- Structured Output: Produces clean Markdown or JSON
Usage
Basic Table Recognition
# Using Ollama
ollama run glm-ocr Table Recognition: ./table.pngAPI Call
import requests
response = requests.post(
"https://api.z.ai/api/paas/v4/layout_parsing",
headers={"Authorization": "Bearer your-api-key"},
json={
"model": "glm-ocr",
"file": "https://example.com/table.png"
}
)
# Output is structured Markdown table
print(response.json()["content"])Output Formats
Markdown Output
GLM-OCR outputs tables in clean Markdown format:
| Product | Q1 | Q2 | Q3 | Q4 | Total |
|---------|-----|-----|-----|-----|-------|
| Widget A | 100 | 150 | 200 | 180 | 630 |
| Widget B | 80 | 120 | 140 | 160 | 500 |
| **Total** | **180** | **270** | **340** | **340** | **1130** |Handling Merged Cells
For tables with merged cells, GLM-OCR preserves the structure:
| Category | | Sales | |
|----------|----------|-------|-------|
| | Product | 2023 | 2024 |
| Electronics | Phone | 1000 | 1200 |
| Electronics | Laptop | 800 | 950 |
| Furniture | Chair | 500 | 600 |Real-World Examples
Financial Reports
GLM-OCR handles complex financial tables with:
- Multiple header rows
- Currency formatting
- Percentage calculations
- Footnote references
Academic Papers
Scientific tables often include:
- Statistical data
- Confidence intervals
- P-values
- Multi-column layouts
Business Documents
Common business table types:
- Invoice line items
- Inventory lists
- Employee records
- Project timelines
Best Practices
Image Quality
- Resolution: Minimum 150 DPI recommended
- Contrast: Ensure clear distinction between text and background
- Orientation: Correct any rotation before processing
Complex Tables
For very complex tables:
- Crop the table: Remove surrounding text
- Enhance contrast: Improve visibility of grid lines
- Split large tables: Process sections separately if needed
Post-Processing
import pandas as pd
from io import StringIO
# Parse Markdown table to DataFrame
markdown_table = """
| Product | Sales | Revenue |
|---------|-------|---------|
| A | 100 | $1000 |
| B | 200 | $2000 |
"""
# Convert to DataFrame for further processing
df = pd.read_csv(
StringIO(markdown_table.replace("|", ",")),
skipinitialspace=True
)Performance Comparison
| Feature | GLM-OCR | Traditional OCR |
|---|---|---|
| Merged Cells | Excellent | Poor |
| Multi-level Headers | Excellent | Limited |
| Borderless Tables | Good | Poor |
| Speed | 1.86 pages/sec | Varies |
| Accuracy | 94.62 (SOTA) | ~80-85 |
Troubleshooting
Common Issues
Issue: Columns misaligned Solution: Ensure the table image is not skewed
Issue: Missing cells Solution: Check image resolution and contrast
Issue: Merged cells not detected Solution: Use higher resolution image
Conclusion
GLM-OCR's table recognition capabilities make it ideal for processing complex business documents, financial reports, and academic papers. Its ability to handle merged cells, multi-level headers, and borderless tables sets it apart from traditional OCR solutions.
Related Articles
Author
More Posts
Structured Information Extraction: GLM-OCR JSON Output for Documents
Learn how to use GLM-OCR for structured information extraction from invoices, ID cards, receipts, and forms with customizable JSON schema output.
GLM-OCR: 0.9B Parameters Achieving OCR SOTA Performance
Introducing GLM-OCR, a lightweight professional OCR model with only 0.9B parameters that achieves state-of-the-art performance on OmniDocBench V1.5 with a score of 94.62.
GLM-OCR Local Deployment: Ollama vs vLLM vs SGLang
Compare different local deployment options for GLM-OCR including Ollama, vLLM, and SGLang. Learn which option is best for your use case.