# Bias Evaluation Dataset Improvements

## Current State Analysis

Our bias evaluation datasets have several limitations that reduce their effectiveness for detecting real-world bias:

### 1. **Gender Bias (WinoBias-style)**
- **Size**: Only 10 occupations × 3 variants = 30 examples
- **Coverage**: Limited to English pronouns (he/she/they)
- **Context**: Simple template sentences, not realistic
- **Intersectionality**: No analysis across gender × ethnicity × occupation
- **Validation**: No statistical validation against real-world distributions

### 2. **Demographic Bias (Names)**
- **Size**: ~100 manually curated names
- **Coverage**: 8 ethnicity categories, but limited examples per category
- **Context**: Generic template "X attended the conference"
- **Frequency**: All names treated equally, ignoring real-world frequency
- **Scripts**: Good coverage but could expand (Thai, Hebrew, etc.)
- **Intersectionality**: Limited to ethnicity × gender

### 3. **Temporal Bias**
- **Size**: ~70 names across decades
- **Coverage**: US-only (SSA data), English names only
- **Context**: Simple template sentences
- **Validation**: No validation against actual name popularity distributions
- **International**: No temporal trends for other countries

### 4. **Length Bias**
- **Size**: ~30 examples total
- **Coverage**: Limited entity types (PER, ORG, LOC)
- **Context**: Simple templates
- **Edge Cases**: Missing compound names, titles, suffixes

## Research-Based Best Practices

Based on recent research (2024-2025), effective bias evaluation datasets should:

1. **Statistical Validation**: Validate against real-world distributions
2. **Stratified Sampling**: Use stratified sampling to ensure representative coverage
3. **Multiple Seeds**: Report variance across multiple evaluation seeds
4. **Intersectional Analysis**: Analyze across multiple dimensions simultaneously
5. **Real-World Context**: Use realistic sentence contexts, not templates
6. **Frequency-Weighted**: Sample based on real-world frequency distributions
7. **Adversarial Examples**: Include edge cases and adversarial examples
8. **Confidence Intervals**: Report statistical confidence, not just point estimates

## Proposed Improvements

### Priority 1: Statistical Validation & Sampling

**Problem**: Datasets are manually curated with no validation against real distributions.

**Solution**: 
- Add frequency-based sampling from real-world name databases (SSA, census data, etc.)
- Validate demographic distributions match real-world proportions
- Use stratified sampling to ensure balanced coverage across dimensions

**Implementation**:
```rust
pub struct BiasDatasetConfig {
    /// Minimum samples per category for statistical validity
    pub min_samples_per_category: usize,
    /// Use frequency-weighted sampling from real distributions
    pub frequency_weighted: bool,
    /// Validate against reference distributions
    pub validate_distributions: bool,
    /// Multiple seeds for variance estimation
    pub evaluation_seeds: Vec<u64>,
}
```

### Priority 2: Expand Dataset Sizes

**Problem**: Current datasets are too small for reliable statistical inference.

**Solution**:
- **Gender Bias**: Expand to 50+ occupations, 500+ examples
- **Demographic**: Expand to 500+ names with proper stratification
- **Temporal**: Expand to 200+ names with decade coverage
- **Length**: Expand to 100+ examples across all entity types

**Target Sizes** (based on statistical power analysis):
- Minimum 30 examples per category for 80% power
- Recommended 100+ per category for robust inference
- Total dataset sizes: 500-1000 examples per bias type

### Priority 3: Real-World Context Sentences

**Problem**: Template sentences don't reflect real-world usage patterns.

**Solution**:
- Extract real sentences from news, Wikipedia, social media
- Use diverse sentence structures and contexts
- Include edge cases: titles, compound names, abbreviations

**Example**:
```rust
// Instead of: "John Smith attended the conference."
// Use real contexts:
"Dr. John Smith, CEO of Acme Corp, announced..."
"Smith, who previously worked at Google, said..."
"John 'Johnny' Smith Jr. was elected..."
```

