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
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
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.
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.
Click Next.
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.
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.
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.
Click Activate Cloud Shell at the top of the Google Cloud console.
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.
(Optional) You can list the active account name with this command:
gcloud auth list
Click Authorize.
Output:
ACTIVE: *
ACCOUNT: {{{user_0.username | "ACCOUNT"}}}
To set the active account, run:
$ gcloud config set account `ACCOUNT`
(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.
Open Cloud Shell by clicking the Activate Cloud Shell button at the top of the console.
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.
Run the following command to install the Python client libraries for Document AI.
You must first create a Form Parser processor instance to use in the Document AI Platform for this tutorial.
From the Navigation Menu, under Artificial Intelligence, select Document AI.
Click Explore Processors, scroll down to Specialized and and inside Invoice Parser, click Create Processor.
Give it the name lab-invoice-uptraining and select the region .
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.
Open Cloud Shell and run the following commands to create a bucket.
Go to the Processor Details tab, and under Dataset, click on Configure Your Dataset.
Click on Show Advanced Options, and select I'll specify my own storage location.
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.
Click Continue or click Create Dataset.
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.
Go to the Train tab, then click on Import Documents.
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.
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.
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.
Highlight the text "14368 Pipeline Ave Chino, CA 91710" and assign the label supplier_address.
Highlight the text "10001" and assign the label invoice_id.
Highlight the text "2020-01-02" and assign the label due_date.
Switch to the Bounding Box tool. Highlight the text "Knuckle Couplers" and assign the label line_item/description.
Highlight the text "9" and assign the label line_item/quantity. Assign it to line_item (Knuckle Couplers).
Highlight the text "74.43" and assign the label line_item/unit_price. Assign it to line_item (Knuckle Couplers).
Highlight the text "669.87" and assign the label line_item/amount. Assign it to line_item (Knuckle Couplers).
On the Knuckle Couplers line item on the left side menu, click on the Add more rows button.
Use the Bounding Box tool to highlight the entire second row.
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:
Highlight the text "1,419.57" (next to Subtotal) and assign the label net_amount.
Highlight the text "113.57" (next to Tax) and assign the label total_tax_amount.
Highlight the text "1,533.14" (next to Total) and assign the label total_amount.
Highlight one of the "$" characters and assign the label currency.
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.
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.
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.
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.
In the training management console, click on Import Documents.
Enter the following path in Source path. This bucket contains pre-labeled documents in the Document JSON format.
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.
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.
Click on Edit Schema on the left side menu.
You should now be in the Label Management console.
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
Click Save when finished.
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.
On the Train page, Click Import Documents.
Copy and paste the following storage path. This directory contains 5 unlabeled invoice PDFs. From the Data split
dropdown list, select Training.
In the Auto-labeling section, select the Import with auto-labeling checkbox.
Select an existing processor version to label the documents.
For example: pretrained-invoice-v1.4-2022-10-21
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.
Click the Auto-labeled section to view the auto-labeled documents.
Click the first document to enter the labeling console.
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.
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.
Click Uptrain New Version.
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.
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.
(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
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:
...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.
Labs erstellen ein Google Cloud-Projekt und Ressourcen für einen bestimmten Zeitraum
Labs haben ein Zeitlimit und keine Pausenfunktion. Wenn Sie das Lab beenden, müssen Sie von vorne beginnen.
Klicken Sie links oben auf dem Bildschirm auf Lab starten, um zu beginnen
Privates Surfen verwenden
Kopieren Sie den bereitgestellten Nutzernamen und das Passwort für das Lab
Klicken Sie im privaten Modus auf Konsole öffnen
In der Konsole anmelden
Melden Sie sich mit Ihren Lab-Anmeldedaten an. Wenn Sie andere Anmeldedaten verwenden, kann dies zu Fehlern führen oder es fallen Kosten an.
Akzeptieren Sie die Nutzungsbedingungen und überspringen Sie die Seite zur Wiederherstellung der Ressourcen
Klicken Sie erst auf Lab beenden, wenn Sie das Lab abgeschlossen haben oder es neu starten möchten. Andernfalls werden Ihre bisherige Arbeit und das Projekt gelöscht.
Diese Inhalte sind derzeit nicht verfügbar
Bei Verfügbarkeit des Labs benachrichtigen wir Sie per E-Mail
Sehr gut!
Bei Verfügbarkeit kontaktieren wir Sie per E-Mail
Es ist immer nur ein Lab möglich
Bestätigen Sie, dass Sie alle vorhandenen Labs beenden und dieses Lab starten möchten
Privates Surfen für das Lab verwenden
Nutzen Sie den privaten oder Inkognitomodus, um dieses Lab durchzuführen. So wird verhindert, dass es zu Konflikten zwischen Ihrem persönlichen Konto und dem Teilnehmerkonto kommt und zusätzliche Gebühren für Ihr persönliches Konto erhoben werden.
In this lab, you will will create an Invoice Parser processor, configure the processor for uptraining, label example documents, and uptrain the processor.