boudinfl/pke

Throws zero division error

shyambhu-mukherjee opened this issue · 3 comments

self.graph[i][j]['weight'] += 1.0 / gap

This line throws zerodivision error when we try to use ngram_selection=5.

ygorg commented

Please share a minimal reproducible example to make debugging easier.
Related PR #177 and issues #142, #77, #27

Example code:

    extractor = pke.unsupervised.TopicRank()

    extractor.load_document(input = total_text,
                            language = 'en')  

    #extractor.candidate_selection()  

    extractor.ngram_selection(n=3)  

    #this default weight was 0.74 in original algorithm  

    extractor.candidate_weighting(threshold = 0.2)  

    keyphrases_response = extractor.get_n_best(n = 30,
                                               redundancy_removal = True)  

When we remove the candidate weighting line, i.e. let it choose default 0.74 value, then it starts generating empty phrase list. Hope this helps.

ygorg commented

Please try to see whether any candidates were selected using len(extractor.candidates) before extractor.candidate_weighting.
Does the code you provided throws ZerodivisionError ? I can't reproduce the behaviour as I don't know what total_text contains.
About Minimal Reproducible Examples