পাঠ ২৯ · ৩০-এর মধ্যে · মডিউল ৩
Home / AI Courses / AI Foundations / Overfitting

Overfitting বনাম Generalization

Overfitting vs Generalization — the heart of ML
৯ মিনিট পড়া মাঝারি · Intermediate Python কোডসহ

এই পাঠে যা শিখবেন

  • Overfitting ও Underfitting — দুটি বিপরীত সমস্যা
  • Generalization — AI-এর প্রকৃত লক্ষ্য
  • Bias-Variance tradeoff — ML-এর সবচেয়ে গুরুত্বপূর্ণ ধারণা
  • Overfitting ঠেকানোর ৭টি কৌশল
  • Curse of Dimensionality — feature বাড়ালে কেন আরও খারাপ হতে পারে

১ · একটি গল্প

কল্পনা করুন একজন শিক্ষার্থী পরীক্ষার আগে শুধু গত বছরের প্রশ্নপত্র মুখস্থ করেছে। ১০০টি প্রশ্নের সঠিক উত্তর জানে।

  • আগের প্রশ্ন: ১০০% মার্কস। অসাধারণ!
  • নতুন প্রশ্ন: ফেল।

এই শিক্ষার্থী মুখস্থ করেছে — শেখেনি। AI মডেল যখন একই কাজ করে — train ডেটা মুখস্থ করে কিন্তু নতুন ডেটায় ব্যর্থ — তাকে বলে Overfitting।

২ · তিনটি অবস্থা

তিন রকম মডেল

UnderfittingUnderfittingমডেল এত সরল যে training data-র pattern-ই ধরতে পারেনি — train ও test দু'জায়গায়ই খারাপ। সমাধান: জটিলতর মডেল, বেশি feature.: Train-ও খারাপ, Test-ও খারাপ। মডেল খুবই সরল।
Just right: Train ভালো, Test ভালো। সাধারণীকরণ হচ্ছে।
OverfittingOverfittingমডেল train data-র noise/spurious pattern মুখস্থ করে — generalize-এ ব্যর্থ। লক্ষণ: train accuracy ≫ test accuracy. সমাধান: more data, regularization, simpler model.: Train চমৎকার, Test খারাপ। মুখস্থ করছে, শিখছে না।

দৃশ্যত — fitting curve

ধরুন ১০টি বিন্দু আছে যেখানে প্রকৃত সম্পর্ক $y \approx x$ (একটি সরল রেখা + সামান্য noise)।

  • Underfit: একটি ধ্রুব রেখা $y = 5$ — অনেক বিন্দু থেকে দূরে।
  • Just right: $y = x + 0.5$ — বিন্দুগুলোর মাঝে যাচ্ছে।
  • Overfit: উচ্চ-degree polynomial যা প্রতিটি বিন্দুতে ছোঁয় — কিন্তু বিন্দু-মাঝে অস্বাভাবিক বাঁক।

৩ · Generalization — আসল লক্ষ্য

GeneralizationGeneralizationtrain data-র বাইরে অজানা/নতুন উদাহরণে মডেলের ভাল কাজ করার সামর্থ্য — AI-র আসল লক্ষ্য। শুধু train accuracy বেশি = মুখস্থ, generalize না। মানে — মডেল train ডেটার বাইরে নতুন ডেটায়ও ভালো করে। এটাই AI-এর আসল উদ্দেশ্য।

একটি স্বাস্থ্যকর AI মডেল চিহ্নিত করতে — train accuracy ও test accuracy দু'টোই কাছাকাছি হবে।

৪ · Bias-Variance TradeoffBias-Variance Tradeoffমডেলের total error দুটি অংশে: Bias (মডেল কতটা সরল/পক্ষপাতী) ও Variance (ডেটার পরিবর্তনে কতটা ওঠানামা)। একটা কমালে অন্যটা বাড়ে — মাঝামাঝি optimal.

দুটি error-এর উৎস

Bias: মডেল কতটা সরল — গড়ে কতটা ভুল। উচ্চ Bias = Underfit.
Variance: মডেল ছোট ছোট ডেটার পরিবর্তনে কতটা পাল্টায়। উচ্চ Variance = Overfit.

