Code4ML: a large-scale dataset of annotated Machine Learning code

Anastasia Drozdova, Ekaterina Trofimova, Polina Guseva, Anna Scherbakova, Andrey Ustyuzhanin

TL;DR

This paper introduces Code4ML, a massive dataset of ~2.5 million Python code snippets from Kaggle notebooks, annotated with semantic ML task descriptions. This resource aims to bridge the gap in annotated code for machine learning, enabling better development of tools for tasks like code classification, synthesis, and auto-completion.

What Problem Does This Paper Address?

The increasing use of machine learning (ML) in software development, including code analysis and generation, is hampered by a lack of large-scale, annotated code datasets. While existing code datasets exist, they often lack domain-specific annotations crucial for training ML models on specialized tasks like building ML pipelines. This is particularly true for ML code itself, where a comprehensive, annotated corpus is needed to advance research in areas like semantic code classification, code generation from natural language descriptions, and code auto-completion.

Methods

The core contribution is the creation of the Code4ML dataset. The authors collected ~2.5 million Python code snippets from ~100,000 Kaggle notebooks. To structure and annotate this data, they developed a "Machine Learning Taxonomy Tree" with two levels: high-level ML pipeline steps and more specific "semantic types." This taxonomy, inspired by data science standards like CRISP-DM, provides a consistent way to categorize code blocks. They also built a user-friendly web interface for human assessors to manually annotate code snippets, assigning them to semantic classes and providing a confidence score. For automatic labeling, they explored SVM models with various kernels and pseudo-labeling techniques.

Datasets

  • Code4ML Corpus: The primary dataset introduced in this paper. It comprises:
  • ~2.5 million Python code snippets from Kaggle notebooks.
  • Metadata for ~107,524 Kaggle notebooks.
  • Information on ~400 Kaggle competitions, including natural language descriptions.
  • Annotated code snippets (initially ~8,000 unique snippets with high confidence).
  • Existing Datasets Mentioned:
    • Boa: Python files and metadata from GitHub projects.
  • JuICe: Jupyter notebooks for programming assignments with natural language descriptions.
  • KGTorrent: Snapshot of Kaggle artifacts (notebooks, descriptions, discussions).
  • CodeNet, POLYCODER: Multi-language code datasets.
  • PY150, CONCODE, Spider: Single-language code datasets.
  • CodeSearchNet, Stack Overflow: Sources for code snippets.

Key Insights and Ideas

  • The Power of Structured Annotation: The ML Taxonomy Tree is a key innovation, providing a standardized way to break down complex ML pipelines into manageable, semantically meaningful code components. This structured approach is more robust than relying solely on natural language descriptions.
  • Kaggle as a Rich Source: Kaggle's platform, with its competitive nature and emphasis on sharing solutions, provides a fertile ground for collecting real-world ML code and associated metadata.
  • Bridging the Gap for Code Generation: The combination of competition descriptions and annotated code snippets in Code4ML is crucial for training models that can generate ML code from natural language prompts, a significant challenge in current AI research.
  • Human-in-the-Loop for Quality: The emphasis on manual annotation with confidence scores and the development of a web application for volunteers highlight the importance of human expertise in creating high-quality datasets for complex tasks.

Key Results

  • The Code4ML dataset contains approximately 2.5 million Python code snippets.
  • A subset of ~8,000 unique snippets were manually annotated with high confidence (around 68% received a confidence score of 5).
  • Baseline SVM models trained on the manually labeled data achieved F1-scores up to 0.872 and accuracies up to 0.872 when using 100% pseudo-labels.

Limitations and Future Work

  • Corpus Bias: The dataset, derived from Kaggle, may be biased towards certain types of ML problems (e.g., tabular data) and programming languages, potentially limiting its generalizability to other data science tasks.
  • Annotation Quality Variability: While efforts were made to ensure annotation quality, variations can still exist. The authors mitigate this by providing confidence scores and flagging "too long" snippets that are ambiguous.
  • Limited Manual Annotation: Currently, only a fraction of the dataset has been manually labeled.
  • Future Work: The authors suggest extending the dataset to cover more Kaggle ML snippets and encourage community contributions through their developed web application. They also envision Code4ML being used for code classification, segmentation, generation, and advancing AutoML research.

Summary updated

BibTeX
@article{drozdova2023code,
  author = {Anastasia Drozdova and Ekaterina Trofimova and Polina Guseva and Anna Scherbakova and Andrey Ustyuzhanin},
  title = {{Code4ML: a large-scale dataset of annotated Machine Learning code}},
  journal = {Peerj Comput. sci},
  year = {2023},
  doi = {10.7717/peerj-cs.1230},
}
Figure