Compose custom models

This article applies to: Form Recognizer v3.0 checkmark Form Recognizer v3.0. Earlier version: Form Recognizer v2.1

A composed model is created by taking a collection of custom models and assigning them to a single model ID. You can assign up to 100 trained custom models to a single composed model ID. When a document is submitted to a composed model, the service performs a classification step to decide which custom model accurately represents the form presented for analysis. Composed models are useful when you've trained several models and want to group them to analyze similar form types. For example, your composed model might include custom models trained to analyze your supply, equipment, and furniture purchase orders. Instead of manually trying to select the appropriate model, you can use a composed model to determine the appropriate custom model for each analysis and extraction.

To learn more, see Composed custom models.

In this article, you'll learn how to create and use composed custom models to analyze your forms and documents.

Prerequisites

To get started, you'll need the following resources:

  • An Azure subscription. You can create a free Azure subscription.

  • A Form Recognizer instance. Once you have your Azure subscription, create a Form Recognizer resource in the Azure portal to get your key and endpoint. If you have an existing Form Recognizer resource, navigate directly to your resource page. You can use the free pricing tier (F0) to try the service, and upgrade later to a paid tier for production.

    1. After the resource deploys, select Go to resource.

    2. Copy the Keys and Endpoint values from the Azure portal and paste them in a convenient location, such as Microsoft Notepad. You'll need the key and endpoint values to connect your application to the Form Recognizer API.

    Still photo showing how to access resource key and endpoint URL.

    Tip

    For more information, see create a Form Recognizer resource.

  • An Azure storage account. If you don't know how to create an Azure storage account, follow the Azure Storage quickstart for Azure portal. You can use the free pricing tier (F0) to try the service, and upgrade later to a paid tier for production.

Create your custom models

First, you'll need a set of custom models to compose. You can use the Form Recognizer Studio, REST API, or client-library SDKs. The steps are as follows:

Assemble your training dataset

Building a custom model begins with establishing your training dataset. You'll need a minimum of five completed forms of the same type for your sample dataset. They can be of different file types (jpg, png, pdf, tiff) and contain both text and handwriting. Your forms must follow the input requirements for Form Recognizer.

Tip

Follow these tips to optimize your data set for training:

  • If possible, use text-based PDF documents instead of image-based documents. Scanned PDFs are handled as images.
  • For filled-in forms, use examples that have all of their fields filled in.
  • Use forms with different values in each field.
  • If your form images are of lower quality, use a larger data set (10-15 images, for example).

See Build a training data set for tips on how to collect your training documents.

Upload your training dataset

When you've gathered a set of training documents, you'll need to upload your training data to an Azure blob storage container.

If you want to use manually labeled data, you'll also have to upload the .labels.json and .ocr.json files that correspond to your training documents.

Train your custom model

When you train your model with labeled data, the model uses supervised learning to extract values of interest, using the labeled forms you provide. Labeled data results in better-performing models and can produce models that work with complex forms or forms containing values without keys.

Form Recognizer uses the prebuilt-layout model API to learn the expected sizes and positions of typeface and handwritten text elements and extract tables. Then it uses user-specified labels to learn the key/value associations and tables in the documents. We recommend that you use five manually labeled forms of the same type (same structure) to get started with training a new model. Then, add more labeled data, as needed, to improve the model accuracy. Form Recognizer enables training a model to extract key-value pairs and tables using supervised learning capabilities.

To create custom models, start with configuring your project:

  1. From the Studio homepage, select Create new from the Custom model card.

  2. Use the ➕ Create a project command to start the new project configuration wizard.

  3. Enter project details, select the Azure subscription and resource, and the Azure Blob storage container that contains your data.

  4. Review and submit your settings to create the project.

Animation showing create a custom project in Form Recognizer Studio.

While creating your custom models, you may need to extract data collections from your documents. The collections may appear one of two formats. Using tables as the visual pattern:

  • Dynamic or variable count of values (rows) for a given set of fields (columns)

  • Specific collection of values for a given set of fields (columns and/or rows)

See Form Recognizer Studio: labeling as tables

Create a composed model

Note

the create compose model operation is only available for custom models trained with labels. Attempting to compose unlabeled models will produce an error.

With the create compose model operation, you can assign up to 100 trained custom models to a single model ID. When analyze documents with a composed model, Form Recognizer first classifies the form you submitted, then chooses the best matching assigned model, and returns results for that model. This operation is useful when incoming forms may belong to one of several templates.

Once the training process has successfully completed, you can begin to build your composed model. Here are the steps for creating and using composed models:

Gather your model IDs

When you train models using the Form Recognizer Studio, the model ID is located in the models menu under a project:

Screenshot: model configuration window in Form Recognizer Studio.

Compose your custom models

  1. Select a custom models project.

  2. In the project, select the Models menu item.

  3. From the resulting list of models, select the models you wish to compose.

  4. Choose the Compose button from the upper-left corner.

  5. In the pop-up window, name your newly composed model and select Compose.

  6. When the operation completes, your newly composed model will appear in the list.

  7. Once the model is ready, use the Test command to validate it with your test documents and observe the results.

Analyze documents

The custom model Analyze operation requires you to provide the modelID in the call to Form Recognizer. You should provide the composed model ID for the modelID parameter in your applications.

Screenshot of a composed model ID in Form Recognizer Studio.

Manage your composed models

You can manage your custom models throughout life cycles:

  • Test and validate new documents.
  • Download your model to use in your applications.
  • Delete your model when its lifecycle is complete.

