Contrastive Learning (대조학습)
Contrastive Learning (대조학습)
Positive Pair(같은 샘플의 변형, 유사 샘플)는 임베딩 공간에서 가깝게, Negative Pair(다른 샘플)는 멀게 학습하여 강력한 표현(Representation)을 획득하는 Self-Supervised Learning 방법으로, SimCLR, MoCo, CLIP이 대표적이며 비전·NLP에서 활용
목적: 표현 학습, 레이블 없이 유사도 학습, 일반화 능력 향상, 전이학습 성능 향상
특징: Positive/Negative Pair 대조, Augmentation 중요, InfoNCE Loss, 대규모 Batch
구성요소
- •Positive Pair: 같은 이미지 2개 증강(Crop, Flip, Color), 같은 문장 변형
- •Negative Pair: 배치 내 다른 샘플, Queue(MoCo)
- •Encoder: 입력→임베딩, ResNet, Transformer
- •Projection Head: 임베딩→저차원 벡터(128D), MLP
- •손실 함수: InfoNCE Loss, NT-Xent Loss
InfoNCE Loss
- •정의: Positive Pair 유사도 최대화, Negative Pair 최소화, Softmax 기반
- •수식: -log(exp(sim(z_i, z_j)/τ) / Σ_k exp(sim(z_i, z_k)/τ)), τ=온도 파라미터
- •특징: Temperature Scaling(τ), Negative Sample 많을수록 성능 향상
대표 모델
- •SimCLR: 이미지 2개 증강, 대규모 Batch(4096), Strong Augmentation, Projection Head, NT-Xent Loss
- •MoCo(Momentum Contrast): Queue 기반 Negative Sample(65536), Momentum Encoder(EMA), 작은 Batch 가능
- •BYOL(Bootstrap Your Own Latent): Negative Sample 불필요, Predictor + Target Network(EMA), Collapse 방지
- •CLIP(OpenAI): 이미지-텍스트 대조학습, 4억 쌍 학습, Zero-Shot 분류
- •SwAV: Clustering + Contrastive, Prototypes, Multi-Crop
Augmentation: Random Crop, Flip, Color Jitter, Gaussian Blur, RandAugment(강한 증강이 중요)
장점: 레이블 불필요, 강력한 표현 학습, 전이학습 성능 높음, Zero-Shot 가능(CLIP)
단점: 대규모 Batch·Negative Sample 필요, 계산 비용 높음, Augmentation 설계 중요, Collapse 위험
적용사례: 이미지 분류(SimCLR→ImageNet), Zero-Shot 비전(CLIP), 자연어 임베딩(SentenceBERT)
기술요소: InfoNCE Loss, NT-Xent, Augmentation, Momentum Encoder, Projection Head, Temperature Scaling
비교: SimCLR(대규모 Batch) vs MoCo(Queue) vs BYOL(Negative 불필요) vs CLIP(Multi-Modal)
연관: Self-Supervised Learning, SimCLR, MoCo, CLIP, InfoNCE, Transfer Learning, Representation Learning