Search⌘ K
AI Features

Performing Text Summarization

Explore how to perform text summarization using Azure Language Cognitive Services. Understand the extractive summarization method that extracts key sentences from large texts to provide concise summaries. Learn to implement this feature with the Azure Language SDK, handling setup, sending documents, and processing results effectively.

What is text summarization?

Text summarization is one of the most popular features used in the field of Natural ...

Python
from azure.ai.textanalytics import TextAnalyticsClient, ExtractSummaryAction
from azure.core.credentials import AzureKeyCredential
client = TextAnalyticsClient(
endpoint=text_analytics_endpoint,
credential = AzureKeyCredential(text_analytics_key)
)
document = [
"The extractive summarization feature uses natural language processing techniques to locate key sentences in an unstructured text document. "
"These sentences collectively convey the main idea of the document. This feature is provided as an API for developers. "
"They can use it to build intelligent solutions based on the relevant information extracted to support various use cases. "
"In the public preview, extractive summarization supports several languages. It is based on pretrained multilingual transformer models, part of our quest for holistic representations. "
"It draws its strength from transfer learning across monolingual and harness the shared nature of languages to produce models of improved quality and efficiency. "
]
response = client.begin_analyze_actions(document, actions=[ExtractSummaryAction(MaxSentenceCount=4)])
result = response.result()
for res in result:
for doc_result in range(len(res)):
print("Document Number: ", doc_result)
extract_summary_result = res[doc_result]
if extract_summary_result.is_error:
print("Error Code: '{}', Error Message: '{}'".format(
extract_summary_result.code, extract_summary_result.message))
else:
print("Summary extracted: \n{}".format(
" ".join([sentence.text for sentence in extract_summary_result.sentences])))

Explanation

...