গাণিতিকভাবে: $\text{Error} = \text{Bias}^2 + \text{Variance} + \text{Irreducible Error}$। আদর্শ — দু'টোই কম। কিন্তু সাধারণত একটা কমালে অন্যটা বাড়ে — এটাই tradeoff.

উদাহরণ

  • সরল মডেল (linear regression): কম variance, বেশি bias. Underfit.
  • খুব জটিল মডেল (deep neural net): কম bias, বেশি variance. Overfit ঝুঁকি।
  • মাঝারি মডেল (regularized): দু'টোই মাঝারি — সাধারণত সেরা।

৫ · Python-এ Overfitting দেখা

একটি সরল প্রদর্শনী — polynomial regression-এ degree বাড়িয়ে।

Python · NumPy · Polynomial Overfit
import numpy as np

# কৃত্রিম ডেটা: y = 2x + 1 + noise
np.random.seed(42)
x_train = np.linspace(0, 10, 15)
y_train = 2 * x_train + 1 + np.random.normal(0, 2, 15)

x_test = np.linspace(0, 10, 100)
y_test = 2 * x_test + 1 + np.random.normal(0, 2, 100)

def fit_and_eval(degree):
    coeffs = np.polyfit(x_train, y_train, degree)
    p = np.poly1d(coeffs)
    train_mse = np.mean((y_train - p(x_train)) ** 2)
    test_mse = np.mean((y_test - p(x_test)) ** 2)
    return train_mse, test_mse

print("Degree | Train MSE | Test MSE")
print("-" * 35)
for d in [1, 3, 5, 9, 14]:
    tr, te = fit_and_eval(d)
    note = "Overfit!" if te > 5 * tr else ""
    print(f"  {d:2d}   | {tr:9.3f} | {te:9.3f}  {note}")

    
Degree বাড়ানোর সাথে train MSE কমে — কিন্তু test MSE প্রথমে কমে, তারপর বাড়তে শুরু করে। এটাই overfitting-এর সিগনেচার। Degree 1 underfit হতে পারে, degree 14 overfit, degree 3 — সম্ভবত সেরা।

৬ · Overfitting ঠেকানোর ৭টি কৌশল

১. বেশি ডেটা সংগ্রহ

সবচেয়ে কার্যকর। বেশি উদাহরণ থাকলে — মডেল মুখস্থ করতে পারে না।

২. সরল মডেল

ছোট ডেটায় Deep Learning ব্যবহার না করে — Random Forest বা Logistic Regression-এ যান।

৩. RegularizationRegularizationমডেল-এর জটিলতা কমানোর জন্য loss-এ অতিরিক্ত penalty (যেমন weight-এর আকার) যোগ — overfitting রোধ করে। L1, L2, Dropout সবই এর প্রকার।

Loss function-এ একটি penalty যোগ করুন — যা weights বড় হলে penalize করে।

  • L2L2 Regularization · Ridgeweight-এর বর্গের যোগফলকে penalty হিসেবে যোগ করা — সব weight ছোট ও smooth রাখে। সাধারণ overfitting-প্রতিরোধী। (Ridge): $\sum_i w_i^2$ — সব weights ছোট রাখে।
  • L1L1 Regularization · Lassoweight-এর পরম মানের যোগফলকে penalty হিসেবে যোগ — অপ্রয়োজনীয় feature-এর weight শূন্য করে দেয় (sparsity), automatic feature selection. (Lasso): $\sum_i |w_i|$ — অনেক weights ০ করে দেয় (sparsity)।

Total loss: $\mathcal{L}_{\text{total}} = \mathcal{L}_{\text{data}} + \lambda \cdot \mathcal{L}_{\text{reg}}$। $\lambda$ — regularization strength.

৪. DropoutDropoutপ্রতিটি training step-এ neural network-এর কিছু neuron এলোমেলোভাবে "বন্ধ" করা হয় — মডেল একটি neuron-এর উপর নির্ভর করতে পারে না, robustly শেখে। Hinton et al. (২০১৪)। (Neural Networks-এ)

প্রতিটি training ধাপে — কিছু neurons এলোমেলোভাবে "বন্ধ" করুন। মডেল কোনো একটি neuron-এর উপর অতিনির্ভর হতে পারে না। Hinton et al. (২০১৪)।

