Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.62k stars 2.83k forks source link

unexpected behavior in begin_classify_document (DocumentAnalysisClient) #33292

Closed SolidadeFabio closed 11 months ago

SolidadeFabio commented 11 months ago

Describe the bug When using a classification model trained by Document Intelligence Studio, we are encountering unexpected results with a 0% confidence level. On the platform, the responses are highly satisfactory and consistent. However, when we implement the example from the documentation in code, the results are nonsensical. I've attempted to modify the object reading in various ways that are accepted by the method, but to no avail.

To Reproduce Steps to reproduce the behavior:

def classify_document(path):
    endpoint = os.getenv('FORM_ENDPOINT')
    key = os.getenv('FORM_KEY')
    classifier_id = os.getenv('CLASSIFICADOR_MODEL_ID')

    document_analysis_client = DocumentAnalysisClient(
        endpoint=endpoint, credential=AzureKeyCredential(key)
    )

    with open(path, "rb") as f:
        content = f.read()

    stream = io.BytesIO(content)

    poller = document_analysis_client.begin_classify_document(
        classifier_id, document=stream
    )
    result = poller.result()

    return result

Expected behavior the json below was taken from the document intelligence studio platform response:

{
    "status": "succeeded",
    "createdDateTime": "2023-11-24T17:09:06Z",
    "lastUpdatedDateTime": "2023-11-24T17:09:09Z",
    "analyzeResult": {
        "apiVersion": "2023-10-31-preview",
        "modelId": "teste",
        "stringIndexType": "utf16CodeUnit",
        "content": "",
        "pages": [
            {
                "pageNumber": 1,
                "angle": 0,
                "width": 8.25,
                "height": 11.6806,
                "unit": "inch",
                "words": [],
                "lines": [],
                "spans": [
                    {
                        "offset": 0,
                        "length": 0
                    }
                ]
            }
        ],
        "documents": [
            {
                "docType": "nfe",
                "boundingRegions": [
                    {
                        "pageNumber": 1,
                        "polygon": [
                            0,
                            0,
                            8.25,
                            0,
                            8.25,
                            11.6806,
                            0,
                            11.6806
                        ]
                    }
                ],
                "confidence": 0.979,
                "spans": [
                    {
                        "offset": 0,
                        "length": 0
                    }
                ]
            }
        ],
        "contentFormat": "text"
    }
}

Real response in code

{
    "api_version": "2023-07-31",
    "model_id": "teste",
    "content": "",
    "languages": [],
    "pages": [
        {
            "page_number": 1,
            "angle": 0.05888567119836807,
            "width": 8.25,
            "height": 11.6806,
            "unit": "inch",
            "lines": [],
            "words": [],
            "selection_marks": [],
            "spans": [
                {
                    "offset": 0,
                    "length": 0
                }
            ],
            "barcodes": [],
            "formulas": []
        }
    ],
    "paragraphs": [],
    "tables": [],
    "key_value_pairs": [],
    "styles": [],
    "documents": [
        {
            "doc_type": "comprovante pagamento",
            "bounding_regions": [
                {
                    "page_number": 1,
                    "polygon": [
                        {"x": 0.0, "y": 0.0},
                        {"x": 8.25, "y": 0.0},
                        {"x": 8.25, "y": 11.6806},
                        {"x": 0.0, "y": 11.6806}
                    ]
                }
            ],
            "spans": [
                {
                    "offset": 0,
                    "length": 0
                }
            ],
            "fields": {},
            "confidence": 0.142
        }
    ]
}
xiangyan99 commented 11 months ago

Thanks for the feedback, we’ll investigate asap.

SolidadeFabio commented 11 months ago

I noticed that the latest version available for training on the Document Intelligence Studio platform is 2023-10-31-preview and this is not available in the SDK which calls version 2023-07-31 by default.

xiangyan99 commented 11 months ago

The API version 2023-10-31-preview is supported in a rebranding package azure-ai-documentintelligence. We are not planning to support any new API in azure-ai-formrecognizer.

Could you try that one instead?

github-actions[bot] commented 11 months ago

Hi @SolidadeFabio. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

github-actions[bot] commented 11 months ago

Hi @SolidadeFabio, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

SolidadeFabio commented 11 months ago

Problem solved with the suggestion given above

github-actions[bot] commented 11 months ago

Hi @SolidadeFabio. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.