Mir-2002's picture
Update README.md
d53ce63 verified
metadata
task_categories:
  - summarization
  - text-generation
language:
  - en
tags:
  - code
size_categories:
  - 10K<n<100K

Overview

This dataset contains 34,000+ rows of code-docstring-ast data along with additional metadata. Data was gathered from various Python libraries and frameworks and their publicly available GitHub repos. This dataset was created for the purpose of training the CodeT5+ transformer on AST-enhanced code-to-doc tasks.

Sources

The dataset was gathered from various GitHub repos sampled from this repo by Vinta.

The 26 repos are:

  • matplotlib
  • pytorch
  • cryptography
  • django
  • prospector
  • scikit-learn
  • pandas
  • numpy
  • uvicorn
  • feincms
  • algorithms
  • scrapy
  • authlib
  • seaborn
  • coconut
  • tensorflow
  • flexx
  • salmon
  • mongo-python-driver
  • virtualenv
  • sphinx
  • schema
  • kornia
  • scipy
  • cherrypy
  • pygame

Sampling was at random; I simply browsed through each category from Vinta's list and chose one from a random interesting category.

Dataset Instance

An instance of the dataset is as follows:

{
  <library> : <The library from which the source code came from>,
  <name> : <The name of the function/class/method>,
  <source_code> : <The raw source code itself stripped of its docstrings and comments>,
  <docstring> : <The corresponding docstring of the code>,
  <type> : <Whether it's a function, method, or class>,
  <file_path> : <The relative path of the file containing the function>,
  <ast_data> : <A flattened representation of the parsed AST. For more info about this, see section below>
}

The AST Data

An extractor only focuses on specific nodes relevant for docstring generation denoted by this set:

KEEP_NODES = {
        'FunctionDef', 'AsyncFunctionDef', 'ClassDef',
        'arguments', 'arg', 'Return',
        'If', 'For', 'While', 'Try', 'With',
        'Assign', 'Call',
        'Raise', 'ExceptHandler',
        'decorator', 'bases',
        'Compare', 'BoolOp'
    }

Everything else is discarded. For example

Source Code

def tox_append_version_info() -> str: return '[toxfile]'

Resulting AST Dictionary

"ast_data": {
      "type": "FunctionDef",
      "children": [
        {
          "type": "arguments",
          "args": []
        },
        {
          "type": "Return",
          "has_value": true
        }
      ],
      "name": "tox_append_version_info"
    }

This dictionary is then flattened via a helper function which would then look something like FunctionDef name:tox_append_version_info arguments Return return:yes.

Preprocessing

The dataset generally follows CodeBERT's code2nl dataset cleaning standards which are as follows:

  • Removed comments from the code
  • Removed examples where code cannot be parsed into an AST
  • Remove examples that documents contain special tokens (e.g. <img ...> or https:...)
  • Remove examples that documents are not English

Furthermore, the following cleaning steps specific to this dataset were applied:

  • Removed examples where, using CodeT5+'s tokenizer, the combined tokens of the source_code + ast_data is > 512
  • Removed examples where, using CodeT5+'s tokenizer, the docstrings are > 512

Final Statistics

{
  "original_samples": 128880,
  "processed_samples": 34537,
  "filter_stats": {
    "success": 34537,
    "non_english": 1202,
    "docstring_too_long": 3848,
    "input_too_long": 8366,
    "docstring_too_short": 74013,
    "error": 0,
    "error: unhashable type: 'list'": 6914
  },
  "split_sizes": {
    "train": 24175,
    "val": 5180,
    "test": 5182
  },
  "input_token_stats": {
    "min": 16,
    "max": 505,
    "avg": 164.071
  },
  "target_token_stats": {
    "min": 4,
    "max": 254,
    "avg": 52.758
  },
  "type_distribution": {
    "method": 12682,
    "function": 8733,
    "class": 2760
  }
}

NOTE

This dataset is imperfect. Use under your own volition.