数据集:
Cohere/wikipedia-22-12
这个数据集包含了经过预处理的维基百科内容,适用于语义搜索。
你可以像这样加载数据集:
from datasets import load_dataset lang = 'en' data = load_dataset(f"Cohere/wikipedia-22-12", lang, split='train', streaming=True) for row in data: print(row) break
这将以流式模式加载数据集(这样你就不需要下载整个数据集),并且可以逐行处理。
文章被分割成段落。此外,对于每篇文章,我们还添加了2022年页面访问量以及文章在多少种其他语言中可用的统计数据。数据集按照页面访问量排序,因此最受欢迎的维基百科文章排在前面。因此,如果你阅读前10万行,你将得到关于广泛受人们关注的主题的相当好的涵盖范围。
我们还提供了使用语义搜索嵌入技术对文档进行嵌入的版本,例如, wikipedia-22-12-en-embeddings 包含英文段落及其相应的嵌入。您可以在数据集wikipedia-22-12-{lang}-embeddings中找到其他语言的嵌入数据集。
使用2022年12月20日的维基百科数据集(下称 XML data dumps ) ,并使用 wikiextractor (版本:2.75)进行处理。处理命令如下:
python WikiExtractor.py --json -s --lists ../dumps/dewiki-20210101-pages-articles.xml.bz2 -o text_de
为了计算每篇文章可用的语言数量,我们从以下链接下载了语言链接的SQL文件:
https://dumps.wikimedia.org/{lang}wiki/{datestr}/{filename}
并处理SQL文件以读取每篇文章的出站链接。
页面访问量从以下链接下载:
https://dumps.wikimedia.org/other/pageviews/{year}/{year}-{month_str}/pageviews-{year}{month_str}{day_str}-{hour_str}0000.gz
我们每天随机选择一个小时下载页面访问量。然后计算页面访问量的调和平均值。我们使用对数分数来增加数字的稳定性。
计算页面访问量的代码如下:
import gzip
import sys
from collections import Counter, defaultdict
import math
import tqdm
import json
title_views = {}
#Score: Harmonic mean (View_Day_1 * View_Day_2 * View_day_3)
# Add log for better numerical stabilitiy
# Add +1 to avoid log(0)
# Compare the sum, so that days without view are counted as 0 views
for filepath in tqdm.tqdm(sys.argv[1:]):
with gzip.open(filepath, "rt") as fIn:
for line in fIn:
splits = line.strip().split()
if len(splits) == 4:
lang, title, views, _ = line.strip().split()
lang = lang.lower()
if lang.endswith(".m"): #Add mobile page scores to main score
lang = lang[0:-2]
if lang.count(".") > 0:
continue
if lang not in title_views:
title_views[lang] = {}
if title not in title_views[lang]:
title_views[lang][title] = 0.0
title_views[lang][title] += math.log(int(views)+1)
#Save results
for lang in title_views:
with open(f"pageviews_summary/{lang}.json", "w") as fOut:
fOut.write(json.dumps(title_views[lang]))
筛选以BULLET::::、Section::::、<templatestyles、或[[File:开头的段落。此外,我们还仅包括至少包含100个字符的段落(使用Python len方法进行判断)。