How to enforce sentence_count in abstractive summary.

RoryCorneliusSmith-5098 5 Reputation points
2025-10-13T11:02:06.56+00:00

Simple text abstractive summary question from my experiences using the Python SDK and the online language studio tryout.

The latter seems to provide much more concise abstractive text summaries as opposed to my efforts with the Python SDK and I am wondering why this is? I know the sentence_count parameter is an unenforceable parameter but I am wondering why there is such a discrepancy and how to overcome this?

AbstractiveSummaryAction(sentence_count=3, model_version="latest")

Using the above as an action input to begin_analyze_actions but I have also experimented with begin_abstract_summary equally with a sentence count set to 3. In both cases with the SDK I get an output longer than my input closer to 7/8 in sentence count.

Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
{count} votes

1 answer

Sort by: Most helpful
  1. Manas Mohanty 11,690 Reputation points Microsoft External Staff Moderator
    2025-10-17T13:42:24.62+00:00

    Hi RoryCorneliusSmith-5098

    Answer lies in the keyword itself. AbstractiveSummaryAction

    Abstract summarization will add more context to input statements; Approximate count of Summary will be around the Sentence count (might exceed to give proper summary.

    It will try to provide output summary and not intended to truncate summary to exact sentence count.

    Please use Extractive Summary instead which truncates and give expected result with max_sentence_count.

       import os
       from azure.core.credentials import AzureKeyCredential
       from azure.ai.textanalytics import TextAnalyticsClient
    
       
    
       text_analytics_client = TextAnalyticsClient(
           endpoint=endpoint,
           credential=AzureKeyCredential(key),
       )
    
       document = [
           "At Microsoft, we have been on a quest to advance AI beyond existing techniques, by taking a more holistic, "
           "human-centric approach to learning and understanding. As Chief Technology Officer of Azure AI Cognitive "
           "Services, I have been working with a team of amazing scientists and engineers to turn this quest into a "
           "reality. In my role, I enjoy a unique perspective in viewing the relationship among three attributes of "
           "human cognition: monolingual text (X), audio or visual sensory signals, (Y) and multilingual (Z). At the "
           "intersection of all three, there's magic-what we call XYZ-code as illustrated in Figure 1-a joint "
           "representation to create more powerful AI that can speak, hear, see, and understand humans better. "
           "We believe XYZ-code will enable us to fulfill our long-term vision: cross-domain transfer learning, "
           "spanning modalities and languages. The goal is to have pretrained models that can jointly learn "
           "representations to support a broad range of downstream AI tasks, much in the way humans do today. "
           "Over the past five years, we have achieved human performance on benchmarks in conversational speech "
           "recognition, machine translation, conversational question answering, machine reading comprehension, "
           "and image captioning. These five breakthroughs provided us with strong signals toward our more ambitious "
           "aspiration to produce a leap in AI capabilities, achieving multisensory and multilingual learning that "
           "is closer in line with how humans learn and understand. I believe the joint XYZ-code is a foundational "
           "component of this aspiration, if grounded with external knowledge sources in the downstream AI tasks."
       ]
    
       poller = text_analytics_client.begin_extract_summary(document, max_sentence_count= 2)
       extract_summary_results = poller.result()
       for result in extract_summary_results:
           if result.kind == "ExtractiveSummarization":
               print("Summary extracted: \n{}".format(
                   " ".join([sentence.text for sentence in result.sentences]))
               )
           elif result.is_error is True:
               print("...Is an error with code '{}' and message '{}'".format(
                   result.error.code, result.error.message
               ))
    
    

    Output

     At the intersection of all three, there's magic-what we call XYZ-code as illustrated in Figure 1-a joint representation to create more powerful AI that can speak, hear, see, and understand humans better. The goal is to have pretrained models that can jointly learn representations to support a broad range of downstream AI tasks, much in the way humans do today.
    
    
    

    Hope It clarifies the intended behaviour of Abstractive and Extractive summary api.

    Reference used - https://free.blessedness.top/en-us/python/api/azure-ai-textanalytics/azure.ai.textanalytics.textanalyticsclient?view=azure-python#azure-ai-textanalytics-textanalyticsclient-begin-extract-summary

    Thank you.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.