|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""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"data/train/Batchfile/part.{part}.parquet" for part in range(3)], |
|
"c#": [f"data/train/C#/part.{part}.parquet" for part in range(10)], |
|
"c++": [f"data/train/C++/part.{part}.parquet" for part in range(15)], |
|
"css": [f"data/train/CSS/part.{part}.parquet" for part in range(3)], |
|
"erlang": [f"data/train/Erlang/part.{part}.parquet" for part in range(1)], |
|
"go": [f"data/train/Go/part.{part}.parquet" for part in range(15)], |
|
"haskell": [f"data/train/Haskell/part.{part}.parquet" for part in range(2)], |
|
"html": [f"data/train/HTML/part.{part}.parquet" for part in range(15)], |
|
"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(15)], |
|
"jupyter_notebook": [f"data/train/Jupyter Notebook/part.{part}.parquet" for part in range(2)], |
|
"lua": [f"data/train/Lua/part.{part}.parquet" for part in range(15)], |
|
"markdown": [f"data/train/Markdown/part.{part}.parquet" for part in range(15)], |
|
"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)], |
|
"perl": [f"data/train/Perl/part.{part}.parquet" for part in range(3)], |
|
"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(15)], |
|
"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(2)], |
|
"ruby": [f"data/train/Ruby/part.{part}.parquet" for part in range(4)], |
|
"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(3)], |
|
"shell": [f"data/train/Shell/part.{part}.parquet" for part in range(6)], |
|
"sql": [f"data/train/SQL/part.{part}.parquet" for part in range(4)], |
|
"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(3)], |
|
"typescript": [f"data/train/TypeScript/part.{part}.parquet" for part in range(6)], |
|
"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 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 |