DEV Community


Discussion on: Build a quick Summarizer with Python and NLTK

sushant097 profile image

Thanks @david Israwi for this simple and interesting text summarizer program.
I see and analyze your code.
The most error i found is index out of range and most of the people seem to have the same error a lot.
The one thing i am confuse in this part of code:

summary = ''
for sentence in sentences:
     if (sentence in sentenceValue) and (sentenceValue[sentence] > (1.5 * average)):
          summary += " " + sentence

why and how the only 1.5 average is used.
How about the the large one line text instead it not summarize it.
For example:

For example, the Center for a New American Dream envisions "... a focus on more of what really matters, such as creating a meaningful life, contributing to community and society, valuing nature, and spending time with family and friends and even altogether"

I am using python 3 and i resolve the index out of range error as:

for sentence in sentences:
     for index, wordValue in enumerate(freqTable, start=1):
          if wordValue in sentence.lower(): # index[0] return word
               if sentence in sentenceValue:  
                    sentenceValue[sentence] += index # index return value of occurence of that word
                    #sentenceValue.update({sentence: index})
                   # sentenceValue[sentence] = wordValue
                    sentenceValue[sentence] = index

Thanks a lot! This post is really helpful! If you have other resources including making chatbot can be really helpful to me.
I am little bit interesting about how to implement the Text Summarizer using machine learning model. I am looking for this too...
You can directly send information at

Forem Open with the Forem app