SlideShare a Scribd company logo
1 of 14
D S A I Lab.
2021.01.26
About Knowledge distillation
Distilling the Knowledge in a Neural Network (Hinton et al., NIPS 2015)
On the Efficacy of Knowledge Distillation (Cho et al., ICCV 2019)
TinyBERT : Distilling BERT for natural language understanding (Jiao et al., EMNLP 2020)
숭실대학교 소프트웨어학과 DSAI Lab. 지승현 발표
1
D S A I Lab.
목차
1. Knowledge distillation 개요
2. Characteristics of Knowledge distillation
– 빠른 수렴 및 학습 방해
– 좋은 Teacher model의 조건
– Attention transfer
3. BERT distillation
4. 결론
2
D S A I Lab.
1. Knowledge distillation 개요
– Knowledge distillation : 잘 학습된 대형 모델을 사용, 소형 모델에 지식을 증류
– Teacher model과 Student model를 가정
– Input에 대한 Teacher model의 출력을 흉내내도록 Student model을 학습
 이를 통해 Student model을 처음부터 학습 (from scratch) 하는것보다 성능을 높이는 것이 목표
3
D S A I Lab.
1. Knowledge distillation 개요
– 일반 학습 Loss과의 차이점
– 정답을 one-hot vector 형태의 “Hard Target” 으로 변환하는 것이 통상적
– 이 때 one-hot vector와 cross-entropy를 수행
– 그러나 Knowledge distillation (이하 KD) Loss 는 Soft target에 대한 경우가 많음.
4
클래스 정답확률
q_1 0
q_2 0
… …
q_i 1
클래스 정답확률
q_1 0.1
q_2 0.05
… …
q_i 0.6
일반 학습 Loss KD Loss
D S A I Lab.
1. Knowledge distillation 개요
– Hinton et al. 은 Teacher Model 출력에 Temperature를 제안 (2015)
– Temperature이란 출력 결과를 더 부드럽게 만들어주는 기법
– 이를 통해 Teacher model의 출력 결과 정보를 더 잘 전달할 수 있다고 주장
– 𝒒𝒊가 Teacher model의 출력 확률, 𝒛𝒊가 클래스 i에 대한 활성화 이전 출력값이라면
𝒒𝒊 =
𝒆𝒙𝒑 𝒛𝒊/𝑻
𝒋 𝒆𝒙𝒑 𝒛𝒋/𝑻
에서 𝑻 = Temperature
5
(임의 예시)
클래스 정답확률
q_1 0.1
q_2 0.05
… …
q_i 0.6
클래스 정답확률
q_1 0.15
q_2 0.07
… …
q_i 0.5
D S A I Lab.
1. Knowledge distillation 개요
– 통상적인 KD는 KD Loss에 일반 Loss를 섞은 함수로 학습하는 방법을 지칭
– 𝒒𝒊 =
𝒆𝒙𝒑 𝒛𝒊/𝑻
𝒋 𝒆𝒙𝒑 𝒛𝒋/𝑻
, 𝒑𝒊는 Student Model의 출력 확률일 때
ℒ𝑲𝑫 = −𝑻𝟐
𝒌
𝒒𝒌 𝒍𝒐𝒈𝒑𝒌
ℒ = 𝜶ℒ𝑲𝑫 + (𝟏 − 𝜶)ℒ𝑪𝑳𝑺
– 이 때 𝜶는 Hyperparameter, ℒ𝑪𝑳𝑺는 일반 학습에서의 loss
– 통상적으로 𝜶=0.9, 𝑻 ∈ {𝟑, 𝟒, 𝟓}
6
D S A I Lab.
2. Characteristics of Knowledge distillation (1)
– KD loss는 빠르게 학습시키지만, 점점 성능향상을 방해한다.*
– From scratch 학습 시보다 빠르게 수렴된다. (좌)
– 그러나 일정 반복 (epoch) 수를 넘어서면 KD의 수렴이 더 느려진다. (좌)
– 따라서 일정 epoch까지만 KD로 학습 후 일반 학습으로만 진행하는 방법 (ESKD) 이 효과적. (우)
7
D S A I Lab.
2. Characteristics of Knowledge distillation (2)
– 좋은 Teacher는 용량이 크거나 정확도가 높은 모델이 아님
– 오히려 용량이 적은 Teacher 모델이 distillation을 더 잘 수행한 것으로 나타남 (좌)
– distillation 성능과 Teacher 모델 용량은 비례하지 않으며 최적 용량이 존재하는 것으로 파악 (우)
– Teacher 모델의 정확도보다는 세밀함이 더 중요한 것이라는 주장도 존재*
8
* Muller et al., NIPS 2019
D S A I Lab.
2. Characteristics of Knowledge distillation (3)
– 출력값 뿐만이 아니라 Attention Layer를 전달할 필요가 있다.
– Attention Transfer* 는 Teacher의 Attention layer를 Student가 모방하도록 하는 방법 (좌)
– j번째 Student의 attention layer (𝑸𝑺
𝒋
) 와 Teacher의 attention layer (𝑸𝑻
𝒋
) 를 근사 (우)
– 이를 위해 Normalized된 형태 (
𝑸
𝑸 𝟐
) 를 사용하고, Student – Teacher의 차를 Loss 함수에 삽입
– ESKD와 함께 적용시 추가적으로 KD 성능이 향상되는 것으로 확인
9
* Zagoruyko et al., ICLR 2017
D S A I Lab.
3. BERT distillation
– TinyBERT는 KD Loss만을 고려한 distillated 모델
– BERT에 KD를 적용한 사례
– Attention transfer를 차용, KD Loss를 Layer Loss로 전환
– Layer Loss만을 사용하여 학습 (ESKD는 미사용)
– g(m) 을 통해 Teacher Layer를 Student Layer에 적절히 매핑
10
* https://jalammar.github.io/illustrated-transformer/
여러 Layer의
BERT의 구조*
D S A I Lab.
3. BERT distillation
– Layer의 인덱스에 따라 Loss 함수의 성격이 변화
– Student의 Layer가 총 M개, Loss 함수를 계산중인 인덱스가 m일 때,
11
간략화한
BERT의
구조
D S A I Lab.
3. BERT distillation
– 본 KD 방법의 우수성을 실험을 통해 확인
1) 언어모델 학습 (Pretrain) 시에 KD 적용시 Student의 성능은 더 나빠짐
2) 그러나 각 태스크에 대해 학습 (Fine-tune) 시에 KD를 적용하면 Student의 성능이 더 좋아짐
1) 동일 파라미터 수로 학습된 소형 BERT 모델보다 더 좋은 성능을 나타냄
2) Teacher 모델보다 파라미터가 적더라도 성능은 거의 유사
* 성능 측정은 언어모델의 성능을 11종의 태스크로 평가하는 GLUE benchmark 사용
12
D S A I Lab.
4. 결론
– 요약 :
– Knowledge distillation은 이미 학습된 모델을 활용하여 경량화된 모델을 더 빠르게 학습
– 그러나 단순 출력값만을 이용하면 더 나쁜 결과를 초래
– 학습된 모델의 가중치 값까지 활용하면 from scratch 학습보다 좋은 결과로 이어짐
– 발표자의 사견:
– 대체어 추출이 가능한 언어모델은 모델의 P() 출력이 현실의 P()와 더 가까워진다고 가정
– 이를 통해 KD를 수행할 수 있다고 생각하여 공부
– 그러나 생각보다 많은 어려움이 있는 것으로 파악
13
D S A I Lab.
4. 결론
– 논문 메타분석 (발표자의 사견)
– ESKD 방법을 적용한 BERT distillation을 연구할 수 있을 것으로 사료
– 또한 BERT pretraining에서 왜 KD가 작동하지 않는지 연구해볼 만하다고 사료
– 충분한 Layer 수를 가진 신경망 모델은 전방 레이어가 그래디언트의 대부분을 전파한다고 알려짐
(Veit et al., NIPS 2016)
– 따라서 Attention transfer 혹은 KD에서 이러한 원리를 차용, 전방 레이어를 흉내내는 모델에 대
해 연구할 수 있을 것으로 사료
14

