知識蒸留
term_id: knowledge_distillation
Category: training_techniques
Definition
知識蒸留は、大規模で複雑なニューラルネットワーク(教師)を、より小さく効率的なネットワーク(学生)に圧縮するために使用される機械学習手法です。学生モデルは教師の出力分布を学習します。
Summary
知識蒸留は、小さな学生モデルが大きな教師モデルの動作を模倣するように学習させるモデル圧縮技術です。
Key Concepts
- 教師-学生モデル
- モデル圧縮
- ソフトターゲット
- 効率性
Use Cases
- エッジデバイスへのモデル展開
- 推論レイテンシの削減
- クラウドコンピューティングコストの低減
Code Example
import torch
import torch.nn as nn
def distillation_loss(student_logits, teacher_logits, temperature=2.0):
T = temperature
student_probs = nn.functional.softmax(student_logits / T, dim=1)
teacher_probs = nn.functional.softmax(teacher_logits / T, dim=1)
return nn.functional.kl_div(
nn.functional.log_softmax(student_logits / T, dim=1),
teacher_probs,
reduction='batchmean'
) * (T * T)