arrow_back

Uptraining with Document AI Workbench

Sign in Join
Get access to 700+ labs and courses

Uptraining with Document AI Workbench

Lab 1 hour universal_currency_alt 5 Credits show_chart Intermediate
info This lab may incorporate AI tools to support your learning.
Get access to 700+ labs and courses

GSP1141

Overview

Document AI is a document understanding solution that takes unstructured data (e.g. documents, emails, invoices, forms, etc.) and makes the data easier to understand, analyze, and consume. The API provides structure through content classification, entity extraction, advanced searching, and more. With Document AI Workbench, you can achieve higher document processing accuracy by creating fully customized models using your own training data.

By using uptraining through Document AI Workbench, you can achieve higher document processing accuracy by providing additional labeled examples for Specialized Document Types and creating a new model version. In this lab, you will create an Invoice Parser processor, configure the processor for uptraining, label example documents, and uptrain the processor.

The document dataset used in this lab consists of randomly-generated invoices for a fictional piping company.

Objectives

In this lab, you will learn how to perform the following tasks:

  • Configure Uptraining for an Invoice Parser processor.
  • Label Document AI training data using the annotation tool.
  • Kick off training for a new model version.

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.

This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details pane.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details pane.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field.

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell at the top of the Google Cloud console.

  2. Click through the following windows:

    • Continue through the Cloud Shell information window.
    • Authorize Cloud Shell to use your credentials to make Google Cloud API calls.

When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Task 1. Enable the Document AI API

Before you can begin using Document AI, you must enable the API.

  1. Open Cloud Shell by clicking the Activate Cloud Shell button at the top of the console.

  2. In Cloud Shell, run the following command to enable the API for Document AI.

gcloud services enable documentai.googleapis.com

You should see something like this:

Operation "operations/..." finished successfully.
  1. Run the following command to install the Python client libraries for Document AI.
pip3 install --upgrade google-cloud-documentai

You should see something like this:

... Installing collected packages: google-cloud-documentai Successfully installed google-cloud-documentai-2.15.0

Now, you're ready to use the Document AI API!

Click Check my progress to verify the objective.

Enable the Document AI API

Task 2. Create a processor

You must first create a Form Parser processor instance to use in the Document AI Platform for this tutorial.

  1. From the Navigation Menu, under Artificial Intelligence, select Document AI.

  1. Click Explore Processors, scroll down to Specialized and and inside Invoice Parser, click Create Processor.

  1. Give it the name lab-invoice-uptraining and select the region .

  2. Click Create to create your processor.

Click Check my progress to verify the objective.

Create a Processor

Task 3. Create a dataset

In order to train your processor, we will have to create a dataset with training and testing data to help the processor identify the entities we want to extract.

You will need to create a new bucket in Cloud Storage to store the dataset.

  1. Open Cloud Shell and run the following commands to create a bucket.
