Document Classification Training

Document classification assigns a document to a predefined category before extracting the data. This helps match Document Definitions faster and improve data extraction quality. For best classification results, use classification training.

Prepare for training

The batch for classification training should contain enough images of each document class for the classifier to learn the difference between the classes. In addition, you need to set up the mapping between classes and sections of the Document Definitions. This will allow the trained classifier to apply the correct Document Definition to each image.

  1. Create a new classification training batch using the AddNew method of the ClassificationTrainingBatches object.
  2. Add the images for classification training. Convert the training batch to a working batch using the AsBatch property of the ClassificationTrainingBatch object and then add images.
    Important! Make sure that all the setting up described in the following steps is done within the same Open/Close batch session. Once you close the working batch, the PageClass object is no longer available.
  3. Add new page classes to the PageClasses collection of the batch.
  4. Assign page classes and training states to the images. For each document in the ClassificationTrainingDocuments collection of the classification training batch:
    1. Iterate through its ClassificationTrainingPages collection and assign the page classes you've just set up to the ReferenceClass property of each ClassificationTrainingPage object.
    2. Set the TrainingState property of each ClassificationTrainingDocument to DTS_ForTraining or DTS_ForTesting. We recommend a 70:30 ratio of training to testing images for each class.
  5. Link each page class to a Document Definition section. In non-invoice projects, you can also link a page class to a section variant.
    1. Get the section definition from the Document Definition using its Sections property.
    2. Find the section variant you need in the "Variants" data set using its LookUp method.
    3. Create links using the AddNew method of the LinksToSections collection of each PageClass object.

C# code

Train the classifier

During training, the classifier attempts to learn the differences between the images that belong to different classes. Since training may decrease classification quality in some cases, it's up to you to decide whether the classifier should be updated when the training is completed. You can add more documents to the training batch and run training again, examine the validation results and update the classifier when needed.

  1. Get the classification trainer object using the ClassificationTrainer property of the ClassificationTrainingBatch object.
  2. Call the CheckOut method of the ClassificationTrainer object to switch the classifier to training mode. Set up classification trainer parameters using its ClassificationTrainingParams property.
  3. Perform training by calling the Train method.
  4. Examine the training results. From the TrainingResults object returned from the previous call, you can access the CandidateResults and the CurrentResults properties. The CandidateResults refers to the ValidationResults object with statistics for the newly trained classifier. The CurrentResults object contains the statistics for the previously used classifier.
  5. Compare the statistics and decide whether you want to use the newly trained classifier or not. You can also consult the ShouldApply property of the TrainingResults object. This boolean property is an integral estimate of whether the new classifier is "better" than the old one. Depending on your decision, call one of the two methods:
    1. The CheckIn method of the ClassificationTrainer object — if you choose to apply the new classifier, this method will publish the classifier and switch off the training mode.
    2. The UndoCheckout method of the ClassificationTrainer object — if you prefer the previously used classifier, this method will discard the changes and switch off the training mode.

C# code

Use the classifier

Document recognition uses the classifier automatically to match the Document Definitions faster. To enable this behavior, you should set the working batch to use the classifier from the right classification training batch.

  1. Create a new batch type and link it to the classifier:
    1. Create a BatchTypeParams object using the CreateBatchTypeParams method of the Project object.
    2. Set the UseClassifier property of the BatchTypeParams object to TRUE, so that all batches of this type will use classifier.
    3. Link the BatchTypeParams object to the classification training batch by setting its ClassificationBatch property.
      Note: You can also specify text recognition parameters using the FullTextRecognitionParams property.
    4. Create a batch type: call the AddNew method of the BatchTypes object and pass the BatchTypeParams you have just configured.
  2. Create a working batch using the AddNewEx method of the Batches collection and specify the batch type you have just created. Add the images to the working batch.
  3. Process the images in the batch using the Recognize method. During recognition, the Document Definitions will be matched with the help of the classifier.
    Note: To check which Document Definition has been matched to a document, you can use the DocumentDefinition property of the Document object.

C# code

Samples

See the Classification code sample for an implementation of this scenario.

See also

Classification Training Objects

15.08.2023 13:19:30

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.