Datasets:
File size: 16,630 Bytes
7c3a4b1 8e4e6a1 7c3a4b1 2a4b729 57a2140 d0b4fad 70c602f d0b4fad 57a2140 70c602f 57a2140 70c602f 57a2140 d0b4fad 57a2140 d0b4fad 57a2140 70c602f f8b11c5 d0b4fad 57a2140 b84e667 d0b4fad b84e667 d0b4fad b84e667 d0b4fad f8b11c5 d0b4fad 57a2140 2a4b729 7c3a4b1 6bd6694 2a4b729 6bd6694 7c3a4b1 57a2140 b84e667 57a2140 b84e667 57a2140 b84e667 57a2140 b84e667 57a2140 b84e667 57a2140 b84e667 57a2140 b84e667 57a2140 b84e667 57a2140 b84e667 57a2140 b84e667 57a2140 04b336b 7c3a4b1 8e4e6a1 7c3a4b1 2a4b729 8e4e6a1 7c3a4b1 2a4b729 8e4e6a1 7c3a4b1 2a4b729 7c3a4b1 def2b41 6029b84 def2b41 2a4b729 57a2140 2a4b729 84b1474 2a4b729 7c3a4b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.
"""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/"
# TODO: Add the license for the dataset here if you can find it
_LICENSE = ""
# Add link to the official dataset URLs here
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
_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",
}
# Add all existing urls to the dict
_URLS["train"]["all"] = [url for urls in _URLS["train"].values() for url in urls]
# Name of the dataset usually match the script name with CamelCase instead of snake_case
class SmartContracts(datasets.GeneratorBasedBuilder):
"""Smart Contracts Dataset."""
VERSION = datasets.Version("1.0.0")
# You will be able to load one or the other configurations in the following list with
# data = datasets.load_dataset('my_dataset', 'all')
# data = datasets.load_dataset('my_dataset', 'plain_text')
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" # It's not mandatory to have a default configuration. Just use one if it make sense.
def _info(self):
# This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
features = datasets.Features(
{
"text": datasets.Value("string"),
"meta": {'language': datasets.Value('string')},
}
)
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features, # Here we define them above because they are different between the two configurations
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
# supervised_keys=("sentence", "label"),
# Homepage of the dataset for documentation
homepage=_HOMEPAGE,
# License for the dataset if available
license=_LICENSE,
# Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager):
# This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
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]}),
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, split_key, files):
"""Yields examples."""
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
#data = pd.read_parquet(filepath)
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(" ", "_") # e.g. "Jupyter Notebook" -> "jupyter_notebook"
if language == self.config.name:
yield key, {
"text": row.text,
"meta": row.meta,
}
else:
continue
key += 1 |