TypeError:应为str、bytes或os.PathLike对象,而不是mallet中的_io.BufferedReader

2024-05-19 08:37:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我在这里学习了mallethttps://www.youtube.com/watch?v=TgXLq1XIdA0&t=823s的教程。 但是,我在运行python脚本后出现了这个错误

Traceback (most recent call last):
  File "tm.py", line 38, in <module> 
    lda_model = gensim.models.wrappers.ldamallet.LdaMallet(
  File "C:\Users\mmb\anaconda3\lib\site-packages\gensim\models\wrappers\ldamallet.py", line 126, in __init__
    self.train(corpus)
  File "C:\Users\mmb\anaconda3\lib\site-packages\gensim\models\wrappers\ldamallet.py", line 279, in train
    self.word_topics = self.load_word_topics()
  File "C:\Users\mmb\anaconda3\lib\site-packages\gensim\models\wrappers\ldamallet.py", line 337, in load_word_topics
    with utils.smart_open(self.fstate()) as fin:
  File "C:\Users\mmb\anaconda3\lib\site-packages\smart_open\smart_open_lib.py", line 138, in smart_open
    return file_smart_open(parsed_uri.uri_path, mode)
  File "C:\Users\mmb\anaconda3\lib\site-packages\smart_open\smart_open_lib.py", line 642, in file_smart_open
    return compression_wrapper(open(fname, mode), fname, mode)
  File "C:\Users\mmb\anaconda3\lib\site-packages\smart_open\smart_open_lib.py", line 630, in compression_wrapper
    return make_closing(GzipFile)(file_obj, mode)
  File "C:\Users\mmb\anaconda3\lib\gzip.py", line 173, in __init__
    fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
TypeError: expected str, bytes or os.PathLike object, not _io.BufferedReader

错误发生在创建lda_mallet模型的过程中

mallet_path = os.path.join('C:\mallet','bin','mallet')

# create the mallet modeling object
lda_model = gensim.models.wrappers.ldamallet.LdaMallet(
    mallet_path,
    corpus=processed_corpus,
    id2word=corpus_dictionary,
    num_topics=number_of_topics,
    optimize_interval=10,
    prefix='fed_'
)

Tags: inpysmartmodelslibpackageslinesite

热门问题