Performing Text Summarization
Learn to use the text analytics service from Azure to summarize a big chunk of text using the SDK.
We'll cover the following...
What is text summarization?
Text summarization is one of the most popular features used in the field of Natural Language Processing. In this process, a big chunk of text, documents, articles, etc. is condensed into a small chunk of text. This small chunk of text consists of the most important sentences present in the original text.
This feature is very useful when the user just wants to get a gist of the complete text without even reading it completely. The Azure Language service provides this summarization feature as a part of its service. This summarization is also called ...
Python
from azure.ai.textanalytics import TextAnalyticsClient, ExtractSummaryActionfrom azure.core.credentials import AzureKeyCredentialclient = 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])))