|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io |
|
from typing import Iterator, List, Tuple |
|
|
|
import datasets |
|
import pyarrow as pa |
|
|
|
|
|
_DESCRIPTION = ( |
|
"書籍『大規模言語モデル入門』で使用する Wikipedia 文のデータセットです。" |
|
"GitHub リポジトリ singletongue/wikipedia-utils で公開されているデータセットを利用しています。" |
|
) |
|
_HOMEPAGE = "https://github.com/singletongue/wikipedia-utils" |
|
_LICENSE = ( |
|
"本データセットで使用している Wikipedia のコンテンツは、クリエイティブ・コモンズ表示・継承ライセンス 3.0 (CC BY-SA 3.0) " |
|
"および GNU 自由文書ライセンス (GFDL) の下に配布されているものです。" |
|
) |
|
|
|
_URL = "https://github.com/singletongue/wikipedia-utils/releases/download/2023-04-03/corpus-jawiki-20230403.txt.gz" |
|
|
|
|
|
class JaWikiSentences(datasets.ArrowBasedBuilder): |
|
VERSION = datasets.Version("1.0.0") |
|
|
|
def _info(self) -> datasets.DatasetInfo: |
|
features = datasets.Features({"text": datasets.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) |
|
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": filepath})] |
|
|
|
def _generate_tables(self, filepath: str, chunksize: int = 10 << 20) -> Iterator[Tuple[int, pa.Table]]: |
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
batch_idx = 0 |
|
while True: |
|
batch = f.read(chunksize) |
|
if not batch: |
|
break |
|
|
|
batch += f.readline() |
|
batch = [line.rstrip("\n") for line in io.StringIO(batch).readlines()] |
|
pa_table = pa.Table.from_arrays([pa.array(batch)], names=["text"]) |
|
|
|
yield batch_idx, pa_table |
|
batch_idx += 1 |
|
|