id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id
title
category
status
canonical_id
aliases
duplicate_of
source_trust_level
confidence_score
verification_status
tags
raw_sources
last_reinforced
github_commit
tech_stack
wiki-2026-0508-loss-functions-foundations
Loss Functions Foundations
10_Wiki/Topics
verified
self
Loss Functions
Cost Functions
Objective Functions
Loss-Functions
none
A
0.95
applied
loss
objective
training
mse
cross-entropy
focal
contrastive
dice
2026-05-10
pending
language
framework
Python
PyTorch
Loss Functions Foundations
매 한 줄
"매 loss는 task가 정한다" . Regression→MSE/MAE/Huber, Classification→CE/Focal, Metric→Contrastive/Triplet, Segmentation→Dice/IoU.
매 핵심
매 회귀 (Regression)
MSE (L2) : ½(y-ŷ)². 미분 깔끔, outlier에 민감.
MAE (L1) : |y-ŷ|. robust, 0에서 미분 불가.
Huber : |e|<δ면 MSE, 아니면 MAE. δ=1 기본.
Log-cosh : smooth Huber. 자동 미분 친화.
Quantile : max(τe, (τ-1)e). 중앙값/구간 예측.
매 분류 (Classification)
BCE : -[y log p + (1-y) log(1-p)]. 이진/다중라벨.
CE (softmax) : -Σ y_k log p_k. 다중클래스.
Focal (Lin 2017): -α (1-p)^γ log p. easy example down-weight, γ =2 기본.
Label smoothing : y → y(1-ε) + ε/K. overconfidence 방지.
Hinge : max(0, 1-y·ŷ). SVM. y∈{-1,+1}.
매 Metric Learning
Contrastive (Hadsell 2006): pair. y·d² + (1-y)·max(0, m-d)².
Triplet : max(0, d(a,p) - d(a,n) + margin).
InfoNCE / NT-Xent (SimCLR): -log exp(sim+/τ) / Σ exp(sim/τ).
Cosine embedding : 1 - cos(a,b).
매 Segmentation
Dice : 1 - 2|A∩B|/(|A|+|B|). class imbalance 강함.
IoU/Jaccard : 1 - |A∩B|/|A∪ B|.
Tversky : FP/FN weight 조정.
Boundary loss : 거리변환 가중.
💻 패턴
Regression losses
Classification losses
Focal loss (이진)
Triplet & InfoNCE
Dice + BCE (segmentation 표준)
Class imbalance 가중
매 결정 기준
Task
Default
변형
Regression normal
MSE
outlier→Huber, robust→MAE
Binary classification
BCE w/ logits
imbalance→Focal
Multi-class
CE w/ label smoothing
imbalance→class weights
Multi-label
BCE per-class
Embedding learning
InfoNCE
small batch→Triplet
Segmentation
BCE+Dice
small object→Tversky
Object detection
Focal + IoU/GIoU
(RetinaNet, YOLO)
기본값 : classification CE+label smoothing 0.1, regression Huber.
🔗 Graph
🤖 LLM 활용
언제 : task→loss 매핑, gradient 직관, 코드 템플릿 생성.
언제 X : domain-specific custom loss 설계는 검증 필수 (분포·gradient 분석).
❌ 안티패턴
softmax 후 nll_loss 손수 (numerical) ← cross_entropy 사용
BCE에 binary_cross_entropy(sigmoid(...)) ← _with_logits 사용
Imbalance 무시한 CE
Dice loss만 단독 (gradient 불안정) → BCE+Dice 혼합
Focal γ를 imbalance 없을 때 사용 (성능↓)
🧪 검증 / 중복
Verified (Goodfellow DL ch5, Lin 2017 Focal, SimCLR, Milletari V-Net Dice). 신뢰도 A.
Canonical for Loss-Functions-Foundations (redirect).
🕓 Changelog
날짜
변경
2026-05-08
Phase 1
2026-05-10
Manual cleanup — canonical 강화, segmentation/metric 추가