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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
import traceback
|
| 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.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
_URL_LISTS = {
|
| 32 |
+
"arxiv": "urls/arxiv.txt",
|
| 33 |
+
"book": "urls/book.txt",
|
| 34 |
+
"github": "urls/github.txt",
|
| 35 |
+
"stackexchange": "urls/stackexchange.txt",
|
| 36 |
+
"wikipedia": "urls/wikipedia.txt",
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class RedPajama1TConfig(datasets.BuilderConfig):
|
| 41 |
+
"""BuilderConfig for RedPajama sample."""
|
| 42 |
+
|
| 43 |
+
def __init__(self, *args, subsets, **kwargs):
|
| 44 |
+
"""BuilderConfig for RedPajama.
|
| 45 |
+
Args:
|
| 46 |
+
**kwargs: keyword arguments forwarded to super.
|
| 47 |
+
"""
|
| 48 |
+
super(RedPajama1TConfig, self).__init__(**kwargs)
|
| 49 |
+
|
| 50 |
+
self.subsets = subsets
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class RedPajama1T(datasets.GeneratorBasedBuilder):
|
| 54 |
+
"""RedPajama: Reproducing the LLaMA training dataset of over 1.2 trillion tokens. Version 1.0.0."""
|
| 55 |
+
|
| 56 |
+
BUILDER_CONFIGS = [
|
| 57 |
+
RedPajama1TConfig(
|
| 58 |
+
subsets = list(_URL_LISTS.keys()),
|
| 59 |
+
name="plain_text",
|
| 60 |
+
version=datasets.Version("1.0.0", ""),
|
| 61 |
+
description="Plain text",
|
| 62 |
+
),
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
def _info(self):
|
| 66 |
+
return datasets.DatasetInfo(
|
| 67 |
+
description=_DESCRIPTION,
|
| 68 |
+
features=datasets.Features(
|
| 69 |
+
{
|
| 70 |
+
"text": datasets.Value("string"),
|
| 71 |
+
"meta": datasets.Value("string"),
|
| 72 |
+
"red_pajama_subset": datasets.Value("string"),
|
| 73 |
+
}
|
| 74 |
+
),
|
| 75 |
+
supervised_keys=None,
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
def _split_generators(self, dl_manager):
|
| 79 |
+
url_lists = dl_manager.download_and_extract({
|
| 80 |
+
subset: _URL_LISTS[subset] for subset in self.config.subsets
|
| 81 |
+
})
|
| 82 |
+
|
| 83 |
+
urls = {}
|
| 84 |
+
|
| 85 |
+
for subset, url_list in url_lists.items():
|
| 86 |
+
with open(url_list, encoding="utf-8") as f:
|
| 87 |
+
urls[subset] = [line.strip() for line in f][:1]
|
| 88 |
+
|
| 89 |
+
downloaded_files = dl_manager.download(urls)
|
| 90 |
+
|
| 91 |
+
return [
|
| 92 |
+
datasets.SplitGenerator(
|
| 93 |
+
name=datasets.Split.TRAIN,
|
| 94 |
+
gen_kwargs = {
|
| 95 |
+
"files": {
|
| 96 |
+
subset: downloaded_files[subset]
|
| 97 |
+
for subset in self.config.subsets
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
)
|
| 101 |
+
]
|
| 102 |
+
|
| 103 |
+
def _generate_examples(self, files):
|
| 104 |
+
"""This function returns the examples in the raw (text) form."""
|
| 105 |
+
key = 0
|
| 106 |
+
for subset in files:
|
| 107 |
+
if subset == "common_crawl":
|
| 108 |
+
import zstandard as zstd
|
| 109 |
+
|
| 110 |
+
for path in files[subset]:
|
| 111 |
+
with zstd.open(open(path, "rb"), "rt", encoding="utf-8") as f:
|
| 112 |
+
for i, row in enumerate(f):
|
| 113 |
+
try:
|
| 114 |
+
data = json.loads(row)
|
| 115 |
+
text = data["text"]
|
| 116 |
+
del data["text"]
|
| 117 |
+
yield key, {
|
| 118 |
+
"text": text,
|
| 119 |
+
"meta": json.dumps(data),
|
| 120 |
+
"red_pajama_subset": subset,
|
| 121 |
+
}
|
| 122 |
+
key += 1
|
| 123 |
+
except Exception as e:
|
| 124 |
+
print(f'Subset: {subset}')
|
| 125 |
+
print(f'Path: {path}')
|
| 126 |
+
print(f'Row: {row}')
|
| 127 |
+
traceback.print_exc()
|
| 128 |
+
|
| 129 |
+
raise e
|
| 130 |
+
else:
|
| 131 |
+
for path in files[subset]:
|
| 132 |
+
with open(path, encoding="utf-8") as f:
|
| 133 |
+
for i, row in enumerate(f):
|
| 134 |
+
try:
|
| 135 |
+
data = json.loads(row)
|
| 136 |
+
if "meta" not in data:
|
| 137 |
+
text = data["text"]
|
| 138 |
+
del data["text"]
|
| 139 |
+
yield key, {
|
| 140 |
+
"text": text,
|
| 141 |
+
"meta": json.dumps(data),
|
| 142 |
+
"red_pajama_subset": subset,
|
| 143 |
+
}
|
| 144 |
+
else:
|
| 145 |
+
yield key, {
|
| 146 |
+
"text": data["text"],
|
| 147 |
+
"meta": data["meta"],
|
| 148 |
+
"red_pajama_subset": subset,
|
| 149 |
+
}
|
| 150 |
+
key += 1
|
| 151 |
+
except Exception as e:
|
| 152 |
+
print(f'Subset: {subset}')
|
| 153 |
+
print(f'Path: {path}')
|
| 154 |
+
print(f'Row: {row}')
|
| 155 |
+
traceback.print_exc()
|
| 156 |
+
|
| 157 |
+
raise e
|