[英]gensim file not found error
我正在执行以下行:
id2word = gensim.corpora.Dictionary.load_from_text('wiki_en_wordids.txt')
可以从“ https://radimrehurek.com/gensim/wiki.html ”获得此代码。 我下载了Wikipedia语料库并生成了所需的文件,而wiki_en_wordids.txt是这些文件之一。 该文件位于以下位置:
~/gensim/results/wiki_en
因此,当我执行上述代码时,出现以下错误:
Traceback (most recent call last):
File "~\Python\Python36-32\temp.py", line 5, in <module>
id2word = gensim.corpora.Dictionary.load_from_text('wiki_en_wordids.txt')
File "~\Python\Python36-32\lib\site-packages\gensim\corpora\dictionary.py", line 344, in load_from_text
with utils.smart_open(fname) as f:
File "~\Python\Python36-32\lib\site-packages\smart_open\smart_open_lib.py", line 129, in smart_open
return file_smart_open(parsed_uri.uri_path, mode)
File "~\Python\Python36-32\lib\site-packages\smart_open\smart_open_lib.py", line 613, in file_smart_open
return open(fname, mode)
FileNotFoundError: [Errno 2] No such file or directory: 'wiki_en_wordids.txt'
即使该文件在所需的位置可用,我也会收到该错误。 我应该将文件放在其他任何位置吗? 如何确定正确的位置?
代码在这里需要绝对路径。 当在同一目录位置执行整个操作时,应使用相对路径,但是在这种情况下,文件名将作为参数传递给位于其他位置的其他函数。
处理这种情况的一种方法是使用Abspath-
import os
id2word = gensim.corpora.Dictionary.load_from_text(os.path.abspath('wiki_en_wordids.txt'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.