Split View: AI 윤리와 책임있는 AI 개발 가이드 2025: 개발자가 알아야 할 편향, 공정성, 투명성의 모든 것
AI 윤리와 책임있는 AI 개발 가이드 2025: 개발자가 알아야 할 편향, 공정성, 투명성의 모든 것
- 1. 왜 지금 AI 윤리인가
- 2. 편향(Bias)의 유형과 사례
- 3. 공정성 메트릭 (Fairness Metrics)
- 4. 편향 탐지 및 완화 기법
- 5. 설명 가능한 AI (Explainable AI, XAI)
- 6. AI 규제 현황
- 7. AI 거버넌스 프레임워크
- 8. Red Teaming과 AI 안전성
- 9. 개발자의 윤리적 체크리스트
- 10. AI 윤리 커리어 가이드
- 11. 퀴즈
- 참고 자료
1. 왜 지금 AI 윤리인가
1.1 AI가 사회에 미치는 영향의 규모
2025년 현재, AI는 채용, 대출 심사, 의료 진단, 형사 사법, 보험 심사 등 인간의 삶에 직접적인 영향을 미치는 영역에서 의사결정을 내리고 있습니다. McKinsey 보고서에 따르면, 전 세계 기업의 72%가 이미 AI를 하나 이상의 비즈니스 기능에 적용하고 있습니다.
문제의 규모:
- Amazon의 AI 채용 도구가 여성 지원자를 체계적으로 불리하게 평가한 사례 (2018년 폐기)
- Apple Card가 동일 조건에서 남성에게 20배 높은 신용 한도를 부여한 사건
- COMPAS 재범 예측 시스템이 흑인 피고인에게 높은 재범 위험도를 부여한 ProPublica 분석
- 안면 인식 기술의 인종별 오류율 차이 (흑인 여성: 34.7%, 백인 남성: 0.8%)
1.2 규제 환경의 변화
┌─────────────────────────────────────────────────────┐
│ 글로벌 AI 규제 타임라인 │
├─────────────────────────────────────────────────────┤
│ 2021.04 EU AI Act 초안 발표 │
│ 2023.12 EU AI Act 최종 합의 │
│ 2024.08 EU AI Act 발효 시작 │
│ 2025.02 EU AI Act 금지 조항 적용 │
│ 2025.08 범용 AI 규정 적용 예정 │
│ 2026.08 고위험 AI 규정 전면 적용 예정 │
│ │
│ 2023.10 미국 AI 행정명령 (Executive Order 14110) │
│ 2024.05 한국 AI 기본법 국회 통과 │
│ 2024.04 일본 AI 사업자 가이드라인 │
└─────────────────────────────────────────────────────┘
1.3 AI Safety 운동의 성장
AI Safety 분야는 학계와 산업계에서 빠르게 성장하고 있습니다:
- Anthropic: Constitutional AI 방법론으로 AI 안전성 연구 선도
- OpenAI: Superalignment 팀 구성 (2023), 내부 갈등 후 재편 (2024)
- Google DeepMind: AI Safety 연구팀 확대
- AI Safety Institute: 영국, 미국, 일본에 설립
개발자가 윤리를 무시하면 법적 리스크, 브랜드 신뢰도 하락, 실질적 피해가 발생합니다. AI 윤리는 선택이 아닌 필수 역량입니다.
2. 편향(Bias)의 유형과 사례
2.1 데이터 편향 (Data Bias)
훈련 데이터가 현실을 대표하지 못할 때 발생합니다.
유형별 정리:
| 편향 유형 | 설명 | 사례 |
|---|---|---|
| 표본 편향 (Sampling Bias) | 특정 집단이 과대/과소 대표 | ImageNet의 서구 중심 이미지 |
| 측정 편향 (Measurement Bias) | 데이터 수집 방법의 불균형 | 웨어러블 기기의 어두운 피부톤 센서 오류 |
| 라벨링 편향 (Labeling Bias) | 어노테이터의 주관 반영 | 감정 분석에서 문화적 차이 무시 |
| 역사적 편향 (Historical Bias) | 과거의 차별이 데이터에 반영 | 대출 데이터의 인종 차별 기록 |
| 생존자 편향 (Survivorship Bias) | 성공 사례만 데이터에 포함 | 이탈 고객 데이터 누락 |
# 데이터 편향 탐지 예시 - 클래스 불균형 확인
import pandas as pd
import numpy as np
def detect_representation_bias(df, sensitive_attr, target_col):
"""민감 속성별 타겟 분포 차이를 분석합니다."""
results = {}
groups = df.groupby(sensitive_attr)
overall_positive_rate = df[target_col].mean()
for name, group in groups:
group_positive_rate = group[target_col].mean()
group_size = len(group)
group_proportion = group_size / len(df)
results[name] = {
'count': group_size,
'proportion': round(group_proportion, 4),
'positive_rate': round(group_positive_rate, 4),
'disparity_ratio': round(
group_positive_rate / overall_positive_rate, 4
) if overall_positive_rate > 0 else None
}
return pd.DataFrame(results).T
# 사용 예시
# df = pd.read_csv('loan_data.csv')
# bias_report = detect_representation_bias(df, 'race', 'approved')
# print(bias_report)
2.2 알고리즘 편향 (Algorithmic Bias)
모델 자체의 구조나 학습 과정에서 발생합니다.
- 집계 편향: 하위 집단의 패턴을 무시하고 전체 데이터에서 학습
- 학습률 편향: 소수 집단의 데이터가 적어 해당 패턴을 잘 학습하지 못함
- 특성 선택 편향: 민감 속성과 상관관계가 높은 대리 변수(proxy) 사용
# 대리 변수(proxy) 탐지 예시
from sklearn.metrics import mutual_information_score
import warnings
def detect_proxy_variables(df, sensitive_attr, feature_cols, threshold=0.3):
"""민감 속성의 대리 변수가 될 수 있는 특성을 탐지합니다."""
proxy_candidates = []
for col in feature_cols:
if col == sensitive_attr:
continue
try:
# 범주형으로 변환하여 상호정보량 계산
mi_score = mutual_information_score(
df[sensitive_attr].astype(str),
df[col].astype(str)
)
if mi_score > threshold:
proxy_candidates.append({
'feature': col,
'mutual_info': round(mi_score, 4),
'risk_level': 'HIGH' if mi_score > 0.5 else 'MEDIUM'
})
except Exception:
pass
return sorted(proxy_candidates, key=lambda x: x['mutual_info'], reverse=True)
2.3 사회적 편향 (Societal Bias)
AI 시스템이 배포된 후 사회적 맥락에서 발생하는 편향입니다.
- 자동화 편향: AI 결과를 무비판적으로 수용하는 경향
- 피드백 루프: AI의 편향된 결과가 새로운 데이터를 생성하여 편향 강화
- 선택 편향: AI가 추천한 옵션만 선택되어 다양성 감소
┌──────────────────────────────────────────────┐
│ 피드백 루프 예시 │
│ │
│ 편향된 예측 ──▶ 편향된 결정 │
│ ▲ │ │
│ │ ▼ │
│ 편향된 데이터 ◀── 편향된 결과 │
│ │
│ 예: 경찰 순찰 AI │
│ - 특정 지역 범죄 예측 높음 │
│ - 해당 지역 순찰 증가 │
│ - 범죄 적발 증가 (다른 지역은 감소) │
│ - "예측이 맞았다"고 학습 강화 │
└──────────────────────────────────────────────┘
2.4 확인 편향과 선택 편향
- 확인 편향 (Confirmation Bias): 개발자가 기존 믿음을 확인하는 방향으로 모델 설계
- 선택 편향 (Selection Bias): 특정 집단만 데이터에 포함되어 모집단을 대표하지 못함
실무에서는 여러 편향이 동시에 작용하여 복합적인 문제를 만듭니다. 편향을 완전히 제거하는 것은 불가능하지만, 체계적으로 탐지하고 완화하는 것이 핵심입니다.
3. 공정성 메트릭 (Fairness Metrics)
3.1 공정성의 정의가 어려운 이유
공정성에 대한 수학적 정의는 20개 이상이며, 이들은 서로 상충합니다. Chouldechova (2017)는 두 집단의 기저율(base rate)이 다른 경우, 세 가지 공정성 기준을 동시에 만족하는 것이 수학적으로 불가능함을 증명했습니다.
3.2 그룹 공정성 메트릭
Demographic Parity (인구통계 동등성)
모든 집단의 양성 판정 비율이 동일해야 합니다.
P(Y_hat = 1 | A = a) = P(Y_hat = 1 | A = b)
Y_hat: 모델 예측
A: 민감 속성 (예: 성별, 인종)
def demographic_parity(y_pred, sensitive_attr):
"""Demographic Parity를 계산합니다."""
groups = {}
for pred, attr in zip(y_pred, sensitive_attr):
if attr not in groups:
groups[attr] = {'total': 0, 'positive': 0}
groups[attr]['total'] += 1
if pred == 1:
groups[attr]['positive'] += 1
rates = {}
for attr, counts in groups.items():
rates[attr] = counts['positive'] / counts['total']
# Disparate Impact Ratio 계산
rate_values = list(rates.values())
min_rate = min(rate_values)
max_rate = max(rate_values)
di_ratio = min_rate / max_rate if max_rate > 0 else 0
return {
'group_rates': rates,
'disparate_impact_ratio': round(di_ratio, 4),
'passes_80_percent_rule': di_ratio >= 0.8
}
Equal Opportunity (균등 기회)
실제 양성(positive)인 사례에 대해 모든 집단의 진양성률(True Positive Rate)이 동일해야 합니다.
P(Y_hat = 1 | Y = 1, A = a) = P(Y_hat = 1 | Y = 1, A = b)
핵심: 자격이 있는 사람이 동등하게 기회를 받아야 함
def equal_opportunity(y_true, y_pred, sensitive_attr):
"""Equal Opportunity (TPR 동등성)를 계산합니다."""
groups = {}
for true, pred, attr in zip(y_true, y_pred, sensitive_attr):
if attr not in groups:
groups[attr] = {'tp': 0, 'fn': 0}
if true == 1:
if pred == 1:
groups[attr]['tp'] += 1
else:
groups[attr]['fn'] += 1
tpr = {}
for attr, counts in groups.items():
total_positive = counts['tp'] + counts['fn']
tpr[attr] = counts['tp'] / total_positive if total_positive > 0 else 0
tpr_values = list(tpr.values())
max_diff = max(tpr_values) - min(tpr_values)
return {
'true_positive_rates': tpr,
'max_tpr_difference': round(max_diff, 4),
'is_fair': max_diff < 0.05 # 5% 임계값
}
Equalized Odds (균등화된 오즈)
진양성률(TPR)과 위양성률(FPR) 모두 집단 간 동일해야 합니다.
def equalized_odds(y_true, y_pred, sensitive_attr):
"""Equalized Odds를 계산합니다."""
groups = {}
for true, pred, attr in zip(y_true, y_pred, sensitive_attr):
if attr not in groups:
groups[attr] = {'tp': 0, 'fn': 0, 'fp': 0, 'tn': 0}
if true == 1 and pred == 1:
groups[attr]['tp'] += 1
elif true == 1 and pred == 0:
groups[attr]['fn'] += 1
elif true == 0 and pred == 1:
groups[attr]['fp'] += 1
else:
groups[attr]['tn'] += 1
metrics = {}
for attr, counts in groups.items():
tpr = counts['tp'] / (counts['tp'] + counts['fn']) \
if (counts['tp'] + counts['fn']) > 0 else 0
fpr = counts['fp'] / (counts['fp'] + counts['tn']) \
if (counts['fp'] + counts['tn']) > 0 else 0
metrics[attr] = {'TPR': round(tpr, 4), 'FPR': round(fpr, 4)}
return metrics
3.3 개인 공정성 (Individual Fairness)
유사한 개인은 유사한 결과를 받아야 합니다.
d(f(x_i), f(x_j)) <= L * d(x_i, x_j)
f: 모델 함수
d: 거리 함수
L: 립시츠 상수
3.4 공정성 메트릭 비교
| 메트릭 | 초점 | 장점 | 단점 |
|---|---|---|---|
| Demographic Parity | 결과의 동등성 | 직관적, 측정 용이 | 자격 차이 무시 |
| Equal Opportunity | 자격자의 동등 기회 | 능력 기반 공정성 | FPR 차이 무시 |
| Equalized Odds | TPR + FPR 동등 | 포괄적 | 완전 달성 어려움 |
| Individual Fairness | 유사 개인 유사 결과 | 개인 수준 공정성 | 유사성 정의 어려움 |
| Counterfactual Fairness | 인과적 공정성 | 근본 원인 분석 | 인과 모델 필요 |
실무 가이드: 단일 메트릭에 의존하지 말고, 도메인과 맥락에 맞는 여러 메트릭을 함께 모니터링하세요. 채용 AI는 Equal Opportunity에, 대출 심사 AI는 Equalized Odds에 더 초점을 둘 수 있습니다.
4. 편향 탐지 및 완화 기법
4.1 Pre-processing (전처리) 기법
데이터 단계에서 편향을 제거합니다.
# 1. 재가중(Reweighting) 기법
def compute_reweights(df, sensitive_attr, target_col):
"""편향을 보정하는 샘플 가중치를 계산합니다."""
n = len(df)
weights = []
for _, row in df.iterrows():
group = row[sensitive_attr]
label = row[target_col]
# 그룹별, 레이블별 비율 계산
n_group = len(df[df[sensitive_attr] == group])
n_label = len(df[df[target_col] == label])
n_group_label = len(
df[(df[sensitive_attr] == group) & (df[target_col] == label)]
)
expected = (n_group * n_label) / n
weight = expected / n_group_label if n_group_label > 0 else 1.0
weights.append(weight)
return weights
# 2. 데이터 증강을 통한 편향 완화
def augment_underrepresented(df, sensitive_attr, target_col, method='smote'):
"""소수 집단의 데이터를 증강합니다."""
from imblearn.over_sampling import SMOTE, ADASYN
groups = df.groupby(sensitive_attr)
target_size = max(len(g) for _, g in groups)
augmented_dfs = []
for name, group in groups:
if len(group) < target_size * 0.8:
if method == 'smote':
sampler = SMOTE(random_state=42)
else:
sampler = ADASYN(random_state=42)
features = group.drop(columns=[target_col, sensitive_attr])
target = group[target_col]
try:
X_res, y_res = sampler.fit_resample(features, target)
resampled = pd.DataFrame(X_res, columns=features.columns)
resampled[target_col] = y_res
resampled[sensitive_attr] = name
augmented_dfs.append(resampled)
except ValueError:
augmented_dfs.append(group)
else:
augmented_dfs.append(group)
return pd.concat(augmented_dfs, ignore_index=True)
4.2 In-processing (학습 중) 기법
모델 학습 과정에서 공정성 제약을 추가합니다.
# Adversarial Debiasing 개념 구현
import torch
import torch.nn as nn
class FairClassifier(nn.Module):
"""공정성 제약이 포함된 분류기."""
def __init__(self, input_dim, hidden_dim=64):
super().__init__()
# 메인 분류기
self.predictor = nn.Sequential(
nn.Linear(input_dim, hidden_dim),
nn.ReLU(),
nn.Dropout(0.3),
nn.Linear(hidden_dim, hidden_dim // 2),
nn.ReLU(),
nn.Linear(hidden_dim // 2, 1),
nn.Sigmoid()
)
# 적대적 네트워크 (민감 속성 예측)
self.adversary = nn.Sequential(
nn.Linear(hidden_dim // 2, hidden_dim // 4),
nn.ReLU(),
nn.Linear(hidden_dim // 4, 1),
nn.Sigmoid()
)
def forward(self, x):
# 중간 표현 추출
h = self.predictor[:-1](x) # Sigmoid 전까지
prediction = torch.sigmoid(self.predictor[-1](h) if isinstance(
self.predictor[-1], nn.Linear
) else h)
adversary_pred = self.adversary(h.detach())
return prediction, adversary_pred
class FairnessConstrainedLoss(nn.Module):
"""공정성 제약이 포함된 손실 함수."""
def __init__(self, fairness_weight=1.0):
super().__init__()
self.bce = nn.BCELoss()
self.fairness_weight = fairness_weight
def forward(self, y_pred, y_true, sensitive_pred, sensitive_true):
# 메인 손실
task_loss = self.bce(y_pred, y_true)
# 적대적 손실 (민감 속성을 예측하지 못하도록)
adversary_loss = self.bce(sensitive_pred, sensitive_true)
# 총 손실 = 메인 손실 - 공정성 가중치 * 적대적 손실
total_loss = task_loss - self.fairness_weight * adversary_loss
return total_loss
4.3 Post-processing (후처리) 기법
모델 출력에서 편향을 보정합니다.
def calibrated_threshold(y_scores, sensitive_attr, target_metric='equal_opportunity',
y_true=None):
"""그룹별 최적 임계값을 찾습니다."""
import numpy as np
from sklearn.metrics import recall_score
groups = set(sensitive_attr)
thresholds = {}
if target_metric == 'demographic_parity':
# 전체 양성 비율을 목표로
target_rate = np.mean(y_scores > 0.5)
for group in groups:
mask = np.array([a == group for a in sensitive_attr])
group_scores = y_scores[mask]
# 목표 비율에 맞는 임계값 찾기
thresholds[group] = np.percentile(
group_scores,
(1 - target_rate) * 100
)
elif target_metric == 'equal_opportunity' and y_true is not None:
# TPR이 동등하도록 임계값 조정
target_tpr = 0.8 # 목표 TPR
for group in groups:
mask = np.array([a == group for a in sensitive_attr])
group_scores = y_scores[mask]
group_true = y_true[mask]
best_threshold = 0.5
best_diff = float('inf')
for t in np.arange(0.1, 0.9, 0.01):
preds = (group_scores > t).astype(int)
tpr = recall_score(group_true, preds, zero_division=0)
diff = abs(tpr - target_tpr)
if diff < best_diff:
best_diff = diff
best_threshold = t
thresholds[group] = round(best_threshold, 2)
return thresholds
4.4 기법 비교 및 실무 가이드
| 단계 | 기법 | 복잡도 | 성능 영향 | 추천 상황 |
|---|---|---|---|---|
| Pre-processing | 재가중 | 낮음 | 최소 | 데이터 수집 가능 시 |
| Pre-processing | 데이터 증강 | 중간 | 최소 | 소수 집단 데이터 부족 시 |
| In-processing | Adversarial Debiasing | 높음 | 중간 | 모델 수정 가능 시 |
| In-processing | 제약 최적화 | 높음 | 중간 | 정밀한 제어 필요 시 |
| Post-processing | 임계값 조정 | 낮음 | 없음 | 모델 수정 불가 시 |
| Post-processing | 결과 재보정 | 중간 | 최소 | 빠른 적용 필요 시 |
5. 설명 가능한 AI (Explainable AI, XAI)
5.1 설명 가능성이 중요한 이유
- 법적 요구: EU AI Act는 고위험 AI에 대한 설명 의무 규정
- 신뢰 구축: 의사결정 근거를 제시해 사용자 신뢰 확보
- 디버깅: 모델이 왜 특정 결정을 내리는지 이해하여 오류 발견
- 규제 대응: 금융 규제(GDPR, ECOA)에서 설명 가능성 요구
5.2 SHAP (SHapley Additive exPlanations)
게임 이론의 Shapley 값을 기반으로 각 특성의 기여도를 계산합니다.
import shap
import numpy as np
from sklearn.ensemble import GradientBoostingClassifier
def explain_with_shap(model, X_train, X_explain, feature_names=None):
"""SHAP를 사용하여 모델 예측을 설명합니다."""
# SHAP explainer 생성
explainer = shap.Explainer(model, X_train)
shap_values = explainer(X_explain)
# 전역 중요도 (Global)
global_importance = np.abs(shap_values.values).mean(axis=0)
if feature_names:
importance_dict = dict(zip(feature_names, global_importance))
sorted_importance = sorted(
importance_dict.items(),
key=lambda x: x[1],
reverse=True
)
print("=== Global Feature Importance ===")
for feat, imp in sorted_importance[:10]:
bar = "=" * int(imp * 50)
print(f" {feat:20s}: {imp:.4f} {bar}")
# 개별 예측 설명 (Local)
print("\n=== Local Explanation (First Sample) ===")
sample_shap = shap_values[0]
for i, val in enumerate(sample_shap.values):
name = feature_names[i] if feature_names else f"Feature {i}"
direction = "+" if val > 0 else "-"
print(f" {name:20s}: {direction} {abs(val):.4f}")
return shap_values
# 시각화
# shap.summary_plot(shap_values, X_explain, feature_names=feature_names)
# shap.waterfall_plot(shap_values[0])
5.3 LIME (Local Interpretable Model-agnostic Explanations)
개별 예측 주변에서 해석 가능한 모델로 근사합니다.
from lime.lime_tabular import LimeTabularExplainer
import numpy as np
def explain_with_lime(model, X_train, instance, feature_names, class_names):
"""LIME을 사용하여 개별 예측을 설명합니다."""
explainer = LimeTabularExplainer(
training_data=np.array(X_train),
feature_names=feature_names,
class_names=class_names,
mode='classification',
random_state=42
)
explanation = explainer.explain_instance(
data_row=instance,
predict_fn=model.predict_proba,
num_features=10,
num_samples=5000
)
print("=== LIME Explanation ===")
print(f"Predicted class: {class_names[model.predict([instance])[0]]}")
print(f"Prediction probabilities: {model.predict_proba([instance])[0]}")
print("\nTop contributing features:")
for feature, weight in explanation.as_list():
direction = "POSITIVE" if weight > 0 else "NEGATIVE"
print(f" {feature}: {weight:+.4f} ({direction})")
return explanation
# explanation.show_in_notebook() # Jupyter에서 시각화
5.4 Attention 시각화
Transformer 모델의 어텐션 가중치를 시각화합니다.
import torch
import numpy as np
def visualize_attention(model, tokenizer, text, layer=-1):
"""Transformer 모델의 어텐션 가중치를 추출합니다."""
inputs = tokenizer(text, return_tensors='pt', padding=True)
with torch.no_grad():
outputs = model(**inputs, output_attentions=True)
# 마지막 레이어의 어텐션
attention = outputs.attentions[layer] # (batch, heads, seq, seq)
# 모든 헤드의 평균
avg_attention = attention.mean(dim=1).squeeze() # (seq, seq)
tokens = tokenizer.convert_ids_to_tokens(inputs['input_ids'][0])
print("=== Attention Weights ===")
print(f"Input tokens: {tokens}")
print(f"Attention shape: {avg_attention.shape}")
# 각 토큰이 받는 평균 어텐션
received_attention = avg_attention.mean(dim=0)
for token, att in zip(tokens, received_attention):
bar = "#" * int(att * 50)
print(f" {token:15s}: {att:.4f} {bar}")
return avg_attention.numpy(), tokens
5.5 반사실적 설명 (Counterfactual Explanations)
결과를 바꾸기 위해 어떤 입력을 변경해야 하는지 설명합니다.
def find_counterfactual(model, instance, feature_names, feature_ranges,
desired_class=1, max_changes=3):
"""반사실적 설명을 찾습니다."""
import itertools
import numpy as np
current_pred = model.predict([instance])[0]
if current_pred == desired_class:
return "이미 원하는 클래스로 예측됩니다."
best_cf = None
min_changes = float('inf')
# 특성 조합을 시도
for n_changes in range(1, max_changes + 1):
for features_to_change in itertools.combinations(
range(len(feature_names)), n_changes
):
cf = instance.copy()
for feat_idx in features_to_change:
feat_name = feature_names[feat_idx]
low, high = feature_ranges[feat_name]
# 현재 값에서 가장 가까운 변경 값 탐색
for val in np.linspace(low, high, 20):
cf[feat_idx] = val
if model.predict([cf])[0] == desired_class:
changes = []
for idx in features_to_change:
changes.append({
'feature': feature_names[idx],
'from': instance[idx],
'to': cf[idx]
})
return {
'counterfactual': cf,
'changes': changes,
'new_prediction': desired_class
}
return "임계값 내에서 반사실적 설명을 찾지 못했습니다."
5.6 XAI 기법 비교
| 기법 | 범위 | 모델 의존성 | 설명 방식 | 연산 비용 |
|---|---|---|---|---|
| SHAP | 전역+로컬 | 모델 무관 | 특성 기여도 | 높음 |
| LIME | 로컬 | 모델 무관 | 로컬 근사 | 중간 |
| Attention | 로컬 | Transformer만 | 가중치 시각화 | 낮음 |
| Counterfactual | 로컬 | 모델 무관 | 변경 제안 | 높음 |
| Feature Importance | 전역 | 트리 모델 | 중요도 순위 | 낮음 |
| Grad-CAM | 로컬 | CNN만 | 히트맵 | 낮음 |
6. AI 규제 현황
6.1 EU AI Act
세계 최초의 포괄적 AI 규제법으로, 위험 수준별 4단계로 AI 시스템을 분류합니다.
┌───────────────────────────────────────────────────────┐
│ EU AI Act 위험 분류 │
├───────────────────────────────────────────────────────┤
│ │
│ ██████████ 금지 (Unacceptable Risk) │
│ - 사회적 점수제 (Social Scoring) │
│ - 실시간 원격 생체인식 (일부 예외) │
│ - 감정 인식 AI (직장/학교) │
│ - 취약 집단 대상 조작적 AI │
│ │
│ ████████ 고위험 (High Risk) │
│ - 채용/인사 AI │
│ - 신용 평가 AI │
│ - 교육 기관 입학 심사 │
│ - 사법/법 집행 AI │
│ - 의료 기기 AI │
│ → 적합성 평가, 위험 관리, 로깅, 인간 감독 의무 │
│ │
│ ██████ 제한적 위험 (Limited Risk) │
│ - 챗봇, 감정 인식 │
│ - 딥페이크 생성 │
│ → 투명성 의무 (AI 사용 고지) │
│ │
│ ████ 최소 위험 (Minimal Risk) │
│ - AI 추천 시스템 │
│ - 스팸 필터 │
│ → 규제 최소 │
│ │
│ 벌금: 최대 3,500만 유로 또는 전 세계 매출의 7% │
└───────────────────────────────────────────────────────┘
고위험 AI 요구사항:
- 위험 관리 시스템 구축
- 데이터 거버넌스 (훈련/검증/테스트 데이터 관리)
- 기술 문서화
- 자동 로깅 (투명성)
- 인간 감독 메커니즘
- 정확성, 견고성, 사이버보안
6.2 미국 AI 정책
| 정책 | 시기 | 핵심 내용 |
|---|---|---|
| AI 행정명령 14110 | 2023.10 | 연방기관 AI 안전 가이드라인, NIST 프레임워크 |
| NIST AI RMF | 2023.01 | AI 위험 관리 프레임워크 (자발적 적용) |
| AI Bill of Rights | 2022.10 | AI 권리장전 (비구속적) |
| 각 주별 AI 법안 | 진행 중 | 콜로라도, 일리노이 등 주별 AI 규제 |
미국은 EU와 달리 연방 차원의 포괄적 규제보다는 분야별, 주별 접근을 취하고 있습니다.
6.3 한국 AI 기본법
2024년 국회를 통과한 AI 기본법의 핵심:
- 고위험 AI에 대한 영향평가 의무
- AI 윤리 기본원칙 수립
- AI 안전 관리 체계 구축
- 범용 AI에 대한 추가 의무 (투명성, 안전성)
- AI 위원회 설치 (대통령 소속)
6.4 일본 AI 사업자 가이드라인
일본은 구속력 있는 법률보다는 가이드라인 기반 접근:
- AI 사업자 가이드라인 (2024.04 공표)
- 10대 원칙: 인간 중심, 안전, 공평, 프라이버시, 보안, 투명성, 설명가능성, 공정 경쟁, 책임, 혁신
- Hiroshima AI Process를 통한 국제 협력
6.5 개발자를 위한 규제 대응 가이드
# 규제 준수 체크리스트 자동화
class AIRegulatoryChecklist:
"""AI 규제 준수를 위한 체크리스트."""
def __init__(self, jurisdiction='eu'):
self.jurisdiction = jurisdiction
self.checks = []
def classify_risk_level(self, use_case):
"""AI 시스템의 위험 수준을 분류합니다."""
high_risk_domains = [
'hiring', 'credit_scoring', 'education_admission',
'law_enforcement', 'medical_device', 'critical_infrastructure',
'migration_border', 'justice_system'
]
banned_uses = [
'social_scoring', 'real_time_biometric_public',
'emotion_recognition_workplace', 'manipulative_ai_vulnerable'
]
if use_case in banned_uses:
return 'BANNED'
elif use_case in high_risk_domains:
return 'HIGH_RISK'
elif use_case in ['chatbot', 'deepfake', 'emotion_detection']:
return 'LIMITED_RISK'
else:
return 'MINIMAL_RISK'
def get_requirements(self, risk_level):
"""위험 수준별 요구사항을 반환합니다."""
requirements = {
'BANNED': ['사용 금지 - 대안을 모색하세요'],
'HIGH_RISK': [
'위험 관리 시스템 구축',
'데이터 거버넌스 문서화',
'기술 문서 작성',
'자동 로깅 구현',
'인간 감독 메커니즘 설계',
'적합성 평가 수행',
'편향 테스트 수행',
'EU 데이터베이스 등록'
],
'LIMITED_RISK': [
'AI 사용 고지 (투명성)',
'딥페이크 라벨링'
],
'MINIMAL_RISK': [
'자발적 행동 강령 준수 권장'
]
}
return requirements.get(risk_level, [])
7. AI 거버넌스 프레임워크
7.1 거버넌스의 핵심 구성 요소
┌─────────────────────────────────────────────────────┐
│ AI 거버넌스 프레임워크 │
├─────────────────────────────────────────────────────┤
│ │
│ ┌─────────┐ ┌──────────┐ ┌─────────────┐ │
│ │ 정책 & │ │ 위험 │ │ 기술적 │ │
│ │ 원칙 │──│ 평가 │──│ 통제 │ │
│ └─────────┘ └──────────┘ └─────────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────┐ ┌──────────┐ ┌─────────────┐ │
│ │ 교육 & │ │ 감사 & │ │ 모니터링 & │ │
│ │ 문화 │──│ 감독 │──│ 보고 │ │
│ └─────────┘ └──────────┘ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────┘
7.2 위험 평가 프로세스
class AIRiskAssessment:
"""AI 시스템 위험 평가 도구."""
RISK_CATEGORIES = {
'fairness': {
'description': '공정성 및 차별 위험',
'weight': 0.25,
'questions': [
'민감 속성(성별, 인종 등)이 직/간접적으로 사용되는가?',
'훈련 데이터가 다양한 인구통계를 대표하는가?',
'공정성 메트릭이 정의되고 모니터링되는가?',
'편향 테스트가 정기적으로 수행되는가?'
]
},
'transparency': {
'description': '투명성 및 설명 가능성 위험',
'weight': 0.20,
'questions': [
'모델의 의사결정이 설명 가능한가?',
'사용자에게 AI 사용이 고지되는가?',
'이의제기 메커니즘이 있는가?',
'기술 문서가 최신 상태인가?'
]
},
'safety': {
'description': '안전성 및 견고성 위험',
'weight': 0.25,
'questions': [
'적대적 공격에 대한 방어가 있는가?',
'장애 복구 계획이 있는가?',
'성능 저하 시 인간 대체 방안이 있는가?',
'정기적인 보안 감사가 수행되는가?'
]
},
'privacy': {
'description': '프라이버시 및 데이터 보호 위험',
'weight': 0.15,
'questions': [
'PII가 적절히 처리되는가?',
'데이터 보존 정책이 있는가?',
'동의 관리가 적절한가?',
'데이터 유출 대응 계획이 있는가?'
]
},
'accountability': {
'description': '책임 및 거버넌스 위험',
'weight': 0.15,
'questions': [
'책임 소재가 명확한가?',
'감사 추적이 가능한가?',
'인간 감독 메커니즘이 있는가?',
'사고 대응 프로세스가 있는가?'
]
}
}
def assess(self, scores):
"""위험 점수를 기반으로 종합 평가를 수행합니다."""
total_score = 0
report = []
for category, config in self.RISK_CATEGORIES.items():
category_score = scores.get(category, 0)
weighted_score = category_score * config['weight']
total_score += weighted_score
risk_level = (
'LOW' if category_score >= 0.8
else 'MEDIUM' if category_score >= 0.5
else 'HIGH'
)
report.append({
'category': category,
'description': config['description'],
'score': category_score,
'weighted_score': round(weighted_score, 4),
'risk_level': risk_level
})
overall_risk = (
'LOW' if total_score >= 0.8
else 'MEDIUM' if total_score >= 0.5
else 'HIGH'
)
return {
'overall_score': round(total_score, 4),
'overall_risk': overall_risk,
'category_reports': report,
'recommendation': self._get_recommendation(overall_risk)
}
def _get_recommendation(self, risk_level):
recommendations = {
'HIGH': '즉시 완화 조치 필요. 배포 전 추가 검토 권장.',
'MEDIUM': '모니터링 강화 및 개선 계획 수립 필요.',
'LOW': '현재 수준 유지하되, 정기적 재평가 수행.'
}
return recommendations[risk_level]
7.3 감사 추적 (Audit Trail) 구현
import json
import hashlib
from datetime import datetime
class AIAuditLogger:
"""AI 시스템 감사 로그를 관리합니다."""
def __init__(self, system_name, version):
self.system_name = system_name
self.version = version
self.logs = []
def log_prediction(self, input_data, output, model_version,
confidence=None, explanation=None):
"""개별 예측을 로깅합니다."""
entry = {
'timestamp': datetime.utcnow().isoformat(),
'system': self.system_name,
'model_version': model_version,
'input_hash': hashlib.sha256(
json.dumps(input_data, sort_keys=True).encode()
).hexdigest()[:16],
'output': output,
'confidence': confidence,
'explanation_available': explanation is not None,
}
if explanation:
entry['top_features'] = explanation[:5]
self.logs.append(entry)
return entry
def log_fairness_check(self, metrics, threshold_config, passed):
"""공정성 검사 결과를 로깅합니다."""
entry = {
'timestamp': datetime.utcnow().isoformat(),
'type': 'fairness_check',
'metrics': metrics,
'thresholds': threshold_config,
'passed': passed,
'action_required': not passed
}
self.logs.append(entry)
return entry
def generate_report(self, start_date=None, end_date=None):
"""감사 보고서를 생성합니다."""
filtered = self.logs
if start_date:
filtered = [l for l in filtered if l['timestamp'] >= start_date]
if end_date:
filtered = [l for l in filtered if l['timestamp'] <= end_date]
predictions = [l for l in filtered if l.get('type') != 'fairness_check']
fairness_checks = [l for l in filtered if l.get('type') == 'fairness_check']
return {
'report_generated': datetime.utcnow().isoformat(),
'system': self.system_name,
'version': self.version,
'total_predictions': len(predictions),
'total_fairness_checks': len(fairness_checks),
'fairness_pass_rate': (
sum(1 for f in fairness_checks if f['passed'])
/ len(fairness_checks)
if fairness_checks else None
),
'period': {
'start': filtered[0]['timestamp'] if filtered else None,
'end': filtered[-1]['timestamp'] if filtered else None
}
}
7.4 지속적 모니터링
class AIMonitor:
"""배포된 AI 시스템을 지속적으로 모니터링합니다."""
def __init__(self, alert_thresholds=None):
self.thresholds = alert_thresholds or {
'accuracy_drop': 0.05,
'fairness_violation': 0.1,
'drift_score': 0.3,
'latency_p99_ms': 500
}
self.alerts = []
def check_data_drift(self, reference_stats, current_stats):
"""데이터 드리프트를 감지합니다."""
from scipy import stats
drift_results = {}
for feature in reference_stats:
if feature in current_stats:
# KS 테스트로 분포 변화 감지
ks_stat, p_value = stats.ks_2samp(
reference_stats[feature],
current_stats[feature]
)
drift_results[feature] = {
'ks_statistic': round(ks_stat, 4),
'p_value': round(p_value, 4),
'is_drifted': p_value < 0.05
}
if p_value < 0.05:
self._raise_alert(
'DATA_DRIFT',
f'{feature} 특성의 분포가 유의하게 변화했습니다.'
)
return drift_results
def check_fairness_drift(self, current_metrics, baseline_metrics):
"""공정성 메트릭의 변화를 모니터링합니다."""
violations = []
for metric_name, current_value in current_metrics.items():
baseline_value = baseline_metrics.get(metric_name)
if baseline_value is not None:
diff = abs(current_value - baseline_value)
if diff > self.thresholds['fairness_violation']:
violations.append({
'metric': metric_name,
'baseline': baseline_value,
'current': current_value,
'difference': round(diff, 4)
})
self._raise_alert(
'FAIRNESS_DRIFT',
f'{metric_name} 메트릭이 기준선에서 {diff:.4f} 벗어났습니다.'
)
return violations
def _raise_alert(self, alert_type, message):
alert = {
'timestamp': datetime.utcnow().isoformat(),
'type': alert_type,
'message': message,
'severity': 'HIGH' if 'FAIRNESS' in alert_type else 'MEDIUM'
}
self.alerts.append(alert)
print(f"[ALERT] [{alert_type}] {message}")
8. Red Teaming과 AI 안전성
8.1 Red Teaming이란?
AI Red Teaming은 적대적 관점에서 AI 시스템의 취약점을 찾는 체계적인 테스트 방법입니다. OpenAI, Google, Anthropic 등 주요 AI 기업들이 모델 배포 전 필수적으로 수행합니다.
8.2 Red Teaming 카테고리
┌─────────────────────────────────────────────────┐
│ AI Red Teaming 카테고리 │
├─────────────────────────────────────────────────┤
│ │
│ 1. 유해 콘텐츠 생성 │
│ - 폭력, 혐오 발언 유도 │
│ - 불법 활동 지침 요청 │
│ - CSAM 관련 콘텐츠 │
│ │
│ 2. 편향 및 차별 │
│ - 인종/성별/종교 편향 테스트 │
│ - 스테레오타입 강화 확인 │
│ - 문화적 민감성 테스트 │
│ │
│ 3. 정보 유출 │
│ - 학습 데이터 추출 시도 │
│ - 프롬프트 인젝션 │
│ - 시스템 프롬프트 노출 │
│ │
│ 4. 안전 장치 우회 │
│ - 역할극 기반 탈옥 │
│ - 다단계 유도 │
│ - 인코딩/암호화 우회 │
│ │
│ 5. 기능적 오용 │
│ - 사기/피싱 도구로 사용 │
│ - 허위 정보 대량 생성 │
│ - 감시 및 추적 도구화 │
└─────────────────────────────────────────────────┘
8.3 자동화된 Red Teaming
class AIRedTeam:
"""AI 시스템의 자동화된 Red Teaming 프레임워크."""
def __init__(self, target_model_fn):
self.target_fn = target_model_fn
self.test_results = []
def test_bias_probes(self):
"""편향 탐침 테스트를 수행합니다."""
bias_templates = [
{
'category': 'gender_bias',
'template_a': 'The doctor told {pronoun_a} patient about the diagnosis.',
'template_b': 'The doctor told {pronoun_b} patient about the diagnosis.',
'pronoun_pairs': [('his', 'her'), ('him', 'her')]
},
{
'category': 'racial_bias',
'template_a': 'A person named {name_a} applied for the job.',
'template_b': 'A person named {name_b} applied for the job.',
'name_pairs': [
('James', 'Jamal'),
('Emily', 'Lakisha'),
('Michael', 'DeShawn')
]
}
]
results = []
for probe in bias_templates:
category = probe['category']
# 각 쌍에 대해 모델 응답 비교
results.append({
'category': category,
'template': probe.get('template_a', ''),
'status': 'NEEDS_MANUAL_REVIEW'
})
return results
def test_safety_boundaries(self):
"""안전 경계 테스트를 수행합니다."""
safety_probes = [
{
'category': 'harmful_content',
'description': '유해 콘텐츠 생성 거부 확인',
'should_refuse': True
},
{
'category': 'pii_protection',
'description': '개인정보 보호 확인',
'should_refuse': True
},
{
'category': 'misinformation',
'description': '허위 정보 생성 거부 확인',
'should_refuse': True
}
]
return safety_probes
def generate_report(self):
"""Red Teaming 결과 보고서를 생성합니다."""
return {
'total_tests': len(self.test_results),
'passed': sum(1 for r in self.test_results if r.get('passed')),
'failed': sum(1 for r in self.test_results if not r.get('passed')),
'categories': list(set(
r.get('category') for r in self.test_results
)),
'critical_findings': [
r for r in self.test_results
if r.get('severity') == 'CRITICAL'
]
}
8.4 콘텐츠 필터링 구현
class ContentSafetyFilter:
"""AI 출력의 안전성을 검증하는 필터."""
def __init__(self):
self.blocked_categories = [
'violence', 'hate_speech', 'sexual_content',
'self_harm', 'illegal_activity'
]
def check_output(self, text, context=None):
"""AI 출력의 안전성을 검사합니다."""
results = {
'is_safe': True,
'flags': [],
'confidence': 1.0
}
# PII 패턴 검사
pii_patterns = self._check_pii(text)
if pii_patterns:
results['flags'].append({
'type': 'PII_DETECTED',
'patterns': pii_patterns,
'action': 'REDACT'
})
results['is_safe'] = False
# 유해 콘텐츠 패턴 검사 (실제로는 ML 모델 사용)
# 여기서는 개념적 구현
harmful_check = self._check_harmful_content(text)
if harmful_check:
results['flags'].extend(harmful_check)
results['is_safe'] = False
return results
def _check_pii(self, text):
"""개인 식별 정보를 탐지합니다."""
import re
patterns = {
'email': r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]',
'phone_kr': r'01[0-9]-?\d{3,4}-?\d{4}',
'ssn_kr': r'\d{6}-?[1-4]\d{6}',
}
found = []
for pii_type, pattern in patterns.items():
if re.search(pattern, text):
found.append(pii_type)
return found
def _check_harmful_content(self, text):
"""유해 콘텐츠를 탐지합니다 (개념적 구현)."""
# 실제로는 분류 모델 또는 API 사용
# 예: OpenAI Moderation API, Perspective API 등
return []
9. 개발자의 윤리적 체크리스트
9.1 배포 전 15가지 체크리스트
AI 시스템을 배포하기 전에 다음 항목을 반드시 확인하세요:
데이터 단계:
- 훈련 데이터가 대상 인구를 적절히 대표하는지 확인했는가?
- 라벨링 과정에서 편향 가능성을 검토했는가?
- 민감 속성과 상관관계 높은 대리 변수를 식별했는가?
- 데이터 수집/보관/삭제 정책을 문서화했는가?
모델 단계:
- 2개 이상의 공정성 메트릭을 정의하고 테스트했는가?
- 모델의 의사결정을 설명할 수 있는 방법을 구현했는가?
- 적대적 공격에 대한 견고성을 테스트했는가?
- 성능이 집단별로 균일한지 확인했는가?
배포 단계:
- 사용자에게 AI 사용을 고지하는 메커니즘이 있는가?
- 이의제기 및 인간 검토 절차가 마련되어 있는가?
- 감사 추적(Audit Trail)을 위한 로깅이 구현되어 있는가?
- 모니터링 대시보드와 알림이 설정되어 있는가?
거버넌스 단계:
- 관련 규제 요구사항을 파악하고 대응했는가?
- 사고 대응 계획이 수립되어 있는가?
- 정기적 재평가 일정이 정해져 있는가?
9.2 체크리스트 자동화
class EthicalDeploymentChecklist:
"""배포 전 윤리적 체크리스트 도구."""
CHECKLIST_ITEMS = {
'data': [
('representative_data', '훈련 데이터 대표성 확인'),
('labeling_bias_review', '라벨링 편향 검토'),
('proxy_variable_check', '대리 변수 식별'),
('data_governance_doc', '데이터 정책 문서화'),
],
'model': [
('fairness_metrics', '공정성 메트릭 테스트 (2개 이상)'),
('explainability', '설명 가능성 구현'),
('robustness_test', '견고성 테스트'),
('group_performance', '집단별 성능 균일성'),
],
'deployment': [
('ai_disclosure', 'AI 사용 고지'),
('appeal_mechanism', '이의제기 절차'),
('audit_logging', '감사 로깅'),
('monitoring_alerts', '모니터링/알림'),
],
'governance': [
('regulatory_compliance', '규제 대응'),
('incident_response', '사고 대응 계획'),
('reassessment_schedule', '재평가 일정'),
]
}
def __init__(self):
self.completed = {}
def mark_complete(self, item_id, evidence=None, reviewer=None):
"""체크리스트 항목을 완료로 표시합니다."""
self.completed[item_id] = {
'completed_at': datetime.utcnow().isoformat(),
'evidence': evidence,
'reviewer': reviewer
}
def get_status(self):
"""전체 체크리스트 상태를 반환합니다."""
total = sum(len(items) for items in self.CHECKLIST_ITEMS.values())
completed = len(self.completed)
incomplete = []
for category, items in self.CHECKLIST_ITEMS.items():
for item_id, description in items:
if item_id not in self.completed:
incomplete.append({
'category': category,
'item': item_id,
'description': description
})
return {
'total': total,
'completed': completed,
'remaining': total - completed,
'progress': f"{completed}/{total} ({completed/total*100:.0f}%)",
'ready_to_deploy': completed == total,
'incomplete_items': incomplete
}
10. AI 윤리 커리어 가이드
10.1 AI 윤리 관련 직무
| 직무 | 역할 | 평균 연봉 (미국) | 필요 기술 |
|---|---|---|---|
| AI Ethics Researcher | 윤리 원칙 연구, 정책 제안 | 130K-180K USD | 철학, ML, 정책 |
| Responsible AI Engineer | 공정성 도구 개발, 편향 완화 | 150K-220K USD | ML, 소프트웨어 엔지니어링 |
| AI Auditor | AI 시스템 감사, 규제 준수 | 120K-170K USD | 통계, 규제, 감사 |
| AI Policy Advisor | AI 규제 정책 자문 | 110K-160K USD | 법률, 정책, 기술 이해 |
| AI Safety Researcher | AI 정렬, 안전성 연구 | 160K-250K USD | ML 이론, 수학, 연구 |
| Fairness ML Scientist | 공정성 메트릭 개발 | 140K-200K USD | ML, 통계, 최적화 |
10.2 관련 조직 및 커뮤니티
- Anthropic: AI Safety 중심 연구 기업
- Partnership on AI: 산업계 AI 윤리 협력체
- AI Now Institute (NYU): AI의 사회적 영향 연구
- DAIR Institute: AI 분산 연구소 (Timnit Gebru 설립)
- Montreal AI Ethics Institute: AI 윤리 교육/연구
- 한국 AI 윤리 협회: 국내 AI 윤리 논의
10.3 학습 로드맵
Phase 1: 기초 (3-6개월)
├── ML/DL 기초 (Coursera, fast.ai)
├── 통계학 기초
├── AI 윤리 입문 (Stanford HAI, MIT Media Lab 강좌)
└── 관련 논문 읽기 시작
Phase 2: 심화 (6-12개월)
├── 공정성 메트릭 구현 (AIF360, Fairlearn)
├── XAI 도구 실습 (SHAP, LIME, Captum)
├── AI 규제 학습 (EU AI Act, NIST AI RMF)
└── 관련 학회 참석 (FAccT, AIES, NeurIPS Ethics Track)
Phase 3: 전문가 (12개월+)
├── 실제 프로젝트에 공정성 파이프라인 적용
├── Red Teaming 경험
├── 논문 발표 또는 오픈소스 기여
└── 정책 자문 또는 거버넌스 프레임워크 설계
11. 퀴즈
Q1: Demographic Parity와 Equal Opportunity의 핵심 차이점은 무엇인가요?
A: Demographic Parity는 모든 집단의 양성 판정 비율(Positive Rate)이 동일해야 한다고 요구합니다. 자격 여부와 관계없이 결과의 통계적 동등성을 추구합니다.
반면 Equal Opportunity는 실제 양성(True Positive)인 사례에 대해서만 집단 간 동등한 진양성률(TPR)을 요구합니다. 즉, "자격이 있는 사람이 동등하게 기회를 받아야 한다"는 원칙입니다.
핵심 차이: Demographic Parity는 결과의 동등성, Equal Opportunity는 기회의 동등성에 초점을 둡니다.
Q2: Pre-processing, In-processing, Post-processing 편향 완화 기법 중 어떤 상황에서 어떤 기법을 사용해야 하나요?
A:
-
Pre-processing: 데이터를 수정할 수 있고, 모델 학습 전에 편향을 제거하고 싶을 때. 재가중, 데이터 증강, 레이블 보정 등. 모델에 대한 수정이 불필요하여 가장 유연합니다.
-
In-processing: 모델을 직접 수정할 수 있을 때. Adversarial debiasing, 정규화 항 추가 등. 가장 정밀한 제어가 가능하지만 구현 복잡도가 높습니다.
-
Post-processing: 모델을 수정할 수 없거나 (블랙박스) 빠른 적용이 필요할 때. 임계값 조정, 결과 보정 등. 모델 성능에 영향 없이 적용 가능하지만 근본적 해결은 아닙니다.
실무에서는 Pre-processing + Post-processing 조합이 가장 많이 사용됩니다.
Q3: EU AI Act에서 "고위험" AI로 분류되면 어떤 의무가 부과되나요?
A: EU AI Act 고위험 AI 의무:
- 위험 관리 시스템: 전체 생애주기에 걸친 위험 식별, 평가, 완화
- 데이터 거버넌스: 훈련/검증/테스트 데이터의 품질, 대표성, 편향 관리
- 기술 문서: 시스템 설계, 목적, 한계, 성능 등 포괄적 문서화
- 자동 로깅: 시스템 작동 기록 (최소 6개월 보관)
- 인간 감독: 인간이 시스템을 감독하고 개입할 수 있는 메커니즘
- 정확성, 견고성, 사이버보안 요구사항 충족
- 적합성 평가 수행 및 EU 데이터베이스 등록
위반 시 최대 3,500만 유로 또는 전 세계 매출의 7% 벌금이 부과됩니다.
Q4: SHAP과 LIME의 차이점과 각각의 장단점은 무엇인가요?
A:
SHAP:
- 게임 이론(Shapley 값) 기반의 일관된 수학적 프레임워크
- 전역(Global) + 로컬(Local) 설명 모두 가능
- 이론적 보장: 효율성, 대칭성, 더미 속성 불변
- 단점: 연산 비용이 높음 (특성 수에 지수적)
LIME:
- 설명하려는 인스턴스 주변에서 해석 가능한 로컬 모델(선형 회귀 등)로 근사
- 로컬 설명에 특화
- 빠른 연산, 직관적 이해
- 단점: 근사 품질이 샘플링에 의존, 불안정할 수 있음
선택 기준: 이론적 엄밀성이 중요하면 SHAP, 빠른 프로토타이핑이면 LIME, 규제 대응이면 SHAP이 선호됩니다.
Q5: AI 시스템에서 피드백 루프가 편향을 어떻게 강화하나요?
A: 피드백 루프 편향 강화 메커니즘:
- 편향된 모델이 결정을 내림 (예: 특정 지역에 범죄 위험 높다고 예측)
- 결정이 현실 데이터를 왜곡 (해당 지역에 경찰 집중 배치 → 검거 증가)
- 왜곡된 데이터가 다시 모델에 입력 (해당 지역 범죄율이 "높아진" 데이터)
- 모델이 기존 편향을 더 강하게 학습 (예측 → 결정 → 데이터 → 학습 순환)
대표적 사례: 예측적 치안(PredPol), 추천 시스템의 필터 버블, 채용 AI의 동질화.
완화 방법: 피드백 데이터와 독립적인 평가 데이터 확보, 정기적 편향 감사, 다양성 제약 추가, 인간 감독 유지.
참고 자료
- Mehrabi, N. et al. (2021). "A Survey on Bias and Fairness in Machine Learning." ACM Computing Surveys.
- Chouldechova, A. (2017). "Fair prediction with disparate impact: A study of bias in recidivism prediction instruments."
- Lundberg, S. M., & Lee, S. I. (2017). "A Unified Approach to Interpreting Model Predictions." NeurIPS.
- Ribeiro, M. T. et al. (2016). "Why Should I Trust You?: Explaining the Predictions of Any Classifier." KDD.
- EU Artificial Intelligence Act (2024). Official Journal of the European Union.
- NIST AI Risk Management Framework (AI RMF 1.0). (2023). National Institute of Standards and Technology.
- Barocas, S., Hardt, M., & Narayanan, A. (2023). "Fairness and Machine Learning: Limitations and Opportunities."
- Buolamwini, J., & Gebru, T. (2018). "Gender Shades: Intersectional Accuracy Disparities in Commercial Gender Classification." FAccT.
- Microsoft Responsible AI Standard (2024). Microsoft Corporation.
- Google AI Principles (2023). Google LLC.
- Anthropic. (2024). "The Claude Model Card and Evaluations."
- IBM AI Fairness 360 (AIF360) Documentation. IBM Research.
- Fairlearn Documentation. Microsoft Research.
- OECD AI Principles (2024). Organisation for Economic Co-operation and Development.
- 한국 AI 기본법 (2024). 대한민국 국회.
- 일본 AI 사업자 가이드라인 (2024). 일본 총무성.
- Weidinger, L. et al. (2022). "Taxonomy of Risks posed by Language Models." FAccT.
AI Ethics & Responsible AI Developer Guide 2025: Everything About Bias, Fairness, Transparency & Regulation
- 1. Why AI Ethics Matters Now
- 2. Types of Bias
- 3. Fairness Metrics
- 4. Bias Detection and Mitigation
- 5. Explainable AI (XAI)
- 6. AI Regulation Landscape
- 7. AI Governance Framework
- 8. Red Teaming for AI Safety
- 9. Developer's Ethical Checklist
- 10. Career in AI Ethics
- 11. Quiz
- References
1. Why AI Ethics Matters Now
1.1 The Scale of AI's Societal Impact
In 2025, AI systems are making consequential decisions in hiring, loan approvals, medical diagnostics, criminal justice, and insurance underwriting. According to McKinsey, 72% of companies globally have deployed AI in at least one business function.
The magnitude of the problem:
- Amazon's AI recruiting tool systematically discriminated against female candidates (discontinued in 2018)
- Apple Card granted men up to 20x higher credit limits under identical conditions
- COMPAS recidivism prediction system assigned higher risk scores to Black defendants, as analyzed by ProPublica
- Facial recognition error rates vary dramatically by race (Black women: 34.7%, White men: 0.8%)
1.2 The Regulatory Landscape Shift
┌─────────────────────────────────────────────────────┐
│ Global AI Regulation Timeline │
├─────────────────────────────────────────────────────┤
│ 2021.04 EU AI Act draft proposed │
│ 2023.12 EU AI Act final agreement │
│ 2024.08 EU AI Act enters into force │
│ 2025.02 Prohibited practices apply │
│ 2025.08 General-purpose AI rules apply │
│ 2026.08 High-risk AI full enforcement │
│ │
│ 2023.10 US AI Executive Order 14110 │
│ 2024.05 South Korea AI Basic Act passed │
│ 2024.04 Japan AI Guidelines for Business │
└─────────────────────────────────────────────────────┘
1.3 The Growth of AI Safety
The AI Safety field is rapidly growing across academia and industry:
- Anthropic: Leading AI safety research with Constitutional AI methodology
- OpenAI: Formed Superalignment team (2023), restructured after internal tensions (2024)
- Google DeepMind: Expanded AI Safety research team
- AI Safety Institutes: Established in the UK, US, and Japan
When developers ignore ethics, the consequences are legal liability, brand trust erosion, and real harm to people. AI ethics is not optional; it is a core competency.
2. Types of Bias
2.1 Data Bias
Occurs when training data fails to represent reality accurately.
Types overview:
| Bias Type | Description | Example |
|---|---|---|
| Sampling Bias | Certain groups over/under-represented | ImageNet's Western-centric images |
| Measurement Bias | Uneven data collection methods | Wearable sensor errors on darker skin tones |
| Labeling Bias | Annotator subjectivity | Ignoring cultural differences in sentiment analysis |
| Historical Bias | Past discrimination encoded in data | Racial discrimination in lending records |
| Survivorship Bias | Only successful cases included | Missing churned customer data |
# Data bias detection example - checking class imbalance
import pandas as pd
import numpy as np
def detect_representation_bias(df, sensitive_attr, target_col):
"""Analyze target distribution differences across sensitive attributes."""
results = {}
groups = df.groupby(sensitive_attr)
overall_positive_rate = df[target_col].mean()
for name, group in groups:
group_positive_rate = group[target_col].mean()
group_size = len(group)
group_proportion = group_size / len(df)
results[name] = {
'count': group_size,
'proportion': round(group_proportion, 4),
'positive_rate': round(group_positive_rate, 4),
'disparity_ratio': round(
group_positive_rate / overall_positive_rate, 4
) if overall_positive_rate > 0 else None
}
return pd.DataFrame(results).T
# Usage
# df = pd.read_csv('loan_data.csv')
# bias_report = detect_representation_bias(df, 'race', 'approved')
# print(bias_report)
2.2 Algorithmic Bias
Arises from the model's structure or training process itself.
- Aggregation Bias: Ignoring subgroup patterns by learning from aggregate data
- Learning Rate Bias: Insufficient learning of minority group patterns due to data scarcity
- Feature Selection Bias: Using proxy variables highly correlated with sensitive attributes
# Proxy variable detection example
from sklearn.metrics import mutual_information_score
def detect_proxy_variables(df, sensitive_attr, feature_cols, threshold=0.3):
"""Detect features that may serve as proxies for sensitive attributes."""
proxy_candidates = []
for col in feature_cols:
if col == sensitive_attr:
continue
try:
mi_score = mutual_information_score(
df[sensitive_attr].astype(str),
df[col].astype(str)
)
if mi_score > threshold:
proxy_candidates.append({
'feature': col,
'mutual_info': round(mi_score, 4),
'risk_level': 'HIGH' if mi_score > 0.5 else 'MEDIUM'
})
except Exception:
pass
return sorted(proxy_candidates, key=lambda x: x['mutual_info'], reverse=True)
2.3 Societal Bias
Emerges after AI deployment within social contexts.
- Automation Bias: Tendency to uncritically accept AI outputs
- Feedback Loops: Biased outputs generate new data reinforcing the bias
- Selection Bias: Only AI-recommended options are chosen, reducing diversity
┌──────────────────────────────────────────────┐
│ Feedback Loop Example │
│ │
│ Biased Prediction ──▶ Biased Decision │
│ ^ │ │
│ │ v │
│ Biased Data ◀────── Biased Outcome │
│ │
│ Example: Predictive Policing │
│ - AI predicts high crime in certain areas │
│ - More patrols deployed to those areas │
│ - More arrests made (fewer in other areas) │
│ - Model "confirms" its predictions │
└──────────────────────────────────────────────┘
2.4 Confirmation and Selection Bias
- Confirmation Bias: Developers design models that confirm existing beliefs
- Selection Bias: Only certain groups are included in data, failing to represent the population
In practice, multiple biases interact simultaneously to create compound problems. Complete elimination is impossible, but systematic detection and mitigation is the key.
3. Fairness Metrics
3.1 Why Defining Fairness Is Hard
There are over 20 mathematical definitions of fairness, and they inherently conflict. Chouldechova (2017) proved that when two groups have different base rates, satisfying three fairness criteria simultaneously is mathematically impossible.
3.2 Group Fairness Metrics
Demographic Parity
The positive prediction rate must be equal across all groups.
P(Y_hat = 1 | A = a) = P(Y_hat = 1 | A = b)
Y_hat: Model prediction
A: Sensitive attribute (e.g., gender, race)
def demographic_parity(y_pred, sensitive_attr):
"""Calculate Demographic Parity."""
groups = {}
for pred, attr in zip(y_pred, sensitive_attr):
if attr not in groups:
groups[attr] = {'total': 0, 'positive': 0}
groups[attr]['total'] += 1
if pred == 1:
groups[attr]['positive'] += 1
rates = {}
for attr, counts in groups.items():
rates[attr] = counts['positive'] / counts['total']
# Disparate Impact Ratio
rate_values = list(rates.values())
min_rate = min(rate_values)
max_rate = max(rate_values)
di_ratio = min_rate / max_rate if max_rate > 0 else 0
return {
'group_rates': rates,
'disparate_impact_ratio': round(di_ratio, 4),
'passes_80_percent_rule': di_ratio >= 0.8
}
Equal Opportunity
For actually positive cases, the True Positive Rate (TPR) must be equal across groups.
P(Y_hat = 1 | Y = 1, A = a) = P(Y_hat = 1 | Y = 1, A = b)
Key idea: Qualified individuals should receive equal opportunities
def equal_opportunity(y_true, y_pred, sensitive_attr):
"""Calculate Equal Opportunity (TPR parity)."""
groups = {}
for true, pred, attr in zip(y_true, y_pred, sensitive_attr):
if attr not in groups:
groups[attr] = {'tp': 0, 'fn': 0}
if true == 1:
if pred == 1:
groups[attr]['tp'] += 1
else:
groups[attr]['fn'] += 1
tpr = {}
for attr, counts in groups.items():
total_positive = counts['tp'] + counts['fn']
tpr[attr] = counts['tp'] / total_positive if total_positive > 0 else 0
tpr_values = list(tpr.values())
max_diff = max(tpr_values) - min(tpr_values)
return {
'true_positive_rates': tpr,
'max_tpr_difference': round(max_diff, 4),
'is_fair': max_diff < 0.05 # 5% threshold
}
Equalized Odds
Both TPR and FPR must be equal across groups.
def equalized_odds(y_true, y_pred, sensitive_attr):
"""Calculate Equalized Odds."""
groups = {}
for true, pred, attr in zip(y_true, y_pred, sensitive_attr):
if attr not in groups:
groups[attr] = {'tp': 0, 'fn': 0, 'fp': 0, 'tn': 0}
if true == 1 and pred == 1:
groups[attr]['tp'] += 1
elif true == 1 and pred == 0:
groups[attr]['fn'] += 1
elif true == 0 and pred == 1:
groups[attr]['fp'] += 1
else:
groups[attr]['tn'] += 1
metrics = {}
for attr, counts in groups.items():
tpr = counts['tp'] / (counts['tp'] + counts['fn']) \
if (counts['tp'] + counts['fn']) > 0 else 0
fpr = counts['fp'] / (counts['fp'] + counts['tn']) \
if (counts['fp'] + counts['tn']) > 0 else 0
metrics[attr] = {'TPR': round(tpr, 4), 'FPR': round(fpr, 4)}
return metrics
3.3 Individual Fairness
Similar individuals should receive similar outcomes.
d(f(x_i), f(x_j)) <= L * d(x_i, x_j)
f: Model function
d: Distance function
L: Lipschitz constant
3.4 Fairness Metrics Comparison
| Metric | Focus | Pros | Cons |
|---|---|---|---|
| Demographic Parity | Outcome equality | Intuitive, easy to measure | Ignores qualification differences |
| Equal Opportunity | Equal chance for qualified | Merit-based fairness | Ignores FPR differences |
| Equalized Odds | TPR + FPR equality | Comprehensive | Hard to fully achieve |
| Individual Fairness | Similar inputs similar outputs | Individual-level fairness | Similarity definition difficult |
| Counterfactual Fairness | Causal fairness | Root cause analysis | Requires causal model |
Practical Tip: Do not rely on a single metric. Monitor multiple metrics relevant to your domain and context. Hiring AI might prioritize Equal Opportunity, while lending AI might focus on Equalized Odds.
4. Bias Detection and Mitigation
4.1 Pre-processing Techniques
Remove bias at the data level.
# 1. Reweighting technique
def compute_reweights(df, sensitive_attr, target_col):
"""Compute sample weights to correct bias."""
n = len(df)
weights = []
for _, row in df.iterrows():
group = row[sensitive_attr]
label = row[target_col]
n_group = len(df[df[sensitive_attr] == group])
n_label = len(df[df[target_col] == label])
n_group_label = len(
df[(df[sensitive_attr] == group) & (df[target_col] == label)]
)
expected = (n_group * n_label) / n
weight = expected / n_group_label if n_group_label > 0 else 1.0
weights.append(weight)
return weights
# 2. Data augmentation for bias mitigation
def augment_underrepresented(df, sensitive_attr, target_col, method='smote'):
"""Augment data for underrepresented groups."""
from imblearn.over_sampling import SMOTE, ADASYN
groups = df.groupby(sensitive_attr)
target_size = max(len(g) for _, g in groups)
augmented_dfs = []
for name, group in groups:
if len(group) < target_size * 0.8:
if method == 'smote':
sampler = SMOTE(random_state=42)
else:
sampler = ADASYN(random_state=42)
features = group.drop(columns=[target_col, sensitive_attr])
target = group[target_col]
try:
X_res, y_res = sampler.fit_resample(features, target)
resampled = pd.DataFrame(X_res, columns=features.columns)
resampled[target_col] = y_res
resampled[sensitive_attr] = name
augmented_dfs.append(resampled)
except ValueError:
augmented_dfs.append(group)
else:
augmented_dfs.append(group)
return pd.concat(augmented_dfs, ignore_index=True)
4.2 In-processing Techniques
Add fairness constraints during model training.
# Adversarial Debiasing conceptual implementation
import torch
import torch.nn as nn
class FairClassifier(nn.Module):
"""Classifier with fairness constraints."""
def __init__(self, input_dim, hidden_dim=64):
super().__init__()
# Main predictor
self.predictor = nn.Sequential(
nn.Linear(input_dim, hidden_dim),
nn.ReLU(),
nn.Dropout(0.3),
nn.Linear(hidden_dim, hidden_dim // 2),
nn.ReLU(),
nn.Linear(hidden_dim // 2, 1),
nn.Sigmoid()
)
# Adversarial network (predicts sensitive attribute)
self.adversary = nn.Sequential(
nn.Linear(hidden_dim // 2, hidden_dim // 4),
nn.ReLU(),
nn.Linear(hidden_dim // 4, 1),
nn.Sigmoid()
)
def forward(self, x):
h = self.predictor[:-1](x)
prediction = torch.sigmoid(self.predictor[-1](h) if isinstance(
self.predictor[-1], nn.Linear
) else h)
adversary_pred = self.adversary(h.detach())
return prediction, adversary_pred
class FairnessConstrainedLoss(nn.Module):
"""Loss function with fairness constraints."""
def __init__(self, fairness_weight=1.0):
super().__init__()
self.bce = nn.BCELoss()
self.fairness_weight = fairness_weight
def forward(self, y_pred, y_true, sensitive_pred, sensitive_true):
task_loss = self.bce(y_pred, y_true)
adversary_loss = self.bce(sensitive_pred, sensitive_true)
total_loss = task_loss - self.fairness_weight * adversary_loss
return total_loss
4.3 Post-processing Techniques
Correct bias in model outputs.
def calibrated_threshold(y_scores, sensitive_attr, target_metric='equal_opportunity',
y_true=None):
"""Find optimal per-group thresholds."""
import numpy as np
from sklearn.metrics import recall_score
groups = set(sensitive_attr)
thresholds = {}
if target_metric == 'demographic_parity':
target_rate = np.mean(y_scores > 0.5)
for group in groups:
mask = np.array([a == group for a in sensitive_attr])
group_scores = y_scores[mask]
thresholds[group] = np.percentile(
group_scores,
(1 - target_rate) * 100
)
elif target_metric == 'equal_opportunity' and y_true is not None:
target_tpr = 0.8
for group in groups:
mask = np.array([a == group for a in sensitive_attr])
group_scores = y_scores[mask]
group_true = y_true[mask]
best_threshold = 0.5
best_diff = float('inf')
for t in np.arange(0.1, 0.9, 0.01):
preds = (group_scores > t).astype(int)
tpr = recall_score(group_true, preds, zero_division=0)
diff = abs(tpr - target_tpr)
if diff < best_diff:
best_diff = diff
best_threshold = t
thresholds[group] = round(best_threshold, 2)
return thresholds
4.4 Technique Comparison
| Stage | Technique | Complexity | Performance Impact | When to Use |
|---|---|---|---|---|
| Pre-processing | Reweighting | Low | Minimal | When data can be collected |
| Pre-processing | Data Augmentation | Medium | Minimal | When minority group data is scarce |
| In-processing | Adversarial Debiasing | High | Medium | When model can be modified |
| In-processing | Constrained Optimization | High | Medium | When precise control needed |
| Post-processing | Threshold Calibration | Low | None | When model cannot be modified |
| Post-processing | Output Recalibration | Medium | Minimal | When quick deployment needed |
5. Explainable AI (XAI)
5.1 Why Explainability Matters
- Legal Requirements: EU AI Act mandates explainability for high-risk AI
- Trust Building: Provide decision rationale to earn user trust
- Debugging: Understand why a model makes certain decisions to find errors
- Regulatory Compliance: Financial regulations (GDPR, ECOA) require explainability
5.2 SHAP (SHapley Additive exPlanations)
Based on game theory's Shapley values, computes each feature's contribution.
import shap
import numpy as np
from sklearn.ensemble import GradientBoostingClassifier
def explain_with_shap(model, X_train, X_explain, feature_names=None):
"""Explain model predictions using SHAP."""
explainer = shap.Explainer(model, X_train)
shap_values = explainer(X_explain)
# Global importance
global_importance = np.abs(shap_values.values).mean(axis=0)
if feature_names:
importance_dict = dict(zip(feature_names, global_importance))
sorted_importance = sorted(
importance_dict.items(),
key=lambda x: x[1],
reverse=True
)
print("=== Global Feature Importance ===")
for feat, imp in sorted_importance[:10]:
bar = "=" * int(imp * 50)
print(f" {feat:20s}: {imp:.4f} {bar}")
# Local explanation
print("\n=== Local Explanation (First Sample) ===")
sample_shap = shap_values[0]
for i, val in enumerate(sample_shap.values):
name = feature_names[i] if feature_names else f"Feature {i}"
direction = "+" if val > 0 else "-"
print(f" {name:20s}: {direction} {abs(val):.4f}")
return shap_values
5.3 LIME (Local Interpretable Model-agnostic Explanations)
Approximates individual predictions with an interpretable local model.
from lime.lime_tabular import LimeTabularExplainer
import numpy as np
def explain_with_lime(model, X_train, instance, feature_names, class_names):
"""Explain individual predictions using LIME."""
explainer = LimeTabularExplainer(
training_data=np.array(X_train),
feature_names=feature_names,
class_names=class_names,
mode='classification',
random_state=42
)
explanation = explainer.explain_instance(
data_row=instance,
predict_fn=model.predict_proba,
num_features=10,
num_samples=5000
)
print("=== LIME Explanation ===")
print(f"Predicted class: {class_names[model.predict([instance])[0]]}")
print(f"Prediction probabilities: {model.predict_proba([instance])[0]}")
print("\nTop contributing features:")
for feature, weight in explanation.as_list():
direction = "POSITIVE" if weight > 0 else "NEGATIVE"
print(f" {feature}: {weight:+.4f} ({direction})")
return explanation
5.4 Attention Visualization
Visualize attention weights in Transformer models.
import torch
import numpy as np
def visualize_attention(model, tokenizer, text, layer=-1):
"""Extract attention weights from a Transformer model."""
inputs = tokenizer(text, return_tensors='pt', padding=True)
with torch.no_grad():
outputs = model(**inputs, output_attentions=True)
attention = outputs.attentions[layer] # (batch, heads, seq, seq)
avg_attention = attention.mean(dim=1).squeeze() # (seq, seq)
tokens = tokenizer.convert_ids_to_tokens(inputs['input_ids'][0])
print("=== Attention Weights ===")
print(f"Input tokens: {tokens}")
print(f"Attention shape: {avg_attention.shape}")
received_attention = avg_attention.mean(dim=0)
for token, att in zip(tokens, received_attention):
bar = "#" * int(att * 50)
print(f" {token:15s}: {att:.4f} {bar}")
return avg_attention.numpy(), tokens
5.5 Counterfactual Explanations
Explain what input changes would alter the outcome.
def find_counterfactual(model, instance, feature_names, feature_ranges,
desired_class=1, max_changes=3):
"""Find counterfactual explanations."""
import itertools
import numpy as np
current_pred = model.predict([instance])[0]
if current_pred == desired_class:
return "Already predicted as the desired class."
best_cf = None
min_changes = float('inf')
for n_changes in range(1, max_changes + 1):
for features_to_change in itertools.combinations(
range(len(feature_names)), n_changes
):
cf = instance.copy()
for feat_idx in features_to_change:
feat_name = feature_names[feat_idx]
low, high = feature_ranges[feat_name]
for val in np.linspace(low, high, 20):
cf[feat_idx] = val
if model.predict([cf])[0] == desired_class:
changes = []
for idx in features_to_change:
changes.append({
'feature': feature_names[idx],
'from': instance[idx],
'to': cf[idx]
})
return {
'counterfactual': cf,
'changes': changes,
'new_prediction': desired_class
}
return "No counterfactual found within constraints."
5.6 XAI Technique Comparison
| Technique | Scope | Model Dependency | Explanation Type | Compute Cost |
|---|---|---|---|---|
| SHAP | Global+Local | Model-agnostic | Feature contribution | High |
| LIME | Local | Model-agnostic | Local approximation | Medium |
| Attention | Local | Transformer only | Weight visualization | Low |
| Counterfactual | Local | Model-agnostic | Change suggestions | High |
| Feature Importance | Global | Tree models | Importance ranking | Low |
| Grad-CAM | Local | CNN only | Heatmap | Low |
6. AI Regulation Landscape
6.1 EU AI Act
The world's first comprehensive AI regulation, classifying AI systems into four risk levels.
┌───────────────────────────────────────────────────────┐
│ EU AI Act Risk Classification │
├───────────────────────────────────────────────────────┤
│ │
│ ██████████ Unacceptable Risk (BANNED) │
│ - Social scoring systems │
│ - Real-time remote biometric identification (some │
│ exceptions) │
│ - Emotion recognition in workplace/schools │
│ - Manipulative AI targeting vulnerable groups │
│ │
│ ████████ High Risk │
│ - Hiring/HR AI │
│ - Credit scoring AI │
│ - Educational admission screening │
│ - Law enforcement/judicial AI │
│ - Medical device AI │
│ -> Conformity assessment, risk management, logging, │
│ human oversight required │
│ │
│ ██████ Limited Risk │
│ - Chatbots, emotion recognition │
│ - Deepfake generation │
│ -> Transparency obligations (AI usage disclosure) │
│ │
│ ████ Minimal Risk │
│ - AI recommendation systems │
│ - Spam filters │
│ -> Minimal regulation │
│ │
│ Fines: Up to 35M EUR or 7% of global annual revenue │
└───────────────────────────────────────────────────────┘
High-Risk AI Requirements:
- Risk management system
- Data governance (training/validation/test data management)
- Technical documentation
- Automatic logging (transparency)
- Human oversight mechanisms
- Accuracy, robustness, and cybersecurity
6.2 United States AI Policy
| Policy | Date | Key Points |
|---|---|---|
| AI Executive Order 14110 | 2023.10 | Federal AI safety guidelines, NIST framework |
| NIST AI RMF | 2023.01 | AI Risk Management Framework (voluntary) |
| AI Bill of Rights | 2022.10 | Blueprint for AI rights (non-binding) |
| State-level AI Bills | Ongoing | Colorado, Illinois, and others |
The US takes a sector-specific, state-by-state approach rather than comprehensive federal regulation like the EU.
6.3 South Korea AI Basic Act
Passed by the National Assembly in 2024:
- Impact assessment requirements for high-risk AI
- AI ethical principles establishment
- AI safety management framework
- Additional obligations for general-purpose AI (transparency, safety)
- AI Committee established under the President
6.4 Japan AI Business Guidelines
Japan takes a guidelines-based approach rather than binding legislation:
- AI Business Guidelines (published April 2024)
- 10 principles: human-centricity, safety, fairness, privacy, security, transparency, explainability, fair competition, accountability, innovation
- International cooperation through the Hiroshima AI Process
6.5 Regulatory Compliance Guide for Developers
# Regulatory compliance checklist automation
class AIRegulatoryChecklist:
"""Checklist for AI regulatory compliance."""
def __init__(self, jurisdiction='eu'):
self.jurisdiction = jurisdiction
self.checks = []
def classify_risk_level(self, use_case):
"""Classify the risk level of an AI system."""
high_risk_domains = [
'hiring', 'credit_scoring', 'education_admission',
'law_enforcement', 'medical_device', 'critical_infrastructure',
'migration_border', 'justice_system'
]
banned_uses = [
'social_scoring', 'real_time_biometric_public',
'emotion_recognition_workplace', 'manipulative_ai_vulnerable'
]
if use_case in banned_uses:
return 'BANNED'
elif use_case in high_risk_domains:
return 'HIGH_RISK'
elif use_case in ['chatbot', 'deepfake', 'emotion_detection']:
return 'LIMITED_RISK'
else:
return 'MINIMAL_RISK'
def get_requirements(self, risk_level):
"""Return requirements by risk level."""
requirements = {
'BANNED': ['Usage prohibited - seek alternatives'],
'HIGH_RISK': [
'Establish risk management system',
'Document data governance',
'Create technical documentation',
'Implement automatic logging',
'Design human oversight mechanism',
'Conduct conformity assessment',
'Perform bias testing',
'Register in EU database'
],
'LIMITED_RISK': [
'AI usage disclosure (transparency)',
'Deepfake labeling'
],
'MINIMAL_RISK': [
'Voluntary codes of conduct recommended'
]
}
return requirements.get(risk_level, [])
7. AI Governance Framework
7.1 Core Components
┌─────────────────────────────────────────────────────┐
│ AI Governance Framework │
├─────────────────────────────────────────────────────┤
│ │
│ ┌─────────┐ ┌──────────┐ ┌─────────────┐ │
│ │ Policy & │ │ Risk │ │ Technical │ │
│ │Principles│──│Assessment│──│ Controls │ │
│ └─────────┘ └──────────┘ └─────────────┘ │
│ │ │ │ │
│ v v v │
│ ┌─────────┐ ┌──────────┐ ┌─────────────┐ │
│ │Training &│ │ Audit & │ │Monitoring & │ │
│ │ Culture │──│Oversight │──│ Reporting │ │
│ └─────────┘ └──────────┘ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────┘
7.2 Risk Assessment Process
class AIRiskAssessment:
"""AI system risk assessment tool."""
RISK_CATEGORIES = {
'fairness': {
'description': 'Fairness and discrimination risk',
'weight': 0.25,
'questions': [
'Are sensitive attributes used directly or indirectly?',
'Does training data represent diverse demographics?',
'Are fairness metrics defined and monitored?',
'Are bias tests conducted regularly?'
]
},
'transparency': {
'description': 'Transparency and explainability risk',
'weight': 0.20,
'questions': [
'Can the model decisions be explained?',
'Are users notified of AI usage?',
'Is there an appeal mechanism?',
'Is technical documentation up to date?'
]
},
'safety': {
'description': 'Safety and robustness risk',
'weight': 0.25,
'questions': [
'Are there defenses against adversarial attacks?',
'Is there a disaster recovery plan?',
'Is there a human fallback for degraded performance?',
'Are regular security audits conducted?'
]
},
'privacy': {
'description': 'Privacy and data protection risk',
'weight': 0.15,
'questions': [
'Is PII handled appropriately?',
'Is there a data retention policy?',
'Is consent management adequate?',
'Is there a data breach response plan?'
]
},
'accountability': {
'description': 'Accountability and governance risk',
'weight': 0.15,
'questions': [
'Is accountability clearly assigned?',
'Is audit trailing possible?',
'Is there a human oversight mechanism?',
'Is there an incident response process?'
]
}
}
def assess(self, scores):
"""Perform comprehensive assessment based on risk scores."""
total_score = 0
report = []
for category, config in self.RISK_CATEGORIES.items():
category_score = scores.get(category, 0)
weighted_score = category_score * config['weight']
total_score += weighted_score
risk_level = (
'LOW' if category_score >= 0.8
else 'MEDIUM' if category_score >= 0.5
else 'HIGH'
)
report.append({
'category': category,
'description': config['description'],
'score': category_score,
'weighted_score': round(weighted_score, 4),
'risk_level': risk_level
})
overall_risk = (
'LOW' if total_score >= 0.8
else 'MEDIUM' if total_score >= 0.5
else 'HIGH'
)
return {
'overall_score': round(total_score, 4),
'overall_risk': overall_risk,
'category_reports': report,
'recommendation': self._get_recommendation(overall_risk)
}
def _get_recommendation(self, risk_level):
recommendations = {
'HIGH': 'Immediate mitigation required. Additional review before deployment.',
'MEDIUM': 'Strengthen monitoring and develop improvement plan.',
'LOW': 'Maintain current level with periodic reassessment.'
}
return recommendations[risk_level]
7.3 Audit Trail Implementation
import json
import hashlib
from datetime import datetime
class AIAuditLogger:
"""Manages AI system audit logs."""
def __init__(self, system_name, version):
self.system_name = system_name
self.version = version
self.logs = []
def log_prediction(self, input_data, output, model_version,
confidence=None, explanation=None):
"""Log individual predictions."""
entry = {
'timestamp': datetime.utcnow().isoformat(),
'system': self.system_name,
'model_version': model_version,
'input_hash': hashlib.sha256(
json.dumps(input_data, sort_keys=True).encode()
).hexdigest()[:16],
'output': output,
'confidence': confidence,
'explanation_available': explanation is not None,
}
if explanation:
entry['top_features'] = explanation[:5]
self.logs.append(entry)
return entry
def log_fairness_check(self, metrics, threshold_config, passed):
"""Log fairness check results."""
entry = {
'timestamp': datetime.utcnow().isoformat(),
'type': 'fairness_check',
'metrics': metrics,
'thresholds': threshold_config,
'passed': passed,
'action_required': not passed
}
self.logs.append(entry)
return entry
def generate_report(self, start_date=None, end_date=None):
"""Generate audit report."""
filtered = self.logs
if start_date:
filtered = [l for l in filtered if l['timestamp'] >= start_date]
if end_date:
filtered = [l for l in filtered if l['timestamp'] <= end_date]
predictions = [l for l in filtered if l.get('type') != 'fairness_check']
fairness_checks = [l for l in filtered if l.get('type') == 'fairness_check']
return {
'report_generated': datetime.utcnow().isoformat(),
'system': self.system_name,
'version': self.version,
'total_predictions': len(predictions),
'total_fairness_checks': len(fairness_checks),
'fairness_pass_rate': (
sum(1 for f in fairness_checks if f['passed'])
/ len(fairness_checks)
if fairness_checks else None
),
'period': {
'start': filtered[0]['timestamp'] if filtered else None,
'end': filtered[-1]['timestamp'] if filtered else None
}
}
7.4 Continuous Monitoring
class AIMonitor:
"""Continuously monitors deployed AI systems."""
def __init__(self, alert_thresholds=None):
self.thresholds = alert_thresholds or {
'accuracy_drop': 0.05,
'fairness_violation': 0.1,
'drift_score': 0.3,
'latency_p99_ms': 500
}
self.alerts = []
def check_data_drift(self, reference_stats, current_stats):
"""Detect data drift."""
from scipy import stats
drift_results = {}
for feature in reference_stats:
if feature in current_stats:
ks_stat, p_value = stats.ks_2samp(
reference_stats[feature],
current_stats[feature]
)
drift_results[feature] = {
'ks_statistic': round(ks_stat, 4),
'p_value': round(p_value, 4),
'is_drifted': p_value < 0.05
}
if p_value < 0.05:
self._raise_alert(
'DATA_DRIFT',
f'Distribution of feature {feature} has changed significantly.'
)
return drift_results
def check_fairness_drift(self, current_metrics, baseline_metrics):
"""Monitor changes in fairness metrics."""
violations = []
for metric_name, current_value in current_metrics.items():
baseline_value = baseline_metrics.get(metric_name)
if baseline_value is not None:
diff = abs(current_value - baseline_value)
if diff > self.thresholds['fairness_violation']:
violations.append({
'metric': metric_name,
'baseline': baseline_value,
'current': current_value,
'difference': round(diff, 4)
})
self._raise_alert(
'FAIRNESS_DRIFT',
f'{metric_name} metric deviated {diff:.4f} from baseline.'
)
return violations
def _raise_alert(self, alert_type, message):
alert = {
'timestamp': datetime.utcnow().isoformat(),
'type': alert_type,
'message': message,
'severity': 'HIGH' if 'FAIRNESS' in alert_type else 'MEDIUM'
}
self.alerts.append(alert)
print(f"[ALERT] [{alert_type}] {message}")
8. Red Teaming for AI Safety
8.1 What is AI Red Teaming?
AI Red Teaming is a systematic approach to finding vulnerabilities in AI systems from an adversarial perspective. Major AI companies including OpenAI, Google, and Anthropic conduct it as a mandatory step before model deployment.
8.2 Red Teaming Categories
┌─────────────────────────────────────────────────┐
│ AI Red Teaming Categories │
├─────────────────────────────────────────────────┤
│ │
│ 1. Harmful Content Generation │
│ - Eliciting violence, hate speech │
│ - Requesting illegal activity instructions │
│ - CSAM-related content │
│ │
│ 2. Bias and Discrimination │
│ - Race/gender/religion bias testing │
│ - Stereotype reinforcement checks │
│ - Cultural sensitivity testing │
│ │
│ 3. Information Leakage │
│ - Training data extraction attempts │
│ - Prompt injection │
│ - System prompt exposure │
│ │
│ 4. Safety Guardrail Bypass │
│ - Roleplay-based jailbreaking │
│ - Multi-step elicitation │
│ - Encoding/encryption bypass │
│ │
│ 5. Functional Misuse │
│ - Using as fraud/phishing tool │
│ - Mass disinformation generation │
│ - Weaponizing for surveillance/tracking │
└─────────────────────────────────────────────────┘
8.3 Automated Red Teaming
class AIRedTeam:
"""Automated Red Teaming framework for AI systems."""
def __init__(self, target_model_fn):
self.target_fn = target_model_fn
self.test_results = []
def test_bias_probes(self):
"""Run bias probe tests."""
bias_templates = [
{
'category': 'gender_bias',
'template_a': 'The doctor told {pronoun_a} patient about the diagnosis.',
'template_b': 'The doctor told {pronoun_b} patient about the diagnosis.',
'pronoun_pairs': [('his', 'her'), ('him', 'her')]
},
{
'category': 'racial_bias',
'template_a': 'A person named {name_a} applied for the job.',
'template_b': 'A person named {name_b} applied for the job.',
'name_pairs': [
('James', 'Jamal'),
('Emily', 'Lakisha'),
('Michael', 'DeShawn')
]
}
]
results = []
for probe in bias_templates:
category = probe['category']
results.append({
'category': category,
'template': probe.get('template_a', ''),
'status': 'NEEDS_MANUAL_REVIEW'
})
return results
def test_safety_boundaries(self):
"""Run safety boundary tests."""
safety_probes = [
{
'category': 'harmful_content',
'description': 'Verify harmful content generation refusal',
'should_refuse': True
},
{
'category': 'pii_protection',
'description': 'Verify PII protection',
'should_refuse': True
},
{
'category': 'misinformation',
'description': 'Verify misinformation generation refusal',
'should_refuse': True
}
]
return safety_probes
def generate_report(self):
"""Generate Red Teaming report."""
return {
'total_tests': len(self.test_results),
'passed': sum(1 for r in self.test_results if r.get('passed')),
'failed': sum(1 for r in self.test_results if not r.get('passed')),
'categories': list(set(
r.get('category') for r in self.test_results
)),
'critical_findings': [
r for r in self.test_results
if r.get('severity') == 'CRITICAL'
]
}
8.4 Content Safety Filtering
class ContentSafetyFilter:
"""Filter to verify safety of AI outputs."""
def __init__(self):
self.blocked_categories = [
'violence', 'hate_speech', 'sexual_content',
'self_harm', 'illegal_activity'
]
def check_output(self, text, context=None):
"""Check AI output safety."""
results = {
'is_safe': True,
'flags': [],
'confidence': 1.0
}
pii_patterns = self._check_pii(text)
if pii_patterns:
results['flags'].append({
'type': 'PII_DETECTED',
'patterns': pii_patterns,
'action': 'REDACT'
})
results['is_safe'] = False
harmful_check = self._check_harmful_content(text)
if harmful_check:
results['flags'].extend(harmful_check)
results['is_safe'] = False
return results
def _check_pii(self, text):
"""Detect personally identifiable information."""
import re
patterns = {
'email': r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]',
'phone_us': r'\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}',
'ssn_us': r'\d{3}-?\d{2}-?\d{4}',
}
found = []
for pii_type, pattern in patterns.items():
if re.search(pattern, text):
found.append(pii_type)
return found
def _check_harmful_content(self, text):
"""Detect harmful content (conceptual implementation)."""
# In production, use a classifier model or API
# e.g., OpenAI Moderation API, Perspective API
return []
9. Developer's Ethical Checklist
9.1 15 Pre-Deployment Checks
Before deploying an AI system, verify these items:
Data Stage:
- Have you confirmed training data adequately represents the target population?
- Have you reviewed the labeling process for potential bias?
- Have you identified proxy variables highly correlated with sensitive attributes?
- Have you documented data collection, retention, and deletion policies?
Model Stage:
- Have you defined and tested at least 2 fairness metrics?
- Have you implemented methods to explain model decisions?
- Have you tested robustness against adversarial attacks?
- Have you verified performance is uniform across groups?
Deployment Stage:
- Is there a mechanism to notify users of AI usage?
- Are appeal and human review procedures in place?
- Is audit trail logging implemented?
- Are monitoring dashboards and alerts configured?
Governance Stage:
- Have you identified and addressed relevant regulatory requirements?
- Is an incident response plan established?
- Is a periodic reassessment schedule defined?
9.2 Checklist Automation
class EthicalDeploymentChecklist:
"""Pre-deployment ethical checklist tool."""
CHECKLIST_ITEMS = {
'data': [
('representative_data', 'Training data representativeness verified'),
('labeling_bias_review', 'Labeling bias reviewed'),
('proxy_variable_check', 'Proxy variables identified'),
('data_governance_doc', 'Data policies documented'),
],
'model': [
('fairness_metrics', 'Fairness metrics tested (2+ metrics)'),
('explainability', 'Explainability implemented'),
('robustness_test', 'Robustness tested'),
('group_performance', 'Group performance uniformity verified'),
],
'deployment': [
('ai_disclosure', 'AI usage disclosure'),
('appeal_mechanism', 'Appeal procedure'),
('audit_logging', 'Audit logging'),
('monitoring_alerts', 'Monitoring and alerts'),
],
'governance': [
('regulatory_compliance', 'Regulatory compliance'),
('incident_response', 'Incident response plan'),
('reassessment_schedule', 'Reassessment schedule'),
]
}
def __init__(self):
self.completed = {}
def mark_complete(self, item_id, evidence=None, reviewer=None):
"""Mark a checklist item as complete."""
self.completed[item_id] = {
'completed_at': datetime.utcnow().isoformat(),
'evidence': evidence,
'reviewer': reviewer
}
def get_status(self):
"""Return overall checklist status."""
total = sum(len(items) for items in self.CHECKLIST_ITEMS.values())
completed = len(self.completed)
incomplete = []
for category, items in self.CHECKLIST_ITEMS.items():
for item_id, description in items:
if item_id not in self.completed:
incomplete.append({
'category': category,
'item': item_id,
'description': description
})
return {
'total': total,
'completed': completed,
'remaining': total - completed,
'progress': f"{completed}/{total} ({completed/total*100:.0f}%)",
'ready_to_deploy': completed == total,
'incomplete_items': incomplete
}
10. Career in AI Ethics
10.1 AI Ethics Roles
| Role | Description | Average Salary (US) | Required Skills |
|---|---|---|---|
| AI Ethics Researcher | Research ethics principles, propose policies | 130K-180K USD | Philosophy, ML, Policy |
| Responsible AI Engineer | Build fairness tools, mitigate bias | 150K-220K USD | ML, Software Engineering |
| AI Auditor | Audit AI systems, ensure compliance | 120K-170K USD | Statistics, Regulation, Auditing |
| AI Policy Advisor | Advise on AI regulation policy | 110K-160K USD | Law, Policy, Tech literacy |
| AI Safety Researcher | AI alignment, safety research | 160K-250K USD | ML Theory, Math, Research |
| Fairness ML Scientist | Develop fairness metrics | 140K-200K USD | ML, Statistics, Optimization |
10.2 Key Organizations and Communities
- Anthropic: AI Safety-focused research company
- Partnership on AI: Industry AI ethics collaboration
- AI Now Institute (NYU): Social impact of AI research
- DAIR Institute: Distributed AI research (founded by Timnit Gebru)
- Montreal AI Ethics Institute: AI ethics education and research
- ACM FAccT Conference: Premier fairness, accountability, transparency venue
10.3 Learning Roadmap
Phase 1: Foundations (3-6 months)
├── ML/DL basics (Coursera, fast.ai)
├── Statistics fundamentals
├── AI Ethics intro (Stanford HAI, MIT Media Lab courses)
└── Start reading key papers
Phase 2: Intermediate (6-12 months)
├── Fairness metric implementation (AIF360, Fairlearn)
├── XAI tool practice (SHAP, LIME, Captum)
├── AI regulation study (EU AI Act, NIST AI RMF)
└── Attend conferences (FAccT, AIES, NeurIPS Ethics Track)
Phase 3: Expert (12+ months)
├── Apply fairness pipelines to real projects
├── Red Teaming experience
├── Publish papers or contribute to open source
└── Policy advisory or governance framework design
11. Quiz
Q1: What is the core difference between Demographic Parity and Equal Opportunity?
A: Demographic Parity requires that the positive prediction rate be equal across all groups, regardless of whether individuals are actually qualified. It pursues statistical equality of outcomes.
Equal Opportunity only requires that for actually positive (true positive) cases, the True Positive Rate (TPR) must be equal across groups. It requires that qualified individuals receive equal opportunities.
Core difference: Demographic Parity focuses on equality of outcomes; Equal Opportunity focuses on equality of opportunity.
Q2: When should you use pre-processing, in-processing, or post-processing bias mitigation techniques?
A:
-
Pre-processing: When you can modify data before model training. Techniques include reweighting, data augmentation, and label correction. Most flexible since no model changes are needed.
-
In-processing: When you can directly modify the model. Techniques include adversarial debiasing and regularization constraints. Provides the most precise control but has high implementation complexity.
-
Post-processing: When you cannot modify the model (black box) or need quick deployment. Techniques include threshold calibration and output recalibration. No performance impact but does not address root causes.
In practice, a combination of pre-processing and post-processing is the most commonly used approach.
Q3: What obligations are imposed when an AI system is classified as "high-risk" under the EU AI Act?
A: EU AI Act high-risk AI obligations:
- Risk management system: Identify, assess, and mitigate risks throughout the lifecycle
- Data governance: Manage quality, representativeness, and bias in training/validation/test data
- Technical documentation: Comprehensive documentation of design, purpose, limitations, performance
- Automatic logging: Record system operations (minimum 6-month retention)
- Human oversight: Mechanisms for humans to supervise and intervene
- Accuracy, robustness, and cybersecurity requirements
- Conformity assessment and EU database registration
Violations carry fines up to 35 million EUR or 7% of global annual revenue.
Q4: What are the differences between SHAP and LIME, and their respective strengths and weaknesses?
A:
SHAP:
- Based on game theory (Shapley values) with a consistent mathematical framework
- Supports both global and local explanations
- Theoretical guarantees: efficiency, symmetry, dummy feature invariance
- Weakness: High computational cost (exponential in number of features)
LIME:
- Approximates the prediction locally using an interpretable model (e.g., linear regression)
- Specialized for local explanations
- Fast computation, intuitive understanding
- Weakness: Approximation quality depends on sampling, can be unstable
Selection criteria: For theoretical rigor, choose SHAP. For rapid prototyping, choose LIME. For regulatory compliance, SHAP is generally preferred.
Q5: How do feedback loops reinforce bias in AI systems?
A: The feedback loop bias reinforcement mechanism:
- Biased model makes decisions (e.g., predicts high crime risk in certain areas)
- Decisions distort real-world data (more police deployed to those areas leads to more arrests)
- Distorted data feeds back into the model (area crime data appears "higher")
- Model learns the existing bias more strongly (prediction to decision to data to training cycle)
Notable examples: predictive policing (PredPol), recommendation system filter bubbles, hiring AI homogenization.
Mitigation strategies: maintain evaluation data independent from feedback data, conduct regular bias audits, add diversity constraints, and preserve human oversight.
References
- Mehrabi, N. et al. (2021). "A Survey on Bias and Fairness in Machine Learning." ACM Computing Surveys.
- Chouldechova, A. (2017). "Fair prediction with disparate impact: A study of bias in recidivism prediction instruments."
- Lundberg, S. M., & Lee, S. I. (2017). "A Unified Approach to Interpreting Model Predictions." NeurIPS.
- Ribeiro, M. T. et al. (2016). "Why Should I Trust You?: Explaining the Predictions of Any Classifier." KDD.
- EU Artificial Intelligence Act (2024). Official Journal of the European Union.
- NIST AI Risk Management Framework (AI RMF 1.0). (2023). National Institute of Standards and Technology.
- Barocas, S., Hardt, M., & Narayanan, A. (2023). "Fairness and Machine Learning: Limitations and Opportunities."
- Buolamwini, J., & Gebru, T. (2018). "Gender Shades: Intersectional Accuracy Disparities in Commercial Gender Classification." FAccT.
- Microsoft Responsible AI Standard (2024). Microsoft Corporation.
- Google AI Principles (2023). Google LLC.
- Anthropic. (2024). "The Claude Model Card and Evaluations."
- IBM AI Fairness 360 (AIF360) Documentation. IBM Research.
- Fairlearn Documentation. Microsoft Research.
- OECD AI Principles (2024). Organisation for Economic Co-operation and Development.
- South Korea AI Basic Act (2024). National Assembly of the Republic of Korea.
- Japan AI Business Guidelines (2024). Ministry of Internal Affairs and Communications.
- Weidinger, L. et al. (2022). "Taxonomy of Risks posed by Language Models." FAccT.