Mir-2002's picture
Update README.md
d2cb6f7 verified
|
raw
history blame
4.19 kB
metadata
task_categories:
  - summarization
  - text-generation
language:
  - en
tags:
  - code
size_categories:
  - 10K<n<100K

Overview

This dataset contains 18,219 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>,
  <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>,
  <line_number> : <The line number of the function, method, or class within the file>,
  <ast_sequence> : <The ast sequence of the raw source code. Scroll down for more info about this>
}

The AST Sequence

A function recursively converts the AST tree into a linear sequence. It uses depth markers (β”œ1>, β””2>, etc.) to show parent-child relationships. It also adds node identifiers by pairing each node type with a meaningful identifier. Furthermore, pruning is also applied to irrelevant and shallow identifiers to denoise the dataset.

Here's an example of how the AST sequence is generated:

Example Code

def calculate_area(radius):
    """
    Calculate the area of a circle.
    
    Parameters:
        radius (float): The radius of the circle
        
    Returns:
        float: The area of the circle
    """
    PI = 3.14159
    area = PI * radius * radius
    return area

Resulting AST Sequence

FunctionDef:calculate_area
β”œ1> args:[radius]
β”œ1> Assign:PI
β”‚ β””2> Constant:
β”œ1> Assign:area
β”‚ β””2> BinOp:
β”‚   β”œ3> BinOp:
β”‚   β”‚ β”œ4> Name:PI
β”‚   β”‚ β””4> Name:radius
β”‚   β””3> Name:radius
β””1> Return:
  β””2> Name:area
  1. The code is parsed via Python's ast module
  2. A method traverses this tree and linearizes the sequence
  3. Each node is then converted to a string with type-identifier keys
  4. Structural relationships are preserved using the depth markers
  5. Denoising of irrelevant and shallow nodes are applied

Preprocessing

The following preprocessing steps were applied:

Text Cleaning

  • Removed comments
  • Filtering unusual/control characters
  • Removed trailing whitespaces
  • Converts all whitespace into a single spaces
  • Removed tags from docstrings

AST Cleaning

  • Removed noise using a custom blacklist
  • Removed abnormally long nodes (>100)
  • Stripped blank AST entries
  • Ensured ASTs start with the proper root nodes (FunctionDef or ClassDef)

Language Filtering

  • Removed non-English documentations
  • Keeps an item if detection fails

Similarity Filtering

  • Removed entries where similarity exceeds threshold (0.7)

Split

  • Dataset was split into a 70/15/15 ratio

Final Statistics

The final statistics of the dataset before and after preprocessing are as follows:

Original Count: 25,480

After Preprocessing: 18,219

Retention Rate: 72%

Average Docstring Length: 272

Average Source Code Length: 1219

Average AST Sequence Length: 91

Type Distribution:

  • Methods: 9,135 (50.1%)
  • Functions: 6,322 (34.7%)
  • Classes: 2, 762 (15.2%)

Top Contributors:

  • pytorch: 4,330 (23.8%)
  • tensorflow: 3,972 (21.8%)
  • django: 1,778 (9.8%)
  • matplotlib: 1,454 (8%)
  • pandas: 903 (5%)