৫. Early StoppingEarly Stoppingvalidation loss বাড়তে শুরু করলেই training থামিয়ে দেওয়া — overfit হওয়ার আগেই সবচেয়ে ভাল generalization বিন্দুতে আটকানো।

Validation loss বাড়তে শুরু করলে — train থামিয়ে দিন। সেই বিন্দুই সবচেয়ে ভালো generalization.

৬. Data AugmentationData Augmentationসংরক্ষিত ডেটায় ছোট ছোট রূপান্তর (ছবি ঘোরানো, কাটা, রঙ বদল; টেক্সটে synonym) করে কৃত্রিমভাবে dataset বাড়ানো — overfitting কমায়, কম ডেটায় বেশি বৈচিত্র্য।

আপনার সংরক্ষিত ডেটার নতুন রূপ তৈরি — ছবি ঘোরানো, কাটা, রঙ বদল। কণ্ঠে noise যোগ। বাংলা টেক্সটে synonym.

৭. Cross-Validation

একাধিক train/test বিভাজনে evaluate. মডেল সব split-এই ভালো কাজ করছে কি না দেখুন।

Bias-Variance Tradeoff — তিন অবস্থা "Memorize → Learn → Apply" Underfit High Bias, Low Variance Train: 60% — Test: 58% model too simple e.g. linear on curves Just right Balanced bias & variance Train: 92% — Test: 90% generalizes well small train-test gap Overfit Low Bias, High Variance Train: 99% — Test: 70% memorizes noise e.g. degree-14 poly কী লক্ষণ? Train acc - Test acc > 10%? → Overfit. Train acc < 80%? → Underfit. 🛠 Anti-Overfit Toolkit ১. বেশি ডেটা most effective cannot memorize ২. সরল মডেল fewer params capacity ↓ ৩. Regularization L1 (sparsity) L2 (small weights) ৪. Dropout random off neurons DL specific ৫. Early Stop val loss ↑ → stop automatic ৬. Augmentation flip, crop, paraphrase data ↑ for free ৭. Cross-Val k-fold robust estimate + Ensemble multiple models avg → variance ↓ Total Error = Bias² + Variance + Irreducible Noise "Memorize → Generalize" — AI-র সবচেয়ে গুরুত্বপূর্ণ যাত্রা
তিন অবস্থা — diagnose করুন train-test gap থেকে। ৭টি কৌশল — সবগুলোই situational; একটাই rule নয়।

৭ · কখন কোন কৌশল?

  • Train ≪ Test (underfit): বেশি জটিল মডেল, বেশি features, কম regularization.
  • Train ≫ Test (overfit): বেশি ডেটা, বেশি regularization, dropout, early stopping.
  • Train ≈ Test (just right): ভালো! আরও ভালো করতে চাইলে — model architecture বদলান বা feature engineering.

৮ · একটি ধাঁধা — Curse of Dimensionality

Feature বাড়ালে মডেল আরও শক্তিশালী হবার কথা — কিন্তু নয়। কারণ —

  • প্রতিটি feature যোগ মানে — মডেল আরও জটিল।
  • আরও জটিল মডেল মানে — overfit ঝুঁকি বেশি।
  • উচ্চ-মাত্রায় ডেটা "ছড়িয়ে" থাকে — patterns খুঁজে পেতে কঠিন।

সমাধান: Feature selection, dimensionality reduction (PCA), regularization.

"More is more" সত্য নয়। কম, ভালো features বেশি features-এর চেয়ে ভালো। সবসময় সরল-এ শুরু, প্রয়োজনে জটিল করুন।

৯ · একটি বাস্তব গল্প

Amazon-এর প্রকৌশলীরা একবার একটি AI-চাকরি-সিলেকশন সিস্টেম বানিয়েছিলেন (২০১৪-২০১৮)। Train-এ চমৎকার accuracy. কিন্তু বাস্তবে — সিস্টেম শুধু পুরুষ candidate-দের পছন্দ করছিল। কারণ প্রশিক্ষণ ডেটায় (অতীত successful resume) এই pattern মুখস্থ হয়েছিল। সিস্টেম ২০১৮-এ scrap করা হয়।