export PROJECT_ID=$(gcloud config get-value project) gcloud storage buckets create "gs://${PROJECT_ID}-uptraining-lab" --location={{{project_0.startup_script.documentai_region|Region}}}
  1. Go to the Processor Details tab, and under Dataset, click on Configure Your Dataset.

  1. Click on Show Advanced Options, and select I'll specify my own storage location.

  1. Paste the bucket name from the bucket you created in step one into the Destination Path field. (Don't include gs://).

This should be: -uptraining-lab.

  1. Click Continue or click Create Dataset.

  2. Wait for the dataset to be created, then it should direct you to the Processor Details page. Your dataset details should be listed under Dataset.

Click Check my progress to verify the objective.

Create a Dataset

Task 4. Import a test document

Now you will import a sample invoice PDF into your dataset.

  1. Go to the Train tab, then click on Import Documents.

  2. A a sample PDF is available for you to use in this lab. Copy and paste the following link into the Source Path box. Leave the Data split as Unassigned for now.

cloud-samples-data/documentai/codelabs/uptraining/pdfs

  1. Click Import.

  2. When the import completes, click on the fake_invoice_10001 document. You should see the document in the train management UI.

Click Check my progress to verify the objective.

Import a Test Document

Task 5. Label the test document

Next, you will identify text elements and labels for the entities you would like to extract. These labels will be used to train your model to parse this specific document structure and identify the correct types.

  1. Click on the Select Text Tool, then highlight the text "McWilliam Piping International Piping Company" and assign the label supplier_name. You can use the text filter to search for label names.

  1. Highlight the text "14368 Pipeline Ave Chino, CA 91710" and assign the label supplier_address.

  1. Highlight the text "10001" and assign the label invoice_id.

  1. Highlight the text "2020-01-02" and assign the label due_date.

  1. Switch to the Bounding Box tool. Highlight the text "Knuckle Couplers" and assign the label line_item/description.

  1. Highlight the text "9" and assign the label line_item/quantity. Assign it to line_item (Knuckle Couplers).

  1. Highlight the text "74.43" and assign the label line_item/unit_price. Assign it to line_item (Knuckle Couplers).

  1. Highlight the text "669.87" and assign the label line_item/amount. Assign it to line_item (Knuckle Couplers).

  1. On the Knuckle Couplers line item on the left side menu, click on the Add more rows button.

  1. Use the Bounding Box tool to highlight the entire second row.

  2. Repeat this for the third row. If needed, update the labels to match the first row's structure.

It should look like this when complete:

  1. Highlight the text "1,419.57" (next to Subtotal) and assign the label net_amount.

  1. Highlight the text "113.57" (next to Tax) and assign the label total_tax_amount.

  1. Highlight the text "1,533.14" (next to Total) and assign the label total_amount.

  1. Highlight one of the "$" characters and assign the label currency.

  1. The labeled document should look like this when complete. Note, you can make adjustments to these labels by clicking on the bounding box in the document or the label name/value on the left side menu. Click Mark as Labeled when you are finished labeling.

  1. Here is the full list of labels and values
Label Name Text
supplier_name McWilliam Piping International Piping Company
supplier_address 14368 Pipeline Ave Chino, CA 91710
invoice_id 10001
due_date 2020-01-02
line_item/description Knuckle Couplers
line_item/quantity 9
line_item/unit_price 74.43
line_item/amount 669.87
line_item/description PVC Pipe 12 Inch
line_item/quantity 7
line_item/unit_price 15.90
line_item/amount 111.30
line_item/description Copper Pipe
line_item/quantity 7
line_item/unit_price 91.20
line_item/amount 638.40
net_amount 1,419.57
total_tax_amount 113.57
total_amount 1,533.14
currency $

Click Check my progress to verify the objective.

Create Labels

Task 6. Assign document to training set

You should now be back at the Training page. Notice that the number of Labeled and Unlabeled documents have changed as well as the numbers of active labels.

  1. You now need to assign this document to either the "Training" or "Test" set. Select the Document, click Assign to Set, then click on Training.

  1. Notice the Data Split numbers have changed. You should see 1 document in the Training set and 0 in the Test set.

Click Check my progress to verify the objective.

Assign Document to Training Set

Task 7. Import pre-labeled data

Document AI Uptraining requires a minimum of 10 documents in both the training and test sets, along with 10 instances of each label in each set. It's recommended to have at least 50 documents in each set with 50 instances of each label for best performance. More training data generally equates to higher accuracy.

It will take a long time to manually label 100 documents, so we have some pre-labeled documents that you can import for this lab. You can import pre-labeled document files in the Document.json format. These can be results from calling a processor and verifying the accuracy using Human in the Loop (HITL).

Note: when importing pre-labeled data, it is highly recommended to manually review annotations before a model is trained.
  1. In the training management console, click on Import Documents.

  2. Enter the following path in Source path. This bucket contains pre-labeled documents in the Document JSON format.

cloud-samples-data/documentai/Custom/Invoices/JSON
  1. From the Data split list, select Auto-split. This automatically splits the documents to have 80% in the training set, and 20% in the test set. Leave Import with auto-labeling unchecked.

  2. Click Import. The import might take several minutes to complete.

When the import is finished, you will find the documents on the Train tab.

Click Check my progress to verify the objective.

Import pre-labeled data

Task 8. Edit labels

The sample documents we are using for this example do not contain every label supported by the Invoice Parser. We will need to mark the labels we are not using as inactive before training. You can also follow similar steps to add a custom label before Uptraining.

  1. Click on Edit Schema on the left side menu.

  2. You should now be in the Label Management console.

  1. Use the Checkboxes and the Disable/Enable buttons to mark ONLY the following labels as Enabled.

    • invoice_date
    • line_item > amount
    • line_item > description
    • receiver_address
    • receiver_name
    • supplier_address
    • supplier_name
    • total_amount
  2. Click Save when finished.

  1. Click on the Back arrow to return to the Dataset management console. If asked to save the schema, click Save.

Notice that the labels with 0 instances have been marked as Inactive.

Click Check my progress to verify the objective.

Edit labels

Task 9. Auto-label newly imported documents

When importing unlabeled documents for a processor with an existing deployed processor version, you can use Auto-labeling to save time on labeling.

  1. On the Train page, Click Import Documents.

  2. Copy and paste the following storage path. This directory contains 5 unlabeled invoice PDFs. From the Data split dropdown list, select Training.

cloud-samples-data/documentai/Custom/Invoices/PDF_Unlabeled
  1. In the Auto-labeling section, select the Import with auto-labeling checkbox.

  2. Select an existing processor version to label the documents.

    • For example: pretrained-invoice-v1.4-2022-10-21
  3. Click Import and wait for the documents to import. You can leave this page and return later.

  • When complete, the documents appear in the Train page in the Auto-labeled section.You cannot use auto-labeled documents for training or testing without marking them as labeled.
  1. Click the Auto-labeled section to view the auto-labeled documents.

  1. Click the first document to enter the labeling console.

  2. Verify the labels, bounding boxes, and values to ensure they are correct. Label any values that were omitted. Click Mark as labeled when finished with each document.

  3. Repeat the label verification for each auto-labeled document, then return to the Train page to use the data for training.

Click Check my progress to verify the objective.

Auto-label newly imported documents

Task 10. Uptrain the Model

Now, you are ready to begin training your Invoice Parser.

  1. Click Uptrain New Version.

  1. Set your version name to lab-uptraining-test-1. The Base version is the model version this new version will be built from. If you're using a new processor, the only option should be Google Pretrained Next with Uptraining.

  1. Click on Start Training to begin the Uptraining process. You should be redirected to the Dataset management page. You can view the training status on the right side. Training will take a few hours to complete.

  2. (Optional) You can also select View Label Stats to see metrics about the labels in your dataset.

Click Check my progress to verify the objective.

Uptrain the Model
  1. If you click on the version name, you will be directed to the Manage Versions page, which shows the Version ID and the current status of the Training Job.

Great! You have now started training your first uptraining job for Document AI. Since the training job will take around an hour, the lab will end here. If you are interested in learning more about testing the model version and evaluation, you can check out the following documentation guide.

Congratulations!

Congratulations, you've successfully used Document AI to uptrain an Invoice Parser. You can now use this processor to parse invoices just as you would for any Specialized Processor. You can refer to the Specialized Processors Codelab to review how to handle the processing response.

Next steps/Learn more

Check out the following resources to learn more about Document AI and the Python Client Library:

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated: April 24, 2024

Lab Last Tested: April 24, 2024

Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.