Responsible AI at Scale โš–๏ธ

Class 10Age 14โ€“15Lesson 11 of 12๐Ÿ†“ Free
Student in Visakhapatnam studying AI fairness โ€” balance scale illustration, demographic parity chart, model card document visible on screen
Watch first - 2-3 minutes

Class 10 Lesson 11 - Responsible AI at Scale

No sign-in needed - English narration - Safe for all school ages

Meet Amar โ€” Class 10, Visakhapatnam

Amar was excited. His loan default predictor from Lessons 7โ€“8 had 87% accuracy. He showed it to a microfinance NGO in Vizag that lends to self-help groups in fishing villages. They wanted to use it. But then one of their officers asked: "Did you check if it treats applicants from coastal communities the same as urban applicants? Our training data has very few loans from Araku Valley โ€” it might just deny everyone from there."

Amar ran a fairness audit. He was disturbed by what he found: his model was 79% accurate for urban applicants but only 61% accurate for rural applicants. It had a false positive rate (incorrectly flagging good loans as risky) of 8% for urban areas but 31% for rural areas. "My model would have denied loans to 3ร— more legitimate rural borrowers," he said. "That's not a technical bug. That's an injustice."

Why Fairness Matters
Bias Amplification at Scale

A human loan officer making a biased decision affects one person. An AI model deployed at scale makes biased decisions millions of times per day โ€” and because it feels "objective" and algorithmic, the bias is harder to detect and challenge.

In India, historical bias in data is especially acute:

