-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Text Analytics] Add a sample for model versions #19087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
deyaaeldeen
merged 3 commits into
Azure:main
from
deyaaeldeen:textanalytics/model-version-sample
Dec 9, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
sdk/textanalytics/ai-text-analytics/samples-dev/modelVersion.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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". | ||
| * 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); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
sdk/textanalytics/ai-text-analytics/samples/v5/javascript/modelVersion.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/modelVersion.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ;)