More Related Content

Similar to (in Korean) about knowledge distillation

220707 지승현 About Ensemble Distillation.pdf
220707 지승현 About Ensemble Distillation.pdf220707 지승현 About Ensemble Distillation.pdf
220707 지승현 About Ensemble Distillation.pdfssuserf03c031
 
Dense sparse-dense training for dnn and Other Models
Dense sparse-dense training for dnn and Other ModelsDense sparse-dense training for dnn and Other Models
Dense sparse-dense training for dnn and Other ModelsDong Heon Cho
 
Improving bert fine tuning via self-ensemble and self-distilation (1)
Improving bert fine tuning   via self-ensemble and self-distilation  (1)Improving bert fine tuning   via self-ensemble and self-distilation  (1)
Improving bert fine tuning via self-ensemble and self-distilation (1)taeseon ryu
 
PR-383: Solving ImageNet: a Unified Scheme for Training any Backbone to Top R...
PR-383: Solving ImageNet: a Unified Scheme for Training any Backbone to Top R...PR-383: Solving ImageNet: a Unified Scheme for Training any Backbone to Top R...
PR-383: Solving ImageNet: a Unified Scheme for Training any Backbone to Top R...Sunghoon Joo
 
Transfer learning usage
Transfer learning usageTransfer learning usage
Transfer learning usageTae Young Lee
 
