This is a Python project that implements a text summarization algorithm using Natural Language Processing (NLP) techniques. The algorithm aims to generate a summary of a given text document by extracting the most important sentences.
- The input text document is read and split into individual sentences.
- Stop words (common words that do not carry much meaning) are removed from the sentences.
- A similarity matrix is built, which represents the similarity between each pair of sentences in the document.
- The similarity matrix is used to create a graph, where each sentence is a node and the similarity score between sentences is an edge.
- The sentences are ranked based on their importance using the PageRank algorithm.
- The top-ranked sentences are selected to form the summary.
This project requires the following dependencies:
- nltk
- numpy
- networkx
You can install these dependencies using pip:
pip install nltk numpy networkx
To generate a summary, follow these steps:
- Import the necessary libraries:
import nltk
from nltk.corpus import stopwords
from nltk.cluster.util import cosine_distance
import numpy as np
import networkx as nx
-
Define the functions
read_article
,sentence_similarity
,build_similarity_matrix
, andgenerate_summary
as provided in the code. -
Call the
generate_summary
function with the path to the text file and the desired number of sentences in the summary. For example:
generate_summary("Coding.txt", 2)
This will generate a summary of the text document "Coding.txt" containing 2 sentences.
Note: The input text document should be in plain text format.
This project was inspired by the field of NLP and its applications in text summarization. It incorporates various techniques and algorithms to achieve the goal of generating a summary from a given text document.
If you have any questions, suggestions, or feedback, please feel free to contact me at [email protected] .