Datasets:

Languages:
English
Size:
n>1T
ArXiv:
License:
dolma / dolma.py
soldni's picture
gitignore
7d5c7f2
raw
history blame
4.7 kB
# Copyright 2023 Allen Institute for AI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""Dolma: an Open Corpus of Three Trillion Tokens for Language Model Pretraining Research"""
import json
from pathlib import Path
from typing import Dict, List
import datasets
import traceback
import os
logger = datasets.logging.get_logger(__name__)
_CURRENT_DIR = Path(__file__).resolve().parent
_DESCRIPTION = """\
Dolma: an Open Corpus of Three Trillion Tokens for Language Model Pretraining Research
"""
_SUBSET_URLS = {
"v1": _CURRENT_DIR / "urls/dolma-v1.txt",
"v1_5r1": _CURRENT_DIR / "urls/dolma-v1_5r1.txt",
"v1_5r1-sample": _CURRENT_DIR / "urls/dolma-v1_5r1-sample.txt",
"v1_5r2": _CURRENT_DIR / "urls/dolma-v1_5r2.txt",
}
_SUBSET_VERSION = {
"v1": "1.0.0",
"v1_5r1": "1.5.0",
"v1_5r1-sample": "1.5.0",
"v1_5r2": "1.5.0",
}
_SUBSET_NAME = {
"v1": "Dolma v1 (Aug 2023)",
"v1_5r1": "Dolma v1.5r1 (Oct 2023)",
"v1_5r1-sample": "Dolma v1.5r1, 2T sample (Oct 2023)",
"v1_5r2": "Dolma v1.5r2 (Dec 2023)",
}
_BASE_URL = "https://olmo-data.org"
_DATA_DIR = os.environ.get("DOLMA_DATA_DIR", None)
_CITATION = """\
@article{dolma,
title = {{Dolma: An Open Corpus of Three Trillion Tokens for Language Model Pretraining Research}},
author = {Luca Soldaini and Rodney Kinney and Akshita Bhagia and Dustin Schwenk and David Atkinson and Russell Authur and Ben Bogin and Khyathi Chandu and Jennifer Dumas and Yanai Elazar and Valentin Hofmann and Ananya Harsh Jha and Sachin Kumar and Li Lucy and Xinxi Lyu and Ian Magnusson and Jacob Morrison and Niklas Muennighoff and Aakanksha Naik and Crystal Nam and Matthew E. Peters and Abhilasha Ravichander and Kyle Richardson and Zejiang Shen and Emma Strubell and Nishant Subramani and Oyvind Tafjord and Evan Pete Walsh and Hannaneh Hajishirzi and Noah A. Smith and Luke Zettlemoyer and Iz Beltagy and Dirk Groeneveld and Jesse Dodge and Kyle Lo},
year = {2024},
journal={arXiv preprint},
}
"""
class RedPajama1TConfig(datasets.BuilderConfig):
"""BuilderConfig for RedPajama sample."""
def __init__(self, *args, subsets: List[str], url_file: Path, **kwargs):
"""BuilderConfig for RedPajama.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(RedPajama1TConfig, self).__init__(*args, **kwargs)
self.subsets = subsets
self.url_file = url_file
class RedPajama1T(datasets.GeneratorBasedBuilder):
"""Dolma: an Open Corpus of Three Trillion Tokens for Language Model Pretraining Research"""
config: RedPajama1TConfig
BUILDER_CONFIGS = [
RedPajama1TConfig(
name=subset,
subsets=[subset],
url_file=_SUBSET_URLS[subset],
version=datasets.Version(_SUBSET_VERSION[subset], _SUBSET_NAME[subset]),
description=_DESCRIPTION,
)
for subset in _SUBSET_URLS
]
DEFAULT_CONFIG_NAME = "v1_5r2"
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"text": datasets.Value("string"),
"metadata": datasets.Value("string"),
"added": datasets.Value("string"),
# "metadata": datasets.Value("")
}
),
supervised_keys=None,
)
def _split_generators(self, dl_manager):
with open(self.config.url_file, encoding="utf-8") as f:
subset_urls: Dict[str, List[str]] = json.load(f)
breakpoint()
url_lists: Dict[str, List[str]] = {}
for subset in self.config.subsets:
url_lists[subset] = dl_manager.download(subset_urls[subset])
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN._name,
gen_kwargs={"files": {subset: url_lists[subset] for subset in self.config.subsets}},
)
]
def _generate_examples(self, files):
"""This function returns the examples in the raw (text) form."""
breakpoint()