PR-203: Class-Balanced Loss Based on Effective Number of Samples
PR-203: Class-Balanced Loss Based on Effective Number of SamplesPR-203: Class-Balanced Loss Based on Effective Number of Samples
PR-203: Class-Balanced Loss Based on Effective Number of SamplesSunghoon Joo
 
Distilling the knowledge in a neural network
Distilling the knowledge in a neural networkDistilling the knowledge in a neural network
Distilling the knowledge in a neural networkKyeongUkJang
 
PR-339: Maintaining discrimination and fairness in class incremental learning
PR-339: Maintaining discrimination and fairness in class incremental learningPR-339: Maintaining discrimination and fairness in class incremental learning
PR-339: Maintaining discrimination and fairness in class incremental learningSunghoon Joo
 
Self Supervised Learning 세미나.pptx
Self Supervised Learning 세미나.pptxSelf Supervised Learning 세미나.pptx
Self Supervised Learning 세미나.pptxDongkyunKim17
 
딥러닝 논문읽기 efficient netv2 논문리뷰
딥러닝 논문읽기 efficient netv2  논문리뷰딥러닝 논문읽기 efficient netv2  논문리뷰
딥러닝 논문읽기 efficient netv2 논문리뷰taeseon ryu
 
MRC recent trend_ppt
MRC recent trend_pptMRC recent trend_ppt
MRC recent trend_pptseungwoo kim
 
20210131deit-210204074124.pdf
20210131deit-210204074124.pdf20210131deit-210204074124.pdf
20210131deit-210204074124.pdfssusera9c46c
 
Training data-efficient image transformers & distillation through attention
Training data-efficient image transformers & distillation through attentionTraining data-efficient image transformers & distillation through attention
Training data-efficient image transformers & distillation through attentiontaeseon ryu
 
SAGAN_2024seminar announce_seoultech.pptx
SAGAN_2024seminar announce_seoultech.pptxSAGAN_2024seminar announce_seoultech.pptx
SAGAN_2024seminar announce_seoultech.pptxssuser4b2fe7
 

Similar to (in Korean) about knowledge distillation (14)

220707 지승현 About Ensemble Distillation.pdf
220707 지승현 About Ensemble Distillation.pdf220707 지승현 About Ensemble Distillation.pdf
220707 지승현 About Ensemble Distillation.pdf
 
Dense sparse-dense training for dnn and Other Models
Dense sparse-dense training for dnn and Other ModelsDense sparse-dense training for dnn and Other Models
Dense sparse-dense training for dnn and Other Models
 
Improving bert fine tuning via self-ensemble and self-distilation (1)
Improving bert fine tuning   via self-ensemble and self-distilation  (1)Improving bert fine tuning   via self-ensemble and self-distilation  (1)
Improving bert fine tuning via self-ensemble and self-distilation (1)
 
PR-383: Solving ImageNet: a Unified Scheme for Training any Backbone to Top R...
PR-383: Solving ImageNet: a Unified Scheme for Training any Backbone to Top R...PR-383: Solving ImageNet: a Unified Scheme for Training any Backbone to Top R...
PR-383: Solving ImageNet: a Unified Scheme for Training any Backbone to Top R...
 
