Page Classification enables you to automatically categorize pages within documents based on their content.
This allows you to label pages to filter them for downstream use-cases like structured extraction and OCR.
How Page Classification works
Page Classifications work by analyzing each page of a document and assigning it to one or more predefined categories that you
specify. When you initiate a parse job, you can provide a list of page classification configurations as part of your request. Each page
classification configuration consists of:
- Name: A unique identifier for the page class
- Description: A detailed description that guides the AI model in identifying pages that belong to this category
If you have specified page classes in your parse request, Tensorlake analyzes each page of the document and assigns it to one or more categories that you specify.
Classification Example
import time
from tensorlake.documentai import (
DocumentAI,
PageClassConfig,
)
doc_ai = DocumentAI(api_key="YOUR_TENSORLAKE_API_KEY")
# Define page classifications
page_classifications = [
PageClassConfig(
name="signature_page",
description="Pages containing signatures, signature lines, or signature blocks"
),
PageClassConfig(
name="terms_and_conditions",
description="If the has Terms and Conditions as a section header, classify as terms_and_conditions"
)
]
parse_id = doc_ai.classify(
file_id="https://pub-226479de18b2493f96b64c6674705dd8.r2.dev/Fake_Terms_Conditions.pdf",
page_classifications=page_classifications
)
print(f"Parse job submitted with ID: {parse_id}")
# Get the result
result = doc_ai.wait_for_completion(parse_id=parse_id)
for page_classification in result.page_classes:
print(f"Classification: {page_classification.page_class}")
print(f"Page: {page_classification.page_numbers}")
Classification Results
When you use page classification, the parse results include a page_classifications
field that contains an array of classification results:
{
"parse_id": "parse_xxxxx",
"status": "successful",
"page_classes": {
"terms_and_conditions": {
"page_class": "terms_and_conditions",
"page_numbers": [
1
]
},
"signature_page": {
"page_class": "signature_page",
"page_numbers": [
2
]
}
},
// ... other parse results
}
Each classification result includes:
- page_class: The classification name you provided. This will match the
name
field in your PageClassConfig
.
- page_numbers: An array of page numbers (1-indexed) that match this classification.
You can combine page classification with structured data extraction to only extract data from specific page types.
This allows speeding up structured extraction in long documents, and often improves accuracy of extraction.
Check out this Colab Notebook to
see an example of combining Page Classification with Structured Extraction.
Best Practices
Writing Effective Descriptions
The quality of your page classifications depends heavily on the descriptions you provide. Here are some tips:
Be specific and descriptive
# Good
PageClassConfig(
name="financial_summary",
description="Pages containing financial summaries, balance sheets, income statements, or tables with monetary values and financial metrics"
)
# Less effective
PageClassConfig(
name="financial_summary",
description="Financial pages"
)
Include visual and content cues
PageClassConfig(
name="signature_page",
description="Pages with signature lines, signature blocks, 'Sign here' text, or actual handwritten signatures. May include date fields next to signatures."
)
Mention common patterns
PageClassConfig(
name="form_page",
description="Pages with form fields, checkboxes, fill-in-the-blank sections, or structured input areas for data entry"
)
Common Use Cases
Insurance Claims Processing
page_classifications = [
PageClassConfig(
name="claim_form",
description="Insurance claim forms with policy numbers, incident details, and claimant information"
),
PageClassConfig(
name="supporting_documents",
description="Supporting documentation like police reports, medical records, or receipts"
),
PageClassConfig(
name="photos_evidence",
description="Pages containing photographs, images, or visual evidence of damages"
)
]
Legal Document Processing
page_classifications = [
PageClassConfig(
name="contract_terms",
description="Main contract pages with terms, conditions, and legal clauses"
),
PageClassConfig(
name="signature_pages",
description="Pages requiring signatures from parties, with signature lines and date fields"
),
PageClassConfig(
name="exhibits_attachments",
description="Exhibits, attachments, or addendums referenced in the main contract"
)
]
Financial Document Analysis
page_classifications = [
PageClassConfig(
name="executive_summary",
description="Executive summary or overview pages with key financial highlights"
),
PageClassConfig(
name="financial_statements",
description="Balance sheets, income statements, cash flow statements with numerical financial data"
),
PageClassConfig(
name="notes_disclosures",
description="Footnotes, accounting policies, or disclosure pages explaining financial data"
)
]
Page classification works with all supported document types including PDFs, Word documents, images, and more. The AI model analyzes both textual content and visual layout to make classification decisions.