로드 중...
검색 결과가 없습니다.

Google Cloud Skills Boost

Google Cloud 콘솔에서 기술 적용


700개 이상의 실습 및 과정 이용하기

Custom Document Extraction with Document AI Workbench

실습 1시간 universal_currency_alt 크레딧 5개 show_chart 중급
info 이 실습에는 학습을 지원하는 AI 도구가 통합되어 있을 수 있습니다.
700개 이상의 실습 및 과정 이용하기

GSP1142

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.

You can create Custom Document Extractors (CDE) that are specifically suited to your documents, and trained and evaluated with your data. This processor identifies and extracts entities from your documents. You can then use this trained processor on additional documents. You typically would use a CDE on documents that are all of one type, such as your institution's enrollment forms.

In this lab, you will learn how to use Document AI Workbench to create and train a Custom Document Extractor that processes W-2 (US tax form) documents. Most of the document preparation work has been done so that you can focus on the other mechanics of creating a CDE.

Objectives

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

  • Create a Custom Document Extractor in Document AI Workbench
  • Define and create the processor schema
  • Import documents
  • Annotate documents manually in Document AI Workbench
  • Use generative AI to auto-label documents
  • Kick off a training job for the processor

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. 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!

Enable the Document AI API

Task 2. Create a processor

You must first create an Custom Document Extractor processor to use for this lab.

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

  1. From the Navigation menu select View all products. Under Artificial Intelligence, select Document AI.

  1. Click Create Custom Processor.

  2. Inside the Custom Extractor box, click Create Processor.

  3. Give it the name lab-custom-extractor and select the region US (United States) on the list.

  4. Click Create to create your processor.

Click Check my progress to verify the objective.

Create a Processor

Task 3. Define processor fields

You are now on the Processor overview page of the processor you just created.

You can specify the fields you want the processor to extract and begin labeling documents.

  1. Click on the Get started tab. The Fields menu appears.

  2. Click Create New Field.

  3. Enter the name for the field. Select the Data type and the Occurrence. Click Create. Refer to Define processor schema for detailed instructions on creating and editing a schema.

  4. Create each of the following labels for the processor schema.

Name Data Type Occurrence
control_number Number Optional multiple
employees_social_security_number Number Required multiple
employer_identification_number Number Required multiple
employers_name_address_and_zip_code Address Required multiple
federal_income_tax_withheld Money Required multiple
social_security_tax_withheld Money Required multiple
social_security_wages Money Required multiple
wages_tips_other_compensation Money Required multiple

You can also create and use other types of labels in your processor schema, such as checkboxes and tabular entities. For example, the W-2 forms contain a Statutory employee, Retirement plan, and Third party sick pay check boxes that you could also add to the schema.

Click Check my progress to verify the objective. Create Labels

Task 4. Upload a sample document

Next, you upload a sample W-2 PDF and label it.

  1. Click Upload Sample Document.

  2. In the sidebar, click Import documents from Google Cloud Storage.

  3. For this example, enter this bucket name in Source path. This links directly to one document.

cloud-samples-data/documentai/Custom/W2/PDF/W2_XL_input_clean_2950.pdf
  1. Click Import.

You are redirected to the labeling console.

Task 5. Label a document

The process of selecting text in a document, and applying labels is known as annotation.

  1. When you're at the labeling console, notice that many of the labels are already populated.

Note: Your results might look slightly different than the sample image.
  1. To use the suggested labels, hold the pointer over each label in the side panel, and click on the check mark to confirm the label is correct. You can edit the values if they do not match the document text.

  2. In this example, the values at the bottom of the document were not identified automatically, so you will need to label them manually.

  3. Use the Bounding box tool by default, or the Select text tool for multi-line values, to select the content and apply the label.

Note: The Select text tool does not work for all text values, so use the Bounding box if appropriate. You can also select non-text fields such as checkboxes using the Bounding box tool.
  1. In this example, the value of wages_tips_other_compensation was selected with the Bounding box tool, and that label is applied.

  1. Review the detected text values to ensure that they reflect the correct text from the document.

The labeled W-2 document should look like this when complete:

  1. If needed, you can click Create New Field to add a new field to the schema from this page.

  2. Click Mark as Labeled when you have finished annotating the document.

You are redirected to the Get started tab.

Task 6. Build processor version using foundation model

After labeling a single document, you can create a processor version using the pretrained foundation model to extract entities.

  1. Click on the Build tab.

  1. Under Call foundation model, click Create New Version.

  2. Enter a name for your processor version, such as w2-foundation-model.

  3. Click Create. It takes a few minutes to create.

