Evaluating Gemma-2-9B-it's self-awareness on user profiles.
Based on Designing a Dashboard for Transparency and Control of Conversational AI by Chen et al. (2024).
This project evaluates how well the Gemma-2-9B language model can estimate user demographics through conversational interactions. The system:
- Uses GPT-4o to simulate users with specific demographic profiles
- Has Gemma-2-9B act as an assistant in natural conversations
- Prompts Gemma-2-9B to estimate the user's demographics based on the conversation
- Compares estimated demographics against actual profiles to measure accuracy
The project now includes run_probes_on_modal.py, which uses TransformerLens and linear probes to investigate what demographic information is encoded in Gemma-2-9B's internal activations. See SETUP_MODAL.md for details.
- Python 3.10+
- UV package manager
- OpenRouter API key (for accessing GPT-4o and Gemma-2-9B)
# Install dependencies
uv sync
# Set up your API key
export OPENROUTER_API_KEY='your-api-key-here'Run full demographic estimation pipeline:
uv run python gemma_age_estimation.pyThis will:
- Load personas from data/personas.json
- Generate conversations for each persona (using GPT-4o as user, Gemma-2-9B as assistant)
- Estimate demographics after each exchange
- Save results to data/results/results.json
- Generate visualization plots and accuracy reports
Generate visualizations from existing results without running new experiments:
uv run python gemma_age_estimation.py --visualize-onlyWhat it does:
- Loads all data points from data/results/results.json
- Creates accuracy plots for age, income, and categorical demographics
- Generates summary statistics
- No API calls made (free and fast)
Control the number of parallel API calls (default: 5):
uv run python gemma_age_estimation.py --threads 10What it does:
- Processes multiple personas concurrently
- Faster execution for large persona sets
- Higher thread counts = more API calls in parallel
Print all API responses and detailed progress in terminal:
uv run python gemma_age_estimation.py --verboseWhat it does:
- Shows full conversations as they're generated
- Displays demographic estimations in real-time
- Shows retry attempts when tag validation fails
- Disables tqdm progress bar (uses detailed logging instead)
Without verbose (default):
- Shows clean tqdm progress bar
- Minimal terminal output
- Faster visual feedback
Quick visualization of existing results:
uv run python gemma_age_estimation.py --visualize-onlyFast processing with many threads:
uv run python gemma_age_estimation.py --threads 20Debug mode with full output:
uv run python gemma_age_estimation.py --verbose --threads 3Process 10 personas in parallel with progress bar:
uv run python gemma_age_estimation.py --threads 10- Validates that all 12 required XML tags are present in estimation responses
- Automatically retries up to 5 times if tags are missing
- Ensures data quality and prevents parsing errors
- Parallel API calls using ThreadPoolExecutor
- Configurable thread count via
--threadsflag - Significantly faster for large persona sets
- Age estimation accuracy plots
- Income estimation accuracy plots
- Categorical demographic accuracy (education, sex, visa status)
- Summary statistics and confidence analysis
- tqdm progress bar (default mode)
- Real-time status updates
- Verbose mode for detailed debugging
All results are saved to data/results/:
results.json- Full results with conversations and estimationsage_accuracy.png- Age estimation accuracy visualizationincome_accuracy.png- Income estimation accuracy visualizationcategorical.png- Categorical demographic accuracy
- Persona Definition: Define user demographics in data/personas.json
- Conversation Generation: GPT-4o simulates a user with those demographics
- Assistant Response: Gemma-2-9B responds naturally as an AI assistant
- Demographic Estimation: After each exchange, Gemma-2-9B estimates user demographics
- Tag Validation: System validates all required tags are present (retries if needed)
- Accuracy Analysis: Compare estimated vs. actual demographics
- Visualization: Generate plots and summary statistics
# 1. Set your API key
export OPENROUTER_API_KEY='...'
# 2. Run the full pipeline with 10 parallel threads
uv run python gemma_age_estimation.py --threads 10
# 3. View the results
cat data/results/results.json
# 4. Re-generate visualizations if needed
uv run python gemma_age_estimation.py --visualize-onlyBased on Designing a Dashboard for Transparency and Control of Conversational AI by Chen et al. (2024).