A comprehensive research toolkit for analyzing energy consumption patterns across different Large Language Models (LLMs). This project measures and compares the energy efficiency of various AI models when processing different types of prompts.
This research project provides tools to:
- Download and process large conversation datasets
- Extract and clean prompts from conversations
- Measure energy consumption of different LLM models
- Perform feature engineering and exploratory analysis
- Conduct statistical analysis and generate insights
MeasuringPromptEnergyinLLMs/
├── data/
│ ├── raw_conversations.jsonl # Raw conversation data from LMSYS
│ ├── clean_prompts.jsonl # Extracted and cleaned prompts
│ └── energy_measurements.jsonl # Energy consumption measurements
├── 01_data_collection.ipynb # Download LMSYS dataset
├── 02_data_cleaning.ipynb # Extract and clean prompts
├── 03_energy_measurement.ipynb # Measure energy consumption
├── 04_feature_engineering.ipynb # Comprehensive feature engineering
├── 05_exploratory_data_analysis.ipynb # EDA (placeholder)
├── 06_statistical_analysis.ipynb # Statistical analysis (placeholder)
└── requirements.txt # Python dependencies
# Clone the repository
git clone <repository-url>
cd MeasuringPromptEnergyinLLMs
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your API keysCreate a .env file with your API credentials:
HUGGINGFACE_HUB_TOKEN=your_hf_token_here
OPENAI_API_KEY=your_openai_key_here
GROQ_API_KEY=your_groq_key_here
MISTRAL_API_KEY=your_mistral_key_hereStep 1: Data Collection
# Run the data collection notebook
jupyter notebook 01_data_collection.ipynb
# Execute all cells to download LMSYS datasetStep 2: Data Cleaning
# Run the data cleaning notebook
jupyter notebook 02_data_cleaning.ipynb
# Execute all cells to extract prompts from conversationsStep 3: Energy Measurement
# Run the energy measurement notebook
jupyter notebook 03_energy_measurement.ipynb
# Execute all cells to start energy measurementsStep 4: Analysis (Coming Soon)
# Run the analysis notebooks
jupyter notebook 04_feature_engineering.ipynb
jupyter notebook 05_exploratory_data_analysis.ipynb
jupyter notebook 06_statistical_analysis.ipynbThis notebook downloads the LMSYS Chat 1M dataset:
- Source: Hugging Face
lmsys/lmsys-chat-1mdataset - Output:
data/raw_conversations.jsonl- Raw conversation data - Features:
- Streams data to avoid memory issues
- Progress tracking with visual indicators
- Configurable sample size and parameters
Key Configuration:
samples = 1_000_000
output_path = Path("data/raw_conversations.jsonl")
split = "train"
progress_every = 50_000This notebook extracts and cleans user prompts from conversation data:
- Input:
data/raw_conversations.jsonl- Raw conversation data - Output:
data/clean_prompts.jsonl- Cleaned prompts with metadata - Features:
- Filters for English conversations only
- Validates prompt quality (length, uniqueness, content)
- Generates prompt statistics and visualizations
Key Configuration:
config = {
'min_words': 5,
'max_words': 500,
'min_chars': 20,
'max_chars': 3000,
'min_unique_ratio': 0.3
}This notebook measures energy consumption across different LLM models:
- Supported Models: OpenAI GPT-4o-mini, Groq Llama-3.1-8b, Mistral Large
- Metrics Tracked:
- Energy consumption (Wh)
- Processing time and speed
- Token usage and efficiency
- Response quality metrics
Key Features:
- Incremental processing with resume capability
- Real-time progress tracking
- Automatic error handling and retry logic
- Batch result saving
This notebook creates comprehensive linguistic and semantic features from prompt text:
Text Complexity Features:
syntactic_tree_depth- Maximum depth of syntactic parse treeclause_count- Number of clause markers and conjunctionsflesch_kincaid_grade- Readability grade levelgunning_fog_index- Text complexity indexsmog_index- Simplified Measure of Gobbledygook
Lexical Features:
avg_word_frequency- Average frequency of words in Englishlexical_diversity- Diversity of vocabulary (sqrt normalization)type_token_ratio- Ratio of unique words to total wordsvocabulary_richness- Richness of vocabulary usage
Semantic Features:
named_entity_density- Density of named entities (persons, places, organizations)semantic_category_diversity- Diversity of part-of-speech categories
Sentiment Features:
sentiment_polarity- Overall sentiment score (-1 to 1)sentiment_intensity- Intensity of sentiment expression
Information Content:
information_density- Ratio of content words to total wordsavg_sentence_length_prompt- Average words per sentence
Topic Keyword Density (8 categories):
tech_ai_density- Technology and AI-related keywordsbusiness_finance_density- Business and finance keywordshealth_medical_density- Health and medical keywordseducation_learning_density- Education and learning keywordsscience_research_density- Science and research keywordssocial_relationships_density- Social and relationship keywordsentertainment_culture_density- Entertainment and culture keywordstravel_lifestyle_density- Travel and lifestyle keywords
Concept Density (6 categories):
abstract_thinking_density- Abstract and philosophical conceptsproblem_solving_density- Problem-solving and analytical conceptscommunication_density- Communication and language conceptsemotional_psychological_density- Emotional and psychological conceptsdecision_making_density- Decision-making and choice conceptstime_change_density- Time, change, and temporal concepts
Output: energy_features_dataset.jsonl - Dataset with all engineered features
- Exploratory Data Analysis (
05_exploratory_data_analysis.ipynb): Visualize patterns and relationships - Statistical Analysis (
06_statistical_analysis.ipynb): Conduct hypothesis tests and statistical modeling
The energy measurement supports multiple models with different configurations:
# OpenAI Configuration
model: "gpt-4o-mini"
max_tokens: 50
temperature: 0.3
# Groq Configuration
model: "llama-3.1-8b-instant"
max_tokens: 50
temperature: 0.3
# Mistral Configuration
model: "mistral-large-latest"
max_tokens: 50
temperature: 0.3# Prompt filtering criteria
min_words = 5
max_words = 500
min_chars = 20
max_chars = 3000
min_unique_ratio = 0.3
# Energy measurement settings
max_tokens = 50
temperature = 0.3{
"prompt_text": "How can I improve my productivity?",
"processed": 0
}{
"prompt": "How can I improve my productivity?",
"model": "gpt-4o-mini-2024-07-18",
"timestamp": "2025-01-19 20:18:09",
"duration": 2.03,
"time_to_first_token": 2.029,
"prompt_tokens": 18,
"completion_tokens": 50,
"total_tokens": 68,
"tokens_per_second": 33.5,
"energy_consumed_wh": 0.015,
"response": "Here are several strategies to improve productivity..."
}{
"prompt": "How can I improve my productivity?",
"model": "gpt-4o-mini-2024-07-18",
"timestamp": "2025-01-19 20:18:09",
"duration": 2.03,
"energy_consumed_wh": 0.015,
"syntactic_tree_depth": 3,
"clause_count": 2,
"flesch_kincaid_grade": 8.2,
"gunning_fog_index": 10.1,
"smog_index": 7.5,
"avg_word_frequency": 0.0003,
"lexical_diversity": 0.85,
"type_token_ratio": 0.78,
"vocabulary_richness": 0.82,
"named_entity_density": 0.05,
"semantic_category_diversity": 6,
"sentiment_polarity": 0.2,
"sentiment_intensity": 0.3,
"information_density": 0.75,
"avg_sentence_length_prompt": 12.5,
"tech_ai_density": 0.02,
"business_finance_density": 0.15,
"health_medical_density": 0.01,
"education_learning_density": 0.08,
"science_research_density": 0.03,
"social_relationships_density": 0.05,
"entertainment_culture_density": 0.01,
"travel_lifestyle_density": 0.02,
"abstract_thinking_density": 0.12,
"problem_solving_density": 0.18,
"communication_density": 0.25,
"emotional_psychological_density": 0.08,
"decision_making_density": 0.15,
"time_change_density": 0.10
}- Energy Consumption (Wh): Total energy used per request
- Duration: Total processing time in seconds
- Time to First Token: Latency before response starts
- Tokens per Second: Processing throughput
- Energy per Token: Efficiency metric (lower is better)
- Energy per Character: Character-level efficiency
API Rate Limits
- The system automatically handles rate limits with retry logic
- Consider adjusting processing speed for different APIs
Memory Issues with Large Datasets
- The system processes data incrementally to avoid memory issues
- Large conversation files are processed line-by-line
Incomplete Processing
- The system tracks progress and can resume from interruptions
- Check
processedstatus inclean_prompts.jsonlto see completion
For Large Datasets:
- Process in smaller batches if needed
- Monitor API usage and costs
- Use incremental processing for very large datasets
For Faster Processing:
- Adjust
max_tokensparameter for shorter responses - Consider parallel processing for multiple models
- Optimize prompt filtering criteria
This toolkit is designed for:
- Academic Research: Energy efficiency studies, model comparisons
- Industry Analysis: Cost optimization, performance benchmarking
- Environmental Impact: Carbon footprint analysis of AI systems
- Model Development: Efficiency improvements and optimization
To contribute to this project:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you use this toolkit in your research, please cite:
@software{llm_energy_measurement,
title={Measuring Prompt Energy in LLMs},
author={Your Name},
year={2025},
url={https://github.com/your-repo/MeasuringPromptEnergyinLLMs}
}For questions, issues, or contributions:
- Open an issue on GitHub
- Check the documentation in each notebook
- Review the configuration options above
- Comprehensive feature engineering with 30+ linguistic and semantic features
- Topic keyword density analysis across 8 major categories
- Concept density analysis across 6 cognitive categories
- Advanced text analysis including sentiment, readability, and complexity metrics
- Enhanced data processing with spaCy, NLTK, and textstat libraries
- Restructured project with numbered notebooks following data science workflow
- Added data collection step for downloading LMSYS dataset
- Improved organization with clear separation of concerns
- Enhanced documentation with step-by-step instructions
- Added placeholder notebooks for feature engineering, EDA, and statistical analysis
- Initial release with core functionality
- Support for OpenAI, Groq, and Mistral APIs
- Comprehensive analysis and visualization tools
- Incremental processing with resume capability