cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
powerdiver
Level 8

AI Builder - Text Classification in a Flow

Should I share these here too ?

Use Case

Some of my current learning objectives are about understanding the capabilities of the Flow connectors as well as the new Power Platform capabilities, such as the AI Builder fonctions.
 
In that line, I took a look the new connector from Aquaforest to integrate PDFs in a flow and considered combining it with AI Builder's Text Classification tool, all this in order to answer this hypothetical use case:
  • Based on a PDF file received (in a OneDrive folder in this case)
  • Convert the content of that PDF into plain text
  • Use Text Classification to identify the document and establish if it's an invoice or a purchase order
  • Then based on this classification, process the request accordingly

Step 1 - Build the Text Classification model

The trigger of this process is a user adding a file to a monitored folder, could be any other similar trigger (email received, file transferred from an app and so on). The objective is to recognize if that file is an invoice or a purchase order.
 
In order to process this file, I'm using a Text Classification model, part of the AI Builder suite of solutions. As a simple solution I've created a CDS entity containing about 50 rows of words pertaining to an invoice and another set of rows relative to a purchase order.
 
I built and trained my model, generating it with results of 2 tags ("invoice", "order").
 
 

Step 2 - Setup Aquaforest PDF API

The Text Classification tool requires text to issue it's tag / predictions. With the hypothesis that the source file is a PDF, the content of this file must be converted to plain text.
 
The team at Aquaforest has done a tremendous job at documenting their connector and procedure ti implement it, congratulations to them, they're to take as an example.
 
I signed up with the Free API account and generated the API key required to establish the connection to Aquaforest in my flow.
 
 

Step 3 - Create a Flow to automate the process

Kudos to the AI Builder product team providing detailed documentation on the process of using text classification in a Flow. Followed the steps and most importantly, created that flow from within a CDS solution (this causes some difficulties I'll talk about later on in this article).
 
Don't fall into the same trap as I and get errors in your flow processing, don't forget to read ALL the instructions ;-)
 
 

 

My flow

  • Monitor a OneDrive folder
  • Convert the file from PDF to plain text, using Aquaforest connector (would a good practice to validate the file extension / file type first)
  • Send the converted text to the Text Classification model in order to get the tag(s) it finds. Important note: if you don't create the flow from a solution, you will not find the Predict connector. Also, not to forget the extra info that must surround the actual text in the payload parameter (this is a part where the product team could definitely ease the process and not require us to add this extra text).
  • Parse the result (response payload you get from the Text Classification model) using the schema available with the official connector documentation
  • Since the AI Builder model may generate multiple tags, you then have to loop into each of the resulting tags and process them
  • First step within this loop is to confirm that you've had a successful prediction and branch into error management or your regular process
  • In my demo here, I simply send email notifications where I adapt the subject and message based upon the situation. In a real business process, this could be adapted with updates to a log, an entity or a notification system
  • In the successful branch, I evaluate if the tag is either "invoice" or not (assuming the only 2 options are invoice and order) and send the email notification with attached document, accordingly. Here it could also be a good practice to look at the score and/or provide it in your process notification so you act based on a defined confidence level / threshold.
 
 
  • Next cool step? If the invoices or purchase order were to be in a standard format, we could send them to the Form Processing model for data identification.

Bit of pain

One of the difficulties I've had in working with this flow and where I feel there could be enhancements is where the fact that the flow is built from within a solution (that's my best guess, because I have not faced this issue otherwise) and I needed to edit, save or test the flow. I literally had to keep two browser page opened and go from one another to:

  • Turn off (deactivate) the workflow when I needed to save it
  • Turn on (activate) the workflow when I needed to test it
 
Otherwise I received the following error messages:
 

 

 

 

 

Overview

In the hope that this was a useful example for you too of how we can integrate some of the AI Builder functionality within a real business case. Here's a recap of the Flow:

  • Trigger: Add a new PDF file to my OneDrive directory
 
  • Result: based on the analysis of the file, send a request to process the invoice / purchase order to the right department
  • Flow overview:

This is an extract from my blogpost article available at https://powerdiver.blogspot.com/

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Administrator
Administrator

Re: AI Builder - Text Classification in a Flow

Hey, @powerdiver!

Awesome Flow Recipe & Awesome Blog! 😁👍🏼

Keep up the great work and feel free to come and share Flow recipes anytime! 

 

Happy Flowing!

 

-Gabriel
Microsoft Flow Community Manager
1 REPLY 1
Highlighted
Administrator
Administrator

Re: AI Builder - Text Classification in a Flow

Hey, @powerdiver!

Awesome Flow Recipe & Awesome Blog! 😁👍🏼

Keep up the great work and feel free to come and share Flow recipes anytime! 

 

Happy Flowing!

 

-Gabriel
Microsoft Flow Community Manager

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

thirdImage

New Flow Community Board!

Check out the new Microsoft Flow Community Blog Topic Suggestion board!

fourthImage

Australia Summit

Travel to Melbourne and network with thousands of peers!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 27 members 4,222 guests
Please welcome our newest community members: