File size: 1,942 Bytes
4a723f2 c41b7f5 4a723f2 c41b7f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | """Raw RedPajamas Custom Loading Script"""
import json
import datasets
from huggingface_hub import HfFileSystem
_CITATION = """"""
_DESCRIPTION = """"""
_HOMEPAGE = ""
_LICENSE = ""
class RawRedPajamas(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.1.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="contents_only", version=VERSION, description="This returns the content field only."
),
]
DEFAULT_CONFIG_NAME = "contents_only" # It's not mandatory to have a default configuration. Just use one if it make sense.
def _info(self):
features = datasets.Features({"content": datasets.Value("string")})
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
fs = HfFileSystem(token=self.token)
files = [file.split(f"/{self.repo_id}/")[-1] for file in fs.glob(f"datasets/{self.repo_id}/data/*.json")]
downloaded_files = dl_manager.download_and_extract(files)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepaths": downloaded_files,
},
),
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, filepaths):
for filepath in filepaths:
with open(filepath, encoding="utf-8") as f:
for key, row in enumerate(f):
data = json.loads(row)
content = data["raw_content"]
yield key, {
"content": content.strip().rstrip().lstrip(),
} |