File size: 8,337 Bytes
bd204a8 c073894 bd204a8 650ab66 bd204a8 11716e7 77a2397 bd204a8 378947b bd204a8 5970942 11716e7 378947b bd204a8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
import gzip
import json
import os
import datasets
from datasets import Features, Sequence, Value
logger = datasets.logging.get_logger(__name__)
_FILES = [
'kwnlp-enwiki-20220901-link-annotated-text1-p1p41242.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text2-p41243p151573.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text3-p151574p311329.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text4-p311330p558391.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text5-p558392p958045.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text6-p958046p1483661.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text7-p1483662p2134111.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text8-p2134112p2936260.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text9-p2936261p4045402.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text10-p4045403p5399366.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text11-p5399367p6899366.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text11-p6899367p7054859.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text12-p7054860p8554859.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text12-p8554860p9172788.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text13-p10672789p11659682.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text13-p9172789p10672788.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text14-p11659683p13159682.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text14-p13159683p14324602.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text15-p14324603p15824602.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text15-p15824603p17324602.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text15-p17324603p17460152.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text16-p17460153p18960152.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text16-p18960153p20460152.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text16-p20460153p20570392.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text17-p20570393p22070392.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text17-p22070393p23570392.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text17-p23570393p23716197.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text18-p23716198p25216197.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text18-p25216198p26716197.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text18-p26716198p27121850.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text19-p27121851p28621850.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text19-p28621851p30121850.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text19-p30121851p31308442.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text20-p31308443p32808442.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text20-p32808443p34308442.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text20-p34308443p35522432.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text21-p35522433p37022432.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text21-p37022433p38522432.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text21-p38522433p39996245.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text22-p39996246p41496245.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text22-p41496246p42996245.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text22-p42996246p44496245.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text22-p44496246p44788941.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text23-p44788942p46288941.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text23-p46288942p47788941.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text23-p47788942p49288941.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text23-p49288942p50564553.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text24-p50564554p52064553.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text24-p52064554p53564553.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text24-p53564554p55064553.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text24-p55064554p56564553.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text24-p56564554p57025655.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text25-p57025656p58525655.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text25-p58525656p60025655.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text25-p60025656p61525655.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text25-p61525656p62585850.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text26-p62585851p63975909.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text27-p63975910p65475909.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text27-p65475910p66975909.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text27-p66975910p68475909.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text27-p68475910p69975909.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text27-p69975910p71475909.jsonl.gz',
'kwnlp-enwiki-20220901-link-annotated-text27-p71475910p71655058.jsonl.gz',
]
_VERSION = datasets.Version("1.0.0")
_DESCRIPTION = "Wikipedia text with metadata"
FEATURES = {
"all": Features(
{
"page_id": Value("int64"),
"page_title": Value("string"),
"paragraphs": [
{
"plaintext": Value("string"),
"section_idx": Value("int64"),
"section_name": Value("string"),
"target_page_ids": Sequence(Value("int64")),
"anchor_spans": Sequence(Sequence(Value("int64"), length=2)),
}
],
"revision_id": Value("int64"),
"categories": Sequence(Value("string")),
"item_id": Value("int64"),
"in_link_count": Value("int64"),
"out_link_count": Value("int64"),
"tmpl_good_article": Value("bool"),
"tmpl_featured_article": Value("bool"),
"item_label": Value("string"),
"item_description": Value("string"),
"item_alias": Sequence(Value("string")),
}
),
"text": Features(
{
"paragraph": Value("string")
}
),
"text-intros": Features(
{
"paragraph": Value("string")
}
),
}
class HacdcWikipedia(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="all", version=_VERSION, description=_DESCRIPTION),
datasets.BuilderConfig(name="text", version=_VERSION, description=_DESCRIPTION),
datasets.BuilderConfig(
name="text-intros", version=_VERSION, description=_DESCRIPTION
),
]
DEFAULT_CONFIG_NAME = "all"
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=FEATURES[self.config.name],
)
def _split_generators(self, dl_manager):
paths = [os.path.join("data", filename) for filename in _FILES]
downloaded_files = dl_manager.download_and_extract(paths)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files}),
]
def _generate_examples(self, filepaths):
"""Generate examples.
Args:
filepaths: a list of file paths
Yields:
dictionaries representing article data and metadata
"""
_id = 0
for filepath in filepaths:
logger.info("generating examples from = %s", filepath)
with open(filepath, "r") as fp:
for line in fp:
data = json.loads(line)
if self.config.name == "all":
yield _id, data
_id += 1
continue
for paragraph in data["paragraphs"]:
if self.config.name == "text":
yield _id, {"paragraph": paragraph["plaintext"]}
_id += 1
if self.config.name == "text-intros":
if paragraph["section_idx"] == 0:
yield _id, {"paragraph": paragraph["plaintext"]}
_id += 1
|