Calling Custom (NER) Demo Deployment

Glen Sale 0 Reputation points
2024-04-18T19:08:47.49+00:00

Hi I tried calling my custom (NER) which I am trying to use my custom labeling for PII recognition, however when calling the prediction URL I would get a response of error 404: Resource not found"

URL: https://glen-apd-language-demo.cognitiveservices.azure.com/language/analyze-text/jobs?api-version=2022-10-01-preview
User's image

I'm calling the correct API Key from
User's image

just calling https://glen-apd-language-demo.cognitiveservices.azure.com/ with apikey uses the standard task PII recognition but not custom (NER)

// Import required modules
const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");

// Function to redact PII using Azure Text Analytics with custom entity recognition
async function redactPIIWithAzure(text) {
    const textAnalyticsEndpoint = "https://glen-apd-language-demo.cognitiveservices.azure.com/language/analyze-text/jobs?api-version=2022-10-01-preview";
    const textAnalyticsApiKey = "xxxxx";

    const client = new TextAnalyticsClient(textAnalyticsEndpoint, new AzureKeyCredential(textAnalyticsApiKey));

    // Add custom entity recognition task
    const customEntityRecognitionTask = {
        kind: 'CustomEntityRecognition',
        parameters: {
            projectName: 'APD_Model',
            deploymentName: 'demoDeploy',
            stringIndexType: 'TextElement_v8'
        }
    };

    try {
        const redactedText = await client.recognizePiiEntities([text], "en", {
            tasks: [customEntityRecognitionTask],
            redaction: true,
        });

        console.log("Redacted text:", redactedText[0].redactedText);
        console.log("Response:", redactedText);

        return redactedText[0].redactedText;
    } catch (error) {
        console.error("Error while redacting PII:", error);
        throw error;
    }
}


// Example usage
(async () => {
    const text = "Your sensitive text containing PII.";
    try {
        const redactedText = await redactPIIWithAzure(text);
        console.log(redactedText);
    } catch (error) {
        console.error("Failed to redact PII:", error);
    }
})();

May you please help me investigate on why my custom (NER) doesn't get return

Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
357 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 17,120 Reputation points Microsoft Employee
    2024-04-19T08:07:14.04+00:00

    @Glen Sale For Custom NER, you need to use the below sample, Please update the Key, endpoint, project name and deployment name accordingly:

    Sample code:

    https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/cognitivelanguage/ai-language-text/samples/v1/javascript/customEntityRecognition.js

    Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help.

    **

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.