Transfer learning usage
Transfer learning usageTransfer learning usage
Transfer learning usage
 
PR-203: Class-Balanced Loss Based on Effective Number of Samples
PR-203: Class-Balanced Loss Based on Effective Number of SamplesPR-203: Class-Balanced Loss Based on Effective Number of Samples
PR-203: Class-Balanced Loss Based on Effective Number of Samples
 
Distilling the knowledge in a neural network
Distilling the knowledge in a neural networkDistilling the knowledge in a neural network
Distilling the knowledge in a neural network
 
PR-339: Maintaining discrimination and fairness in class incremental learning
PR-339: Maintaining discrimination and fairness in class incremental learningPR-339: Maintaining discrimination and fairness in class incremental learning
PR-339: Maintaining discrimination and fairness in class incremental learning
 
Self Supervised Learning 세미나.pptx
Self Supervised Learning 세미나.pptxSelf Supervised Learning 세미나.pptx
Self Supervised Learning 세미나.pptx
 
딥러닝 논문읽기 efficient netv2 논문리뷰
딥러닝 논문읽기 efficient netv2  논문리뷰딥러닝 논문읽기 efficient netv2  논문리뷰
딥러닝 논문읽기 efficient netv2 논문리뷰
 
MRC recent trend_ppt
MRC recent trend_pptMRC recent trend_ppt
MRC recent trend_ppt
 
20210131deit-210204074124.pdf
20210131deit-210204074124.pdf20210131deit-210204074124.pdf
20210131deit-210204074124.pdf
 
Training data-efficient image transformers & distillation through attention
Training data-efficient image transformers & distillation through attentionTraining data-efficient image transformers & distillation through attention
Training data-efficient image transformers & distillation through attention
 
SAGAN_2024seminar announce_seoultech.pptx
SAGAN_2024seminar announce_seoultech.pptxSAGAN_2024seminar announce_seoultech.pptx
SAGAN_2024seminar announce_seoultech.pptx
 

More from ssuser23ed0c

220825 지승현 ERM-based regularization.pdf
220825 지승현 ERM-based regularization.pdf220825 지승현 ERM-based regularization.pdf
220825 지승현 ERM-based regularization.pdfssuser23ed0c
 
220825 지승현 ERM-based regularization.pptx
220825 지승현 ERM-based regularization.pptx220825 지승현 ERM-based regularization.pptx
220825 지승현 ERM-based regularization.pptxssuser23ed0c
 
220510 지승현 Unpaired Image-to-Image Translation.pptx
220510 지승현 Unpaired Image-to-Image Translation.pptx220510 지승현 Unpaired Image-to-Image Translation.pptx
220510 지승현 Unpaired Image-to-Image Translation.pptxssuser23ed0c
 
220412 지승현 Mask RCNN.pptx
220412 지승현 Mask RCNN.pptx220412 지승현 Mask RCNN.pptx
220412 지승현 Mask RCNN.pptxssuser23ed0c
 
220112 지승현 mauve
220112 지승현 mauve220112 지승현 mauve
220112 지승현 mauvessuser23ed0c
 
211223 지승현 text generation survey
211223 지승현 text generation survey211223 지승현 text generation survey
211223 지승현 text generation surveyssuser23ed0c
 

More from ssuser23ed0c (6)

220825 지승현 ERM-based regularization.pdf
220825 지승현 ERM-based regularization.pdf220825 지승현 ERM-based regularization.pdf
220825 지승현 ERM-based regularization.pdf
 
220825 지승현 ERM-based regularization.pptx
220825 지승현 ERM-based regularization.pptx220825 지승현 ERM-based regularization.pptx
220825 지승현 ERM-based regularization.pptx
 
220510 지승현 Unpaired Image-to-Image Translation.pptx
220510 지승현 Unpaired Image-to-Image Translation.pptx220510 지승현 Unpaired Image-to-Image Translation.pptx
220510 지승현 Unpaired Image-to-Image Translation.pptx
 
220412 지승현 Mask RCNN.pptx
220412 지승현 Mask RCNN.pptx220412 지승현 Mask RCNN.pptx
220412 지승현 Mask RCNN.pptx
 
220112 지승현 mauve
220112 지승현 mauve220112 지승현 mauve
220112 지승현 mauve
 
