|
import datasets |
|
|
|
_DESCRIPTION = """\ |
|
Dataset for the shared baby language modeling task. |
|
The goal is to train a language model from scratch on this data which represents |
|
roughly the amount of text and speech data a young child observes. |
|
""" |
|
|
|
_HOMEPAGE = "https://babylm.github.io" |
|
|
|
class BabyLM(datasets.GeneratorBasedBuilder): |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="strict_small", |
|
description="Small version of the dataset with 10M words", |
|
version="1.0.0", |
|
data_dir="10M", |
|
features=["text"] |
|
), |
|
datasets.BuilderConfig( |
|
name="strict", |
|
description="Full version of the dataset with 100M words", |
|
version="1.0.0", |
|
data_dir="100M", |
|
features=["text"] |
|
) |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "strict_small" |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"text": datasets.Value("string"), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: |
|
""" |
|
Returns data for different splits |
|
""" |
|
|
|
if self.config.name == "strict_small": |
|
train_data_dir = "10M" |
|
else: |
|
train_data_dir = "100M" |
|
|
|
urls_to_download = { |
|
"train": f"{train_data_dir}/*.txt", |
|
"dev": "dev/*.txt", |
|
"test": "test/*.txt" |
|
} |
|
|
|
downloaded_files = dl_manager.download_and_extract(urls_to_download) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"split": "train", |
|
"filepaths": downloaded_files["train"]} |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"split": "dev", |
|
"filepaths": downloaded_files["dev"]} |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"split": "test", |
|
"filepaths": downloaded_files["test"] |
|
} |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, split, filepaths): |
|
|
|
|
|
|
|
if isinstance(filepaths, str): |
|
filepaths = [filepaths] |
|
|
|
global_idx = 0 |
|
|
|
for filepath in filepaths: |
|
with open(filepath, encoding="utf-8") as f: |
|
for row in f: |
|
yield global_idx, {"text": row} |