Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FormTrainingClient

Package version

Client class for training and managing custom form models.

Hierarchy

  • FormTrainingClient

Index

Constructors

constructor

Properties

endpointUrl

endpointUrl: string

Url to an Azure Form Recognizer service endpoint

Methods

beginCopyModel

  • Copies a custom model from this resource (the source) to the specified target Form Recognizer resource. This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.

    Example usage:

    const targetClient = new FormTrainingClient(targetEndpoint, new AzureKeyCredential(targetApiKey));
    const authorization = await targetClient.getCopyAuthorization(targetResourceId, targetResourceRegion);
    
    const sourceClient = new FormTrainingClient(endpoint, new AzureKeyCredential(apiKey));
    const poller = await sourceClient.beginCopyModel(sourceModelId, authorization, {
      onProgress: (state) => {
        console.log(`Copy model status: ${state.status}`);
      }
    });
    const result = await poller.pollUntilDone();
    summary

    Copies custom model to target resource

    Parameters

    • modelId: string

      Id of the custom model in this resource to be copied to the target Form Recognizer resource

    • target: CopyAuthorization

      Copy authorization produced by calling targetTrainingClient.getCopyAuthorization()

    • Default value options: BeginCopyModelOptions = {}

    Returns Promise<PollerLike<CopyModelOperationState, CustomFormModelInfo>>

beginCreateComposedModel

  • Combines pre-existing models with labels into a single composed model.

    The composed model will contain copies of all of its input submodels, and it will choose (using a machine learning algorithm) the most appropriate of its input models to use during form recognition.

    This method returns a long-running operation poller that allows you to wait indefinitely until the operation is completed.

    Notes:

    • Only labeled models can be composed. Attempting to compose an unlabeled model will result in an error.
    • the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.
    • evena when the training operation fails, a model is still created in the Azure Form Recognizer resource.

    Example usage:

    const modelIds = ["<model ID 1>", "<model ID 2>", "<model ID 3>"];
    const trainingClient = new FormTrainingClient(endpoint, new AzureKeyCredential(apiKey));
    
    const poller = await trainingClient.beginCreateComposedModel(modelIds, {
      modelName: "<optional name for the composed model>",
      onProgress: (state) => { console.log("training status: "); console.log(state); }
    });
    const composedModel = await poller.pollUntilDone();
    summary

    Combines pre-existing models with labels into a single composed model.

    Parameters

    • modelIds: string[]

      an array of model IDs within the Form Recognizer resouce to compose

    • options: BeginCreateComposedModelOptions

      Options to start the create composed model operation

    Returns Promise<PollerLike<TrainingOperationState, CustomFormModel>>

beginTraining

  • Creates and trains a custom form model.

    If the useTrainingLabels parameter is set to true, then the operation will search for label files in addition to the training documents, and it will create a labeled model with the field names specified by the labels. Otherwise, it will create an unlabeled model automatically that returns generated field names for the items it determines are fields within the document structure.

    This method returns a long-running operation poller that allows you to wait indefinitely until the operation is completed.

    Notes:

    • The onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.
    • Even when the training operation fails, a model is still created in the Azure Form Recognizer resource.

    Example usage:

    const trainingFilesUrl = "<url to the blob container storing training documents>";
    const trainingClient = new FormTrainingClient(endpoint, new AzureKeyCredential(apiKey));
    
    const poller = await trainingClient.beginTraining(trainingFilesUrl, false, {
      onProgress: (state) => { console.log("training status: "); console.log(state); }
    });
    const model = await poller.pollUntilDone();
    summary

    Creates and trains a custom form model.

    Parameters

    • trainingFilesUrl: string

      accessible url to an Azure Storage Blob container storing the training documents and optional label files

    • useTrainingLabels: boolean

      specifies whether or not to search for and train using label files

    • Default value options: BeginTrainingOptions = {}

      options to start the model training operation

    Returns Promise<PollerLike<TrainingOperationState, CustomFormModel>>

deleteModel

getAccountProperties

getCopyAuthorization

  • Generate an authorization for copying a custom model into this Azure Form Recognizer resource.

    This method should be called on a client that is authenticated using the target resource (where the model will be copied to) credentials, and the output can be passed as the target parameter to the beginCopyModel method of a source client.

    The required resourceId and resourceRegion are properties of an Azure Form Recognizer resource and their values can be found in the Azure Portal.

    Parameters

    • resourceId: string

      Id of the Azure Form Recognizer resource where a custom model will be copied to

    • resourceRegion: string

      Location of the Azure Form Recognizer resource, must be a valid region name supported by Azure Cognitive Services. See https://aka.ms/azsdk/cognitiveservices/regionalavailability for information about the regional availability of Azure Cognitive Services.

    • Default value options: GetCopyAuthorizationOptions = {}

    Returns Promise<CopyAuthorization>

    The authorization to copy a custom model

getCustomModel

getFormRecognizerClient

listCustomModels

  • Returns an async iterable iterator to list information about all models in the cognitive service account.

    .byPage() returns an async iterable iterator to list the blobs in pages.

    Example using for await syntax:

    const client = new FormTrainingClient(endpoint, new AzureKeyCredential(apiKey));
    const result = client.listCustomModels();
    let i = 1;
    for await (const model of result) {
      console.log(`model ${i++}:`);
      console.log(model);
    }

    Example using iter.next():

    let i = 1;
    let iter = client.listCustomModels();
    let modelItem = await iter.next();
    while (!modelItem.done) {
      console.log(`model ${i++}: ${modelItem.value}`);
      modelItem = await iter.next();
    }

    Example using byPage():

     let i = 1;
     for await (const response of client.listCustomModels().byPage()) {
       for (const modelInfo of response.modelList!) {
         console.log(`model ${i++}: ${modelInfo.modelId}`);
       }
     }

    Parameters

    Returns PagedAsyncIterableIterator<CustomFormModelInfo, ListCustomModelsResponse>

Generated using TypeDoc