Skip to content

Bearwick/GenAI-GreenML

Repository files navigation

GenAI-GreenML

GenAI-GreenML is an open-source dataset consisting of curated machine learning repositories collected for research on generative artificial intelligence and sustainable machine learning development. The dataset includes 50 small-scale (<500 MB) GitHub projects focused on tabular and natural language processing (NLP) tasks. Each repository contains both source code and datasets that enable reproducible experiments on model performance, energy consumption, and green coding practices.

This dataset was developed as part of a master’s thesis at the Norwegian University of Science and Technology (NTNU), investigating how large language models (LLMs) can be utilised in producing more energy-efficient machine learning code.

Table of Contents

  1. Repository Information
    1. Repository Content
    2. Intended Use
    3. Citation
    4. Video Code Walkthrough
  2. Experiment Pipeline
  3. Adding ML Projects
  4. Environment Variables Setup
  5. Adding LLMs
    1. Free LLM API
  6. Generate LLM Code
    1. Delete Old Generated Code
    2. Runability Check
  7. Run Projects and Capture Telemetry
  8. Analyse Results
    1. Analyse File Sizes
  9. Generate Code Iterations (Failed Scripts)
  10. Analyse Failed Code
  11. Analyse Errors
  12. Generate Code Differences
  13. Analyse Code Complexity (SonarQube)

Repository Information

Repository Content

  • 50 open-source ML repositories (tabular and NLP tasks)
  • Metadata on repository size, task type, and primary programming language
  • Experiment design and evaluation scripts for code generated by LLMs
  • Benchmarking tools for predictive performance, execution time, energy consumption, robustness, and cyclomatic complexity

Intended Use

The dataset supports reproducible research on:

  • LLM-based code generation and refactoring
  • Sustainable and energy-aware machine learning practices
  • Comparative benchmarking of original vs. AI-generated (assisted and autonomous) implementations

Citation

If you use this dataset in academic work, please cite it as:

Bjørnevik, E. (2025). GenAI-GreenML: A Dataset for Evaluating Generative AI in Green Machine Learning Code. NTNU, Department of Computer Science.

Video Code Walkthrough

Watch video here.

Experiment Pipeline

The overall experiment pipeline is illustrated in the figure below. The following sections describe the individual scripts and stages included in the pipeline.

Experiment Pipeline

The experiment evaluates three different implementation conditions:

  • Original: Human-written machine learning implementations collected from GitHub repositories
  • Assisted: LLM-generated refactoring based on the original implementation and additional optimisation instructions.
  • Autonomous: Fully LLM-generated implementations created from repository context and task descriptions without access to the original implementation

To ensure consistent and reproducible execution across all conditions, the original human-written scripts required minor standardisation changes before inclusion in the experiment pipeline. These modifications were intentionally minimal and designed to preserve the original functionality while enabling automated execution and telemetry collection. Typical changes included ensuring accuracy were explicitly printed to stdout, removing interactive inputs, removing visualisations and plotting functionality, and disabling file-writing and model persistence operations. The figure below illustrates the information provided to the LLM in each prompting condition.

Experiment Prompts

Adding ML Projects

To add a new ML project run the following from project root:

./scripts/import_repo.sh <repo_url>

If the repository includes multiple python files, rename the correct file to original.py

Environment Variables Setup

Run from repo root to create API.env:

cat <<'EOF' > API.env
# Gemini
GEMINI_API_KEY=

# OpenAI (ChatGPT/Codex)
OPENAI_API_KEY=

# Claude
export ANTHROPIC_API_KEY=

# Groq
export GROQ_API_KEY=
EOF

Add your API keys and source API.env:

source API.env

Adding LLMs

Add LLM APIs in scripts/APIs and make sure the module expose:
generate_code(mode, source_code, dataset_headers="", exampleRowDataset="", datasetPath="", projectContext="") -> str

Then in generate_llm_code.py:

  1. Update DEFAULT_ALL_LLMS on line 75 with the LLM name.

  2. Register the module at the bottom of the function load_llm_clients.
    Add a line in the registry section starting on line 509:
    registry["newllm"] = _try_load("newllm", "newllm_api")

Finally, add API key to API.env and source from project root:

source API.env

Free LLM Groq

Groq is a free LLM API but is currenlty commented out because of not satisfactory performance. If wanted, uncomment where 'groq' appears in generate_llm_code.py.