Screenshot of a composed model in the Form Recognizer Studio

Great! You've learned the steps to create custom and composed models and use them in your Form Recognizer projects and applications.

Next steps

Try one of our Form Recognizer quickstarts:

C#

This article applies to: Form Recognizer v2.1 checkmark Form Recognizer v2.1. Later version: Form Recognizer v3.0

Form Recognizer uses advanced machine-learning technology to detect and extract information from document images and return the extracted data in a structured JSON output. With Form Recognizer, you can train standalone custom models or combine custom models to create composed models.

  • Custom models. Form Recognizer custom models enable you to analyze and extract data from forms and documents specific to your business. Custom models are trained for your distinct data and use cases.

  • Composed models. A composed model is created by taking a collection of custom models and assigning them to a single model that encompasses your form types. When a document is submitted to a composed model, the service performs a classification step to decide which custom model accurately represents the form presented for analysis.

In this article, you'll learn how to create Form Recognizer custom and composed models using our Form Recognizer Sample Labeling tool, REST APIs, or client-library SDKs.

Sample Labeling tool

Try extracting data from custom forms using our Sample Labeling tool. You'll need the following resources:

  • An Azure subscription—you can create one for free

  • A Form Recognizer instance in the Azure portal. You can use the free pricing tier (F0) to try the service. After your resource deploys, select Go to resource to get your key and endpoint.

Screenshot: keys and endpoint location in the Azure portal.

In the Form Recognizer UI:

  1. Select Use Custom to train a model with labels and get key value pairs.

    Screenshot of the FOTT tool select custom model option.

  2. In the next window, select New project:

    Screenshot of the FOTT tool select new project option.

Create your models

The steps for building, training, and using custom and composed models are as follows:

Assemble your training dataset

Building a custom model begins with establishing your training dataset. You'll need a minimum of five completed forms of the same type for your sample dataset. They can be of different file types (jpg, png, pdf, tiff) and contain both text and handwriting. Your forms must follow the input requirements for Form Recognizer.

Upload your training dataset

You'll need to upload your training data to an Azure blob storage container. If you don't know how to create an Azure storage account with a container, see Azure Storage quickstart for Azure portal. You can use the free pricing tier (F0) to try the service, and upgrade later to a paid tier for production.

Train your custom model

You train your model with labeled data sets. Labeled datasets rely on the prebuilt-layout API, but supplementary human input is included such as your specific labels and field locations. Start with at least five completed forms of the same type for your labeled training data.

When you train with labeled data, the model uses supervised learning to extract values of interest, using the labeled forms you provide. Labeled data results in better-performing models and can produce models that work with complex forms or forms containing values without keys.

Form Recognizer uses the Layout API to learn the expected sizes and positions of typeface and handwritten text elements and extract tables. Then it uses user-specified labels to learn the key/value associations and tables in the documents. We recommend that you use five manually labeled forms of the same type (same structure) to get started when training a new model. Add more labeled data as needed to improve the model accuracy. Form Recognizer enables training a model to extract key value pairs and tables using supervised learning capabilities.

Get started with Train with labels

Create a composed model

Note

Model Compose is only available for custom models trained with labels. Attempting to compose unlabeled models will produce an error.

With the Model Compose operation, you can assign up to 100 trained custom models to a single model ID. When you call Analyze with the composed model ID, Form Recognizer will first classify the form you submitted, choose the best matching assigned model, and then return results for that model. This operation is useful when incoming forms may belong to one of several templates.

Using the Form Recognizer Sample Labeling tool, the REST API, or the Client-library SDKs, follow the steps below to set up a composed model:

  1. Gather your custom model IDs
  2. Compose your custom models

Gather your custom model IDs

Once the training process has successfully completed, your custom model will be assigned a model ID. You can retrieve a model ID as follows:

When you train models using the Form Recognizer Sample Labeling tool, the model ID is located in the Train Result window:

Screenshot: training results window.

Compose your custom models

After you've gathered your custom models corresponding to a single form type, you can compose them into a single model.

The Sample Labeling tool enables you to quickly get started training models and composing them to a single model ID.

After you have completed training, compose your models as follows:

  1. On the left rail menu, select the Model Compose icon (merging arrow).

  2. In the main window, select the models you wish to assign to a single model ID. Models with the arrows icon are already composed models.

  3. Choose the Compose button from the upper-left corner.

  4. In the pop-up window, name your newly composed model and select Compose.

When the operation completes, your newly composed model will appear in the list.

Screenshot of the model compose window.

Analyze documents with your custom or composed model

The custom form Analyze operation requires you to provide the modelID in the call to Form Recognizer. You can provide a single custom model ID or a composed model ID for the modelID parameter.

  1. On the tool's left-pane menu, select the Analyze icon (light bulb).

  2. Choose a local file or image URL to analyze.

  3. Select the Run Analysis button.

  4. The tool will apply tags in bounding boxes and report the confidence percentage for each tag.

Screenshot: Form Recognizer tool analyze-a-custom-form window.

Test your newly trained models by analyzing forms that weren't part of the training dataset. Depending on the reported accuracy, you may want to do further training to improve the model. You can continue further training to improve results.

Manage your custom models

You can manage your custom models throughout their lifecycle by viewing a list of all custom models under your subscription, retrieving information about a specific custom model, and deleting custom models from your account.

Great! You've learned the steps to create custom and composed models and use them in your Form Recognizer projects and applications.

Next steps

Learn more about the Form Recognizer client library by exploring our API reference documentation.