singletongue commited on
Commit
b79ed38
1 Parent(s): 3232fdf

Add a dataset loading script

Browse files
Files changed (2) hide show
  1. README.md +28 -0
  2. jawiki-sentences.py +65 -0
README.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - ja
4
+ size_categories:
5
+ - 10M<n<100M
6
+ license:
7
+ - cc-by-sa-3.0
8
+ - gfdl
9
+ dataset_info:
10
+ features:
11
+ - name: text
12
+ dtype: string
13
+ splits:
14
+ - name: train
15
+ num_bytes: 3569619848
16
+ num_examples: 24387500
17
+ download_size: 1297833377
18
+ dataset_size: 3569619848
19
+ ---
20
+
21
+ # Dataset Card for llm-book/jawiki-sentences
22
+
23
+ 書籍『大規模言語モデル入門』で使用する Wikipedia 文のデータセットです。
24
+ GitHub リポジトリ [singletongue/wikipedia-utils](https://github.com/singletongue/wikipedia-utils) で公開されているデータセットを利用しています。
25
+
26
+ ## Licence
27
+
28
+ 本データセットで使用している Wikipedia のコンテンツは、[クリエイティブ・コモンズ表示・継承ライセンス 3.0 (CC BY-SA 3.0)](https://creativecommons.org/licenses/by-sa/3.0/deed.ja) および [GNU 自由文書ライセンス (GFDL)](https://www.gnu.org/licenses/fdl.html) の下に配布されているものです。
jawiki-sentences.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors.
2
+ # Copyright 2023 Masatoshi Suzuki (@singletongue).
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ import io
16
+ from typing import Iterator, List, Tuple
17
+
18
+ import datasets
19
+ import pyarrow as pa
20
+
21
+
22
+ _DESCRIPTION = (
23
+ "書籍『大規模言語モデル入門』で使用する Wikipedia 文のデータセットです。"
24
+ "GitHub リポジトリ singletongue/wikipedia-utils で公開されているデータセットを利用しています。"
25
+ )
26
+ _HOMEPAGE = "https://github.com/singletongue/wikipedia-utils"
27
+ _LICENSE = (
28
+ "本データセットで使用している Wikipedia のコンテンツは、クリエイティブ・コモンズ表示・継承ライセンス 3.0 (CC BY-SA 3.0) "
29
+ "および GNU 自由文書ライセンス (GFDL) の下に配布されているものです。"
30
+ )
31
+
32
+ _URL = "https://github.com/singletongue/wikipedia-utils/releases/download/2023-04-03/corpus-jawiki-20230403.txt.gz"
33
+
34
+
35
+ class JaWikiSentences(datasets.ArrowBasedBuilder):
36
+ VERSION = datasets.Version("1.0.0")
37
+
38
+ def _info(self) -> datasets.DatasetInfo:
39
+ features = datasets.Features({"text": datasets.Value("string")})
40
+ return datasets.DatasetInfo(
41
+ description=_DESCRIPTION,
42
+ homepage=_HOMEPAGE,
43
+ license=_LICENSE,
44
+ features=features,
45
+ )
46
+
47
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
48
+ filepath = dl_manager.download_and_extract(_URL)
49
+ return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": filepath})]
50
+
51
+ def _generate_tables(self, filepath: str, chunksize: int = 10 << 20) -> Iterator[Tuple[int, pa.Table]]:
52
+ # cf. https://github.com/huggingface/datasets/blob/2.12.0/src/datasets/packaged_modules/text/text.py
53
+ with open(filepath) as f:
54
+ batch_idx = 0
55
+ while True:
56
+ batch = f.read(chunksize)
57
+ if not batch:
58
+ break
59
+
60
+ batch += f.readline()
61
+ batch = [line.rstrip("\n") for line in io.StringIO(batch).readlines()]
62
+ pa_table = pa.Table.from_arrays([pa.array(batch)], names=["text"])
63
+
64
+ yield batch_idx, pa_table
65
+ batch_idx += 1