|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""GitHub subset of The Pile.""" |
|
|
|
|
|
import pandas as pd |
|
import datasets |
|
import json |
|
|
|
|
|
_CITATION = """\ |
|
@misc{gao2020pile, |
|
title={The Pile: An 800GB Dataset of Diverse Text for Language Modeling}, |
|
author={Leo Gao and Stella Biderman and Sid Black and Laurence Golding and Travis Hoppe and Charles Foster and Jason Phang and Horace He and Anish Thite and Noa Nabeshima and Shawn Presser and Connor Leahy}, |
|
year={2020}, |
|
eprint={2101.00027}, |
|
archivePrefix={arXiv}, |
|
primaryClass={cs.CL} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
The Pile is a 825 GiB diverse, open source language modelling data set that consists of 22 smaller, high-quality |
|
datasets combined together. |
|
""" |
|
|
|
_HOMEPAGE = "https://pile.eleuther.ai/" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
|
|
_URLS = { |
|
"train": { |
|
"assembly": [f"data/train/Assembly/part.{part}.parquet" for part in range(3)], |
|
"batchfile": [f"data/train/Batchfile/part.{part}.parquet" for part in range(2)], |
|
"c": [f"data/train/C/part.{part}.parquet" for part in range(15)], |
|
"c#": [f"data/train/C%23/part.{part}.parquet" for part in range(8)], |
|
"c++": [f"data/train/C++/part.{part}.parquet" for part in range(15)], |
|
"clojure": [f"data/train/Clojure/part.{part}.parquet" for part in range(1)], |
|
"cmake": [f"data/train/CMake/part.{part}.parquet" for part in range(1)], |
|
"cobol": [f"data/train/COBOL/part.{part}.parquet" for part in range(1)], |
|
"coffeescript": [f"data/train/CoffeeScript/part.{part}.parquet" for part in range(2)], |
|
"css": [f"data/train/CSS/part.{part}.parquet" for part in range(3)], |
|
"csv": [f"data/train/CSV/part.{part}.parquet" for part in range(2)], |
|
"dart": [f"data/train/Dart/part.{part}.parquet" for part in range(2)], |
|
"dm": [f"data/train/DM/part.{part}.parquet" for part in range(1)], |
|
"dockerfile": [f"data/train/Dockerfile/part.{part}.parquet" for part in range(1)], |
|
"elixir": [f"data/train/Elixir/part.{part}.parquet" for part in range(1)], |
|
"erlang": [f"data/train/Erlang/part.{part}.parquet" for part in range(1)], |
|
"fortran": [f"data/train/Fortran/part.{part}.parquet" for part in range(1)], |
|
"go": [f"data/train/Go/part.{part}.parquet" for part in range(15)], |
|
"groovy": [f"data/train/Groovy/part.{part}.parquet" for part in range(4)], |
|
"haskell": [f"data/train/Haskell/part.{part}.parquet" for part in range(1)], |
|
"html": [f"data/train/HTML/part.{part}.parquet" for part in range(10)], |
|
"ini": [f"data/train/INI/part.{part}.parquet" for part in range(3)], |
|
"java": [f"data/train/Java/part.{part}.parquet" for part in range(15)], |
|
"javascript": [f"data/train/JavaScript/part.{part}.parquet" for part in range(10)], |
|
"json": [f"data/train/JSON/part.{part}.parquet" for part in range(6)], |
|
"julia": [f"data/train/Julia/part.{part}.parquet" for part in range(1)], |
|
"kotlin": [f"data/train/Kotlin/part.{part}.parquet" for part in range(1)], |
|
"lisp": [f"data/train/Lisp/part.{part}.parquet" for part in range(1)], |
|
"lua": [f"data/train/Lua/part.{part}.parquet" for part in range(2)], |
|
"makefile": [f"data/train/Makefile/part.{part}.parquet" for part in range(2)], |
|
"markdown": [f"data/train/Markdown/part.{part}.parquet" for part in range(10)], |
|
"matlab": [f"data/train/Matlab/part.{part}.parquet" for part in range(1)], |
|
"objective-c": [f"data/train/Objective-C/part.{part}.parquet" for part in range(5)], |
|
"ocaml": [f"data/train/OCaml/part.{part}.parquet" for part in range(1)], |
|
"pascal": [f"data/train/Pascal/part.{part}.parquet" for part in range(2)], |
|
"perl": [f"data/train/Perl/part.{part}.parquet" for part in range(2)], |
|
"php": [f"data/train/PHP/part.{part}.parquet" for part in range(8)], |
|
"powershell": [f"data/train/PowerShell/part.{part}.parquet" for part in range(1)], |
|
"prolog": [f"data/train/Prolog/part.{part}.parquet" for part in range(1)], |
|
"python": [f"data/train/Python/part.{part}.parquet" for part in range(10)], |
|
"r": [f"data/train/R/part.{part}.parquet" for part in range(1)], |
|
"ruby": [f"data/train/Ruby/part.{part}.parquet" for part in range(2)], |
|
"rust": [f"data/train/Rust/part.{part}.parquet" for part in range(2)], |
|
"scala": [f"data/train/Scala/part.{part}.parquet" for part in range(2)], |
|
"shell": [f"data/train/Shell/part.{part}.parquet" for part in range(3)], |
|
"sql": [f"data/train/SQL/part.{part}.parquet" for part in range(2)], |
|
"swift": [f"data/train/Swift/part.{part}.parquet" for part in range(2)], |
|
"tex": [f"data/train/TeX/part.{part}.parquet" for part in range(2)], |
|
"toml": [f"data/train/TOML/part.{part}.parquet" for part in range(1)], |
|
"typescript": [f"data/train/TypeScript/part.{part}.parquet" for part in range(4)], |
|
"verilog": [f"data/train/Verilog/part.{part}.parquet" for part in range(1)], |
|
"visual_basic": [f"data/train/Visual%20Basic/part.{part}.parquet" for part in range(1)], |
|
"xml": [f"data/train/XML/part.{part}.parquet" for part in range(10)], |
|
"yaml": [f"data/train/YAML/part.{part}.parquet" for part in range(4)], |
|
"none": [f"data/train/None/part.{part}.parquet" for part in range(1)], |
|
|
|
}, |
|
"dev": "data/validation.parquet", |
|
"test": "data/test.parquet", |
|
} |
|
|
|
|
|
_URLS["train"]["all"] = [url for urls in _URLS["train"].values() for url in urls] |
|
|
|
|
|
|
|
|
|
class ThePileGithub(datasets.GeneratorBasedBuilder): |
|
"""The Pile GitHub Dataset.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="all", version=VERSION, description="All programing languages"), |
|
|
|
datasets.BuilderConfig(name="assembly", version=VERSION, description="All Assembly languages"), |
|
datasets.BuilderConfig(name="batchfile", version=VERSION, description="All Batchfile languages"), |
|
datasets.BuilderConfig(name="c", version=VERSION, description="All C languages"), |
|
datasets.BuilderConfig(name="c#", version=VERSION, description="All C# languages"), |
|
datasets.BuilderConfig(name="c++", version=VERSION, description="All C++ languages"), |
|
datasets.BuilderConfig(name="clojure", version=VERSION, description="All Clojure languages"), |
|
datasets.BuilderConfig(name="cmake", version=VERSION, description="All CMake languages"), |
|
datasets.BuilderConfig(name="cobol", version=VERSION, description="All COBOL languages"), |
|
datasets.BuilderConfig(name="coffeescript", version=VERSION, description="All CoffeeScript languages"), |
|
datasets.BuilderConfig(name="css", version=VERSION, description="All CSS languages"), |
|
datasets.BuilderConfig(name="csv", version=VERSION, description="All CSV languages"), |
|
datasets.BuilderConfig(name="dart", version=VERSION, description="All Dart languages"), |
|
datasets.BuilderConfig(name="dm", version=VERSION, description="All DM languages"), |
|
datasets.BuilderConfig(name="dockerfile", version=VERSION, description="All Dockerfile languages"), |
|
datasets.BuilderConfig(name="elixir", version=VERSION, description="All Elixir languages"), |
|
datasets.BuilderConfig(name="erlang", version=VERSION, description="All Erlang languages"), |
|
datasets.BuilderConfig(name="fortran", version=VERSION, description="All Fortran languages"), |
|
datasets.BuilderConfig(name="go", version=VERSION, description="All Go languages"), |
|
datasets.BuilderConfig(name="groovy", version=VERSION, description="All Groovy languages"), |
|
datasets.BuilderConfig(name="haskell", version=VERSION, description="All Haskell languages"), |
|
datasets.BuilderConfig(name="html", version=VERSION, description="All HTML languages"), |
|
datasets.BuilderConfig(name="ini", version=VERSION, description="All INI languages"), |
|
datasets.BuilderConfig(name="java", version=VERSION, description="All Java languages"), |
|
datasets.BuilderConfig(name="javascript", version=VERSION, description="All JavaScript languages"), |
|
datasets.BuilderConfig(name="json", version=VERSION, description="All JSON languages"), |
|
datasets.BuilderConfig(name="julia", version=VERSION, description="All Julia languages"), |
|
datasets.BuilderConfig(name="kotlin", version=VERSION, description="All Kotlin languages"), |
|
datasets.BuilderConfig(name="lisp", version=VERSION, description="All Lisp languages"), |
|
datasets.BuilderConfig(name="lua", version=VERSION, description="All Lua languages"), |
|
datasets.BuilderConfig(name="makefile", version=VERSION, description="All Makefile languages"), |
|
datasets.BuilderConfig(name="markdown", version=VERSION, description="All Markdown languages"), |
|
datasets.BuilderConfig(name="matlab", version=VERSION, description="All Matlab languages"), |
|
datasets.BuilderConfig(name="objective-c", version=VERSION, description="All Objective-C languages"), |
|
datasets.BuilderConfig(name="ocaml", version=VERSION, description="All Objective OCaml languages"), |
|
datasets.BuilderConfig(name="pascal", version=VERSION, description="All Pascal languages"), |
|
datasets.BuilderConfig(name="perl", version=VERSION, description="All Perl languages"), |
|
datasets.BuilderConfig(name="php", version=VERSION, description="All PHP languages"), |
|
datasets.BuilderConfig(name="powershell", version=VERSION, description="All PowerShell languages"), |
|
datasets.BuilderConfig(name="prolog", version=VERSION, description="All Prolog languages"), |
|
datasets.BuilderConfig(name="python", version=VERSION, description="All Python languages"), |
|
datasets.BuilderConfig(name="r", version=VERSION, description="All R languages"), |
|
datasets.BuilderConfig(name="ruby", version=VERSION, description="All Ruby languages"), |
|
datasets.BuilderConfig(name="rust", version=VERSION, description="All Rust languages"), |
|
datasets.BuilderConfig(name="scala", version=VERSION, description="All Scala languages"), |
|
datasets.BuilderConfig(name="shell", version=VERSION, description="All Shell languages"), |
|
datasets.BuilderConfig(name="sql", version=VERSION, description="All SQL languages"), |
|
datasets.BuilderConfig(name="swift", version=VERSION, description="All Swift languages"), |
|
datasets.BuilderConfig(name="tex", version=VERSION, description="All TeX languages"), |
|
datasets.BuilderConfig(name="toml", version=VERSION, description="All TOML languages"), |
|
datasets.BuilderConfig(name="typescript", version=VERSION, description="All TypeScript languages"), |
|
datasets.BuilderConfig(name="verilog", version=VERSION, description="All Verilog languages"), |
|
datasets.BuilderConfig(name="visual_basic", version=VERSION, description="All Visual Visual Basic languages"), |
|
datasets.BuilderConfig(name="xml", version=VERSION, description="All XML languages"), |
|
datasets.BuilderConfig(name="yaml", version=VERSION, description="All YAML languages"), |
|
datasets.BuilderConfig(name="none", version=VERSION, description="Undefined languages"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "all" |
|
|
|
def _info(self): |
|
|
|
|
|
features = datasets.Features( |
|
{ |
|
"text": datasets.Value("string"), |
|
"meta": {'language': datasets.Value('string')}, |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
|
|
|
|
|
|
|
|
train_urls = _URLS["train"][self.config.name] |
|
train_files = dl_manager.download_and_extract(train_urls) |
|
dev_file = dl_manager.download_and_extract(_URLS["dev"]) |
|
test_file = dl_manager.download_and_extract(_URLS["test"]) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"split_key": "train", "files": train_files}), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"split_key": "validation", "files": [dev_file]}), |
|
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"split_key": "test", "files": [test_file]}), |
|
] |
|
|
|
|
|
def _generate_examples(self, split_key, files): |
|
"""Yields examples.""" |
|
|
|
|
|
|
|
key = 0 |
|
for path in files: |
|
df = pd.read_parquet(path) |
|
|
|
for row in df.itertuples(): |
|
|
|
if split_key == "train": |
|
yield key, { |
|
"text": row.text, |
|
"meta": row.meta, |
|
} |
|
|
|
elif split_key in ["validation", "test"]: |
|
if self.config.name == "all": |
|
yield key, { |
|
"text": row.text, |
|
"meta": row.meta, |
|
} |
|
else: |
|
language = str(row.meta["language"]).lower().replace(" ", "_") |
|
if language == self.config.name: |
|
yield key, { |
|
"text": row.text, |
|
"meta": row.meta, |
|
} |
|
else: |
|
continue |
|
key += 1 |