Entity detection workflow - Enhanced Document Understanding on AWS

Entity detection workflow

The entity detection workflow detects entities such as PII and medical entities in the extracted text from uploaded documents. This workflow uses Amazon Comprehend or Amazon Comprehend Medical depending on the configuration.

Important

You must run the text extraction workflow before the entity detection workflow.

This workflow returns entities that Amazon Comprehend or Amazon Comprehend Medical detect by their character offset. To map these entities to locations on a page, and thereby be able to display bounding boxes around text on the document, the workflow reconciles these results with the Amazon Textract results from the text extraction workflow. The workflow then creates an inference, which maps entities to their physical locations (shown as bounding boxes in the UI) in the document.

Important

You must run the entity detection workflow before running the redaction workflow.

This workflow uses Step Functions, Amazon Comprehend, and other AWS services to detect entities.

Entity detection workflow

The process flow for the entity detection workflow is as follows:

  1. An EventBridge custom event bus invokes a Step Functions state machine.

  2. Based on the content of the event, the state machine determines whether the workflow should process each document.

  3. An Amazon SQS queue pushes a message with metadata information for eligible documents (for example, the document location in Amazon S3 or the AWS API to use for analysis).

  4. A Lambda function consumes the messages from the Amazon SQS queue.

  5. The Lambda function retrieves the inference containing the results of the Amazon Textract DetectDocumentText action created by the text extraction workflow from the ML inferences S3 bucket.

  6. The Lambda function combines the text of each page of the document into a single string.

  7. The Lambda function sends the strings representing the text on each page to Amazon Comprehend or Amazon Comprehend Medical. the service and API used are determined by the current config)

  8. The Lambda function reconciles the Amazon Comprehend or Amazon Comprehend Medical results with the Amazon Textract results.

  9. The Lambda function creates an inference that maps entities to their physical locations (shown as bounding boxes in the UI) in the document.

  10. The Lambda function serializes both the raw Amazon Comprehend or Amazon Comprehend Medical results and the synthesized entity locations inference to JSON files and saves them in the ML inferences S3 bucket.

  11. The Lambda function notifies the calling Step Function of success or failure.

    1. If the text extraction succeeds, this step is complete.

    2. If the text extraction fails, the Step Functions state machine publishes the event to an Amazon SQS dead-letter queue, configured with a default retention period of four days.

  12. The solution publishes the success or failure event to the custom event bus, which invokes the workflow orchestrator Lambda function to create the next workflow event.