|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""GitHub subset of The Pile.""" |
|
|
|
|
|
import os |
|
import re |
|
import pandas as pd |
|
import datasets |
|
|
|
|
|
_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": { |
|
"batchfile": [f"train/data/Batchfile/part.{part}.parquet" for part in range(3)], |
|
"c#": [f"train/data/C#/part.{part}.parquet" for part in range(10)], |
|
"c++": [f"train/data/C++/part.{part}.parquet" for part in range(15)], |
|
"css": [f"train/data/CSS/part.{part}.parquet" for part in range(3)], |
|
"erlang": [f"train/data/Erlang/part.{part}.parquet" for part in range(1)], |
|
"go": [f"train/data/Go/part.{part}.parquet" for part in range(15)], |
|
"haskell": [f"train/data/Haskell/part.{part}.parquet" for part in range(2)], |
|
"html": [f"train/data/HTML/part.{part}.parquet" for part in range(15)], |
|
"java": [f"train/data/Java/part.{part}.parquet" for part in range(15)], |
|
"javascript": [f"train/data/JavaScript/part.{part}.parquet" for part in range(15)], |
|
"jupyter_notebook": [f"train/data/Jupyter Notebook/part.{part}.parquet" for part in range(2)], |
|
"lua": [f"train/data/Lua/part.{part}.parquet" for part in range(15)], |
|
"markdown": [f"train/data/Markdown/part.{part}.parquet" for part in range(15)], |
|
"matlab": [f"train/data/Matlab/part.{part}.parquet" for part in range(1)], |
|
"objective-c": [f"train/data/Objective-C/part.{part}.parquet" for part in range(5)], |
|
"perl": [f"train/data/Perl/part.{part}.parquet" for part in range(3)], |
|
"php": [f"train/data/PHP/part.{part}.parquet" for part in range(8)], |
|
"powershell": [f"train/data/PowerShell/part.{part}.parquet" for part in range(15)], |
|
"python": [f"train/data/Python/part.{part}.parquet" for part in range(10)], |
|
"r": [f"train/data/R/part.{part}.parquet" for part in range(2)], |
|
"ruby": [f"train/data/Ruby/part.{part}.parquet" for part in range(4)], |
|
"rust": [f"train/data/Rust/part.{part}.parquet" for part in range(2)], |
|
"scala": [f"train/data/Scala/part.{part}.parquet" for part in range(3)], |
|
"shell": [f"train/data/Shell/part.{part}.parquet" for part in range(6)], |
|
"sql": [f"train/data/SQL/part.{part}.parquet" for part in range(4)], |
|
"swift": [f"train/data/Swift/part.{part}.parquet" for part in range(2)], |
|
"tex": [f"train/data/TeX/part.{part}.parquet" for part in range(3)], |
|
"typescript": [f"train/data/TypeScript/part.{part}.parquet" for part in range(6)], |
|
"none": [f"train/data/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 SmartContracts(datasets.GeneratorBasedBuilder): |
|
"""Smart Contracts Dataset.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="all", version=VERSION, description="All programing languages"), |
|
datasets.BuilderConfig(name="batchfile", version=VERSION, description="Batchfile programming language"), |
|
datasets.BuilderConfig(name="c#", version=VERSION, description="C# programming language"), |
|
datasets.BuilderConfig(name="c++", version=VERSION, description="C++ programming language"), |
|
datasets.BuilderConfig(name="css", version=VERSION, description="CSS programming language"), |
|
datasets.BuilderConfig(name="erlang", version=VERSION, description="Erlang programming language"), |
|
datasets.BuilderConfig(name="go", version=VERSION, description="Go programming language"), |
|
datasets.BuilderConfig(name="haskell", version=VERSION, description="Haskell programming language"), |
|
datasets.BuilderConfig(name="html", version=VERSION, description="HTML programming language"), |
|
datasets.BuilderConfig(name="java", version=VERSION, description="Java programming language"), |
|
datasets.BuilderConfig(name="javascript", version=VERSION, description="JavaScript programming language"), |
|
datasets.BuilderConfig(name="jupyter_notebook", version=VERSION, description="Jupyter Notebook programming language"), |
|
datasets.BuilderConfig(name="lua", version=VERSION, description="Lua programming language"), |
|
datasets.BuilderConfig(name="markdown", version=VERSION, description="Markdown programming language"), |
|
datasets.BuilderConfig(name="matlab", version=VERSION, description="Matlab programming language"), |
|
datasets.BuilderConfig(name="none", version=VERSION, description="None programming language"), |
|
datasets.BuilderConfig(name="objective-c", version=VERSION, description="Objective-C programming language"), |
|
datasets.BuilderConfig(name="perl", version=VERSION, description="Perl programming language"), |
|
datasets.BuilderConfig(name="php", version=VERSION, description="PHP programming language"), |
|
datasets.BuilderConfig(name="powershell", version=VERSION, description="PowerShell programming language"), |
|
datasets.BuilderConfig(name="python", version=VERSION, description="Python programming language"), |
|
datasets.BuilderConfig(name="r", version=VERSION, description="R programming language"), |
|
datasets.BuilderConfig(name="ruby", version=VERSION, description="Ruby programming language"), |
|
datasets.BuilderConfig(name="rust", version=VERSION, description="Rust programming language"), |
|
datasets.BuilderConfig(name="scala", version=VERSION, description="Scala programming language"), |
|
datasets.BuilderConfig(name="shell", version=VERSION, description="Shell programming language"), |
|
datasets.BuilderConfig(name="sql", version=VERSION, description="SQL programming language"), |
|
datasets.BuilderConfig(name="swift", version=VERSION, description="Swift programming language"), |
|
datasets.BuilderConfig(name="tex", version=VERSION, description="TeX programming language"), |
|
datasets.BuilderConfig(name="typescript", version=VERSION, description="TypeScript programming language"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "all" |
|
|
|
def _info(self): |
|
|
|
|
|
features = datasets.Features( |
|
{ |
|
"text": datasets.Value("string"), |
|
"meta": datasets.Sequence(feature={'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_files = dl_manager.download_and_extract(_URLS["dev"]) |
|
test_files = 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_files}), |
|
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"split_key": "test", "files": test_files}), |
|
] |
|
|
|
|
|
def _generate_examples(self, split_key, files): |
|
"""Yields examples.""" |
|
|
|
|
|
|
|
|
|
key = 0 |
|
for path in files: |
|
data = pd.read_parquet(path) |
|
|
|
for row in data.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 = row.meta[0]["language"].lower().replace(" ", "_") |
|
if language == self.config.name: |
|
yield key, { |
|
"text": row.text, |
|
"meta": row.meta, |
|
} |
|
else: |
|
continue |
|
key += 1 |