---
title: Document ingest and modeling
description: Learn how to ingest PDF documents as an input to modeling.
section_name: AutoML
maturity: public-preview
---

# Document ingest and modeling {: #document-ingest-and-modeling }

PDF documents used for modeling are extracted by tasks within the blueprint and registered as a dataset made of a single text column, with each row in the column representing a single document and with the value being the extracted text&mdash;features of type `document`.

The steps to build models are:

1. [Prepare your data](#prepare-pdf-data).
2. [Model with text](#model-with-text), including ingesting, converting PDF to text, and analyzing data.

## Prepare PDF data {: #prepare-pdf-data }

The following options describe methods of preparing embedded text PDF or PDF documents with scans as data that can be imported into DataRobot for modeling. See the [deep dive](#deep-dive-text-handling-details) below for a more detailed description of both data handling methods.

* Include PDF documents as base64-encoded strings inside the dataset. (See the DataRobot Python client [utility methods](https://datarobot-public-api-client.readthedocs-hosted.com/en/latest-release/reference/modeling/spec/binary_data.html?highlight=binary#working-with-binary-data){ target=_blank } for assistance.)

	![](images/docai-3.png)

* Upload an archive file (e.g., zip) with a dataset file that references PDF documents relative to the dataset (document columns in the dataset contain paths to documents).

	![](images/docai-4.png)

* For binary or multiclass classification, separate the PDF document classes by folder, then compress the separated PDFs into an archive and upload them. DataRobot creates a column with the directory names, which you can use as the target.

	![](images/docai-5.png)

* For unsupervised projects, include all PDF files in the root (no directories needed).

* Include a dataset along with your documents and other binary files (for example, images). In the dataset, you can reference the binary files by their relative path to the dataset file in the archive. This method works for any project type and allows you to combine the document feature type with all the other feature types DataRobot supports.

When uploading a ZIP file, you can also supply an accompanying CSV file to provide additional information to support the uploaded document. One column within the CSV must contain the document file name being referenced. All other values contained in the row are associated with the document and used as modeling features.

![](images/docai-2.png)

!!! note "Text extraction with the Document Text Extractor task"
	DataRobot extracts all text from _text_ PDF documents. If images contain text, that text may or may not be used, depending on how the image was created. To determine if text in an image can be used for modeling, open the image in a PDF editor and try to select it&mdash;if you can select the text, DataRobot will use it for modeling. To ensure DataRobot can extract text from any image, you can select the the Tesseract OCR task.


## Model with text {: #model-with-text }

To start a project using Document AI:

1. Load your prepared [dataset file](#prepare-pdf-data), either via upload or the AI Catalog. Note that:

	- Any `document` type feature is converted to text during modeling (in the blueprint).
	- Each document is represented as a row.
	- All extracted text from the document is represented within a cell for that row.

2. Verify that DataRobot is using the correct [document processing task](#document-settings) and set the language.

2. Examine your data after [EDA1](#data-quality) (ingest) to understand the content of the dataset.

3. Press start to begin modeling building.

4. Examine your data using the [Document AI insights](doc-ai-insights).

## Document settings {: #document-settings }

After setting the target, use the **Document Settings** advanced option to verify or modify the document task type and language.

### Set document task {: #set-document-task }

Select one of two document tasks to be used in the blueprints. &mdash;**Document Text Extractor** or **Tesseract OCR**. During EDA1, if DataRobot can detect embedded text it applies **Document Text Extractor**; otherwise, it selects **Tesseract OCR**.

* For embedded text, the Document Text Extractor is recommended because it's faster and more accurate.
* To extract all visible text, including the text from images inside the documents, select the **Tesseract OCR** task.

* When PDFs contain scans, it is possible that the scans have quality issues&mdash;they contain "noise," the pages are rotated, the contrast is not sharp. Once EDA1 completes, you can view the state of the scans by expanding the `Document` type entry in the data table:

![](images/docai-7.png)

### Set language {: #set-language }

It is important to verify and set the language of the document. The OCR engine must have the correct language set in order to set the appropriate pre-trained language model. DataRobot's OCR engine supports 105 languages.

## Data quality {: #data-quality }

If the dataset was loaded to the AI Catalog, use the **Profile** tab for visual inspection:

![](images/docai-12.png)

After uploading, examine the data, which shows:

* The feature names or, if an archive file is separated into folders, a class column&mdash;the folder names from the ZIP file.

	![](images/docai-6.png)

* The `document` type features.

* The Reference ID, which provides all the file names to later help identify which predictions belong to which file if no dataset file was provided inside the archive file.

Additionally, DataRobot's Data Quality assessment helps to identify issues so that you can identify errors before modeling.

![](images/docai-9.png)

Click **Preview log**, and optionally download the log, to identify errors and fix the dataset. Some of the errors include:

* `There is no file with this name`
* `Found empty path`
* `File not in PDF format or corrupted`
* `The file extension indicates that this file is not of a supported document type`


## Deep dive: Text handling details {: #deep-dive-text-handling-details }

DataRobot handles both embedded text and PDFs with scans. Embedded text documents are PDFs that allow you to select and/or search for text in your PDF viewer. PDF with scans are processed via optical character recognition (OCR) &mdash;text cannot be searched or selected in your PDF viewer. This is because the text is part of an image within the PDF.

### Embedded text {: #embedded-text }

The blueprints available in the [Repository](repository) are the same as those that would be available for a text variable. While text-based blueprints use text directly, in a blueprint with `document` variables, you can see the addition of a **Document Text Extractor** task. It takes the PDF files, extracts the text, and provides the text to all subsequent tasks.

![](images/docai-8.png)

### Scanned text (OCR) {: #scanned-text-ocr }

Because PDF documents with scans do not have the text embedded, the text is not directly machine-readable. DataRobot runs optical character recognition (OCR) on the PDF in an attempt to identify and extract text. Blueprints using OCR use the Tesseract OCR task:

![](images/docai-10.png)

The **Tesseract OCR** task opens the document, converts each page to an image and then processes the images with the Tesseract library to extract the text from them. The **Tesseract OCR** task then passes the text to the next blueprint task.

Use the [**Document Insights**](doc-ai-insights#document-insights) visualization after model building to see example pages and the detected text. Because the Tesseract engine can have issues with small fonts, use [**Advanced Tuning**](doc-ai-insights#advanced-tuning) to adjust the resolution.

### Base64 strings {: #base64-strings }
DataRobot also supports base64-encoded strings. For document (and [image](vai-model)) datasets, DataRobot converts PDF files to base64 strings and includes them in the dataset file during ingest. After ingest, instead of a ZIP file there is a single CSV file that includes the images and PDF files as base64 strings.
