我们在预训练word vector或其他预训练任务时,需要大量的语料数据,Wikipedia开放了英文语料,大约11G:wiki英文语料下载链接
该语料库是.bz2格式,但是不能直接解压,需要使用工具处理,我们介绍两种常用的处理工具,gensim和wikiextractor。
Gensim
gensim提供了处理工具,但是只能够获得文章的词列表,丢失了段落句子以及标点符号。
from gensim.corpora import WikiCorpus
a = 'enwiki-latest-pages-articles.xml.bz2'
wiki = WikiCorpus(a, lemmatize=False, dictionary={})
for text in wiki.get_texts():
for word in text:
pass
Wikiextractor
想要获得原文,可以通过wikiextractor工具。
git clone https://github.com/attardi/wikiextractor
python wikiextractor/WikiExtractor.py INPUT_FILE -o OUTPUT_PATH --json
所有文章会被解压到指定的OUTPUT_PATH文件夹中,可以通过--json指定输出为json格式,也可以参考github设置其他格式。对解压好的文章,可以通过NLTK处理分句以及分词。
参考
https://github.com/EternalFeather/Word2Vec-on-Wikipedia-Corpus
https://github.com/attardi/wikiextractor
https://radimrehurek.com/gensim/corpora/wikicorpus.html
https://blog.youkuaiyun.com/lixintong1992/article/details/50387007
在预训练word vector等任务时,Wikipedia的英文语料库是宝贵的资源。本文介绍了两种处理工具:Gensim和Wikiextractor。Gensim仅提供词列表,而Wikiextractor能保留原文。通过wikiextractor,文章被解压到指定文件夹,可选择json格式,并用NLTK进行分句和分词。
1350

被折叠的 条评论
为什么被折叠?



