github-code / README.md
lvwerra's picture
lvwerra HF staff
update documentation
af403e5
|
raw
history blame
5.67 kB
metadata
annotations_creators: []
language_creators:
  - crowdsourced
  - expert-generated
languages: []
licenses:
  - other-multiple
multilinguality:
  - multilingual
pretty_name: github-code
size_categories:
  - unknown
source_datasets: []
task_categories:
  - sequence-modeling
task_ids:
  - language-modeling

GitHub Code Dataset

Dataset Description

The GitHub Code dataest consists of 115M code files from GitHub in 32 programming languages with 60 extensions totalling in 1TB of text data. The dataset was created from the public GitHub dataset on Google BiqQuery.

How to use it

The GitHub Code dataset is a very large dataset so for most use cases it is recommended to make use of the streaming API of datasets. You can load and iterate through the dataset with the following two lines of code:

from datasets import load_dataset

ds = load_dataset("lvwerra/github-code", streaming=True, split="train")
print(next(iter(ds)))

#OUTPUT:
{
 'code': "import mod189 from './mod189';\nvar value=mod189+1;\nexport default value;\n",
 'repo_name': 'MirekSz/webpack-es6-ts',
 'path': 'app/mods/mod190.js',
 'language': 'JavaScript',
 'license': 'isc',
 'size': 73
}

You can see that besides the code, repo name, and path also the programming language, license, and the size of the file are part of the dataset. You can also filter the dataset for any subset of the 30 included languages (see the full list below) in the dataset. Just pass the list of languages as a list. E.g. if your dream is to build a Codex model for Dockerfiles use the following configuration:

ds = load_dataset("lvwerra/github-code", streaming=True, split="train", languages=["Dockerfile"])
print(next(iter(ds))["code"])

#OUTPUT:
"""\
FROM rockyluke/ubuntu:precise

ENV DEBIAN_FRONTEND="noninteractive" \
    TZ="Europe/Amsterdam"
...
"""

We also have access to the license of the origin repo of a file so we can filter for licenses in the same way we filtered for languages:

ds = load_dataset("lvwerra/github-code", streaming=True, split="train", licenses=["mit", "isc"])

licenses = []
for element in iter(ds).take(10_000):
    licenses.append(element["license"])
print(Counter(licenses))

#OUTPUT:
Counter({'mit': 9896, 'isc': 104})

Naturally, you can also download the full dataset. Note that this will download ~300GB compressed text data and the uncompressed dataset will take up ~1TB of storage:

ds = load_dataset("lvwerra/github-code", split="train")

Data Structure

Data Instances

{
 'code': "import mod189 from './mod189';\nvar value=mod189+1;\nexport default value;\n",
 'repo_name': 'MirekSz/webpack-es6-ts',
 'path': 'app/mods/mod190.js',
 'language': 'JavaScript',
 'license': 'isc',
 'size': 73
}

Data Fields

Field Type Description
code string content of source file
repo_name string name of the GitHub repository
path string path of file in GitHub repository
language string programming language as inferred by extension
license string license of GitHub repository
size int size of source file in bytes

Data Splits

The dataset only contains a train split.

Languages

The dataset contains 30 programming languages with over 60 extensions:

{
    "Assembly": [".asm"],
    "Batchfile": [".bat", ".cmd"],
    "C": [".c", ".h"],
    "C#": [".cs"],
    "C++": [".cpp", ".hpp", ".c++", ".h++", ".cc", ".hh", ".C", ".H"],
    "CMake": [".cmake"],
    "CSS": [".css"],
    "Dockerfile": [".dockerfile", "Dockerfile"],
    "FORTRAN": ['.f90', '.f', '.f03', '.f08', '.f77', '.f95', '.for', '.fpp'],
    "GO": [".go"],
    "Haskell": [".hs"],
    "HTML":[".html"],
    "Java": [".java"],
    "JavaScript": [".js"],
    "Julia": [".jl"],
    "Lua": [".lua"],
    "Makefile": ["Makefile"],
    "Markdown": [".md", ".markdown"],
    "PHP": [".php", ".php3", ".php4", ".php5", ".phps", ".phpt"],
    "Perl": [".pl", ".pm", ".pod", ".perl"],
    "PowerShell": ['.ps1', '.psd1', '.psm1'],
    "Python": [".py"],
    "Ruby": [".rb"],
    "Rust": [".rs"],
    "SQL": [".sql"],
    "Scala": [".scala"],
    "Shell": [".sh", ".bash", ".command", ".zsh"],
    "TypeScript": [".ts", ".tsx"],
    "TeX": [".tex"],
    "Visual Basic": [".vb"]
}

Licenses

Each example is also annotated with the license of the associated repository. There are in total 15 licenses:

[
  'mit',
  'apache-2.0',
  'gpl-3.0',
  'gpl-2.0',
  'bsd-3-clause',
  'agpl-3.0',
  'lgpl-3.0',
  'lgpl-2.1',
  'bsd-2-clause',
  'cc0-1.0',
  'epl-1.0',
  'mpl-2.0',
  'unlicense',
  'isc',
  'artistic-2.0'
 ]

Dataset Creation

The dataset was created in two steps:

  1. Files of with the extensions given in the list above were retrieved from the GitHub dataset on BigQuery (full query here). The query was executed on Feb 14, 2022, 12:03:16 PM UTC+1.
  2. Files with lines longer than 1000 characters and duplicates (exact duplicates ignoring whitespaces) were dropped (full preprocessing script here).

Considerations for Using the Data

The dataset consists of source code from a wide range of repositories. As such they can potentially include harmful or biased code as well as sensitive information like passwords or usernames.

Releases

v1.0

  • Initial release of dataset
  • The query was executed on Feb 14, 2022, 12:03:16 PM UTC+1

v1.1

  • Fix missing Scala/TypeScript
  • Fix deduplication issue with inconsistent Python hash
  • The query was executed on Mar 16, 2022, 6:23:39 PM UTC+1