【问题标题】:Creating Corpus from wiki dump file using Jupyter notebook使用 Jupyter 笔记本从 wiki 转储文件创建语料库
【发布时间】:2021-10-15 20:44:27
【问题描述】:

我正在尝试按照此页面创建一个 wiki 语料库,但我正在使用 Jupiter notebook https://www.kdnuggets.com/2017/11/building-wikipedia-text-corpus-nlp.html

这是我的代码:

import sys
from gensim.test.utils import datapath
from gensim.corpora import WikiCorpus

path_to_wiki_dump = datapath("enwiki-latest-pages-articles.xml.bz2")

wiki = WikiCorpus(path_to_wiki_dump)

output = open('wiki_en.txt', 'w',  encoding='utf-8')

i = 0
for text in wiki.get_texts():
    output.write(bytes(' '.join(text), 'utf-8').decode('utf-8') + '\n')
    i = i + 1
    if (i % 10000 == 0):
        print('Processed ' + str(i) + ' articles')
output.close()
print('Processing complete!')

我得到的错误是

FileNotFoundError: [Errno 2] No such file or directory: '/opt/anaconda3/lib/python3.8/site-packages/gensim/test/test_data/enwiki-latest-pages-articles.xml.bz2'

所有文件都在一个地方,所以我不确定出了什么问题

【问题讨论】:

    标签: python jupyter-notebook gensim wiki corpus


    【解决方案1】:

    你有没有以某种方式下载文件enwiki-latest-pages-articles.xml.bz2

    你有没有专门把它放在路径/opt/anaconda3/lib/python3.8/site-packages/gensim/test/test_data/enwiki-latest-pages-articles.xml.bz2

    如果不是您使用的datapath() 函数,则不会构建正确的路径。 (该特定功能旨在查找与 Gensim 捆绑的测试数据目录,不应真正用于构建您自己下载/创建的文件的路径!)

    您应该指定 actual 路径,而不是使用该函数,您应该将文件放置在 Jupyter 笔记本服务器的本地,作为 WikiCorpus 的字符串参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 2020-10-01
      • 2019-07-17
      • 2017-07-10
      • 1970-01-01
      • 2015-05-12
      相关资源
      最近更新 更多