# 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 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/" # 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 = { "Batchfile": { "train": [f"data/Batchfile/train/part.{part}.parquet" for part in range(3)], "dev": [f"data/Batchfile/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Batchfile/test/part.{part}.parquet" for part in range(1)], }, "C#": { "train": [f"data/C#/train/part.{part}.parquet" for part in range(10)], "dev": [f"data/C#/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/C#/test/part.{part}.parquet" for part in range(1)], }, "C++": { "train": [f"data/C++/train/part.{part}.parquet" for part in range(15)], "dev": [f"data/C++/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/C++/test/part.{part}.parquet" for part in range(1)], }, "CSS": { "train": [f"data/CSS/train/part.{part}.parquet" for part in range(3)], "dev": [f"data/CSS/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/CSS/test/part.{part}.parquet" for part in range(1)], }, "Erlang": { "train": [f"data/Erlang/train/part.{part}.parquet" for part in range(1)], "dev": [f"data/Erlang/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Erlang/test/part.{part}.parquet" for part in range(1)], }, "Go": { "train": [f"data/Go/train/part.{part}.parquet" for part in range(15)], "dev": [f"data/Go/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Go/test/part.{part}.parquet" for part in range(1)], }, "Haskell": { "train": [f"data/Haskell/train/part.{part}.parquet" for part in range(2)], "dev": [f"data/Haskell/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Haskell/test/part.{part}.parquet" for part in range(1)], }, "HTML": { "train": [f"data/HTML/train/part.{part}.parquet" for part in range(15)], "dev": [f"data/HTML/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/HTML/test/part.{part}.parquet" for part in range(1)], }, "Java": { "train": [f"data/Java/train/part.{part}.parquet" for part in range(15)], "dev": [f"data/Java/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Java/test/part.{part}.parquet" for part in range(1)], }, "JavaScript": { "train": [f"data/JavaScript/train/part.{part}.parquet" for part in range(15)], "dev": [f"data/JavaScript/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/JavaScript/test/part.{part}.parquet" for part in range(1)], }, "Jupyter Notebook": { "train": [f"data/Jupyter Notebook/train/part.{part}.parquet" for part in range(2)], "dev": [f"data/Jupyter Notebook/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Jupyter Notebook/test/part.{part}.parquet" for part in range(1)], }, "Lua": { "train": [f"data/Lua/train/part.{part}.parquet" for part in range(15)], "dev": [f"data/Lua/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Lua/test/part.{part}.parquet" for part in range(1)], }, "Markdown": { "train": [f"data/Markdown/train/part.{part}.parquet" for part in range(15)], "dev": [f"data/Markdown/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Markdown/test/part.{part}.parquet" for part in range(1)], }, "Matlab": { "train": [f"data/Matlab/train/part.{part}.parquet" for part in range(1)], "dev": [f"data/Matlab/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Matlab/test/part.{part}.parquet" for part in range(1)], }, "None": { "train": [f"data/None/train/part.{part}.parquet" for part in range(1)], "dev": [f"data/None/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/None/test/part.{part}.parquet" for part in range(1)], }, "Objective-C": { "train": [f"data/Objective-C/train/part.{part}.parquet" for part in range(5)], "dev": [f"data/Objective-C/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Objective-C/test/part.{part}.parquet" for part in range(1)], }, "Perl": { "train": [f"data/Perl/train/part.{part}.parquet" for part in range(3)], "dev": [f"data/Perl/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Perl/test/part.{part}.parquet" for part in range(1)], }, "PHP": { "train": [f"data/PHP/train/part.{part}.parquet" for part in range(8)], "dev": [f"data/PHP/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/PHP/test/part.{part}.parquet" for part in range(1)], }, "PowerShell": { "train": [f"data/PowerShell/train/part.{part}.parquet" for part in range(15)], "dev": [f"data/PowerShell/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/PowerShell/test/part.{part}.parquet" for part in range(1)], }, "Python": { "train": [f"data/Python/train/part.{part}.parquet" for part in range(10)], "dev": [f"data/Python/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Python/test/part.{part}.parquet" for part in range(1)], }, "R": { "train": [f"data/R/train/part.{part}.parquet" for part in range(2)], "dev": [f"data/R/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/R/test/part.{part}.parquet" for part in range(1)], }, "Ruby": { "train": [f"data/Ruby/train/part.{part}.parquet" for part in range(4)], "dev": [f"data/Ruby/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Ruby/test/part.{part}.parquet" for part in range(1)], }, "Rust": { "train": [f"data/Rust/train/part.{part}.parquet" for part in range(2)], "dev": [f"data/Rust/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Rust/test/part.{part}.parquet" for part in range(1)], }, "Scala": { "train": [f"data/Scala/train/part.{part}.parquet" for part in range(3)], "dev": [f"data/Scala/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Scala/test/part.{part}.parquet" for part in range(1)], }, "Shell": { "train": [f"data/Shell/train/part.{part}.parquet" for part in range(6)], "dev": [f"data/Shell/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Shell/test/part.{part}.parquet" for part in range(1)], }, "SQL": { "train": [f"data/SQL/train/part.{part}.parquet" for part in range(4)], "dev": [f"data/SQL/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/SQL/test/part.{part}.parquet" for part in range(1)], }, "Swift": { "train": [f"data/Swift/train/part.{part}.parquet" for part in range(2)], "dev": [f"data/Swift/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/Swift/test/part.{part}.parquet" for part in range(1)], }, "TeX": { "train": [f"data/TeX/train/part.{part}.parquet" for part in range(3)], "dev": [f"data/TeX/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/TeX/test/part.{part}.parquet" for part in range(1)], }, "TypeScript": { "train": [f"data/TypeScript/train/part.{part}.parquet" for part in range(6)], "dev": [f"data/TypeScript/validation/part.{part}.parquet" for part in range(1)], "test": [f"data/TypeScript/test/part.{part}.parquet" for part in range(1)], }, } # Add all existing urls to the dict _URLS["all"] = {split: sum([_URLS[lang][split] for lang in _URLS.keys()], []) for split in ["train", "dev", "test"]} # 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="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" # 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": datasets.Sequence(feature={'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 urls = _URLS[self.config.name] downloaded_files = dl_manager.download_and_extract(urls) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"files": downloaded_files["train"]}), #datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"files": downloaded_files["dev"]}), # TODO: add validation set #datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"files": downloaded_files["test"]}), # TODO: add test set ] # method parameters are unpacked from `gen_kwargs` as given in `_split_generators` def _generate_examples(self, 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: data = pd.read_parquet(path) for row in data.itertuples(): # Yields examples as (key, example) tuples yield key, { "text": row.text, "meta": row.meta, } key += 1