aio-passages / aio-passages.py
singletongue's picture
Update the dataset loading script (no change to the contents)
7f54d80
raw history blame
No virus
2.53 kB
import io
from typing import Iterator, List, Tuple
import datasets
import pyarrow as pa
from datasets import Value
_DESCRIPTION = (
"書籍『大規模言語モデル入門』で使用する、「AI王」コンペティションのパッセージデータセットです。"
"GitHub リポジトリ cl-tohoku/quiz-datasets で公開されているデータセットを利用しています。"
)
_HOMEPAGE = "https://github.com/cl-tohoku/quiz-datasets"
_LICENSE = (
"本データセットで使用している Wikipedia のコンテンツは、クリエイティブ・コモンズ表示・継承ライセンス 3.0 (CC BY-SA 3.0) "
"および GNU 自由文書ライセンス (GFDL) の下に配布されているものです。"
)
_URL_BASE = "https://github.com/cl-tohoku/quiz-datasets/releases/download"
_URL = f"{_URL_BASE}/v1.0.1/passages.jawiki-20220404-c400-large.jsonl.gz"
class AioPassages(datasets.ArrowBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self) -> datasets.DatasetInfo:
features = datasets.Features({
"id": Value("int32"),
"pageid": Value("int32"),
"revid": Value("int32"),
"text": Value("string"),
"section": Value("string"),
"title": Value("string"),
})
return datasets.DatasetInfo(
description=_DESCRIPTION,
homepage=_HOMEPAGE,
license=_LICENSE,
features=features,
)
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
filepath = dl_manager.download_and_extract(_URL)
split_generators = [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": filepath})]
return split_generators
def _generate_tables(self, filepath: str, chunksize: int = 10 << 20) -> Iterator[Tuple[int, pa.Table]]:
# cf. https://github.com/huggingface/datasets/blob/2.12.0/src/datasets/packaged_modules/json/json.py
with open(filepath, "rb") as f:
batch_idx = 0
block_size = max(chunksize // 32, 16 << 10)
while True:
batch = f.read(chunksize)
if not batch:
break
batch += f.readline()
pa_table = pa.json.read_json(
io.BytesIO(batch), read_options=pa.json.ReadOptions(block_size=block_size)
)
yield batch_idx, pa_table
batch_idx += 1