Model Evaluation using Gemini (GPT-Eval)
Evaluates a locally trained Gemma model's story generation using Gemini API to score grammar, creativity, consistency, plot, and instruction adherence.
What this file does
Evaluates a locally trained Gemma model's story generation using Gemini API to score grammar, creativity, consistency, plot, and instruction adherence.
When to use it
- You have a trained Gemma model checkpoint and want automated story quality scoring
- You need LLM-based evaluation similar to GPT-Eval from TinyStories paper
- You want to test model adaptability across different instruction types like word inclusion or plot twists
Assumes this stack
Model Evaluation using Gemini (GPT-Eval)
This document outlines the process for evaluating a locally trained Gemma model using the Gemini API, inspired by the GPT-Eval methodology described in the paper "TinyStories: How Small Can Language Models Be and Still Speak Coherent English?".
Overview
The evaluate_model.py script automates the evaluation of your model's story-generation capabilities. It works as follows:
- Instruction & Prompt Generation: The script begins by using the Gemini API to generate a set of evaluation scenarios. By default, it generates 50 scenarios. Each scenario consists of a random instruction and a compatible story beginning.
- Story Completion: For each scenario, the script feeds the instruction and the story beginning to your trained model, which then generates multiple story completions (10 by default).
- LLM-based Evaluation: Each generated completion is sent to the Gemini API (
gemini-2.5-flash) for evaluation against the initial instruction and story beginning. - Scoring: Gemini grades the completion based on five key dimensions.
- Summarization: The script calculates the average score for each dimension across all completions for a given prompt, and then provides an overall average for the entire evaluation run.
Evaluation Dimensions
The evaluation focuses on the following five criteria:
- Grammar (Score: 1-10): Assesses the grammatical correctness of the generated text.
- Creativity (Score: 1-10): Measures the originality, imagination, and novelty of the story's completion.
- Consistency (Score: 1-10): Evaluates how well the completion aligns with the characters, plot, and tone established in the initial prompt.
- Plot (Score: 1-10): Reflects the extent to which the generated plot is coherent and makes logical sense.
- Instruct (Score: 1-10): Measures how well the generated story adheres to the specific instruction provided in the prompt.
Instruction Types
For each prompt, one of the following instruction types is chosen at random to test the model's ability to adapt:
- Words to Include: The story must contain a specific list of 3-4 simple words.
- Sentence to Include: The story must contain an exact sentence provided in the instruction.
- Features to Include: The story must exhibit 2-3 specific literary features, chosen from:
dialogue,bad ending,moral value,plot twist,foreshadowing,conflict. - Summary to Follow: The story's plot must adhere to a short 1-2 sentence summary.
How to Run the Evaluation
1. Prerequisites
- Ensure you have installed all the required Python packages from
requirements.txt.pip install -r requirements.txt - You must have a Google API key with the Gemini API enabled.
2. Set Environment Variable
You need to set your Google API key as an environment variable.
export GOOGLE_API_KEY='your_google_api_key_here'
Usage
To run the evaluation, you need a trained model checkpoint (e.g., best_model_params.pt) and a Google Cloud API Key with access to Gemini (set as the GOOGLE_API_KEY environment variable).
Basic Evaluation (Default):
python evaluate_model.py --model-path ./models/your_model.pt
Instruction-Based Evaluation:
To generate a different number of prompts for the evaluation, use the --num-prompts argument.
python evaluate_model.py --model-path ./models/your_model.pt --num-prompts 20
Arguments
--model-path(str): Required. Path to the saved model parameters (.ptfile).--num-prompts(int): The number of evaluation prompts (with instructions) to generate using the Gemini API. Default:50.--max-new_tokens(int): Maximum number of new tokens to generate for each completion. Default:200.--temperature(float): Controls the randomness of the generation. Lower values make it more deterministic. Default:1.0.--top-k(int): Samples from the top K most likely tokens at each step. Default:None.
Output
The script will first print the generation and evaluation progress. At the end, it will display two summary tables:
- Evaluation Summary: A table showing the average scores for all five dimensions for each individual prompt.
- Overall Average Scores: The final average scores for all dimensions across the entire set of prompts.
What's inside
5 evaluation dimensions, 4 instruction types, 5 script arguments, 2 output summary tables
Change this for your project
- Replace
best_model_params.ptwith your actual model checkpoint path - Replace
gemini-2.5-flashwith your desired Gemini model version - Replace
./models/your_model.ptwith your model path in usage examples
Where it goes
Keep alongside your test suite. Used to define and score model evaluations.
Worth borrowing
- Using LLM to generate evaluation scenarios and score completions on multiple dimensions
- Randomly selecting instruction types to test model adaptability
Related Documents
AI Tools for Developers
Curates a personal reference of AI coding tools, models, and setup instructions for VS Code, Xcode, and Cursor.
Evaluating AI Agent Systems: Metrics, Benchmarks, and Quality Assurance (2024-2026)
Surveys 2024-2026 metrics, benchmarks, and monitoring tools for evaluating AI agent systems, with recommendations for a self-improving coding agent.
IATA BCBP Standard Compliance
Documents which IATA BCBP fields and barcode formats a Swift library implements, including Version 8 gender code support.
Voice AI Leaderboards, Benchmarks, and Evaluation Gaps (Jan 2025 -- Feb 2026)
Surveys 20+ voice AI benchmarks from Jan 2025, Feb 2026, identifies evaluation gaps, and provides leaderboard data for STT, TTS, and end-to-end voice agents.