### Priority 4: Intersectional Analysis

**Problem**: Limited cross-dimensional analysis (e.g., gender × ethnicity × occupation).

**Solution**:
- Add intersectional categories (e.g., "African-American female engineer")
- Report metrics across all combinations
- Identify which intersections show the most bias

**Implementation**:
```rust
pub struct IntersectionalBiasResults {
    /// Results by ethnicity × gender
    pub ethnicity_gender: HashMap<(Ethnicity, Gender), f64>,
    /// Results by ethnicity × gender × occupation
    pub ethnicity_gender_occupation: HashMap<(Ethnicity, Gender, String), f64>,
    /// Maximum gap across any intersection
    pub max_intersectional_gap: f64,
}
```

### Priority 5: Frequency-Weighted Evaluation

**Problem**: All examples treated equally, ignoring real-world frequency.

**Solution**:
- Weight examples by real-world frequency (e.g., common names vs rare names)
- Report both unweighted and frequency-weighted metrics
- Use frequency distributions from census/SSA data

**Implementation**:
```rust
pub struct FrequencyWeightedResults {
    /// Unweighted recognition rate
    pub unweighted_rate: f64,
    /// Frequency-weighted recognition rate
    pub weighted_rate: f64,
    /// Frequency distribution used
    pub frequency_distribution: HashMap<String, f64>,
}
```

### Priority 6: Multilingual & International Coverage

**Problem**: Primarily English/US-focused.

**Solution**:
- Add international name databases (e.g., Indian, Chinese, Arabic names)
- Support multilingual evaluation
- Include regional variations (e.g., British vs American names)

### Priority 7: Adversarial Examples

**Problem**: Missing edge cases that reveal bias.

**Solution**:
- Compound names: "Mary-Jane Smith", "José María García"
- Titles: "Dr. Jane Smith", "Prof. John Doe"
- Suffixes: "John Smith Jr.", "Robert Williams III"
- Ambiguous cases: "Jordan" (name vs location), "Paris" (name vs location)

### Priority 8: Statistical Reporting

**Problem**: Only point estimates, no confidence intervals.

**Solution**:
- Report mean ± 95% CI across multiple seeds
- Use bootstrap resampling for robust estimates
- Report effect sizes, not just raw differences

**Implementation**:
```rust
pub struct StatisticalBiasResults {
    /// Mean bias gap
    pub mean_gap: f64,
    /// 95% confidence interval
    pub ci_95: (f64, f64),
    /// Standard deviation across seeds
    pub std_dev: f64,
    /// Effect size (Cohen's d)
    pub effect_size: f64,
    /// Statistical significance (p-value)
    pub p_value: Option<f64>,
}
```

## Implementation Plan

### Phase 1: Foundation (High Priority)
1. Add `BiasDatasetConfig` for configuration
2. Implement frequency-weighted sampling
3. Expand dataset sizes to minimum viable (100+ per category)
4. Add statistical reporting (mean ± CI)

### Phase 2: Quality (Medium Priority)
5. Replace templates with real-world sentences
6. Add intersectional analysis
7. Implement validation against reference distributions
8. Add adversarial examples

### Phase 3: Coverage (Lower Priority)
9. Expand multilingual support
10. Add international temporal trends
11. Increase dataset sizes to recommended (500+ per category)
12. Add more edge cases and compound names

## Validation Metrics

For each improved dataset, validate:

1. **Coverage**: Minimum 30 examples per category
2. **Balance**: Entity type/ethnicity/gender distributions within ±10% of target
3. **Diversity**: Unique entity texts > 80% of total
4. **Realism**: Sentence contexts match real-world patterns
5. **Statistical Power**: Sufficient samples for 80% power at α=0.05

## References

- Mishra et al. (2020): "Assessing Demographic Bias in NER"
- Statistical Dataset Evaluation (Cambridge NLP, 2022)
- Recent bias evaluation best practices (2024-2025)