The core problem: AI models optimise for accuracy on average. Average performance hides disaster for minority groups. A model that is 90% accurate overall could be 60% accurate for a specific demographic โ€” making it worse than random for that group.
Fairness Metrics
Measuring Demographic Parity and Equalised Odds
MetricDefinitionFormulaAmar's model result
Demographic ParityEach group gets approved at equal ratesP(approve|urban) โ‰ˆ P(approve|rural)Urban: 72% approve, Rural: 41% approve
Equalised Odds (stronger)Each group has equal TPR AND equal FPRTPR_urban โ‰ˆ TPR_rural AND FPR_urban โ‰ˆ FPR_ruralFPR: 8% urban vs 31% rural โŒ FAILS
CalibrationPredicted probability matches actual rateP(default|score=0.7) โ‰ˆ 70% for all groupsWell-calibrated overall
Fairness trade-offs: It is mathematically impossible to simultaneously satisfy all fairness metrics when base rates differ between groups (Chouldechova's impossibility theorem). Choosing which metric to prioritise is an ethical decision, not just a technical one โ€” and that decision should involve the affected communities.
Fairness Audit Code
Using Fairlearn to Measure and Mitigate Bias
# Responsible AI Audit with Fairlearn โ€” Google Colab
!pip install fairlearn scikit-learn pandas matplotlib -q

import numpy as np
import pandas as pd
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.impute import SimpleImputer
from sklearn.metrics import accuracy_score, confusion_matrix
from fairlearn.metrics import (
    MetricFrame, demographic_parity_difference,
    equalized_odds_difference, false_positive_rate
)
from fairlearn.postprocessing import ThresholdOptimizer
import matplotlib.pyplot as plt

# โ”€โ”€ Step 1: Generate biased dataset โ”€โ”€
np.random.seed(42)
n = 2000

# Rural group (40% of sample, worse features due to historical underbanking)
urban_mask = np.random.choice([0, 1], size=n, p=[0.4, 0.6])
X = np.column_stack([
    np.random.normal(50, 15, n) + urban_mask * 10,  # income higher in urban
    np.random.normal(200, 80, n) - urban_mask * 20, # loan amount
    np.random.normal(650, 80, n) + urban_mask * 40, # credit score biased up for urban
    np.random.normal(5, 3, n).clip(0),              # employment years
    np.random.randint(0, 4, n).astype(float)        # existing loans
])
# Ground truth default: mainly income and loan ratio, NOT location
true_default = ((X[:, 0] / X[:, 1]) < 0.3).astype(int)

df = pd.DataFrame(X, columns=['income', 'loan_amount', 'credit_score',
                                'employment_years', 'existing_loans'])
df['is_urban'] = urban_mask
df['default']  = true_default

X_train, X_test, y_train, y_test, grp_train, grp_test = train_test_split(
    df.drop(['is_urban', 'default'], axis=1),
    df['default'], df['is_urban'],
    test_size=0.3, random_state=42
)

# โ”€โ”€ Step 2: Train baseline model โ”€โ”€
pipeline = Pipeline([
    ('imputer', SimpleImputer(strategy='median')),
    ('scaler',  StandardScaler()),
    ('model',   GradientBoostingClassifier(n_estimators=100, random_state=42))
])
pipeline.fit(X_train, y_train)
y_pred = pipeline.predict(X_test)

print("=== BASELINE MODEL AUDIT ===")
print(f"Overall accuracy: {accuracy_score(y_test, y_pred):.3f}")

# โ”€โ”€ Step 3: Fairness metrics with MetricFrame โ”€โ”€
mf = MetricFrame(
    metrics={
        "accuracy":           accuracy_score,
        "false_positive_rate": false_positive_rate
    },
    y_true=y_test,
    y_pred=y_pred,
    sensitive_features=grp_test.map({0: "Rural", 1: "Urban"})
)

print("\nAccuracy by group:")
print(mf.by_group["accuracy"].to_string())
print("\nFalse Positive Rate by group (incorrectly flagged as default):")
print(mf.by_group["false_positive_rate"].to_string())
print(f"\nDemographic Parity Difference:  {demographic_parity_difference(y_test, y_pred, sensitive_features=grp_test):.3f}")
print(f"Equalised Odds Difference:       {equalized_odds_difference(y_test, y_pred, sensitive_features=grp_test):.3f}")
# 0 = perfectly fair | 1 = maximally unfair

# โ”€โ”€ Step 4: Mitigate bias with ThresholdOptimizer โ”€โ”€
# Adjust decision thresholds per group to equalise FPR
mitigator = ThresholdOptimizer(
    estimator=pipeline,
    constraints="equalized_odds",
    objective="accuracy_score",
    predict_method="auto"
)
mitigator.fit(X_train, y_train, sensitive_features=grp_train)
y_pred_fair = mitigator.predict(X_test, sensitive_features=grp_test)

print("\n=== AFTER FAIRNESS MITIGATION ===")
mf_fair = MetricFrame(
    metrics={"accuracy": accuracy_score, "false_positive_rate": false_positive_rate},
    y_true=y_test, y_pred=y_pred_fair,
    sensitive_features=grp_test.map({0: "Rural", 1: "Urban"})
)
print(f"Overall accuracy: {accuracy_score(y_test, y_pred_fair):.3f} (may decrease slightly)")
print("\nAccuracy by group:")
print(mf_fair.by_group["accuracy"].to_string())
print("\nFalse Positive Rate by group (after mitigation):")
print(mf_fair.by_group["false_positive_rate"].to_string())
print(f"\nEqualised Odds Difference after mitigation: {equalized_odds_difference(y_test, y_pred_fair, sensitive_features=grp_test):.3f}")
Amar's finding after mitigation: The FPR gap dropped from 23 percentage points (8% vs 31%) to under 4 percentage points. Overall accuracy decreased from 87% to 83% โ€” a small cost to ensure rural applicants are treated fairly. Amar wrote in his report: "We chose to sacrifice 4% overall accuracy to prevent 27% more rural families from being wrongly denied credit. That is the right trade-off."
Documentation
Model Cards and India's DPDPA

A Model Card (developed by Google) is a short document every deployed AI model should have. It records:

India's Digital Personal Data Protection Act (DPDPA) 2023 creates legal obligations for AI systems processing personal data:

Pre-deployment audit checklist for your AI projects:

๐Ÿงช Check Your Understanding โ€” Lesson 11 Quiz

1. Why is bias in AI at scale more dangerous than bias in individual human decisions?
a) AI models are always more accurate than humans, so their biases affect more correct outcomes
b) An AI system deployed at scale makes millions of biased decisions per day, feels "objective" so is harder to challenge, and systematically affects entire demographic groups rather than one person at a time
c) AI bias can be fixed by rewriting code, but human bias cannot be fixed at all
d) AI models are regulated by SEBI which makes their decisions legally binding
2. Demographic Parity in a loan approval model means:
a) All demographic groups have the same number of people in the training dataset
b) Each demographic group (urban/rural, male/female) receives loan approvals at approximately equal rates โ€” regardless of any historical patterns in the training data
c) The model uses demographic information as an input feature to improve accuracy
d) All employees who built the model come from diverse backgrounds
3. Equalised Odds (a stricter fairness metric than Demographic Parity) requires:
a) That the model has the same overall accuracy across all groups
b) That both the True Positive Rate AND False Positive Rate are equal across groups โ€” ensuring the model is equally good at identifying real defaulters AND equally unlikely to falsely flag non-defaulters, regardless of group
c) That the model's prediction probabilities are exactly 50% for each group
d) That the training dataset has an equal number of examples from each group
4. In Amar's model, the False Positive Rate was 8% for urban and 31% for rural. This means:
a) The model correctly identifies 8% of urban defaults and 31% of rural defaults
b) 31% of rural applicants who would NOT have defaulted were INCORRECTLY predicted as defaulters โ€” nearly 4ร— the rate for urban applicants. These are good borrowers being denied loans because of where they live.
c) The model rejects 31% of all rural applications
d) Rural applicants file 31% more loan complaints than urban applicants
5. ThresholdOptimizer in Fairlearn mitigates bias by:
a) Retraining the entire model on a new, balanced dataset
b) Adjusting the decision threshold per demographic group (post-processing) โ€” a higher threshold for the advantaged group and a lower threshold for the disadvantaged group โ€” until the specified fairness constraint is approximately satisfied
c) Removing demographic features from the input data before training
d) Adding demographic information as a class weight during training
6. A Model Card should be published because:
a) It improves model accuracy by documenting hyperparameters clearly
b) It communicates to users, regulators, and the public what the model does, who it was tested on, its known limitations, and its fairness metrics โ€” creating accountability and enabling informed use or rejection of the AI system
c) It is required by GitHub to publish AI models in a public repository
d) It automatically generates the Swagger documentation for the FastAPI endpoint
7. Under India's Digital Personal Data Protection Act (DPDPA) 2023, a person denied a loan by an AI system has the right to:
a) Receive a refund of the application fee
b) Ask for an explanation of why the automated system rejected their application โ€” the company (Data Fiduciary) is legally obligated to explain AI decisions and provide a human appeal process
c) Demand that the company delete their AI model and retrain it
d) Sue the AI model itself in a consumer court
8. Amar's decision to accept 4% lower accuracy in exchange for fairer rural FPR was:
a) A poor engineering decision โ€” accuracy should always be maximised
b) The right ethical trade-off โ€” preventing 27% more rural families from being wrongly denied credit is a more important outcome than a small aggregate accuracy improvement. Fairness sometimes costs accuracy, and that cost is often worth paying.
c) Against DPDPA regulations, which require maximum accuracy
d) Unnecessary โ€” the 4% accuracy difference is statistically insignificant
โ† Lesson 10: AI for India Lesson 12: Capstone โ†’