이글은 Medium( https://medium.com/@mahendrakariya/dark-knowledge-in-neural-networks-467e5d699181 ) 글의 내용을 학습하면서 정리한 글입니다.
Neural Network는 그 목적이 각기 다름에도 불구하고, training과정에서 사용하는 network와 deployment과정에서 사용하는 network가 동일한 네트워크입니다. 이를 언급한 위 글에서는 애벌레와 성충이 되는 과정으로 설명하고 있습니다.
1) Dark Knowledge 개념
이러한 내용을 응용하여 neural network에 대한 model compression을 Bucila,.et al( https://www.cs.cornell.edu/~caruana/compression.kdd06.pdf )이 소개하였고, Geoffrey Hinton,.et al에 의해서 일반화( https://arxiv.org/abs/1503.02531 ) 되었습니다.
dark knowledge는 hidden knowledge라고도 하며, 이러한 dark knowledge를 추출하고 사용하는 것을 distillation이라고 합니다. 이를 위 글에서 언급한 내용을 토대로 살펴보면
multi-class classification problem(개, 고양이, 소, 자동차)을 살펴보면 hard-decision, normal softmax 적용후, softened softmax적용후 값의 변화는 아래와 같습니다.
|
Cow |
Dog |
Cat |
Car |
hard targets(one-hot encoding of the gold class) |
0 |
1 |
0 |
0 |
normal softmax |
10^(-6) |
.9 |
.1 |
10^(-9) |
softened softmax (softmax-temperature) |
.05 |
.3 |
.2 |
.005 |
hard decision을 적용 할 경우 True로 판정되는 label에만 1이 표기가 되며, normal softmax를 적용하면 False에 해당하는 Cow와 Car는 무시해도 될만큼(negligible) 값이 작다고 할 수 있습니다. 하지만 softened softmax(softmax-temperature) 를 적용할 경우 normal softmax보다 풍부한 정보를 나타낼수 있게 됩니다. 이는 Cat이 Cow로 mis-classifying될 가능성(.2와 .05)이 Cat이 Car로 mis-classifying될 가능성(.2와 .005)보다 크다고 할 수 있습니다. 이렇게 유실될 수 있는 정보를 보다 더 나타내는 것이 가능해 집니다.
[softmax- temperature]
Hinton에 의해서 소개된 distribution over the class를 계산하기 위한 방법으로, training시기에 student-teacher network에 동일한 temperature parameter 가 적용됩니다. inference시기에는 temperature parameter=1로 설정하여 standard softmax를 사용합니다. 이는 knowledge distillation을 통해 training시 student-teacher에 softened softmax를 사용하여 hidden information이 학습되도록 하고, inference시는 normal softmax를 사용한다는 의미입니다.
pi=−exp(zi/T)∑jexp(zj/T)T is the temperature parameterIf T→0, the distribution → Kronecker (the one−hot target vector)If T→+∞, the distribution →a uniform distributionpi=−exp(zi/T)∑jexp(zj/T)T is the temperature parameterIf T→0, the distribution → Kronecker (the one−hot target vector)If T→+∞, the distribution →a uniform distribution
2) Dark Knwoledge(student teacher) Architecture
dark knowledge를 추출하여 사용하는 방식은 다음과 같습니다. Teacher에 해당하는 Lage Model을 train하고, 이 Neural Network로부터 dark knowledge(hidden knowledge)를 추출합니다. 이 dark knowledge기반으로 Student에 해당하는 Small Network를 학습시키는 방식입니다.

: [Dark Knowledge Transfering Architecture Concept]
위 Concept Architecture에서 확인할 수 있듯이 Teacher에서 Final Activation Layer(softmax)이전까지의 logits를 추출하고, 여기까지의 output에 softened softmax(softmax-temperature)를 적용하고, 이를 student network의 output으로 사용하게 됩니다. 이를 통해 dark knowledge 개념에서 살펴본것 처럼 rich information을 전달할 수 있게 됩니다.
이 그림에서 New Small Model이 우리가 학습시키는 Student Network가 됩니다. 이 모델은 먼저 Small Model을 만들어 Teacher Model에서 사용한 학습데이터(x_train, y_train)를 통해 학습을 하고 마진가지로 logits를 추출하여, New Small Model을 만들게 됩니다. 이 모델에 최종적으로 학습 데이터(x_train, softened_softmax_probaibilties)를 학습시키는 과정을 통해 dark knowledge를 tranfering하게 됩니다.
이러한 과정을 통해 이미지 분류를 위해서 통상적으로 사용하는 Convolution Network보다 훨씬 파라미터수가 적은 비교적 단순한 Dense Network를 통해서 이미지 분류 문제를 수행할 수 있게 됩니다. light-weight Model을 통해 Performance에 크게 손실이 없는 결과를 도출할 수 있게 됩니다.