-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[TA] Added SingleCategoryClassify functionality #24235
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
maririos
merged 9 commits into
Azure:feature/textanalytics/custom
from
AhmedLeithy:TA-SingleCategoryClassify
Sep 29, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
46d27f8
[TA] Added SingleCategoryClassify functionality
AhmedLeithy 4570cfd
Regenerated code to remove comments
AhmedLeithy 860e3a1
Regenerated using new swagger
AhmedLeithy a654b14
Removed Record Parameter from TATestBase
AhmedLeithy 8d8c61f
Applied feedback (rest of docstrings and sample changes)
AhmedLeithy 3d5e09b
classify --> classification
AhmedLeithy 835feb1
classificationResultsCollection ->singleClassificationActionResults
AhmedLeithy 0f3d6dd
Added space in comment. Changed word "Declare" to "Set" for consistency
AhmedLeithy c226664
regenerated netstandard
AhmedLeithy 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
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
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
90 changes: 90 additions & 0 deletions
90
...textanalytics/Azure.AI.TextAnalytics/samples/Sample10_SingleCategoryClassify.md
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,90 @@ | ||
| # Perform Custom Single Category Classification on Documents | ||
| This sample demonstrates how to run a single category classification action in one or more documents. To get started you will need a Text Analytics endpoint and credentials. See [README][README] for links and instructions. | ||
|
|
||
| ## Creating a `TextAnalyticsClient` | ||
|
|
||
| To create a new `TextAnalyticsClient` to perform a single category classify on a document, you need a Text Analytics endpoint and credentials. You can use the [DefaultAzureCredential][DefaultAzureCredential] to try a number of common authentication methods optimized for both running as a service and development. In the sample below, however, you'll use a Text Analytics API key credential by creating an `AzureKeyCredential` object, that if needed, will allow you to update the API key without creating a new client. | ||
|
|
||
| You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. | ||
|
|
||
| ```C# Snippet:CreateTextAnalyticsClient | ||
| string endpoint = "<endpoint>"; | ||
| string apiKey = "<apiKey>"; | ||
| var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); | ||
| ``` | ||
|
|
||
| ## Performing Single Category Classify on one or multiple documents | ||
|
|
||
| To perform Custom Single Category Classification in one or multiple documents, set up a `SingleCategoryClassifyAction` and call `StartAnalyzeActionsAsync` on the documents. The result is a Long Running Operation of type `AnalyzeActionsOperation` which polls for the results from the API. | ||
|
|
||
| ```C# Snippet:TextAnalyticsSingleCategoryClassifyAsync | ||
| // Get input document. | ||
| string document = @"I need a reservation for an indoor restaurant in China. Please don't stop the music. Play music and add it to my playlist."; | ||
|
|
||
| // Prepare analyze operation input. You can add multiple documents to this list and perform the same | ||
| // operation to all of them. | ||
| var batchInput = new List<string> | ||
| { | ||
| document | ||
| }; | ||
|
|
||
| // Set project and deployment names of the target model | ||
| string projectName = "<projectName>"; | ||
| string deploymentName = "<deploymentName>"; | ||
|
|
||
| var singleCategoryClassifyAction = new SingleCategoryClassifyAction(projectName, deploymentName); | ||
|
|
||
| TextAnalyticsActions actions = new TextAnalyticsActions() | ||
| { | ||
| SingleCategoryClassifyActions = new List<SingleCategoryClassifyAction>() { singleCategoryClassifyAction } | ||
| }; | ||
|
|
||
| // Start analysis process. | ||
| AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchInput, actions); | ||
|
|
||
| await operation.WaitForCompletionAsync(); | ||
| ``` | ||
|
|
||
| The returned `AnalyzeActionsOperation` contains general information about the status of the operation. It can be requested while the operation is running or when it has completed. For example: | ||
|
|
||
| ```C# Snippet:TextAnalyticsSingleCategoryClassifyOperationStatus | ||
| // View operation status. | ||
| Console.WriteLine($"AnalyzeActions operation has completed"); | ||
| Console.WriteLine(); | ||
|
|
||
| Console.WriteLine($"Created On : {operation.CreatedOn}"); | ||
| Console.WriteLine($"Expires On : {operation.ExpiresOn}"); | ||
| Console.WriteLine($"Id : {operation.Id}"); | ||
| Console.WriteLine($"Status : {operation.Status}"); | ||
| Console.WriteLine($"Last Modified: {operation.LastModified}"); | ||
| Console.WriteLine(); | ||
| ``` | ||
|
|
||
| To view the final results of the long-running operation: | ||
|
|
||
| ```C# Snippet:TextAnalyticsSingleCategoryClassifyAsyncViewResults | ||
| // View operation results. | ||
| await foreach (AnalyzeActionsResult documentsInPage in operation.Value) | ||
| { | ||
| IReadOnlyCollection<SingleCategoryClassifyActionResult> singleClassificationActionResults = documentsInPage.SingleCategoryClassifyResults; | ||
|
|
||
| foreach (SingleCategoryClassifyActionResult classificationActionResults in singleClassificationActionResults) | ||
| { | ||
| foreach (SingleCategoryClassifyResult documentResults in classificationActionResults.DocumentsResults) | ||
| { | ||
| Console.WriteLine($" Class category \"{documentResults.ClassificationCategory.Category}\" predicted with a confidence score of {documentResults.ClassificationCategory.ConfidenceScore}."); | ||
| Console.WriteLine(); | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| To see the full example source files, see: | ||
|
|
||
| * [Synchronously SingleCategoryClassify](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample10_SingleCategoryClassify.cs) | ||
| * [Asynchronously SingleCategoryClassify](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample10_SingleCategoryClassifyAsync.cs) | ||
| * [Synchronously SingleCategoryClassify Convenience](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample10_SingleCategoryClassifyConvenience.cs) | ||
| * [Asynchronously SingleCategoryClassify Convenience](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample10_SingleCategoryClassifyConvenienceAsync.cs) | ||
|
|
||
| [DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md | ||
| [README]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/README.md | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.