-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TA] Merge branch feature/textanalytics/custom (#24941)
* [TextAnalytics] Generated client from 3.2-preview.2 swagger (#23536) * [TA] Added SingleCategoryClassify functionality (#24235) * [TA] Added MultiCategoryClassify Functionality (#24237) * [TA] Added RecognizeCustomEntities Functionality (#24245) * [TA] Expose ActionName and enable multiple actions from same type (#24619) * Rerecorded all tests excluding AAD ones (#24913) * re-record AAD tests (#24919) * [TA] Enable CI for live tests for custom features (#24916) * add comments Co-authored-by: Caio Saldanha <camaiaor@microsoft.com> Co-authored-by: Ahmed Leithy <v-aleithy@microsoft.com> Co-authored-by: Salah Mostafa <zulamostafa@gmail.com> Co-authored-by: Salah Mostafa <v-samostafa@microsoft.com>
- Loading branch information
1 parent
4a5efb7
commit 7cc705d
Showing
412 changed files
with
38,204 additions
and
57,887 deletions.
There are no files selected for viewing
This file contains 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 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
154 changes: 151 additions & 3 deletions
154
sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs
Large diffs are not rendered by default.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
...textanalytics/Azure.AI.TextAnalytics/samples/Sample10_SingleCategoryClassify.md
This file contains 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,91 @@ | ||
# 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) | ||
{ | ||
Console.WriteLine($" Action name: {classificationActionResults.ActionName}"); | ||
foreach (SingleCategoryClassifyResult documentResults in classificationActionResults.DocumentsResults) | ||
{ | ||
Console.WriteLine($" Class category \"{documentResults.Classification.Category}\" predicted with a confidence score of {documentResults.Classification.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 |
100 changes: 100 additions & 0 deletions
100
...xtanalytics/Azure.AI.TextAnalytics/samples/Sample11_ClassifyCustomCategories.md
This file contains 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,100 @@ | ||
# Perform Custom Multiple Category Classification in Documents | ||
This sample demonstrates how to run a Multi 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 custom multi category classification 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 Custom Multiple Category Classification in one or multiple documents | ||
|
||
To perform Multiple Category Classification in one or multiple documents, set up a `MultiCategoryClassifyAction` 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:TextAnalyticsMultiCategoryClassifyAsync | ||
// 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 multiCategoryClassifyAction = new MultiCategoryClassifyAction(projectName, deploymentName); | ||
|
||
TextAnalyticsActions actions = new TextAnalyticsActions() | ||
{ | ||
MultiCategoryClassifyActions = new List<MultiCategoryClassifyAction>() { multiCategoryClassifyAction } | ||
}; | ||
|
||
// 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:TextAnalyticsMultiCategoryClassifyOperationStatus | ||
// 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:TextAnalyticsMultiCategoryClassifyAsyncViewResults | ||
// View operation results. | ||
await foreach (AnalyzeActionsResult documentsInPage in operation.Value) | ||
{ | ||
IReadOnlyCollection<MultiCategoryClassifyActionResult> multiClassificationActionResults = documentsInPage.MultiCategoryClassifyResults; | ||
|
||
foreach (MultiCategoryClassifyActionResult classificationActionResults in multiClassificationActionResults) | ||
{ | ||
Console.WriteLine($" Action name: {classificationActionResults.ActionName}"); | ||
foreach (MultiCategoryClassifyResult documentResults in classificationActionResults.DocumentsResults) | ||
{ | ||
if (documentResults.Classifications.Count > 0) | ||
{ | ||
Console.WriteLine($" The following classes were predicted for this document:"); | ||
|
||
foreach (ClassificationCategory classification in documentResults.Classifications) | ||
{ | ||
Console.WriteLine($" Class category \"{classification.Category}\" predicted with a confidence score of {classification.ConfidenceScore}."); | ||
} | ||
|
||
Console.WriteLine(); | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
To see the full example source files, see: | ||
|
||
* [Synchronously Multi Category Classify](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample11_MultiCategoryClassify.cs) | ||
* [Asynchronously Multi Category Classify](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample11_MultiCategoryClassifyAsync.cs) | ||
* [Synchronously Multi Category Classify Convenience](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample11_MultiCategoryClassifyConvenience.cs) | ||
* [Asynchronously Multi Category Classify Convenience](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample11_MultiCategoryClassifyConvenienceAsync.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 |
113 changes: 113 additions & 0 deletions
113
...textanalytics/Azure.AI.TextAnalytics/samples/Sample9_RecognizeCustomEntities.md
This file contains 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,113 @@ | ||
# Recognizing Custom Entities from Documents | ||
This sample demonstrates how to recognize custom entities in one or more documents. To get started you'll need a Text Analytics endpoint and credentials. See [README][README] for links and instructions. | ||
|
||
## Creating a `TextAnalyticsClient` | ||
|
||
To create a new `TextAnalyticsClient` to recognize custom entities in 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)); | ||
``` | ||
|
||
## Recognizing custom entities in a single or multiple documents | ||
|
||
To recognize custom entities in documents, set up a `RecognizeCustomEntitiesAction` and call `StartAnalyzeActionsAsync` on the documents. The result is a Long Running operation of type `AnalyzeActionsOperation` which polls for the results from the API. You can use [Azure language studio][azure_language_studio] to train custom models. | ||
|
||
```C# Snippet:RecognizeCustomEntitiesActionAsync | ||
// Create input documents. | ||
string documentA = @"We love this trail and make the trip every year. The views are breathtaking and well | ||
worth the hike! Yesterday was foggy though, so we missed the spectacular views. | ||
We tried again today and it was amazing. Everyone in my family liked the trail although | ||
it was too challenging for the less athletic among us."; | ||
|
||
string documentB = @"Last week we stayed at Hotel Foo to celebrate our anniversary. The staff knew about | ||
our anniversary so they helped me organize a little surprise for my partner. | ||
The room was clean and with the decoration I requested. It was perfect!"; | ||
|
||
var batchDocuments = new List<TextDocumentInput> | ||
{ | ||
new TextDocumentInput("1", documentA) | ||
{ | ||
Language = "en", | ||
}, | ||
new TextDocumentInput("2", documentB) | ||
{ | ||
Language = "en", | ||
} | ||
}; | ||
|
||
// prepare actions. | ||
string projectName = "<projectName>"; | ||
string deploymentName = "<deploymentName>"; | ||
var actions = new TextAnalyticsActions() | ||
{ | ||
RecognizeCustomEntitiesActions = new List<RecognizeCustomEntitiesAction>() | ||
{ | ||
new RecognizeCustomEntitiesAction(projectName, deploymentName); | ||
} | ||
}; | ||
|
||
AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchDocuments, 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:RecognizeCustomEntitiesActionOperationStatus | ||
// 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:RecognizeCustomEntitiesActionAsyncViewResults | ||
await foreach (AnalyzeActionsResult documentsInPage in operation.Value) | ||
{ | ||
IReadOnlyCollection<RecognizeCustomEntitiesActionResult> customEntitiesActionResults = documentsInPage.RecognizeCustomEntitiesResults; | ||
foreach (RecognizeCustomEntitiesActionResult customEntitiesActionResult in customEntitiesActionResults) | ||
{ | ||
Console.WriteLine($" Action name: {customEntitiesActionResult.ActionName}"); | ||
int docNumber = 1; | ||
foreach (RecognizeEntitiesResult documentResults in customEntitiesActionResult.DocumentsResults) | ||
{ | ||
Console.WriteLine($" Document #{docNumber++}"); | ||
Console.WriteLine($" Recognized the following {documentResults.Entities.Count} entities:"); | ||
|
||
foreach (CategorizedEntity entity in documentResults.Entities) | ||
{ | ||
Console.WriteLine($" Entity: {entity.Text}"); | ||
Console.WriteLine($" Category: {entity.Category}"); | ||
Console.WriteLine($" Offset: {entity.Offset}"); | ||
Console.WriteLine($" Length: {entity.Length}"); | ||
Console.WriteLine($" ConfidenceScore: {entity.ConfidenceScore}"); | ||
Console.WriteLine($" SubCategory: {entity.SubCategory}"); | ||
} | ||
Console.WriteLine(""); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
To see the full example source files, see: | ||
|
||
* [Synchronously RecognizeCustomEntities](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample9_RecognizeCustomEntities.cs) | ||
* [Asynchronously RecognizeCustomEntities](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples//Sample9_RecognizeCustomEntitiesAsync.cs) | ||
* [Synchronously RecognizeCustomEntities Convenience](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample9_RecognizeCustomEntitiesConvenience.cs) | ||
* [Asynchronously RecognizeCustomEntities Convenience](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample9_RecognizeCustomEntitiesConvenienceAsync.cs) | ||
|
||
<!-- LINKS --> | ||
[azure_language_studio]: https://language.azure.com/ | ||
[README]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/README.md | ||
[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md |
This file contains 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
Oops, something went wrong.