Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9ac19d4
Resolving generated code
AhmedLeithy Sep 21, 2021
be8113e
Added Models
AhmedLeithy Sep 22, 2021
a2b925e
Added ClassifyCustomCategories to Actions
AhmedLeithy Sep 22, 2021
78660d2
Added ClassifyCustomCategories to CreatedTasks
AhmedLeithy Sep 22, 2021
267ae37
Setup ConvertToClassifyCustomCategoryResultCollection
AhmedLeithy Sep 22, 2021
7685a9c
Fixing CustomEntititesTaskParameters + ModelFactory build errors
AhmedLeithy Sep 22, 2021
4e890f0
Added samples + sample markdown
AhmedLeithy Sep 23, 2021
2cf5583
Updated ChangeLog
AhmedLeithy Sep 23, 2021
66d99e2
Added AnalyzeOperationMock Tests + Adjusted AnalyzeOperationTest
AhmedLeithy Sep 23, 2021
0926b8e
Added Tests
AhmedLeithy Sep 23, 2021
9dbcfc4
Added Test Recordings
AhmedLeithy Sep 23, 2021
03f7f6d
Setting Parameters classes to internal
AhmedLeithy Sep 23, 2021
f12cd0a
Changed TestEnvironment variable name for consistency
AhmedLeithy Sep 23, 2021
d5d222f
Added model Factory methods
AhmedLeithy Sep 26, 2021
725636b
Renamed ClassifyCustomCategories --> MultiCategoryClassify,
AhmedLeithy Sep 26, 2021
52e1850
ReRecorded Tests
AhmedLeithy Sep 26, 2021
0d63356
Regenerated After Cherry picking
AhmedLeithy Sep 26, 2021
408c392
Applied Comments from Single Classify PR
AhmedLeithy Sep 29, 2021
fc0f362
regenerated netstandard
AhmedLeithy Sep 29, 2021
e82d064
Regenerated code + fixed some build errors
AhmedLeithy Sep 30, 2021
22a98c0
Removed unneeded '#IF SNIPPET' directives
AhmedLeithy Oct 5, 2021
8fd78b7
Rename property ClassificationCategories -> Classifications
AhmedLeithy Oct 5, 2021
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
2 changes: 2 additions & 0 deletions sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Features Added
- Added property `SingleCategoryClassifyAction` to `TextAnalyticsActions` to support the new 'Custom Single Classification' API. This action can be used to get a custom classification for an input document or batch of documents.

- Added property `MultiCategoryClassifyAction` to `TextAnalyticsActions` to support the new 'Custom Multiple Classification' API. This action can be used to get multiple custom classifications for an input document or batch of documents.

### Breaking Changes

### Bugs Fixed
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ await foreach (AnalyzeActionsResult documentsInPage in operation.Value)
{
foreach (SingleCategoryClassifyResult documentResults in classificationActionResults.DocumentsResults)
{
Console.WriteLine($" Class category \"{documentResults.ClassificationCategory.Category}\" predicted with a confidence score of {documentResults.ClassificationCategory.ConfidenceScore}.");
Console.WriteLine($" Class category \"{documentResults.Classification.Category}\" predicted with a confidence score of {documentResults.Classification.ConfidenceScore}.");
Console.WriteLine();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# 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)
{
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ internal AnalyzeActionsResult(
IReadOnlyCollection<RecognizeLinkedEntitiesActionResult> recognizeLinkedEntitiesActionResults,
IReadOnlyCollection<AnalyzeSentimentActionResult> analyzeSentimentActionResults,
IReadOnlyCollection<ExtractSummaryActionResult> extractSummaryActionResults,
IReadOnlyCollection<SingleCategoryClassifyActionResult> singleCategoryClassifyActionResults
IReadOnlyCollection<SingleCategoryClassifyActionResult> singleCategoryClassifyActionResults,
IReadOnlyCollection<MultiCategoryClassifyActionResult> multiCategoryClassifyActionResults
)
{
ExtractKeyPhrasesResults = extractKeyPhrasesActionResults;
Expand All @@ -27,6 +28,7 @@ IReadOnlyCollection<SingleCategoryClassifyActionResult> singleCategoryClassifyAc
AnalyzeSentimentResults = analyzeSentimentActionResults;
ExtractSummaryResults = extractSummaryActionResults;
SingleCategoryClassifyResults = singleCategoryClassifyActionResults;
MultiCategoryClassifyResults = multiCategoryClassifyActionResults;
}

/// <summary>
Expand Down Expand Up @@ -63,5 +65,10 @@ IReadOnlyCollection<SingleCategoryClassifyActionResult> singleCategoryClassifyAc
/// Determines the collection of <see cref="SingleCategoryClassifyActionResult"/>.
/// </summary>
public IReadOnlyCollection<SingleCategoryClassifyActionResult> SingleCategoryClassifyResults { get; }

/// <summary>
/// Determines the collection of <see cref="MultiCategoryClassifyActionResult"/>.
/// </summary>
public IReadOnlyCollection<MultiCategoryClassifyActionResult> MultiCategoryClassifyResults { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;

namespace Azure.AI.TextAnalytics
{
/// <summary>
/// Collection of <see cref="ClassificationCategory"/> objects in a document,
/// and warnings encountered while processing the document.
/// </summary>
[DebuggerTypeProxy(typeof(ClassificationCategoryCollectionDebugView))]
public class ClassificationCategoryCollection : ReadOnlyCollection<ClassificationCategory>
{
internal ClassificationCategoryCollection(IList<ClassificationCategory> classificationCategories, IList<TextAnalyticsWarning> warnings)
: base(classificationCategories)
{
Warnings = new ReadOnlyCollection<TextAnalyticsWarning>(warnings);
}

/// <summary>
/// Warnings encountered while processing the document.
/// </summary>
public IReadOnlyCollection<TextAnalyticsWarning> Warnings { get; }

/// <summary>
/// Debugger Proxy class for <see cref="ClassificationCategoryCollection"/>.
/// </summary>
internal class ClassificationCategoryCollectionDebugView
{
private ClassificationCategoryCollection BaseCollection { get; }

public ClassificationCategoryCollectionDebugView(ClassificationCategoryCollection collection)
{
BaseCollection = collection;
}

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public List<ClassificationCategory> Items
{
get
{
return BaseCollection.ToList();
}
}

public IReadOnlyCollection<TextAnalyticsWarning> Warnings
{
get
{
return BaseCollection.Warnings;
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Core;

namespace Azure.AI.TextAnalytics.Models
{
/// <summary>
/// CustomMultiClassificationTasksItem.
/// </summary>
[CodeGenModel("TasksStateTasksCustomMultiClassificationTasksItem")]
internal partial class CustomMultiClassificationTasksItem { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ internal partial class JobManifestTasks
/// CustomSingleClassificationTasks
/// </summary>
internal IList<CustomSingleClassificationTask> CustomSingleClassificationTasks { get; set; }

/// <summary>
/// CustomMultiClassificationTasks
/// </summary>
internal IList<CustomMultiClassificationTask> CustomMultiClassificationTasks { get; set; }
}
}
Loading