Note: Once you create a processor version, you cannot delete fields you have created. You can disable them on the fields page if you no longer need them.
  1. Optional: Click on the Deploy & Use tab. On this page, you can view the available processor versions and the deployment status of the new version.

You test and evaluate this version later in the lab.

Click Check my progress to verify the objective.

Build processor version using foundation model

Task 7. Use generative AI to auto-label documents

The foundation model can accurately extract fields for a variety of document types, but you can also provide additional training data to improve the accuracy of the model for specific document structures.

Document AI Workbench uses the label names you define and previous annotations to make it quicker and easier to label documents at scale with auto-labeling.

  1. Go to the Build page.

  2. Click Import Documents.

  3. In the sidebar, click Import documents from Google Cloud Storage.

  4. Enter this bucket name in Source path. This contains unlabeled W-2 PDF files.

cloud-samples-data/documentai/Custom/W2/AutoLabel
  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.

  2. In the Auto-labeling section, select the Import with auto-labeling checkbox.

  3. Select the foundation model processor version you just created to label the documents.

  4. Click Import and wait for the documents to import. You can leave this page and return later.

  5. You must verify the auto-labeled documents before you can use them for training or testing. Click Start Labeling to view the auto-labeled documents.

  6. To use the suggested labels, hold the pointer over each annotation, and click on the check mark to confirm the label is correct. You can edit the values if they do not match the document text.

  7. Click Mark as Labeled when you have finished annotating the document.

  8. Repeat for each auto-labeled document. For this tutorial, you can skip any documents that were not successfully auto-labeled.

Task 8. Import prelabeled training documents

In this lab, you are provided with prelabeled data. If working on your own project, you have to determine how to label your data. Refer to Labeling options for more details. In general, more training data produces higher accuracy.

  1. Go to the Build page.

  2. Click Import Documents.

  3. In the sidebar, click Import documents from Google Cloud Storage.

  4. Enter the following path in Source path. This bucket contains prelabeled documents in the Document JSON format.

cloud-samples-data/documentai/Custom/W2/JSON-2
  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. Import takes several minutes.

  3. (Optional) From the Build page, you can access the Manage Dataset console to view and edit all documents and labels in the dataset.

Task 9. Train the processor

Now that you have sufficient training and test data, you can train the processor. Because training might take several hours, make sure you have set up the processor with the appropriate data and labels before you begin training.

  1. Under Train a custom model, click Create New Version.

    If Create New Version cannot be clicked, click on View Full Requirements for information about the dataset requirements.

  2. In the Version name field, enter a name for this processor version, such as w2-custom-model.

  3. (Optional) Click View Label Stats to find information about the document labels. That can help determine your coverage. Click Close to return to the training setup.

  4. Under Model training method, select Model based.

  5. Click Start training.

  6. (Optional) Click on the Deploy & Use tab. On this page, you can view the available processor versions and the training status of the new version.

Click Check my progress to verify the objective.

Train the model

Great! You have now started training your first Custom Document AI Processor. Since the training job will take around a few hours, the lab will end here. If you are interested in learning about how to deploy and test the model version, you can check out the following section in the documentation.

Congratulations!

Congratulations, in this lab you've successfully used Document AI to create a Custom Document Extraction processor, import a dataset, and label example documents. You can now use this processor to parse documents in this format just as you would for any Specialized Processor. You can also use this processor to label new documents using auto-labeling as well as use the Document AI Workbench to manage your training data and training jobs.

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 March 17, 2025

Lab Last Tested March 17, 2025

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.

시작하기 전에

  1. 실습에서는 정해진 기간 동안 Google Cloud 프로젝트와 리소스를 만듭니다.
  2. 실습에는 시간 제한이 있으며 일시중지 기능이 없습니다. 실습을 종료하면 처음부터 다시 시작해야 합니다.
  3. 화면 왼쪽 상단에서 실습 시작을 클릭하여 시작합니다.

현재 이 콘텐츠를 이용할 수 없습니다

이용할 수 있게 되면 이메일로 알려드리겠습니다.

감사합니다

이용할 수 있게 되면 이메일로 알려드리겠습니다.

한 번에 실습 1개만 가능

모든 기존 실습을 종료하고 이 실습을 시작할지 확인하세요.

시크릿 브라우징을 사용하여 실습 실행하기

이 실습을 실행하려면 시크릿 모드 또는 시크릿 브라우저 창을 사용하세요. 개인 계정과 학생 계정 간의 충돌로 개인 계정에 추가 요금이 발생하는 일을 방지해 줍니다.