Giter Club home page Giter Club logo

Comments (1)

dipaweshpawarsn avatar dipaweshpawarsn commented on June 6, 2024 2

My code:

import pke
import string
from nltk.corpus import stopwords
import os

extractor = pke.unsupervised.MultipartiteRank()
pos = {'NOUN', 'PROPN', 'ADJ'}
stoplist = list(string.punctuation)
stoplist += ['-lrb-', '-rrb-', '-lcb-', '-rcb-', '-lsb-', '-rsb-']
stoplist += stopwords.words('english')

inputDir='D:\RevAnalyzer\TestingSet'
outputDir='D:\RevAnalyzer\Unsupervised-KeyPhraseExtraction\MultipartiteRank'
i=0
for doc in os.listdir(inputDir):
if doc.endswith(".txt"):
i=i+1
extractor.load_document(input=inputDir+doc)
extractor.candidate_selection(pos=pos, stoplist=stoplist)
extractor.candidate_weighting(alpha=1.1,threshold=0.74,method='average')
keyphrases = extractor.get_n_best(20)
kpFile=open(outputDir+doc.replace('.txt','.key'),'w')
for kp in keyphrases:
kpFile.write(kp[0]+'\n')
print(str(i)+' File Done')

Error

ZeroDivisionError Traceback (most recent call last)
in ()
19 extractor.load_document(input=inputDir+doc)
20 extractor.candidate_selection(pos=pos, stoplist=stoplist)
---> 21 extractor.candidate_weighting(alpha=1.1,threshold=0.74,method='average')
22 keyphrases = extractor.get_n_best(20)
23 kpFile=open(outputDir+doc.replace('.txt','.key'),'w')

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pke\unsupervised\graph_based\multipartiterank.py in candidate_weighting(self, threshold, method, alpha)
216
217 # build the topic graph
--> 218 self.build_topic_graph()
219
220 if alpha > 0.0:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pke\unsupervised\graph_based\multipartiterank.py in build_topic_graph(self)
142 gap -= len(self.candidates[node_j].lexical_form) - 1
143
--> 144 weights.append(1.0 / gap)
145
146 # add weighted edges

ZeroDivisionError: float division by zero

Issue was with initialization of extractor.......After initializing it inside loop this error got fixed

from pke.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.