Generate LLM Code

To generate LLM code using the ML projects in repos, run the following from project root:

cd scripts
source venv/bin/activate
python ./generate_llm_code.py
deactivate
cd ..

CLI Flags

CLI flags can be used together.

To choose specific LLMs to run:

python ./generate_llm_code.py --llms <llm1_name llm2_name>

To only run one generation mode, i.e., assisted or autonomous:

python ./generate_llm_code.py --modes <mode>

To overwrite existing generated code:

python ./generate_llm_code.py --force

Generate specific ML projects:

python ./generate_llm_code.py --project-regex <directory_name>

To turn off original_telemetry generation:

python ./generate_llm_code.py --no-original-telemetry

To stop after processing N projects:

python ./generate_llm_code.py --max-projects <N>

When using Gemini Free Tier, Gemini needs to pause every 10th request:

python ./generate_llm_code.py --gemini-pause

Note: there exists more flags, check the code if interested.

Delete Old Generated Code

To delete old generated code, i.e., files with prefix GENAIGREENML, run the following from project root:

./scripts/delete_generated_ml.sh

Runability Check

This scripts verifies that all ML projects runs. You can skip this check for now, but it exists if there are any problems with the telemetry script below. Note: it only runs the original python code in each ML projects, i.e., it skips if there are multiple python files. That also means, any plots or visuals will be shown.

./scripts/runability_check.sh

Run Projects and Capture Telemetry

From project root:

python scripts/run_ml_projects.py

See output in the results folder.

CLI Flags

Flags can be used together.

Only process projects whose directory name matches this regex:

python scripts/run_ml_projects.py --project-regex <regex>

Timeout per script in seconds:

python scripts/run_ml_projects.py --timeout-s <s>

Stop after processing N projects

python scripts/run_ml_projects.py --max-projects <N>

Note: there exists more flags, check the code if interested.

Analyse Results

The analysis compares assisted and autonomous LLM code against the original code on accuracy, execution time and energy consumption to show if they have increased, decreased or are equal. The output is saved in results/ with naming convention: <input_file>_analysis.

It also does a quantitative analysis of the data and produces box plots.

From project root:

cd scripts
source venv/bin/activate
python ./analyse_results.py
deactivate
cd ..

Box Plot Variables

  • showfliers show/remove outliers from visuals.
  • showmeans show/remove means from visuals.

CLI Flag

Select a specific CSV file from the results folder:

python ./analyse_results.py --results-file results_20260220_135839.csv

Analyse File Sizes

From project root:

cd scripts
source venv/bin/activate
python ./analyse_file_sizes.py
deactivate
cd ..

Generate Code Iterations (Failed Scripts)

The script move_failed_scripts.py moves ML projects with failed scripts, except for GENAIGREENML* files that ran correctly. The ML projects are copied to a folder failed_generated_code_iteration_N and then the failed scripts are removed from the ML projects in repos.

python ./scripts/move_failed_scripts.py

Analyse Failed Code

To analyse the errors occured in generated files. To analyse all iterations use:

python ./scripts/analyse_failed_scripts.py

CLI Flag

To analyse a specific iteration:

python ./scripts/analyse_failed_scripts.py --iteration failed_generated_code_iteration_1

Analyse Errors

Analyse the error analysis from failed iterations.

cd scripts
source venv/bin/activate
python ./error_analysis.py
deactivate
cd ..

Generate Code Differences

Generates code differences comparing original_telemetry with assisted and autonomous implementations by Codex and Gemini. Output folder in results.

python scripts/code_differences.py

Analyse Code Complexity

Add SonarQube tokens and keys to API.env, as shown in env.md. Run the following to generate code complexity analysis:

cd scripts
source venv/bin/activate
python analyse_cyclomatic_code_complexity.py
deactivate
cd ..

To rerun the generation of boxplots without rerunning SonarQube:

cd scripts
source venv/bin/activate
python analyse_cyclomatic_code_complexity.py --reuse-cached-api
deactivate
cd ..

About

GenAI-GreenML is a curated dataset of 50 small-scale (<500 MB) open-source machine learning repositories (tabular and NLP) collected for research on generative AI and sustainable coding. It enables benchmarking of LLM-assisted code generation and energy-efficient ML development.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages