Key Value Pairs doesn't work on Azure Document Intelligence Layout model

ajo 50 Reputation points
2024-01-11T20:26:16.46+00:00

https://learn.microsoft.com/en-us/azure/ai-services/document-intelligence/concept-general-document?view=doc-intel-4.0.0&source=recommendations says that "Layout model with the optional query string parameter features=keyValuePairs enabled" will work. When I call the API or even use the Document Intelligence Studio web app (with the key-value pairs enabled), it doesn't actually get the key value pairs. It works if I use the General Document model, but that is being deprecated so I want it to work with the Layout model. Is this a bug? How do I make it work?

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
2,111 questions
{count} votes

Accepted answer
  1. VasaviLankipalle-MSFT 18,676 Reputation points Moderator
    2024-01-18T00:52:32.6666667+00:00

    Hello @ajo , Thanks for sharing detailed infromation.

    I have reproduced the same on my end with pre-built Layout model using 2023-10-31-preview version and I was able to successfully extract key-value pairs using Document Intelligence studio and python SDK.

    Make sure to install the Azure AI Document Intelligence client library for Python with pip:

    pip install azure-ai-documentintelligence==1.0.0b1
    

    Here is the sample code to enable keyValuePair feature:

    from azure.core.credentials import AzureKeyCredential     
    from azure.ai.documentintelligence import DocumentIntelligenceClient
    from azure.ai.documentintelligence.models import DocumentAnalysisFeature, AnalyzeResult
     
    poller = document_intelligence_client.begin_analyze_document(
            "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.KEY_VALUE_PAIRS], content_type="application/octet-stream"
        )
    
    
        print("----Key-value pairs found in document----")
        if result.key_value_pairs:
            for kv_pair in result.key_value_pairs:
                if kv_pair.key:
                    print(f"Key '{kv_pair.key.content}' found within " f"'{kv_pair.key.bounding_regions}' bounding regions")
                if kv_pair.value:
                    print(
                        f"Value '{kv_pair.value.content}' found within "
                        f"'{kv_pair.value.bounding_regions}' bounding regions\n"
                    )
    

    Output: User's image

    To analyze add-on capabilities, you can refer this sample code: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_languages.py

    The document you are processing may not contain any key-value pairs: you can try enabling the keyValuePairs option under the Analyze options for the Layout model in the DI studio. This option is available as an optional detection feature and needs to be selected in order to extract key-value pairs from the document.

    User's image

    User's image

    I hope this helps.

    Regards,

    Vasavi

    -Please kindly accept the answer and vote 'yes' if you feel helpful to support the community, thanks.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.