Teacher-Student와 Dark Knowledge

마지막 수정:

distillationteacher-studentdark-knowledgesoft-targets

teacher-student 구조는 간단하다.

input
  -> teacher model
  -> teaching signal
  -> student model

여기서 중요한 것은 teacher가 “정답”만 주지 않는다는 점이다. 고전적인 knowledge distillation에서 teacher는 가능한 class 전체에 대한 확률분포를 준다. 이 분포에는 정답뿐 아니라 오답 사이의 관계가 들어 있다.

Hard label

정답 하나만 남긴다.

cat 100%
dog 0%
fox 0%
car 0%
banana 0%

Teacher soft target

오답 사이의 거리도 남긴다.

cat 82%
dog 11%
fox 4%
car <1%
banana <1%
cat answer
dog near miss
fox related
car far
banana very far
The hard label says only which class is correct. The teacher distribution also says which wrong answers are plausible, and that extra structure is the useful dark knowledge.

Hard label이 버리는 것

일반적인 supervised learning의 label은 대개 one-hot이다.

cat = 1
dog = 0
fox = 0
car = 0
banana = 0

이 label은 분명하고 강하다. 하지만 너무 많이 압축되어 있다.

dog도 오답
car도 오답
banana도 오답

hard label 안에서는 세 오답이 모두 같은 0이다. 그래서 student는 dogcar보다 cat에 더 가깝다는 사실을 이 예제 하나만으로는 배울 수 없다.

Teacher 분포가 남기는 것

teacher의 soft target은 다르다.

cat    high
dog    somewhat plausible
fox    weak but related
car    almost impossible
banana almost impossible

이 분포는 정답뿐 아니라 문제 공간의 모양을 보여준다. Hinton, Vinyals, Dean의 distillation 논문에서 말하는 핵심도 여기에 있다. 모델이 배운 지식은 최종 argmax에만 있는 것이 아니라, 정답이 아닌 후보들에 배정한 상대적 확률에도 있다.

이 숨은 구조를 보통 dark knowledge라고 부른다.

dark knowledge
= teacher가 오답 후보들에 나누어 둔 상대적 믿음
= hard label에는 보이지 않는 class similarity

왜 student에게 도움이 되나

student는 teacher보다 작다. 그래서 모든 구조를 raw data에서 처음부터 발견하기 어렵다.

teacher soft target은 student에게 더 부드러운 학습 신호를 준다.

정답만 올려라

가 아니라:

정답은 cat이다.
하지만 dog 쪽 실수는 car 쪽 실수보다 자연스럽다.
그 관계까지 같이 맞춰라.

이런 신호는 특히 애매한 예제에서 강하다. 흐릿한 동물 사진, 여러 의도가 섞인 문장, 비슷한 코드 completion 후보처럼 정답 주변에 그럴듯한 대안이 많은 경우에는 teacher의 uncertainty 자체가 정보가 된다.

Confidence가 아니라 구조다

soft target을 볼 때 주의할 점이 있다. 핵심은 teacher가 “덜 확신한다”는 사실이 아니다. 핵심은 대안들 사이의 순서와 거리다.

cat > dog > fox >>> car > banana

student가 이 순서를 배우면, 단순히 정답을 맞추는 것보다 더 많은 것을 배운다. class들이 어떻게 가까운지, 어떤 오류가 자연스럽고 어떤 오류가 터무니없는지, teacher가 데이터 공간을 어떻게 나누고 있는지를 함께 배운다.

이것이 다음 카드에서 temperature가 필요한 이유다. teacher의 원래 분포가 너무 뾰족하면 dog, fox 같은 작은 확률이 거의 0처럼 보인다. temperature는 이 작은 차이를 student가 볼 수 있게 만든다.

LLM에서는 어떻게 보이나

LLM에서도 같은 아이디어가 token 단위로 나타난다.

prompt: The capital of France is

Paris   high
Lyon    low but country-related
London  low and wrong
banana  almost impossible

다만 현대 LLM distillation에서는 teacher logits 전체를 보지 못하는 경우가 많다. 그래서 실제로는 teacher가 생성한 답변이나 reasoning trace를 학습하는 hard distillation이 많이 쓰인다. 그래도 개념의 뿌리는 같다.

teacher의 출력은
raw label보다 더 구조화된 supervision이다.

참고 자료

  • Geoffrey Hinton, Oriol Vinyals, Jeff Dean, Distilling the Knowledge in a Neural Network
  • 로컬 참고: reference-books/deepseek from scratch/ch08-Knowledge-distillation-Making-powerful-models-practical.md
  • 로컬 참고: reference-books/rlhf-book/ch12-Synthetic-Data.md
  • 로컬 참고: reference-books/Rearchitecting LLMs/ch06-Knowledge-recovery-through-distillation.md

확인

  • hard label은 왜 오답 사이의 관계를 지워버리는가?
  • dark knowledge는 teacher의 정답 confidence인가, 오답 후보들 사이의 상대적 구조인가?
  • teacher 분포가 너무 뾰족하면 왜 다음 단계에서 temperature가 필요해지는가?