OverfittingOverfittingমডেল train data-র "noise" বা spurious pattern মুখস্থ করে — generalize-এ ব্যর্থ। লক্ষণ: train accuracy ≫ test accuracy. সমাধান: more data, regularization, simpler model. সামাজিক প্রভাব: bias amplification. শুধু সংখ্যার সমস্যা নয় — এটি সামাজিক সমস্যাও। মডেল ডেটার পক্ষপাত মুখস্থ করে — ছড়িয়ে দেয়। তাই বৈচিত্র্যপূর্ণ ডেটা ও সতর্ক evaluation অপরিহার্য।

১০ · এক বাক্যে সারাংশ

"AI-এর লক্ষ্য মুখস্থ নয় — সাধারণীকরণ। Train ভালো হলেই যথেষ্ট নয়; Test-এও ভালো হতে হবে।"

ভাবনার প্রশ্ন

প্রতিটি প্রশ্ন নিজে কিছুক্ষণ ভাবুন — তারপর "→ উত্তর" চাপুন।

প্র ০১ "Double Descent" — modern Deep Learning-এর mysterious phenomenon. Classical bias-variance বলে complex model = overfit. কিন্তু GPT-4-এর মতো বিশাল মডেল কেন overfit হয় না? কী হচ্ছে আসলে?

Double Descent — ML theory-এর সবচেয়ে exciting recent discovery (Belkin et al. ২০১৯)। Classical understanding-কে challenge করে এবং modern DL-এর সাফল্য ব্যাখ্যা করে।

(১) Classical bias-variance:

  • Model complexity বাড়ালে: প্রথমে test error কমে, তারপর "U-shape" — overfit.
  • Sweet spot — moderate complexity.
  • ৬০ বছরের ML wisdom.

(২) Modern DL-এর paradox:

  • GPT-4: ১.৭৬ trillion parameters. Training data: ~১৩ trillion token.
  • Param > data — classical theory predicts catastrophic overfit.
  • Reality: state-of-art generalization!

(৩) Double Descent কী?

  • Test error: U-shape না — "double valley"।
  • Underparameterized → moderate → overparameterized.
  • Interpolation threshold: model = data points.
  • সেখান past করলে — error আবার কমতে শুরু!

(৪) Three regimes:

  • Underparameterized:
    • Model capacity < data complexity.
    • Underfit, high bias.
    • Classical regime.
  • Critical (interpolation threshold):
    • Model exactly fits training.
    • Worst test error — variance explodes.
    • Catastrophic overfit.
  • Overparameterized:
    • Model capacity ≫ data.
    • Many solutions all interpolate.
    • Implicit bias selects simple ones.
    • Modern DL territory.

(৫) কেন overparameterized model generalize?

  • Implicit regularization: SGD nature-এ — flat minima preferred.
  • Lottery ticket: Subnetwork "winning" — rest pruned.
  • Linear interpolation: Functions in between training points smooth.
  • Norm-based bound: Effective capacity না, parameter count অনুযায়ী।

(৬) Empirical evidence:

  • ResNet, GPT, ViT — সব overparameterized.
  • Train accuracy ১০০% — তবু test improve.
  • Pruning শোধ — original 10% size-এও similar performance.

(৭) Theory:

  • Neural Tangent Kernel (NTK) — infinite width limit.
  • Mean field theory.
  • Information bottleneck.
  • সব approximate explanation; exact theory open problem.

(৮) Practical implications:

  • "Bigger model + more data" — modern ML mantra.
  • Avoid critical regime — model fully overparameterize.
  • Regularization roles changing.
  • Model size scaling laws.

(৯) Caveats:

  • "Limited" data নয় — bigger model train করতে গেলে data also need.
  • Compute cost — training large model expensive.
  • Energy/environment concerns.
  • Inference cost — production limitation.

(১০) Scaling Laws (Kaplan et al. 2020, Hoffmann et al. 2022):

  • Model size, data size, compute — power-law relationships.
  • Chinchilla: optimal data/model ratio.
  • Predicts performance from scale.

