Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions sdk/textanalytics/ai-text-analytics/samples-dev/modelVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
* This sample shows how to choose model versions to use with pre-built Text
* Analytics models.
*
* @summary shows how to choose model versions for pre-built models.
* @azsdk-weight 40
*/

import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";

const documents = ["This document is written in English."];

export async function main() {
console.log("== Choosing Model Version Sample ==");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

const recognizeEntitiesResults = await client.recognizeEntities(documents, "en", {
/**
* Specify the model version by setting this property. "latest" indicates
* the latest generaly availability version of the model. When not specified,
* latest will be assumed. Model versions are date based, e.g "2021-06-01".
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe include the service doc that shows all the available modelVersions for each endpoint?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, I added a link to the list of versions for NER. I could not find the versions list for all features in one place. @aahill do you know where can I find such list?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are just about to publish one. It's a chicken-egg situation ;)

* See the documentation for a list of all model versions:
* https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model
*/
modelVersion: "latest"
});

console.log(
`The results of recognizeEntities has been computed using model version: ${recognizeEntitiesResults.modelVersion}`
);

const poller = await client.beginAnalyzeActions(
documents,
{
recognizeEntitiesActions: [
{
/**
* Specify the model version by setting this property. "latest" indicates
* the latest generaly availability version of the model. When not specified,
* latest will be assumed. Model versions are date based, e.g "2021-06-01".
* See the documentation for a list of all model versions:
* https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model
*/
modelVersion: "latest"
}
]
},
"en"
);

const beginAnalyzeActionsResults = await poller.pollUntilDone();

for await (const page of beginAnalyzeActionsResults) {
const entitiesAction = page.recognizeEntitiesResults[0];
if (!entitiesAction.error) {
console.log(
`The results of recognizeEntities action has been computed using model version: ${entitiesAction.results.modelVersion}`
);
}
}
}

main().catch((err) => {
console.error("The sample encountered an error:", err);
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ These sample programs show how to use the JavaScript client libraries for Azure
| [authenticationMethods.js][authenticationmethods] | authenticates a service client using both Azure Active Directory and an API key |
| [beginAnalyzeActions.js][beginanalyzeactions] | applies multiple Text Analytics actions per document |
| [customText.js][customtext] | applies multiple Custom Text Analytics actions per document |
| [modelVersion.js][modelversion] | shows how to choose model versions for pre-built models. |

## Prerequisites

Expand Down Expand Up @@ -80,6 +81,7 @@ Take a look at our [API Documentation][apiref] for more information about the AP
[authenticationmethods]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/authenticationMethods.js
[beginanalyzeactions]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/beginAnalyzeActions.js
[customtext]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/customText.js
[modelversion]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/javascript/modelVersion.js
[apiref]: https://docs.microsoft.com/javascript/api/@azure/ai-text-analytics
[freesub]: https://azure.microsoft.com/free/
[createinstance_azurecognitiveservicesinstance]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
* This sample shows how to choose model versions to use with pre-built Text
* Analytics models.
*
* @summary shows how to choose model versions for pre-built models.
*/

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

// Load the .env file if it exists
const dotenv = require("dotenv");
dotenv.config();

// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";

const documents = ["This document is written in English."];

async function main() {
console.log("== Choosing Model Version Sample ==");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

const recognizeEntitiesResults = await client.recognizeEntities(documents, "en", {
/**
* Specify the model version by setting this property. "latest" indicates
* the latest generaly availability version of the model. When not specified,
* latest will be assumed. Model versions are date based, e.g "2021-06-01".
* See the documentation for a list of all model versions:
* https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model
*/
modelVersion: "latest"
});

console.log(
`The results of recognizeEntities has been computed using model version: ${recognizeEntitiesResults.modelVersion}`
);

const poller = await client.beginAnalyzeActions(
documents,
{
recognizeEntitiesActions: [
{
/**
* Specify the model version by setting this property. "latest" indicates
* the latest generaly availability version of the model. When not specified,
* latest will be assumed. Model versions are date based, e.g "2021-06-01".
* See the documentation for a list of all model versions:
* https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model
*/
modelVersion: "latest"
}
]
},
"en"
);

const beginAnalyzeActionsResults = await poller.pollUntilDone();

for await (const page of beginAnalyzeActionsResults) {
const entitiesAction = page.recognizeEntitiesResults[0];
if (!entitiesAction.error) {
console.log(
`The results of recognizeEntities action has been computed using model version: ${entitiesAction.results.modelVersion}`
);
}
}
}

main().catch((err) => {
console.error("The sample encountered an error:", err);
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ These sample programs show how to use the TypeScript client libraries for Azure
| [authenticationMethods.ts][authenticationmethods] | authenticates a service client using both Azure Active Directory and an API key |
| [beginAnalyzeActions.ts][beginanalyzeactions] | applies multiple Text Analytics actions per document |
| [customText.ts][customtext] | applies multiple Custom Text Analytics actions per document |
| [modelVersion.ts][modelversion] | shows how to choose model versions for pre-built models. |

## Prerequisites

Expand Down Expand Up @@ -92,6 +93,7 @@ Take a look at our [API Documentation][apiref] for more information about the AP
[authenticationmethods]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/authenticationMethods.ts
[beginanalyzeactions]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/beginAnalyzeActions.ts
[customtext]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/customText.ts
[modelversion]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/modelVersion.ts
[apiref]: https://docs.microsoft.com/javascript/api/@azure/ai-text-analytics
[freesub]: https://azure.microsoft.com/free/
[createinstance_azurecognitiveservicesinstance]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
* This sample shows how to choose model versions to use with pre-built Text
* Analytics models.
*
* @summary shows how to choose model versions for pre-built models.
*/

import { TextAnalyticsClient, AzureKeyCredential } from "@azure/ai-text-analytics";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

// You will need to set these environment variables or edit the following values
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>";

const documents = ["This document is written in English."];

export async function main() {
console.log("== Choosing Model Version Sample ==");

const client = new TextAnalyticsClient(endpoint, new AzureKeyCredential(apiKey));

const recognizeEntitiesResults = await client.recognizeEntities(documents, "en", {
/**
* Specify the model version by setting this property. "latest" indicates
* the latest generaly availability version of the model. When not specified,
* latest will be assumed. Model versions are date based, e.g "2021-06-01".
* See the documentation for a list of all model versions:
* https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model
*/
modelVersion: "latest"
});

console.log(
`The results of recognizeEntities has been computed using model version: ${recognizeEntitiesResults.modelVersion}`
);

const poller = await client.beginAnalyzeActions(
documents,
{
recognizeEntitiesActions: [
{
/**
* Specify the model version by setting this property. "latest" indicates
* the latest generaly availability version of the model. When not specified,
* latest will be assumed. Model versions are date based, e.g "2021-06-01".
* See the documentation for a list of all model versions:
* https://docs.microsoft.com/en-us/azure/cognitive-services/language-service/named-entity-recognition/how-to-call#specify-the-ner-model
*/
modelVersion: "latest"
}
]
},
"en"
);

const beginAnalyzeActionsResults = await poller.pollUntilDone();

for await (const page of beginAnalyzeActionsResults) {
const entitiesAction = page.recognizeEntitiesResults[0];
if (!entitiesAction.error) {
console.log(
`The results of recognizeEntities action has been computed using model version: ${entitiesAction.results.modelVersion}`
);
}
}
}

main().catch((err) => {
console.error("The sample encountered an error:", err);
});