Measuring Chatbot Climate Impact with CodeCarbon

    Abstract article image showing a fractal pattern in cauliflower
    Article by Gunther Cox
    Posted April 29, 2025

    This past Earth Day GitHub shared their Climate Action Plan for Developers, a collection of resources designed to create tangible steps that developers can use to improve how software impacts the planet.

    This concept has become increasingly relevant as of late with the increasing use of generative AI. A trend in recent news has been to point out the sometimes staggering statistics around the use of water for cooling the hardware on which many AI systems run, as well as the use of electricity. A 2024 article from The Washington Post reports estimates that models such as GPT-4 require approximately 1 bottle’s worth of water (519 milliliters) to write a 100-word email. That same email also consumes roughly the same amount of energy as turning on 14 LED light bulbs for 1 hour (0.14 kilowatt-hours).

    Highlighted amidst GitHub’s list of environmental impact tools was a project called CodeCarbon, a Python library designed to allow developers to estimate the carbon footprint of their work in the form of kilograms of CO₂-equivalents (CO₂eq). Their documentation dives further into the motivation and methodology used to implement their statistics.

    To test out codecarbon we put the following example together, demonstrating the initialization of a simple chat bot, with a small amount of training data.

    Code Setup

    pip install codecarbon chatterbot[dev]
    

    Our example code will be as follows:

    # codecarbon-example.py
    
    from codecarbon import EmissionsTracker
    from chatterbot import ChatBot
    from chatterbot.trainers import ListTrainer
    
    
    with EmissionsTracker() as tracker:
    
        chatbot = ChatBot(
            "Chatbot",
            storage_adapter="chatterbot.storage.SQLStorageAdapter",
            logic_adapters=[
                "chatterbot.logic.BestMatch",
                "chatterbot.logic.TimeLogicAdapter"
            ],
            database_uri="sqlite:///database.sqlite3"
        )
    
        # Train the chatbot with a small amount of simple data
    
        trainer = ListTrainer(chatbot)
    
        trainer.train([
            "Hello, how are you?",
            "I am good, thank you!",
            "You're welcome!",
        ])
    
        trainer.train([
            "Who are you?",
            "I am a chatbot built using ChatterBot.",
            "It's nice to meet you!",
            "Thanks, it's nice to meet you too!",
        ])
    
        message = "Hello, how are you?"
    
        response = chatbot.get_response(message)
    
        print(f"Chatbot response: {response.text}")
    
    # Display the tracked emissions data
    
    print(f"Carbon emissions from computation: {tracker.final_emissions * 1000:.4f} g CO2eq")
    print("Detailed emissions data:", tracker.final_emissions_data)
    
    

    Results

    Next, running the code using python codecarbon-example.py yields the analyzed run for our chat bot. Let’s take a look at some of the results:

    The below tracking methods have been set up:
        RAM Tracking Method: RAM power estimation model
        CPU Tracking Method: cpu_load
        GPU Tracking Method: Unspecified
    
    >>> Tracker's metadata:
      Python version: 3.12.2
      CodeCarbon version: 3.0.0
      Available RAM : 30.541 GB
      CPU count: 4 thread(s) in 1 physical CPU(s)
      CPU model: Intel(R) Core(TM) i7
    
    Energy consumed for RAM : 0.000009 kWh. RAM Power : 10.0 W
    Delta energy consumed for CPU with cpu_load : 0.000010 kWh, power : 10.89 W
    Energy consumed for All CPU : 0.000010 kWh
    0.000018 kWh of electricity used since the beginning.
    Carbon emissions from computation: 0.0068 g CO2eq
    

    ChatterBot’s resource usage is relatively low in this example, likely for a few reasons. Since we used a small amount of training data fewer resources are required to process it. This example is also using ChatterBot’s default search-based response generation (designed to run efficiently on smaller devices such as the Raspberry Pi), which is less processing intensive in most cases compared to using generative models.

    Check out CodeCarbon’s Quickstart guide for more examples of ways their library can be used. Likewise the documentation for ChatterBot can be found at docs.chatterbot.us


    If you found this article useful and want to request similar or related content feel free to open a ticket in this website's issue tracker on GitHub. Please use the "blog post topic" tag when doing so.

    © 2025 Gunther Cox