Prebuilt Models
Complete the full lesson to earn 25 points
Work through each section, then tap “Mark as Complete” on the last one.
Lesson: Mastering Prebuilt Models for Document Intelligence in Foundry
Introduction: Why Document Intelligence Matters
In the modern enterprise, data exists in two primary states: structured and unstructured. While traditional databases thrive on structured data—rows, columns, and predefined relationships—the vast majority of organizational knowledge is trapped in unstructured formats. Documents such as invoices, purchase orders, identity cards, legal contracts, and medical records represent a massive repository of information that is often manually processed, leading to high operational costs, human error, and significant delays.
Document Intelligence is the field of artificial intelligence focused on extracting, classifying, and interpreting this unstructured information. Within the Foundry ecosystem, implementing Document Intelligence means moving away from manual data entry and toward automated, intelligent pipelines that "read" documents as humans do. Prebuilt models are the foundation of this capability. These are pre-trained machine learning models provided by the platform that can immediately recognize common document types and extract specific data fields without requiring the user to train a model from scratch.
Understanding how to effectively deploy these prebuilt models is critical for any data practitioner. It allows you to transform static PDFs and images into actionable data points in your ontology. By mastering these tools, you reduce the time-to-value for your data projects, ensure consistency in data extraction, and free up human resources to focus on high-value decision-making rather than repetitive administrative tasks.
Understanding Prebuilt Document Intelligence Models
At its core, a prebuilt model is a "black box" that has been trained on millions of documents across various industries. When you pass a file to a prebuilt model, it performs a series of complex operations: image preprocessing, optical character recognition (OCR), layout analysis, and entity extraction.
Foundry provides specialized models for different document categories. Using the right model for the right document is the single most important factor in achieving high accuracy. If you attempt to use an invoice-specific model on a standard legal contract, the results will be poor because the model is looking for line items, tax totals, and vendor names, which do not exist in the contract.
Common Categories of Prebuilt Models
- Financial Documents: Designed for invoices, receipts, and purchase orders. These models are adept at detecting currency symbols, dates, line-item tables, and vendor details.
- Identity Documents: Optimized for government-issued IDs, passports, and driver's licenses. These models prioritize data privacy and are trained to handle the specific layouts and security features found on identity cards.
- General Purpose (OCR + Layout): These models provide a "raw" extraction of text and its spatial coordinates without assuming a specific document structure. These are useful when you have highly custom documents that don't fit into standard categories.
- Contract Analysis: These models focus on identifying clauses, parties involved, expiration dates, and signatures within legal documentation.
Callout: Prebuilt vs. Custom Models A common question is: "When should I use a prebuilt model versus training my own?" The answer lies in the variability of your data. Prebuilt models are excellent for standardized documents like invoices or passports where the layout is consistent across many vendors or regions. Custom models are necessary when your documents are highly idiosyncratic, contain proprietary layouts, or require the extraction of highly specific domain-specific entities that a general model wouldn't recognize. Always start with a prebuilt model to establish a baseline before considering the effort of custom training.
Implementing Prebuilt Models: A Step-by-Step Guide
Implementing a prebuilt model in Foundry typically involves a structured workflow. You start with the ingestion of raw documents into a dataset, process them through the model, and then map the output into your object-relational model.
Step 1: Data Ingestion
Before you can run a model, your documents must be accessible in a Foundry dataset. You should use the standard data connection tools to bring your PDFs, TIFFs, or JPEGs into a raw dataset. Ensure that the files are correctly associated with unique identifiers so you can join the extracted data back to the original source.
Step 2: Selecting the Model
Navigate to the "Models" or "Document Intelligence" section of your Foundry environment. You will see a catalog of available models. Select the one that matches your document type.
Step 3: Configuring the Pipeline
You will typically configure the model execution using a transformation script (often in Python or a dedicated low-code interface). The model expects an input stream of files and produces a structured JSON output.
# Example: Using a prebuilt model in a Foundry transform
from foundry_ml import DocumentIntelligence
def process_documents(input_dataset):
# Initialize the prebuilt model for Invoices
model = DocumentIntelligence.get_model("invoice_v2")
# Process the dataset
results = []
for record in input_dataset:
# Extract data from the file path
extracted_data = model.predict(record.file_path)
results.append({
"doc_id": record.id,
"vendor": extracted_data.vendor_name,
"total": extracted_data.total_amount,
"currency": extracted_data.currency
})
return results
Step 4: Validation and Mapping
The model output will be raw data. You must map these values to the properties in your Ontology. This is where you implement logic to handle confidence scores. If a model returns a total amount with a 60% confidence score, you might want to flag that record for human review rather than automatically committing it to your database.
Note: Always store the "Confidence Score" provided by the model in your output dataset. This is crucial for auditing and for building "human-in-the-loop" workflows where records with low scores are routed to a verification task.
Best Practices for Document Intelligence
Achieving high-quality results from AI models requires a disciplined approach. It is not enough to simply run the code; you must manage the data quality and the process around the model.
1. Preprocessing is Paramount
Even the best AI model will struggle if the input images are of poor quality. If your documents are scanned at low resolutions, contain excessive noise, or are skewed, the OCR performance will drop significantly. Implement a preprocessing step in your pipeline that performs:
- Deskewing: Correcting the orientation of the document.
- Binarization: Converting color images to black and white to increase contrast.
- Denoising: Removing artifacts and graininess from low-quality scans.
2. Handling Multi-Page Documents
Many prebuilt models are optimized for single-page documents. If you are dealing with multi-page contracts or reports, you should implement a "splitter" logic in your pipeline. Break the multi-page PDF into individual pages or logical sections before feeding them into the model, and then aggregate the results back together.
3. Implementing Human-in-the-Loop (HITL)
Never assume a model is 100% accurate. The most successful implementations use a threshold-based approach.
- High Confidence (e.g., > 90%): Automatically process the data.
- Medium Confidence (e.g., 70% - 90%): Flag for review by a human.
- Low Confidence (e.g., < 70%): Route to a manual data entry queue.
4. Monitoring Performance Over Time
AI models can experience "drift." As the formats of your incoming documents change (e.g., a vendor changes their invoice template), the performance of your prebuilt model may decline. Monitor the accuracy of your extractions by periodically sampling records and comparing them to manual truth data.
Warning: Be cautious with PII (Personally Identifiable Information). When using cloud-based prebuilt models, ensure that your data governance policies comply with local regulations like GDPR or CCPA. Some models may process data in different regions, so always check the data residency settings of your Foundry environment.
Comparison of Prebuilt Model Capabilities
When choosing your strategy, refer to this table to understand the trade-offs between different approaches:
| Feature | Prebuilt Models | Custom Trained Models | Rule-Based Extraction |
|---|---|---|---|
| Setup Time | Very Fast (Hours) | Slow (Weeks/Months) | Moderate (Days) |
| Accuracy | High on standard docs | Very High on specific docs | Variable/Low |
| Flexibility | Low | High | Very Low |
| Maintenance | Minimal (Managed by provider) | High (Requires retraining) | High (Requires code updates) |
| Expertise | Low | High (Data Science) | Moderate (Engineering) |
Common Pitfalls and How to Avoid Them
Pitfall 1: Over-Reliance on "Default" Settings
Many developers assume the model will "just work" for every variant of a document. In reality, you often need to tune parameters like the confidence threshold or the specific field mappings. Do not treat the model output as ground truth without validating the schema mapping.
Pitfall 2: Ignoring Error Handling
What happens when a file is corrupted, encrypted, or password-protected? If your pipeline does not handle these exceptions, the entire build will fail. Always include robust try-catch blocks and logging in your transformation code to capture these failures without stopping the entire data pipeline.
Pitfall 3: Failing to Clean Data Post-Extraction
Models often output data in slightly different formats (e.g., dates as "MM/DD/YYYY" vs "YYYY-MM-DD"). Always include a normalization layer after the extraction step to ensure that the data entering your ontology is clean, standardized, and ready for downstream analytics.
Pitfall 4: Ignoring Contextual Clues
Sometimes, the model might extract the correct value but assign it to the wrong field. For example, a model might extract a date that is actually a "Due Date" and mislabel it as an "Invoice Date." You should implement validation logic that checks for logical consistency (e.g., the "Due Date" must be after the "Invoice Date").
Advanced Implementation: Scaling Your Document Pipeline
Once you have a single document type working, you will likely need to scale to thousands or millions of documents. This requires moving from interactive development to robust, distributed pipelines.
Parallelization
Foundry’s compute environment is designed for parallel processing. When writing your transformation scripts, ensure that you are not performing operations that force the pipeline to run sequentially. By utilizing the distributed nature of the Foundry compute, you can process thousands of invoices simultaneously, significantly reducing the runtime.
Metadata Enrichment
Do not just store the extracted text. Store metadata about the extraction process itself. This includes:
- Model Version: Which version of the prebuilt model was used? This is essential for reproducibility.
- Timestamp: When was the document processed?
- Processing Logs: Any warnings or errors encountered during OCR.
- Source File URI: A link back to the original document for verification.
Feedback Loops
The most effective way to improve your system is to create a feedback loop. If a user corrects a piece of data in the Foundry platform, that correction should be logged. Over time, you can use these corrections to fine-tune a custom model if the prebuilt model consistently fails on specific document types. This turns your operational system into a data-generating engine.
Callout: The Philosophy of "Good Enough"
Callout: Precision vs. Recall In Document Intelligence, you are constantly balancing precision and recall. High precision means that when the model extracts a value, it is almost certainly correct. High recall means the model finds as much information as possible. In a financial context, you usually prioritize high precision (you don't want to pay the wrong invoice amount). In a search context, you might prioritize high recall (you want to find every document that might be relevant). Understand your business goal before setting your model parameters.
Key Takeaways
- Start with Prebuilt, Then Pivot: Always begin with a prebuilt model to establish a baseline. Only invest in custom training if the prebuilt models fail to meet your accuracy requirements after thorough tuning.
- Prioritize Preprocessing: The quality of your extraction is directly proportional to the quality of the input image. Invest time in deskewing, binarization, and noise reduction.
- Human-in-the-Loop is Mandatory: AI is not infallible. Use confidence scores to automatically route low-certainty extractions to human reviewers to maintain data integrity.
- Normalize and Validate: Never trust the raw output of a model. Build a secondary layer that validates data formats (dates, currencies, totals) and ensures logical consistency before the data enters your ontology.
- Monitor for Drift: Document formats change. Set up dashboards to monitor the performance of your models over time and trigger alerts if the accuracy drops below acceptable levels.
- Build for Auditability: Store the model version, processing logs, and source file references alongside your extracted data. This is critical for compliance and debugging.
- Scale Through Parallelization: Use Foundry’s distributed compute capabilities to process large batches of documents efficiently, ensuring that your pipelines remain performant as your data volume grows.
By following these principles, you will be able to implement robust, scalable, and accurate Document Intelligence solutions that provide genuine value to your organization. The goal is not just to extract text, but to create a reliable stream of data that powers better decision-making across the enterprise.
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles your daily points limit so you progress twice as fast, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× daily points limit
- ✓ Distraction-free lessons