(১১) Counterintuitive insights:

  • "More parameters" ≠ "more overfit"।
  • "Memorization" + generalization coexist.
  • Network can memorize random labels — yet generalize on real (Zhang et al. ২০১৬)।

(১২) Modern best practices:

  • Don't follow "hand-tune for moderate complexity" classical advice.
  • Default: large model + early stopping + light regularization.
  • Compute-aware: data and parameters scale together.

(১৩) Open questions:

  • When does double descent hold?
  • Out-of-distribution generalization?
  • Continual learning + double descent?
  • Foundation model fine-tuning dynamics?

মূল উপলব্ধি: Classical bias-variance — important, but incomplete. Modern DL — overparameterized regime-এ অভিনব। GPT-4-এর সাফল্য — accident নয়, deep mathematical phenomenon-এর result. AI theory এই দশকে rapidly evolving.

প্র ০২ Train: 99%, Test: 70% — overfit signature. আপনি সাত কৌশলের কোনটি প্রথমে চেষ্টা করবেন? কেন? কোন order? Decision criteria কী?

সবগুলো কৌশল একসাথে ছোঁড়া — bad practice. Order matters, cost matters, problem matters. Senior engineer methodology-driven.

(১) প্রথম step — diagnose আরও:

  • Just 99/70 দেখে decide করবেন না।
  • Per-class accuracy?
  • Confusion matrix?
  • Validation loss curve — কখন overfit start?
  • Most-misclassified examples — pattern?

(২) Cost of each fix:

  • More data: HIGH cost (collection/label)।
  • Simpler model: medium effort, may underfit.
  • Regularization: LOW cost — just hyperparameter.
  • Dropout: low cost (DL only)।
  • Early stopping: free (just monitor val loss)।
  • Augmentation: medium effort (domain-specific)।
  • Cross-validation: compute cost (k-fold)।

(৩) Recommended order:

  1. Early stopping first:
    • Free, easy.
    • Best epoch checkpoint.
    • Often gets you 5-10% improvement.
  2. Regularization:
    • L2 + small λ (try 0.01, 0.001)।
    • Grid search on validation.
    • Quick to test.
  3. Dropout (if DL):
    • Add dropout layers (rate 0.2-0.5)।
    • Standard in modern DL anyway.
  4. Data Augmentation:
    • Domain-specific transforms.
    • Free virtual data.
    • Very effective for vision.
  5. Simpler model:
    • Reduce capacity if above না কাজ করে।
    • Step back to safer architecture.
  6. More data:
    • Last resort due to cost.
    • But most effective long-term.
    • Active learning to prioritize.
  7. Cross-validation:
    • Validation method, not fix per se.
    • Use throughout for honest evaluation.

(৪) Combination effect:

  • Multiple regularization stack করা যায়।
  • Early stopping + L2 + dropout + augmentation — common cocktail.
  • প্রতিটির hyperparameter tune validation-এ।

(৫) Domain-specific:

  • Image: RandAugment, MixUp, CutOut.
  • Text: Back-translation, synonym replace.
  • Tabular: Feature selection, target encoding.
  • Time series: Window augmentation, jittering.

(৬) Modern DL specifics:

  • BatchNorm — implicit regularization.
  • LayerNorm in transformers.
  • Weight decay (AdamW)।
  • Label smoothing — prevents overconfidence.
  • Mixup, CutMix — interpolated training.

(৭) Checkpoint strategy:

  • Save best validation performance.
  • Multiple checkpoints — ensemble later.
  • Early stopping patience — যথেষ্ট epochs অপেক্ষা।

(৮) When to give up?

  • সব কৌশল করেও gap বিশাল?
  • Likely data quality/quantity issue.
  • Or task too hard for available data.
  • Reframe problem — easier sub-task?

(৯) Common pitfalls:

  • Overusing dropout (rate 0.7+) — undertrains.
  • L1 + L2 stacked — interaction confusing.
  • Aggressive augmentation — distorts true distribution.
  • Test-set tuning hyperparameters — leakage.

(১০) Production reality:

  • Time-budget aware — choose cheap fixes first.
  • Document each attempt.
  • Validation loss curve mandatory artifact.
  • Stakeholder communication: gap explained.

