hjp709394 commited on
Commit
4a24b8c
1 Parent(s): d237f12

Upload RedPajama-Data-1T-1024Sample.py

Browse files
Files changed (1) hide show
  1. RedPajama-Data-1T-1024Sample.py +107 -0
RedPajama-Data-1T-1024Sample.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2023 Together Computer
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Lint as: python3
16
+ """RedPajama: An Open-Source, Clean-Room 1.2 Trillion Token Dataset."""
17
+
18
+
19
+ import json
20
+
21
+ import datasets
22
+
23
+
24
+ logger = datasets.logging.get_logger(__name__)
25
+
26
+
27
+ _DESCRIPTION = """\
28
+ RedPajama is a clean-room, fully open-source implementation of the LLaMa dataset. This is a 1B-token sample of the full dataset.
29
+ """
30
+
31
+ _URLS = [
32
+ "arxiv_sample.jsonl",
33
+ "book_sample.jsonl",
34
+ "c4_sample.jsonl",
35
+ "cc_2019-30_sample.jsonl",
36
+ "cc_2020-05_sample.jsonl",
37
+ "cc_2021-04_sample.jsonl",
38
+ "cc_2022-05_sample.jsonl",
39
+ "cc_2023-06_sample.jsonl",
40
+ "github_sample.jsonl",
41
+ "stackexchange_sample.jsonl",
42
+ "wikipedia_sample.jsonl",
43
+ ]
44
+
45
+
46
+ class RedPajama1TSampleConfig(datasets.BuilderConfig):
47
+ """BuilderConfig for RedPajama sample."""
48
+
49
+ def __init__(self, **kwargs):
50
+ """BuilderConfig for RedPajama sample.
51
+ Args:
52
+ **kwargs: keyword arguments forwarded to super.
53
+ """
54
+ super(RedPajama1TSampleConfig, self).__init__(**kwargs)
55
+
56
+
57
+ class RedPajama1TSample(datasets.GeneratorBasedBuilder):
58
+ """RedPajama 1T Sample: version 1.0.0."""
59
+
60
+ BUILDER_CONFIGS = [
61
+ RedPajama1TSampleConfig(
62
+ name="plain_text",
63
+ version=datasets.Version("1.0.0", ""),
64
+ description="Plain text",
65
+ ),
66
+ ]
67
+
68
+ def _info(self):
69
+ return datasets.DatasetInfo(
70
+ description=_DESCRIPTION,
71
+ features=datasets.Features(
72
+ {
73
+ "text": datasets.Value("string"),
74
+ "meta": datasets.Value("string"),
75
+ }
76
+ ),
77
+ supervised_keys=None,
78
+ )
79
+
80
+ def _split_generators(self, dl_manager):
81
+ downloaded_files = dl_manager.download_and_extract(_URLS)
82
+
83
+ return [
84
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files})
85
+ ]
86
+
87
+ def _generate_examples(self, filepaths):
88
+ """This function returns the examples in the raw (text) form."""
89
+ logger.info("generating examples from = %s", filepaths)
90
+ key = 0
91
+ for filepath in filepaths:
92
+ with open(filepath, encoding="utf-8") as f:
93
+ for row in f:
94
+ data = json.loads(row)
95
+ if "meta" not in data:
96
+ text = data["text"]
97
+ del data["text"]
98
+ yield key, {
99
+ "text": text,
100
+ "meta": json.dumps(data),
101
+ }
102
+ else:
103
+ yield key, {
104
+ "text": data["text"],
105
+ "meta": data["meta"],
106
+ }
107
+ key += 1