Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text Summarizer using TextRank (NLP) #2973

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Text Summarization (NLP)/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Text Summarization using TextRank (sumy)

This Python script takes a longer piece of text as input and generates a concise summary using the TextRank algorithm from the `sumy` library. TextRank is an extractive text summarization algorithm that identifies important sentences based on the connections between words.

Requirements:

pip install sumy
23 changes: 23 additions & 0 deletions Text Summarization (NLP)/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.summarizers.text_rank import TextRankSummarizer
from sumy.utils import get_stop_words

def summarize_text(text, num_sentences=3):
parser = PlaintextParser.from_string(text, Tokenizer("english"))
summarizer = TextRankSummarizer()
summarizer.stop_words = get_stop_words("english")

summary = summarizer(parser.document, num_sentences)
return "\n".join([str(sentence) for sentence in summary])

def main():
text = input("Enter the longer piece of text: ")
num_sentences = int(input("Enter the number of sentences for summary: "))

summary = summarize_text(text, num_sentences)
print("\nSummary:")
print(summary)

if __name__ == "__main__":
main()