{"id":1287,"date":"2021-12-02T08:29:32","date_gmt":"2021-12-02T08:29:32","guid":{"rendered":"https:\/\/salarydistribution.com\/machine-learning\/2021\/12\/02\/announcing-support-for-extracting-data-from-identity-documents-using-amazon-textract\/"},"modified":"2021-12-02T08:29:32","modified_gmt":"2021-12-02T08:29:32","slug":"announcing-support-for-extracting-data-from-identity-documents-using-amazon-textract","status":"publish","type":"post","link":"https:\/\/salarydistribution.com\/machine-learning\/2021\/12\/02\/announcing-support-for-extracting-data-from-identity-documents-using-amazon-textract\/","title":{"rendered":"Announcing support for extracting data from identity documents using Amazon Textract"},"content":{"rendered":"<div id=\"\">\n<p>Creating efficiencies in your business is at the top of your list. You want your employees to be more productive, have them focus on high impact tasks, or find ways to implement better processes to improve the outcomes to your customers. There are various ways to solve this problem, and more companies are turning to artificial intelligence (AI) and machine learning (ML) to help. In the financial services sector, there is the creation of new accounts online, or in healthcare there are new digital platforms to schedule and manage appointments, which require users to fill out forms. These can be error prone, time consuming, and certainly improved upon. Some businesses (or organizations) have attempted to simplify and automate this process by including identity document uploads, such as a drivers\u2019 license or passport. However, the technology available is template-based and doesn\u2019t scale well. You need a solution to help automate the extraction of information from identity documents to enable your customers to open bank accounts with ease, or schedule and manage appointments online using accurate information.<\/p>\n<p>Today, we are excited to announce a new API to <a href=\"https:\/\/aws.amazon.com\/textract\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Textract<\/a> called Analyze ID that will help you automatically extract information from identification documents, such as driver\u2019s licenses and passports. Amazon Textract uses AI and ML technologies to extract information from identity documents, such as U.S. passports and driver\u2019s licenses, without the need for templates or configuration. You can automatically extract specific information, such as date of expiry and date of birth, as well as intelligently identify and extract implied information, such as name and address.<\/p>\n<p>We will cover the following topics in this post:<\/p>\n<ul>\n<li>How Amazon Textract processes identity documents<\/li>\n<li>A walkthrough of the Amazon Textract console<\/li>\n<li>Structure of the Amazon Textract AnalyzeID API response<\/li>\n<li>How to process the response with the Amazon Textract parser library<\/li>\n<\/ul>\n<h2>Identity Document processing using Amazon Textract<\/h2>\n<p>Companies have accelerated the adoption of digital platforms, especially in light of the COVID-19 pandemic. Organizations are now offering their users the flexibility to use smartphones and other mobile devices for everyday tasks\u2014such as signing up for new accounts, scheduling appointments, completing employment applications online, and many more. Even though your users fill out an online form with personal and demographic information, the process is manual and error-prone, and it can affect the application decision if submitted incorrectly. Some of you have simplified and automated the online application process by asking your users to upload a picture of their ID, and then use market solutions to extract data and prefill the applications automatically. This automation can help you minimize data entry errors and potentially reduce end user abandonments in application completions. However, even the current market solutions are limited in what they can achieve. They often fall short when extracting all of the required fields accurately due to the rich background image on IDs or the inability to recognize names and addresses and the fields associated with them. For example, the Washington State driver license lists home addresses with the key \u201c8\u201d. Another major challenge with the current market solutions is that IDs have a different template or format depending on the issuing country and state, and even those can change from time-to-time. Therefore, the traditional template-based solutions do not work at scale. Even traditional OCR solutions are expensive and slow, especially when combined with human reviews, and they don\u2019t move the needle in digital automation. These approaches provide poor results, thereby inhibiting your organization from scaling and becoming efficient. You need a solution to help automate the extraction of information from identity documents to enable your customers to open bank accounts with ease, or schedule and manage appointments online with accurate information.<\/p>\n<p>To solve this problem, you can now use Amazon Textract\u2019s newly launched Analyze ID API, powered by ML instead of a traditional template matching solution, to process identity documents at scale. It works with U.S. driver\u2019s licenses and passports to extract relevant data, such as name, address, date of birth, date of expiry, place of issue, etc. Analyze ID API returns two categories of data types: (A) Key-value pairs available on IDs, such as Date of Birth, Date of Issue, ID #, Class, Height, and Restrictions. (B) Implied fields on the document that may not have explicit keys, such as Name, Address, and Issued By. The key-value pairs are also normalized into a common taxonomy (for example, Document ID number = LIC# or Passport No.). This lets you easily combine information across many IDs that use different terms for the same concept.<\/p>\n<h2>Amazon Textract console walkthrough<\/h2>\n<p>Before we get started with the API and code samples, let\u2019s review the Amazon Textract console. The following images show examples of a passport and a drivers\u2019 license document on the Analyze Document output tab of the Amazon Textract console. Amazon Textract automatically and easily extracts key-value elements, such as the type, code, passport number, surname, given name, nationality, date of birth, place of birth, and more fields, from the sample image.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-31437\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/11\/30\/1-6671-Results.jpg\" alt=\"\" width=\"800\" height=\"630\"><\/p>\n<p>The following is another example with a sample drivers\u2019 license. Analyze ID extracts key-value elements such as class, as well as implied fields such as first name, last name, and address. It also normalizes keys, such as \u201cDocument number\u201d from \u201c4d NUMBER\u201d as \u201c820BAC729CBAC\u201d, and \u201cDate of birth\u201d from \u201cDOB\u201d as \u201c03\/18\/1978\u201d, so that it is standardized across IDs.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-31527 size-full\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/12\/01\/DLRegular_1.jpg\" alt=\"\" width=\"800\" height=\"657\"><\/p>\n<h2>AnalyzeID API request<\/h2>\n<p>In this section, we explain how to pass the ID image in the request and how to invoke the Analyze ID API. The input document is either in a byte array format or present on an <a href=\"http:\/\/aws.amazon.com\/s3\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Simple Storage Service<\/a> (Amazon S3) object. You pass image bytes to an Amazon Textract API operation by using the <code>Bytes<\/code> property. For example, you can use the Bytes property to pass a document loaded from a local file system. Image bytes passed by using the Bytes property must be base64 encoded. Your code might not need to encode document file bytes if you\u2019re using an AWS SDK to call Amazon Textract API operations. Alternatively, you can pass images stored in an S3 bucket to an Amazon Textract API operation by using the <code>S3Object<\/code> property. Documents stored in an S3 bucket don\u2019t need to be base64 encoded.<\/p>\n<p>The following examples show how to call the Amazon Textract AnalyzeID function in Python and use the CLI command.<\/p>\n<p>Sample Python code:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-python\">import boto3\n\ntextract = boto3.client('textract')\n\n# Call textract AnalyzeId by passing photo on local disk\ndocumentName = \"us-driver-license.jpeg\"\nwith open(documentName, 'rb') as document:\n    imageBytes = bytearray(document.read())\n\nresponse = textract.analyze_id(\n    DocumentPages=[{\"Bytes\":imageBytes}]\n)\n\n# Call textract AnalyzeId by passing photo on S3\nresponse= textract.analyze_id(\n    DocumentPages=[\n        {\n            \"S3Object\":{\n                \"Bucket\":\"BUCKET_NAME\",\n                \"Name\":\"PREFIX_AND_FILE_NAME\"\n            }\n        }\n    ]\n)\n<\/code><\/pre>\n<\/p><\/div>\n<p>Sample CLI command:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-bash\">aws textract analyze-id --document-pages '[{\"S3Object\":{\"Bucket\":\"BUCKET_NAME\",\"Name\":\"PREFIX_AND_FILE_NAME1\"}},{\"S3Object\":{\"Bucket\":\"BUCKET_NAME\",\"Name\":\"PREFIX_AND_FILE_NAME2\"}}]' --region us-east-1<\/code><\/pre>\n<\/p><\/div>\n<h2>Analyze ID API response<\/h2>\n<p>In this section, we explain the <strong>Analyze ID\u00a0<\/strong>response structure using the sample passport image. The following is the sample passport image and the corresponding\u00a0<code>AnalyzeID<\/code> response JSON.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-31439\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/11\/30\/3-6671-Passport.jpg\" alt=\"\" width=\"800\" height=\"505\"><\/p>\n<p><strong><em>Sample\u00a0abbreviated response<\/em><\/strong><\/p>\n<div class=\"hide-language\">\n<div class=\"hide-language\">\n<pre><code class=\"lang-json\">{\n  \"IdentityDocuments\": [\n    {\n      \"DocumentIndex\": 1,\n      \"IdentityDocumentFields\": [\n        {\n          \"Type\": {\n            \"Text\": \"FIRST_NAME\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"LI\",\n            \"Confidence\": 98.9061508178711\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"LAST_NAME\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"JUAN\",\n            \"Confidence\": 99.0864486694336\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"DATE_OF_ISSUE\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"09 MAY 2019\",\n            \"NormalizedValue\": {\n              \"Value\": \"2019-05-09T00:00:00\",\n              \"ValueType\": \"Date\"\n            },\n            \"Confidence\": 98.68514251708984\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"ID_TYPE\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"PASSPORT\",\n            \"Confidence\": 99.3958740234375\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"ADDRESS\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"\",\n            \"Confidence\": 99.62577819824219\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"COUNTY\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"\",\n            \"Confidence\": 99.6469955444336\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"PLACE_OF_BIRTH\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"NEW YORK CITY\",\n            \"Confidence\": 98.29044342041016\n          }\n        }\n      ]\n    }\n  ],\n  \"DocumentMetadata\": {\n    \"Pages\": 1\n  },\n  \"AnalyzeIDModelVersion\": \"1.0\"\n}<\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<p>The\u00a0<code class=\"c-mrkdwn__code\" data-stringify-type=\"code\">AnalyzeID<\/code>\u00a0JSON output contains\u00a0<code class=\"c-mrkdwn__code\" data-stringify-type=\"code\">AnalyzeIDModelVersion<\/code>,\u00a0<code class=\"c-mrkdwn__code\" data-stringify-type=\"code\">DocumentMetadata<\/code>\u00a0and\u00a0<code class=\"c-mrkdwn__code\" data-stringify-type=\"code\">IdentityDocuments<\/code>, and each\u00a0<code class=\"c-mrkdwn__code\" data-stringify-type=\"code\">IdentityDocument<\/code>\u00a0item contains\u00a0<code class=\"c-mrkdwn__code\" data-stringify-type=\"code\">IdentityDocumentFields<\/code>.<\/p>\n<p>The most granular level of data in the <code>IdentityDocumentFields<\/code> response consists of <code>Type<\/code> and <code>ValueDetection<\/code>.<\/p>\n<p>Let\u2019s call this set of data an <code>IdentityDocumentField<\/code> element. The preceding example illustrates an <code>AnalyzeDocument<\/code> containing the <code>Type<\/code> with the <code>Text<\/code> and <code>Confidence<\/code>, and the <code>ValueDetection<\/code> which includes the <code>Text<\/code>, the <code>Confidence<\/code>, and the optional field <code>NormalizedValue<\/code>.<\/p>\n<p>In the preceding example, Amazon Textract detected 44 key-value pairs, including PLACE_OF_BIRTH: <code>New York City For the list of fields extracted from identity documents, refer to the<\/code> <a href=\"https:\/\/docs.aws.amazon.com\/textract\/latest\/dg\/how-it-works-identity.html\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Textract Developer Guide<\/a><code>.<\/code><\/p>\n<p>In addition to the detected content, the Analyze ID API provides information such as confidence scores for detected elements. It gives you control over how you consume extracted content and integrate it into your applications. For example, you can flag any elements that have a confidence score under a certain threshold for manual review.<\/p>\n<p>The following is the\u00a0<strong>Analyze ID\u00a0<\/strong>response structure using the sample driving license image:<\/p>\n<p><strong><em>Sample abbreviated response<\/em><\/strong><\/p>\n<div class=\"hide-language\">\n<div class=\"hide-language\">\n<pre><code class=\"lang-json\">{\n  \"IdentityDocuments\": [\n    {\n      \"DocumentIndex\": 1,\n      \"IdentityDocumentFields\": [\n        {\n          \"Type\": {\n            \"Text\": \"FIRST_NAME\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"GARCIA\",\n            \"Confidence\": 99.48689270019531\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"LAST_NAME\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"MARIA\",\n            \"Confidence\": 98.49578857421875\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"STATE_NAME\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"MASSACHUSETTS\",\n            \"Confidence\": 98.30329132080078\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"DOCUMENT_NUMBER\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"736HDV7874JSB\",\n            \"Confidence\": 95.6583251953125\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"EXPIRATION_DATE\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"01\/20\/2028\",\n            \"NormalizedValue\": {\n              \"Value\": \"2028-01-20T00:00:00\",\n              \"ValueType\": \"Date\"\n            },\n            \"Confidence\": 98.64090728759766\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"DATE_OF_ISSUE\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"03\/18\/2018\",\n            \"NormalizedValue\": {\n              \"Value\": \"2018-03-18T00:00:00\",\n              \"ValueType\": \"Date\"\n            },\n            \"Confidence\": 98.7216567993164\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"ID_TYPE\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"DRIVER LICENSE FRONT\",\n            \"Confidence\": 98.71986389160156\n          }\n        },\n        {\n          \"Type\": {\n            \"Text\": \"PLACE_OF_BIRTH\"\n          },\n          \"ValueDetection\": {\n            \"Text\": \"\",\n            \"Confidence\": 99.62541198730469\n          }\n        }\n      ]\n    }\n  ],\n  \"DocumentMetadata\": {\n    \"Pages\": 1\n  },\n  \"AnalyzeIDModelVersion\": \"1.0\"\n}<\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<h2>Process Analyze ID response with the Amazon Textract parser library<\/h2>\n<p>You can use the Amazon Textract response parser library to easily parse the JSON returned by Amazon Textract AnalyzeID. The library parses JSON and provides programming language specific constructs to work with different parts of the document.<\/p>\n<p>Install the Amazon Textract Response Parser library:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-bash\">python -m pip install amazon-textract-response-parser<\/code><\/pre>\n<\/p><\/div>\n<p>The following example shows how to deserialize Textract AnalyzeID JSON response to an object:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\"># j holds the Textract response JSON\nfrom trp.trp2_analyzeid import TAnalyzeIdDocumentSchema\nt_doc = TAnalyzeIdDocumentSchema().load(json.loads(j))\n<\/code><\/pre>\n<\/p><\/div>\n<p>The following example shows how to serialize a Textract AnalyzeId object to dictionary:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\">from trp.trp2_analyzeid import TAnalyzeIdDocumentSchema\nt_doc = TAnalyzeIdDocumentSchema().dump(t_doc)\n<\/code><\/pre>\n<\/p><\/div>\n<h2>Summary<\/h2>\n<p>In this post, we provided an overview of the new Amazon Textract AnalyzeID API to quickly and easily retrieve structured data from U.S. government-issued drivers\u2019 licenses and passports. We also described how you can parse the Analyze ID response JSON. For more information, see the <a href=\"https:\/\/docs.aws.amazon.com\/textract\/latest\/dg\/how-it-works-identity.html\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Textract Developer Guide<\/a>, or check out the <a href=\"https:\/\/signin.aws.amazon.com\/signin?redirect_uri=https%3A%2F%2Fconsole.aws.amazon.com%2Ftextract%2Fhome%3Fstate%3DhashArgs%2523%26isauthcode%3Dtrue&amp;client_id=arn%3Aaws%3Aiam%3A%3A015428540659%3Auser%2Ftextract&amp;forceMobileApp=0&amp;code_challenge=DesqebSQmjGr64nd2JiMa28obqbfMInJ4GfJ5Its0PA&amp;code_challenge_method=SHA-256\" target=\"_blank\" rel=\"noopener noreferrer\">developer console and try out Analyze ID API<\/a>.<\/p>\n<hr>\n<h3><strong>About the Authors<\/strong><\/h3>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-25013 alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/06\/02\/Wrick-Talukdar.jpg\" alt=\"\" width=\"100\" height=\"135\">Wrick Talukdar <\/strong>is a Senior Solutions Architect with AWS and is based in Calgary, Canada.\u00a0Wrick works with enterprise AWS customers to transform their business through innovative use of cloud technologies.\u00a0Outside of work, he enjoys reading and photography.<\/p>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-31440 alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/11\/30\/Lana-Zhang.jpg\" alt=\"\" width=\"100\" height=\"133\">Lana Zhang<\/strong> is a Sr. Solutions Architect at AWS with expertise in Machine Learning. She is responsible for helping customers architect scalable, secure, and cost-effective workloads on AWS.<\/p>\n<p>       <!-- '\"` -->\n      <\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/aws.amazon.com\/blogs\/machine-learning\/announcing-support-for-extracting-data-from-identity-documents-using-amazon-textract\/<\/p>\n","protected":false},"author":0,"featured_media":1288,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1287"}],"collection":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/comments?post=1287"}],"version-history":[{"count":0,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1287\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media\/1288"}],"wp:attachment":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media?parent=1287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/categories?post=1287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/tags?post=1287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}