How key-value pair extraction works

Nutrient .NET SDK’s (formerly GdPicture.NET) key-value pair (KVP) extraction engine enables you to recognize related data items in a document and export them to an external destination like a spreadsheet. Nutrient .NET SDK can automatically perform all the steps of the following example workflow:

  1. Scan a physical copy of a document or load a document file.
  2. Preprocess the document to correct common problems such as noise, poor character quality, and skewed pages.
  3. Recognize the text with optical character recognition (OCR) technology.
  4. Recognize the document type, such as a bank statement, and adapt the extraction approach accordingly.
  5. Recognize key data items, such as IBANs and addresses.
  6. Export the data to an external destination like a spreadsheet.
  7. Redact sensitive information, such as credit card numbers, from the scanned document.

This guide explains KVP extraction in detail (steps 4 and 5 in the example workflow above). The steps above are illustrative and optional, and your workflow might be significantly different. For example, instead of scanning and preprocessing a physical document, you can use a digitally generated document. Nutrient .NET SDK supports more than 100 file types.

For more information on KVP extraction, watch the video below.

Key-value pair extraction

Key-value pairs are two related data items: a key and a value. Depending on the type of document, the key-value pairs are different. For example, key-value pairs on invoices can be the following:

KeyValue
Invoice NumberNo 00162
Billing Date20/09/2022
Total1,165.10€

Key-value pair fields on government forms can be the following:

KeyValue
Company NameNutrient GmbH
Registration NumberFN 548939p
Date of Incorporation04/10/2013

It’s convenient to get key-value pairs from structured documents like Excel files because the values are all named. However, 90 percent of all documents have unstructured data. For these documents, you need a KVP extraction tool to retrieve the information. Intelligent document processing (IDP) extracts data from unstructured and semi-structured documents using OCR and artificial intelligence (AI) technologies.

By automatically recognizing the document type, Nutrient .NET SDK adapts to the context and determines the extraction approach that makes the best use of available resources. Nutrient .NET SDK recognizes the document type based on adaptive layout understanding and natural language processing (NLP) technologies. This hybrid approach includes heuristics, mathematics, and machine learning (ML) capabilities that address the usual weaknesses of traditional OCR and pure ML engines.

How to use key-value pair extraction

This example retrieves key-value pairs, such as invoice number and billing date, from the scanned invoice below.

Sample invoice

To extract data items from the invoice, use the code example below:

=

using GdPictureOCR gdpictureOCR = new GdPictureOCR();
using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load the source document.
int imageId = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.png");
// Configure the OCR process.
gdpictureOCR.ResourceFolder = @"C:\GdPicture.NET 14\Redist\OCR";
gdpictureOCR.AddLanguage(OCRLanguage.English);
gdpictureOCR.SetImage(imageId);
// Run the OCR process.
string ocrResultId = gdpictureOCR.RunOCR();
string keyValuePairsData = "";
for (int pairIndex = 0; pairIndex < gdpictureOCR.GetKeyValuePairCount(ocrResultId); pairIndex++)
{
keyValuePairsData += $"| Key: {gdpictureOCR.GetKeyValuePairKeyString(ocrResultId, pairIndex)} | " +
$"Value: {gdpictureOCR.GetKeyValuePairValueString(ocrResultId, pairIndex)} | " +
$"Document Type: {gdpictureOCR.GetKeyValuePairDataType(ocrResultId, pairIndex).ToString()} | " +
$"Confidence Level: {Math.Round(gdpictureOCR.GetKeyValuePairConfidence(ocrResultId, pairIndex), 1).ToString()}% |\n";
}
// Write the output to the console.
Console.WriteLine(keyValuePairsData);
// Release unnecessary resources.
gdpictureImaging.ReleaseGdPictureImage(imageId);
gdpictureOCR.ReleaseOCRResults();

=

Format the output to obtain the following table:

KeyValueDocument TypeConfidence Level
Billing date20/09/2022DateTime100%
Order date20/09/2022DateTime100%
Republic of PDF+100 847 738 227PhoneNumber77.2%
IBANAT13 2060 4236 6111 5994IBAN100%
CustomerVandelay Industries Around the Corner 13 NBC CityString69.8%
Delivery addressVandelay Industries Around the Corner 13 NBC CityString69.9%
Invoice numberNo 00162String70.9%
Ref. number34751Number92.9%
No00162Number100%
ReferenceP00201UID100%
Quantity Total (excl. VAT)320.00€Currency59%
Subtotal1,220.00€Currency100%
Discount (10%)-122.00€Currency90.6%
VAT (5.5%)+6710€Currency66.9%
Shipping cost0.00€Currency75%
TOTAL1,165.10€Currency100%
DescriptionLake MirrorString99.6%
VAT5.5%Percentage66.6%
Price per unit (excl. VAT)320.00€Currency80%
Tax No.AT98765321UID73.8%
#[email protected]EmailAddress65.6%
#www.bruuuk.comURL65.6%

This table also contains information about the data type and the confidence level for each key-value pair:

  • The data type describes the nature of the content. In this example, the engine recognizes the value [email protected] as an email and the value +100 847 738 227 as a phone number.
  • The confidence level describes how confident the KVP engine is in the accuracy of the data extraction.

In this example, the KVP engine automatically detected all key-value pairs in the document with minimal code and without any preconfiguration. The engine supports more than 100 formats and languages, and it has no dependencies to external models, resources, and databases.

Next steps