Skip to content

Commit

Permalink
[Text Analytics] Add support for abstractive summarization (#32402)
Browse files Browse the repository at this point in the history
- Added `TextAnalyticsActions.AbstractSummaryActions` to perform abstractive summarization in a batch of actions.
- Added `TextAnalyticsClient.StartAbstractSummary` and `StartAbstractSummaryAsync` to perform abstractive summarization on a collection of documents.
  • Loading branch information
joseharriaga authored Nov 15, 2022
1 parent 2456bc8 commit df9d061
Show file tree
Hide file tree
Showing 45 changed files with 5,194 additions and 83 deletions.
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 @@ -9,6 +9,8 @@
- Added `WellKnownFhirVersion` and `HealthcareDocumentType` enums.
- Added `TextAnalyticsActions.ExtractSummaryActions` to perform extractive summarization in a batch of actions.
- Added `TextAnalyticsClient.StartExtractSummary` and `StartExtractSummaryAsync` to perform extractive summarization on a collection of documents.
- Added `TextAnalyticsActions.AbstractSummaryActions` to perform abstractive summarization in a batch of actions.
- Added `TextAnalyticsClient.StartAbstractSummary` and `StartAbstractSummaryAsync` to perform abstractive summarization on a collection of documents.
- Added `Script` property to `DetectedLanguage`.
- Added `ScriptKind` enum.
- Added the `CategorizedEntity.Resolutions` property.
Expand Down

Large diffs are not rendered by default.

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

namespace Azure.AI.TextAnalytics
{
/// <summary>
/// A set of options used to configure abstractive summarization, including the model version to use, the maximum
/// number of sentences that the resulting summary can have, and more.
/// </summary>
public class AbstractSummaryAction
{
/// <summary>
/// Initializes a new instance of the <see cref="AbstractSummaryAction"/> class.
/// </summary>
public AbstractSummaryAction()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AbstractSummaryAction"/> class based on the given
/// <see cref="AbstractSummaryOptions"/>. It sets the <see cref="ModelVersion"/>,
/// <see cref="DisableServiceLogs"/>, and <see cref="MaxSentenceCount"/> properties.
/// </summary>
public AbstractSummaryAction(AbstractSummaryOptions options)
{
ModelVersion = options.ModelVersion;
DisableServiceLogs = options.DisableServiceLogs;
MaxSentenceCount = options.MaxSentenceCount;
}

/// <summary>
/// The version of the text analytics model that will be used to generate the result. To learn more about the
/// supported model versions for each feature, see
/// <see href="https://learn.microsoft.com/azure/cognitive-services/language-service/concepts/model-lifecycle"/>.
/// </summary>
public string ModelVersion { get; set; }

/// <summary>
/// Indicates whether the service logs your input text for 48 hours, which is solely to allow for
/// troubleshooting, if needed. Setting this property to <c>true</c> disables input logging and may limit our
/// ability to investigate any issues that occur. If not set, the service default is used.
/// <para>
/// Please see the Cognitive Services Compliance and Privacy notes at
/// <see href="https://aka.ms/cs-compliance"/> for additional details, and the Microsoft Responsible AI
/// principles at <see href="https://www.microsoft.com/ai/responsible-ai"/>.
/// </para>
/// </summary>
public bool? DisableServiceLogs { get; set; }

/// <summary>
/// The name of this action. If not set, the service will generate one.
/// </summary>
public string ActionName { get; set; }

/// <summary>
/// The maximum number of sentences that the resulting summaries can have. If not set, the service default is
/// used.
/// </summary>
public int? MaxSentenceCount { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.AI.TextAnalytics.Models;

namespace Azure.AI.TextAnalytics
{
/// <summary>
/// A representation of the result of performing an <see cref="AbstractSummaryAction"/> on a given set of
/// documents.
/// </summary>
public class AbstractSummaryActionResult : TextAnalyticsActionResult
{
private readonly AbstractSummaryResultCollection _documentsResults;

/// <summary>
/// Initializes a successful <see cref="AbstractSummaryActionResult"/>.
/// </summary>
internal AbstractSummaryActionResult(
AbstractSummaryResultCollection result, string actionName, DateTimeOffset completedOn)
: base(actionName, completedOn)
{
_documentsResults = result;
}

/// <summary>
/// Initializes an <see cref="AbstractSummaryActionResult"/> with an error.
/// </summary>
internal AbstractSummaryActionResult(string actionName, DateTimeOffset completedOn, Error error)
: base(actionName, completedOn, error) { }

/// <summary>
/// The collection of results corresponding to each given document.
/// </summary>
public AbstractSummaryResultCollection DocumentsResults
{
get
{
if (HasError)
{
throw new InvalidOperationException(
$"Cannot access the results of this action, due to error {Error.ErrorCode}: {Error.Message}");
}
return _documentsResults;
}
}
}
}
Loading

0 comments on commit df9d061

Please sign in to comment.