(১১) Bangladesh contexts:

  • Limited data — augmentation, transfer learning.
  • Limited compute — small models with strong regularization.
  • Bangla NLP — pretrained model fine-tune (limited fine-tune data)।

মূল উপলব্ধি: Overfitting fix-এর order — cheap-first, effective-first. Random kitchen-sink approach — junior pattern. Methodical, validation-driven approach — senior. Cost-aware engineering = production reality.

প্র ০৩ "Distribution shift" — model production-এ deploy করার পর accuracy ধীরে ধীরে কমতে থাকে। কেন? কীভাবে detect? Continuous learning কী?

Distribution shift — production AI-র চিরশত্রু। Model deploy-এ ৯৫% accuracy, ৬ মাস পর ৭৫%। বাস্তব AI engineering-এর core challenge.

(১) Distribution shift-এর প্রকার:

  • Covariate shift:
    • $P(X)$ বদলায়, $P(Y|X)$ same.
    • Input distribution changes.
    • উদা: New customer demographics.
  • Label shift:
    • $P(Y)$ বদলায়, $P(X|Y)$ same.
    • Class proportions change.
    • উদা: Disease prevalence change in pandemic.
  • Concept drift:
    • $P(Y|X)$ itself changes.
    • Underlying relationship shifts.
    • উদা: Spam patterns evolve.
  • Domain shift:
    • Different deployment context.
    • উদা: Train hospital A, deploy hospital B.

(২) Real-world causes:

  • Seasonality — winter vs summer.
  • Trend changes — fashion, politics.
  • External shocks — covid-19.
  • User behavior evolution.
  • Adversarial actors (spam, fraud)।
  • Sensor degradation.
  • Regulation changes.

(৩) Detection methods:

  • Performance monitoring:
    • Accuracy on labeled holdout.
    • Confidence distribution.
    • Output statistics.
  • Statistical tests:
    • Kolmogorov-Smirnov test.
    • Chi-square for categoricals.
    • Population Stability Index (PSI)।
  • Distribution distances:
    • KL divergence.
    • Wasserstein distance.
    • Jensen-Shannon.
  • Drift detection algorithms:
    • ADWIN, Page-Hinkley.
    • DDM, EDDM.
    • Online learning specific.

(৪) Without ground truth (common):

  • Production-এ labels delayed/expensive.
  • Input drift detect — proxy for performance.
  • Model confidence drift.
  • Feature distribution monitoring.
  • Embedding similarity to training distribution.

(৫) Continuous Learning:

  • Model continuously update with new data.
  • Online learning algorithms.
  • Periodic retraining.
  • Active learning loop.

(৬) Continuous learning challenges:

  • Catastrophic forgetting:
    • New data শিখতে গিয়ে old patterns ভুলে যাওয়া।
    • Solution: replay buffer, EWC, learning without forgetting.
  • Stability-plasticity dilemma:
    • Stable enough যে noise ignore করে।
    • Plastic enough যে real change adopt করে।
  • Label feedback delay:
    • Loan default — months later known.
    • Manual labeling lag.

(৭) Adaptation strategies:

  • Periodic retraining:
    • Monthly/weekly retrain on recent data.
    • Simple, often sufficient.
  • Online learning:
    • Incremental updates per sample.
    • SGD-based methods.
  • Domain adaptation:
    • Source domain → target domain transfer.
    • Adversarial domain training.
  • Test-time adaptation:
    • BatchNorm statistics update at inference.
    • Self-supervised adaptation.

(৮) MLOps integration:

  • Model monitoring dashboards.
  • Automated retraining pipelines.
  • A/B testing infrastructure.
  • Rollback mechanisms.
  • Feature store for consistency.

(৯) Famous case studies:

  • Zillow's iBuying (২০২১):
    • Algorithmic pricing model.
    • COVID housing market shift.
    • $304M loss — model couldn't adapt.
  • Google Flu Trends:
    • ২০০৮ launch — accurate.
    • Search behavior changed.
    • Overestimated flu by 2x.
    • Discontinued ২০১৫।

(১০) Robustness vs Adaptation:

  • Build robust model: handles many distributions.
  • Adapt model: changes with distribution.
  • Combined: distributionally robust + adaptive.

