python 使用 pke 模块提取关键词
python key phrase extraction using pke module
我试图使用 https://github.com/boudinfl/pke 模块提取关键短语。
当我 运行 它一次完美地工作。但是当我 运行 多次使用它时,它会发出以下错误。
ZeroDivisionError:浮点除以零
我的代码如下
extractor = TopicRank()
def key_phrase_extract(path_to_json):
//get_temp_text.txt from json
extractor.load_document(input='temp_text.txt', language="en", max_length=10000000,
normalization='stemming')
extractor.candidate_selection(pos={'NOUN', 'PROPN', 'ADJ'},stoplist=stoplist)
extractor.candidate_weighting(threshold=0.74,
method='average')
kpe_results = []
for (keyphrase, score) in extractor.get_n_best(n=10, stemming=True):
kpe_results.append([keyphrase, score])
print(kpe_results)
for each_json in json_list()
key_phrase_extract('each_json')
第一个 json 文件完美 运行s 但是当开始第二个文件时它给了我
ZeroDivisionError: float division by zero
我能够解决这个问题。问题是在函数外初始化提取器。
def key_phrase_extract(path_to_json):
extractor = TopicRank()
//get_temp_text.txt from json
extractor.load_document(input='temp_text.txt', language="en", max_length=10000000,
normalization='stemming')
extractor.candidate_selection(pos={'NOUN', 'PROPN', 'ADJ'},stoplist=stoplist)
extractor.candidate_weighting(threshold=0.74,
method='average')
kpe_results = []
for (keyphrase, score) in extractor.get_n_best(n=10, stemming=True):
kpe_results.append([keyphrase, score])
print(kpe_results)
for each_json in json_list()
key_phrase_extract('each_json')
我试图使用 https://github.com/boudinfl/pke 模块提取关键短语。 当我 运行 它一次完美地工作。但是当我 运行 多次使用它时,它会发出以下错误。 ZeroDivisionError:浮点除以零
我的代码如下
extractor = TopicRank()
def key_phrase_extract(path_to_json):
//get_temp_text.txt from json
extractor.load_document(input='temp_text.txt', language="en", max_length=10000000,
normalization='stemming')
extractor.candidate_selection(pos={'NOUN', 'PROPN', 'ADJ'},stoplist=stoplist)
extractor.candidate_weighting(threshold=0.74,
method='average')
kpe_results = []
for (keyphrase, score) in extractor.get_n_best(n=10, stemming=True):
kpe_results.append([keyphrase, score])
print(kpe_results)
for each_json in json_list()
key_phrase_extract('each_json')
第一个 json 文件完美 运行s 但是当开始第二个文件时它给了我
ZeroDivisionError: float division by zero
我能够解决这个问题。问题是在函数外初始化提取器。
def key_phrase_extract(path_to_json):
extractor = TopicRank()
//get_temp_text.txt from json
extractor.load_document(input='temp_text.txt', language="en", max_length=10000000,
normalization='stemming')
extractor.candidate_selection(pos={'NOUN', 'PROPN', 'ADJ'},stoplist=stoplist)
extractor.candidate_weighting(threshold=0.74,
method='average')
kpe_results = []
for (keyphrase, score) in extractor.get_n_best(n=10, stemming=True):
kpe_results.append([keyphrase, score])
print(kpe_results)
for each_json in json_list()
key_phrase_extract('each_json')