211223 지승현 text generation survey
211223 지승현 text generation survey211223 지승현 text generation survey
211223 지승현 text generation survey
 

(in Korean) about knowledge distillation

  • 1. D S A I Lab. 2021.01.26 About Knowledge distillation Distilling the Knowledge in a Neural Network (Hinton et al., NIPS 2015) On the Efficacy of Knowledge Distillation (Cho et al., ICCV 2019) TinyBERT : Distilling BERT for natural language understanding (Jiao et al., EMNLP 2020) 숭실대학교 소프트웨어학과 DSAI Lab. 지승현 발표 1
  • 2. D S A I Lab. 목차 1. Knowledge distillation 개요 2. Characteristics of Knowledge distillation – 빠른 수렴 및 학습 방해 – 좋은 Teacher model의 조건 – Attention transfer 3. BERT distillation 4. 결론 2
  • 3. D S A I Lab. 1. Knowledge distillation 개요 – Knowledge distillation : 잘 학습된 대형 모델을 사용, 소형 모델에 지식을 증류 – Teacher model과 Student model를 가정 – Input에 대한 Teacher model의 출력을 흉내내도록 Student model을 학습  이를 통해 Student model을 처음부터 학습 (from scratch) 하는것보다 성능을 높이는 것이 목표 3
  • 4. D S A I Lab. 1. Knowledge distillation 개요 – 일반 학습 Loss과의 차이점 – 정답을 one-hot vector 형태의 “Hard Target” 으로 변환하는 것이 통상적 – 이 때 one-hot vector와 cross-entropy를 수행 – 그러나 Knowledge distillation (이하 KD) Loss 는 Soft target에 대한 경우가 많음. 4 클래스 정답확률 q_1 0 q_2 0 … … q_i 1 클래스 정답확률 q_1 0.1 q_2 0.05 … … q_i 0.6 일반 학습 Loss KD Loss
  • 5. D S A I Lab. 1. Knowledge distillation 개요 – Hinton et al. 은 Teacher Model 출력에 Temperature를 제안 (2015) – Temperature이란 출력 결과를 더 부드럽게 만들어주는 기법 – 이를 통해 Teacher model의 출력 결과 정보를 더 잘 전달할 수 있다고 주장 – 𝒒𝒊가 Teacher model의 출력 확률, 𝒛𝒊가 클래스 i에 대한 활성화 이전 출력값이라면 𝒒𝒊 = 𝒆𝒙𝒑 𝒛𝒊/𝑻 𝒋 𝒆𝒙𝒑 𝒛𝒋/𝑻 에서 𝑻 = Temperature 5 (임의 예시) 클래스 정답확률 q_1 0.1 q_2 0.05 … … q_i 0.6 클래스 정답확률 q_1 0.15 q_2 0.07 … … q_i 0.5
  • 6. D S A I Lab. 1. Knowledge distillation 개요 – 통상적인 KD는 KD Loss에 일반 Loss를 섞은 함수로 학습하는 방법을 지칭 – 𝒒𝒊 = 𝒆𝒙𝒑 𝒛𝒊/𝑻 𝒋 𝒆𝒙𝒑 𝒛𝒋/𝑻 , 𝒑𝒊는 Student Model의 출력 확률일 때 ℒ𝑲𝑫 = −𝑻𝟐 𝒌 𝒒𝒌 𝒍𝒐𝒈𝒑𝒌 ℒ = 𝜶ℒ𝑲𝑫 + (𝟏 − 𝜶)ℒ𝑪𝑳𝑺 – 이 때 𝜶는 Hyperparameter, ℒ𝑪𝑳𝑺는 일반 학습에서의 loss – 통상적으로 𝜶=0.9, 𝑻 ∈ {𝟑, 𝟒, 𝟓} 6
  • 7. D S A I Lab. 2. Characteristics of Knowledge distillation (1) – KD loss는 빠르게 학습시키지만, 점점 성능향상을 방해한다.* – From scratch 학습 시보다 빠르게 수렴된다. (좌) – 그러나 일정 반복 (epoch) 수를 넘어서면 KD의 수렴이 더 느려진다. (좌) – 따라서 일정 epoch까지만 KD로 학습 후 일반 학습으로만 진행하는 방법 (ESKD) 이 효과적. (우) 7
  • 8. D S A I Lab. 2. Characteristics of Knowledge distillation (2) – 좋은 Teacher는 용량이 크거나 정확도가 높은 모델이 아님 – 오히려 용량이 적은 Teacher 모델이 distillation을 더 잘 수행한 것으로 나타남 (좌) – distillation 성능과 Teacher 모델 용량은 비례하지 않으며 최적 용량이 존재하는 것으로 파악 (우) – Teacher 모델의 정확도보다는 세밀함이 더 중요한 것이라는 주장도 존재* 8 * Muller et al., NIPS 2019
  • 9. D S A I Lab. 2. Characteristics of Knowledge distillation (3) – 출력값 뿐만이 아니라 Attention Layer를 전달할 필요가 있다. – Attention Transfer* 는 Teacher의 Attention layer를 Student가 모방하도록 하는 방법 (좌) – j번째 Student의 attention layer (𝑸𝑺 𝒋 ) 와 Teacher의 attention layer (𝑸𝑻 𝒋 ) 를 근사 (우) – 이를 위해 Normalized된 형태 ( 𝑸 𝑸 𝟐 ) 를 사용하고, Student – Teacher의 차를 Loss 함수에 삽입 – ESKD와 함께 적용시 추가적으로 KD 성능이 향상되는 것으로 확인 9 * Zagoruyko et al., ICLR 2017
  • 10. D S A I Lab. 3. BERT distillation – TinyBERT는 KD Loss만을 고려한 distillated 모델 – BERT에 KD를 적용한 사례 – Attention transfer를 차용, KD Loss를 Layer Loss로 전환 – Layer Loss만을 사용하여 학습 (ESKD는 미사용) – g(m) 을 통해 Teacher Layer를 Student Layer에 적절히 매핑 10 * https://jalammar.github.io/illustrated-transformer/ 여러 Layer의 BERT의 구조*
  • 11. D S A I Lab. 3. BERT distillation – Layer의 인덱스에 따라 Loss 함수의 성격이 변화 – Student의 Layer가 총 M개, Loss 함수를 계산중인 인덱스가 m일 때, 11 간략화한 BERT의 구조
  • 12. D S A I Lab. 3. BERT distillation – 본 KD 방법의 우수성을 실험을 통해 확인 1) 언어모델 학습 (Pretrain) 시에 KD 적용시 Student의 성능은 더 나빠짐 2) 그러나 각 태스크에 대해 학습 (Fine-tune) 시에 KD를 적용하면 Student의 성능이 더 좋아짐 1) 동일 파라미터 수로 학습된 소형 BERT 모델보다 더 좋은 성능을 나타냄 2) Teacher 모델보다 파라미터가 적더라도 성능은 거의 유사 * 성능 측정은 언어모델의 성능을 11종의 태스크로 평가하는 GLUE benchmark 사용 12
  • 13. D S A I Lab. 4. 결론 – 요약 : – Knowledge distillation은 이미 학습된 모델을 활용하여 경량화된 모델을 더 빠르게 학습 – 그러나 단순 출력값만을 이용하면 더 나쁜 결과를 초래 – 학습된 모델의 가중치 값까지 활용하면 from scratch 학습보다 좋은 결과로 이어짐 – 발표자의 사견: – 대체어 추출이 가능한 언어모델은 모델의 P() 출력이 현실의 P()와 더 가까워진다고 가정 – 이를 통해 KD를 수행할 수 있다고 생각하여 공부 – 그러나 생각보다 많은 어려움이 있는 것으로 파악 13
  • 14. D S A I Lab. 4. 결론 – 논문 메타분석 (발표자의 사견) – ESKD 방법을 적용한 BERT distillation을 연구할 수 있을 것으로 사료 – 또한 BERT pretraining에서 왜 KD가 작동하지 않는지 연구해볼 만하다고 사료 – 충분한 Layer 수를 가진 신경망 모델은 전방 레이어가 그래디언트의 대부분을 전파한다고 알려짐 (Veit et al., NIPS 2016) – 따라서 Attention transfer 혹은 KD에서 이러한 원리를 차용, 전방 레이어를 흉내내는 모델에 대 해 연구할 수 있을 것으로 사료 14