Intelligence, Inside and Outside.

Using Document AI To Automate Procurement Workflows

Earlier this month we announced the Document AI platform, a unified console for document processing. Document AI is a platform and a family of solutions that help businesses to transform documents into structured data with machine learning. With custom parsers and Natural Language Processing, DocAI can automatically classify, extract, and enrich data within your documents to unlock insights.

We showed you how to visually inspect a parsed document in the console. Now let’s take a look at how you can integrate parsers in your app or service. You can use any programming language of your choice to integrate DocAI and we have client libraries in Java, Node.js, Go and more. Today, I’ll show you how to use our Python client library to extract information from receipts with the Procurement DocAI solution.

Step 1: Create the parser

After enabling the API and service account authentication (instructions), navigate to the Document AI console and select Create Processor.

create the parser

We’ll be using the Receipt Parser, click on it to create an instance.

create

Next you’ll be taken to the processor details page,  copy your processor ID.

 

Step 2: Set up your processor code

In this code snippet, we show how to create a client and reference your processor. This code snippet shows how to create a client and reference your processor. You might want to try one of our quickstarts before integrating this into production code.

# Instantiates a client
client = documentai.DocumentProcessorServiceClient()

# The full resource name of the processor, e.g.:
# projects/project-id/locations/location/processor/processor-id
name = f"projects/{project_id}/locations/{location}/processors/{processor_id}"

...

with open(file_path, "rb") as image:
    image_content = image.read()
document = {"content": image_content, "mime_type": "application/pdf"}

# Configure the process request
request = {"name": name, "document": document}

# Recognizes text entities in the PDF document
result = client.process_document(request=request)

document = result.document
# Configure the process request
request = {"name": name, "document": document}

You can also process large sets of documents with asynchronous batch calls. This is beneficial because you can choose to use a non-blocking background process and poll the operation for its status. This also integrates with GCS and can process more than one document per call.

 

Step 3: Use your data

Inspect your results, each of the fields extracted per processor are relevant to the document type. For our receipt parser, Document AI will correctly identify key information like currency, supplier information (name, address, city) and line items. See the full list here. Across all the parsers, data is grouped naturally where it would be otherwise difficult to parse out with only OCR. For example, see how a receipt’s line items attributes are grouped together in the response.

receipt
"entity":{
  "type": "line_item",
  "mentionText": "ENGLISH COASTAL CHEDDAR 5.99USD",
...
  "textAnchor":{
...
    "content":"ENGLISH COASTAL CHEDDAR"
  },
  "type":"line_item/description",
  "mentionText":"ENGLISH COASTAL CHEDDAR",

...

  "textAnchor":{
...
    "content":"5.99"
  },
  "type":"line_item/amount",
  "mentionText":"5.99"
}

Use the JSON output to extract the data you need and integrate into other systems. With this structure, you can easily create a schema to use with one of our storage solutions such as BigQuery. With the receipt parser, you’ll never have to manually create an expense report again!

output

Get started today! Check out our documentation for more information on all the parser types or contact the Google Cloud sales team.

 

By Anu Srivastava Developer Advocate, AI/ML
Source: Google Cloud Blog


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!
Share this article
Shareable URL
Prev Post

Intel And Consilient Join Forces To Fight Financial Fraud With AI

Next Post

Darktrace Wins ‘Best Enterprise AI Solution’ At The 2020 AIconics Awards

Read next