(১১) Bangladesh context:

  • Rapid digital adoption — user behavior fast change.
  • Bangla NLP: language evolves, slang appears.
  • Economic shifts — demand patterns change.
  • Mobile-first adoption — device characteristics evolve.

(১২) Best practices:

  • Monitor from day-1 deployment.
  • Define drift thresholds upfront.
  • Automated alerts.
  • Regular human review.
  • Documented retraining schedule.
  • Rollback plan.

মূল উপলব্ধি: Model deploy = beginning, not end. Real ML engineering = continuous monitoring, adaptation, retraining. Static model — eventual failure. Distribution shift inevitable; preparation makes the difference.

প্র ০৪ Amazon hiring AI বা healthcare bias — overfit-এর সামাজিক রূপ। Algorithmic bias = pattern memorization. কীভাবে detect, prevent এবং correct?

Algorithmic bias — overfitting-এর সবচেয়ে dangerous form. Numbers improve, but society harm. AI engineer-এর সবচেয়ে গুরুত্বপূর্ণ ethical responsibility.

(১) Overfitting → Bias-এর মেকানিজম:

  • Training data society-র historical bias capture.
  • Model এই pattern accurately learn = bias amplification.
  • Deploy-এ — bias scaled at automation speed.
  • "Garbage in, garbage out" — but worse, "discrimination in, discrimination at scale"।

(২) Famous failures:

  • Amazon Hiring AI (২০১৪-২০১৮):
    • Past resumes — male-dominated tech jobs.
    • Model "shall not include 'women'" patterns.
    • Penalized "women's chess club", all-women's colleges.
    • Scrapped ২০১৮।
  • COMPAS Recidivism (Pro Publica investigation):
    • Racial bias in criminal risk assessment.
    • Black defendants 2x false positive rate.
  • Healthcare AI (Obermeyer et al. ২০১৯):
    • Used health spending as proxy for need.
    • Black patients spent less (access barriers)।
    • Model recommended less care to those needing more.
  • Face recognition (Buolamwini, Gebru ২০১৮):
    • White male: 99% accurate.
    • Black women: 65% accurate.
    • Training data imbalance.

(৩) Detection workflow:

  1. Identify protected attributes.
  2. Disaggregate metrics by group.
  3. Statistical tests for parity.
  4. Counterfactual testing.
  5. Adversarial testing.
  6. External audit.

(৪) Counterfactual fairness:

  • "Same person, different demographic" — same prediction?
  • Causal reasoning framework.
  • Useful but hard to operationalize.

(৫) Debiasing techniques:

  • Pre-processing:
    • Diverse data collection.
    • Reweighting samples.
    • Sampling strategies.
    • Disparate impact remover.
  • In-processing:
    • Fairness-constrained optimization.
    • Adversarial debiasing.
    • Multi-objective loss.
  • Post-processing:
    • Threshold adjustment per group.
    • Calibration per group.
    • Output transformation.

(৬) Trade-offs:

  • Fairness ↔ Accuracy — sometimes tension.
  • Different fairness criteria — mathematically incompatible.
  • Group fairness ↔ Individual fairness.
  • Society-specific value judgments.

(৭) Beyond technical fixes:

  • Diverse engineering teams.
  • Stakeholder consultation.
  • Affected communities involvement.
  • Transparent reporting.
  • Easy redress mechanisms.
  • Iterative improvement.

(৮) Documentation:

  • Datasheets for Datasets (Gebru):
    • Data provenance.
    • Collection methodology.
    • Known biases.
  • Model Cards (Mitchell):
    • Intended use.
    • Performance across groups.
    • Limitations.

(৯) Legal landscape:

  • EU AI Act — high-risk AI fairness audit required.
  • NYC Local Law 144 — hiring AI bias audit mandatory.
  • Various US state laws emerging.
  • Bangladesh: Data Protection Act + emerging AI policy.

(১০) LLM-specific bias:

  • Stereotype amplification.
  • Toxicity towards minorities.
  • Cultural Western bias.
  • Religious assumptions.
  • Gender role reinforcement.
  • RLHF helps, doesn't solve.

