If you are building an application that has the capability to perform natural language processing on text data, it may be because you are
Extractive summarization is a type of summarization in which the articles are summarized by selecting a subset of words from the original article that retain the most important points. With this approach, we would not be generating a summary that contains words other than those present in the original article.
We will use a package named summarizer
to help you generate summarized content in just one line of code!
Let’s first install the package by running:
pip install summarizer
As a dependency of this package, you also need to install nltk
, which is one of the most widely used libraries, to perform Natural Language Processing.
Install this by running:
pip install nltk
We will be using the summarize()
function from this package. Let’s take a look at the details of this function.
The summarize()
function accepts the following parameters:
The summarize()
function returns a list of the most important sentences. This can be treated as the summarized content for your text data.
Now, since we know all the details, let’s move on to the code.
from summarizer import summarizewith open("./data.txt") as f:text = f.read()text = " ".join(text.split())title = "Microsoft Launches Intelligent Cloud Hub To Upskill Students In AI & Cloud Technologies"print("Original Text: \n")print(text)summary = summarize(title, text)print("\nSummarized Text: \n")print(summary)
Explanation
summarize()
function to generate the summary for our text data.So, in this way, with just one line of code, you can generate the extractive summary from any text data using summarizer
in Python.