dimsmauls's picture
Add training CSV (3,063 instruction-code pairs) and document it
97a30ea verified
|
Raw History Blame Contribute Delete
7.91 kB
metadata
license: cc-by-4.0
pretty_name: Code4ML Annotated Subset with SonarQube and MLScent Ratings
language:
  - en
tags:
  - code
  - python
  - machine-learning
  - code4ml
  - kaggle
  - code-quality
  - static-analysis
  - sonarqube
task_categories:
  - text-generation
  - text-classification
size_categories:
  - 1K<n<10K
configs:
  - config_name: default
    data_files:
      - split: train
        path: code4ml_annotated.csv
  - config_name: training
    data_files:
      - split: train
        path: code4ml_annotated_training.csv

Code4ML Annotated Subset with SonarQube and MLScent Ratings

The 7,947 manually annotated Python snippets from the Code4ML corpus (Zenodo record 7312803), joined with their task-class names and annotated with structural code-quality ratings from SonarQube and MLScent.

Code4ML contains 2,599,355 code cells from 23,103 Kaggle notebooks. Only this annotated subset carries a human-assigned task label, so it is the subset usable for building instruction–code pairs. This repository holds that subset in one file. Each snippet was scanned on its own, so the ratings describe the snippet, not its whole notebook.

Dataset summary

Records 7,947
Source file Code4ML markup_data.csv, labels from vertices.csv
Task classes 12 classes, 70 subclasses
Format single comma-delimited CSV with header
Language Python

Columns

column type description
id int row index from Code4ML markup_data.csv
code_block string the Python snippet (one notebook cell, may span multiple lines)
too_long string Yes/No flag from the Code4ML annotators
marks int annotator confidence, 1 (lowest) to 5 (highest)
graph_vertex_id int task-label id from Code4ML vertices.csv
graph_vertex_class string task class, e.g. Data_Transform, Model_Train
graph_vertex_subclass string task subclass, e.g. choose_model_class
kernel_id int or empty Kaggle notebook id, recovered by matching code_block text against Code4ML code_blocks.csv; empty when the text appears in more than one notebook or none
sqale_rating float SonarQube SQALE rating (1.0 = A … 5.0 = E)
maintainability_rating string SonarQube maintainability grade A–E
code_smells int SonarQube code smells
complexity int SonarQube cyclomatic complexity
cognitive_complexity int SonarQube cognitive complexity
bugs int SonarQube bugs
sqale_index int SonarQube technical debt (minutes)
ncloc int or empty non-comment lines of code; empty when SonarQube did not analyse the snippet
mlscent_analysis_status string ok, no_ml_import (no ML library import in the snippet or its recovered notebook imports), or invalid_python
mlscent_smell_count int number of MLScent findings
mlscent_unique_smell_count int number of distinct MLScent smell types
mlscent_findings_json JSON string all MLScent findings
mlscent_ml_rating string A–E from ML-specific findings only, by severity; N/A when MLScent did not analyse the snippet
mlscent_ml_rating_basis string findings and severities behind mlscent_ml_rating
mlscent_ml_findings_json JSON string ML-specific findings used for the rating
mlscent_ignored_findings_json JSON string finding types not used for the rating
context_line_count int lines of recovered notebook ML imports prepended for MLScent analysis
combined_rating string worse of maintainability_rating and mlscent_ml_rating; N/A when either is missing

Statistics

Task classes:

graph_vertex_class Snippets
Data_Transform 2,387
Debug 1,446
Visualization 862
Model_Train 816
Data_Extraction 517
Environment 441
Other 372
Model_Evaluation 354
Data_Export 350
EDA 231
Hyperparam_Tuning 160
Model_Interpretation 11

Annotator confidence (marks):

1 2 3 4 5
44 210 903 1,419 5,371

Other properties:

Property Value
too_long = Yes 1,360
Duplicate code_block values 108
Lines per snippet (median / p75 / max) 2 / 6 / 582

Ratings:

Rating maintainability_rating mlscent_ml_rating combined_rating
A 7,816 3,045 2,996
B 84 952 962
C 40 56 89
D 7 111 117
E 0 8 8
N/A — 3,775 3,775
Rating property Value
kernel_id recovered 4,373
ncloc empty (not analysed by SonarQube) 1,003
mlscent_analysis_status = ok / no_ml_import / invalid_python 4,172 / 3,551 / 224

No rows were removed or modified; duplicates and short snippets are kept as in the source.

How the ratings were produced

  1. SonarQube Community Edition, default Python profile, through a FastAPI wrapper around sonar-scanner (/scan-batch).
  2. MLScent (ml-code-smell-detector==0.1.2), with recovered notebook ML imports prepended as context, through a local rating service (/rate-batch).
  3. The data was split into two halves, each rated by its own SonarQube + MLScent instance pair, then merged back by id.

Training file

code4ml_annotated_training.csv holds 3,063 instruction–code pairs built from code4ml_annotated.csv for fine-tuning:

Step Rule Rows dropped
1 Drop task classes without ML logic: Debug, Environment, Other 2,259
2 Drop combined_rating = N/A 2,502
2 Drop combined_rating = D or E (quality floor) 121
3 Drop duplicate code_block 0
4 Turn the subclass label into an instruction, e.g. train_model → "Write Python code to train the model." —
5 Drop snippets whose 8-grams overlap a DS-1000 reference solution by ≥ 50% 2
6 Split 80/10/10 per task class with seed 42 —
Column Description
id row id in code4ml_annotated.csv
split train (2,451), validation (308), or test (304)
graph_vertex_class, graph_vertex_subclass Code4ML task label
instruction instruction sentence built from the subclass label
code the snippet
combined_rating A (2,122), B (868), or C (73)

Usage

from datasets import load_dataset

ds = load_dataset("dimsmauls/code4ml-annotated-rated", split="train")
print(ds[0]["graph_vertex_class"], ds[0]["combined_rating"], ds[0]["code_block"])

train = load_dataset("dimsmauls/code4ml-annotated-rated", "training", split="train")
train_set = train.filter(lambda row: row["split"] == "train")

Provenance & attribution

  • Source corpus: Code4ML, Zenodo record 7312803, released under CC-BY-4.0.
  • Original code: the snippets are Kaggle notebook cells, each published under the Apache-2.0 license. See NOTICE.txt.
  • This derivative joins markup_data.csv with the class names from vertices.csv and adds SonarQube and MLScent rating columns. No code was changed.

Citation

Please cite the original Code4ML work:

@article{drozdova2023code4ml,
  title={Code4ML: a Large-scale Dataset of Annotated Machine Learning Code},
  author={Drozdova, Anastasia and Trofimova, Ekaterina and Guseva, Polina and Scherbakova, Anna and Ustyuzhanin, Andrey},
  journal={PeerJ Computer Science},
  year={2023},
  doi={10.7717/peerj-cs.1230}
}

License

Released under CC-BY-4.0, the same license as Code4ML. The underlying code_block snippets are Kaggle notebook code under Apache-2.0; that attribution is preserved in NOTICE.txt.