(১১) Bangladesh-specific:

  • Religion bias:
    • Names imply religion.
    • Loan, hiring AI special care.
  • Gender:
    • Workplace AI underrepresent female.
    • Health AI miss pregnancy concerns.
  • Geographic:
    • Dhaka-centric data underrepresents rural.
    • Hill tracts almost absent.
  • Disability:
    • Accessibility largely ignored.
    • Speech patterns variation.
  • Socioeconomic:
    • Education proxies wealth.
    • Digital access matters.

(১২) Ethical principles:

  • Beneficence: Do good.
  • Non-maleficence: Do no harm.
  • Autonomy: Respect human choice.
  • Justice: Fair treatment.
  • Explicability: Decisions explainable.

(১৩) Continuous responsibility:

  • Bias check not one-time event.
  • Distribution shift can introduce new bias.
  • User feedback channels.
  • Regular audits.
  • Transparency reports.

(১৪) Engineer's role:

  • Speak up for fairness measures.
  • Refuse harmful deployments.
  • Educate stakeholders.
  • Support affected users.
  • Career-defining ethical stand.

মূল উপলব্ধি: Overfitting শুধু numbers-এর সমস্যা না — যখন bias data-এ থাকে, overfit = injustice automated. বাংলাদেশের ML community-র দায়িত্ব — না শুধু model বানানো, fair model বানানো। প্রযুক্তি neutral না — engineer-এর choice দিয়ে বাঁকা হয়।

অনুশীলন

  1. চিন্তা করুন: একটি ছাত্র সবসময় শুধু MCQ মুখস্থ করে — এই পদ্ধতির সাথে overfitting-এর কী মিল?
    • Train Set মুখস্থ: ছাত্র = past MCQ; AI = train data.
    • High Train Score: Past MCQ-এ ১০০%; AI train accuracy ৯৯%।
    • Low Test Score: নতুন MCQ-এ ফেল; AI test accuracy ৭০%।
    • সমাধান: Concept বুঝে শেখা (ছাত্র) = generalization (AI)। Practice diverse problems = data augmentation. Take frequent quizzes = validation. Don't keep adding more memorization, simplify understanding = regularization.

    আরও উপমা: Cricketer যিনি শুধু এক ground-এ practice — অন্য ground-এ ফেল। Doctor যিনি শুধু adult deal করেছেন — pediatric case-এ confused.

  2. চেষ্টা করুন: উপরের কোডে noise বাড়িয়ে (যেমন std=4) — overfitting-এর pattern কেমন বদলায়?

    Noise বাড়ালে:

    • Train MSE বাড়বে — মডেল noise capture-এ struggle.
    • Test MSE আরও বেশি বাড়বে — true signal harder to find.
    • Overfit gap (test/train ratio) বেশি হবে — high-degree poly noise মুখস্থ করছে।
    • "Sweet spot" degree কমবে — simpler model = better generalization.

    উপলব্ধি: Noisy data-এ model complexity আরও সাবধানে বাছতে হয়। Real-world data সবসময় noisy — তাই production-এ অনেক regularization.

  3. সিদ্ধান্ত নিন: একটি AI ৯৯% train accuracy ও ৭০% test accuracy পাচ্ছে। আপনি কী কী চেষ্টা করবেন? কোন ক্রমে?

    প্র ০২-এ বিস্তারিত। সংক্ষেপে:

    1. Diagnose আগে: per-class metric, confusion matrix, validation curve, leakage check.
    2. Early stopping (free, immediate gains)।
    3. L2 regularization (cheap hyperparameter search)।
    4. Dropout (DL-এ standard)।
    5. Data Augmentation (domain-specific transforms)।
    6. Simpler model (capacity reduce)।
    7. More data (last resort, highest cost)।

    প্রতিটি change-এর পরে: validation gap measure করুন। Document করুন কী কাজ করল, কী না।

আরও পড়ুন · ABCL TECH-এ আপনার পরবর্তী পদক্ষেপ

Practical advice: প্রতিটি ML project-এ — train-loss ও validation-loss দু'টোই plot করুন। Gap দেখুন। Sense develop করুন কখন কী হচ্ছে। Senior ML engineer = curve দেখেই ৩০ second-এ diagnose.
পূর্ববর্তী পাঠ
পাঠ ২৮ · মডেলের সফলতা মাপা