Azure - Document Intelligence own model is not recognized (Javascript SDK)

485 views Asked by At

I'm trying to call a self-trained model using the Javascript SDK so that I can analyze a document that I receive via URL. However, I get a 404 error and the message

The requested model was not found

If I have all ModelIDs displayed with the following code, I only get all the prebuilt models but not my own. What am I doing wrong?

  const document_model_admin_client = new DocumentModelAdministrationClient(
    endpoint,
    new AzureKeyCredential(key)
  );

  for await (const summary of document_model_admin_client.listDocumentModels()) {
    const {
      modelId, // The model's unique ID
      description, // a textual description of the model, if provided during model creation
    } = summary;

    // You can get the full model info using `getDocumentModel`
    const model = await document_model_admin_client.getDocumentModel(
      modelId
    );

    console.log("MODEL: " + model.modelId);
  }

So I try to call my own model in vain:

const client = new DocumentAnalysisClient(
    endpoint,
    new AzureKeyCredential(key)
  );

  const poller = await client.beginAnalyzeDocumentFromUrl(
    "All",
    downloadUrl
  );

  const { keyValuePairs } = await poller.pollUntilDone();

  if (!keyValuePairs || keyValuePairs.length <= 0) {
    console.log("No key-value pairs were extracted from the document.");
   
  } else {
    console.log("Key-Value Pairs:");
    for (const { key, value, confidence } of keyValuePairs) {
      console.log("- Key  :", `"${key.content}"`);
      console.log(
        "  Value:",
        `"${(value && value.content) || "<undefined>"}" (${confidence})`
      );
    }
    

}

1

There are 1 answers

0
Venkatesan On

The requested model was not found If I have all ModelIDs displayed with the following code, I only get all the prebuilt models but not my own. What am I doing wrong?

The above error occurs when you don't have a model in your Azure form recognizer service or still it is in training the model.

Note: Template models train in a few minutes. Neural models can take up to 30 minutes to train.

You need to check whether the model is completely trained or not. In my environment, I trained my model and it succeeded with the below information.

Portal: enter image description here

Now, I use the same code to get the all models and it executes with all models.

Code:

const { AzureKeyCredential,DocumentModelAdministrationClient} = require("@azure/ai-form-recognizer");


async function main() {
const endpoint = "<Endpoint>";
const key = "<Your-key>";
const document_model_admin_client = new DocumentModelAdministrationClient(
    endpoint,
    new AzureKeyCredential(key)
  );

  for await
   (const summary of document_model_admin_client.listDocumentModels()) {
    const {
      modelId, 
      description,
    } = summary;

    // You can get the full model info using `getDocumentModel`
    const model = await document_model_admin_client.getDocumentModel(
      modelId
    );

    console.log("MODEL: " + model.modelId);
  }
}
main()

Output:

MODEL: prebuilt-businxxx
MODEL: prebuilt-conxxxx
MODEL: prebuilt-docuxxx
MODEL: prebuilt-hexxxxxxx
MODEL: prebuilt-idDxxx
MODEL: prebuilt-inxxxx
MODEL: prebuilt-lxxxx
MODEL: prebuilt-rexxxx
MODEL: prebuilt-rexxxx
MODEL: prebuilt-taxxxxx
MODEL: prebuilt-txxxx
MODEL: prebuilt-txxx
MODEL: prebuilt-txxxx
MODEL: sample1

enter image description here

Now, you can use your same code to analyze a document from a self-trained model using the Javascript SDK.

Reference:

Build and train a custom model - Document Intelligence (formerly Form Recognizer) - Azure AI services | Microsoft Learn