Softmax 함수

박정재·2023년 2월 6일
0

DL Basics

목록 보기
6/9

Softmax 함수

소프트맥스 함수는 다중 클래스 분류를 위해 사용된다. 결과를 확률로 해석할 수 있도록 해준다. 지수를 사용하는 이유는 미분을 깔끔하게 하기 위해서라고 한다. 또한 값의 비교가 명확하기 때문에 사용한다고 한다.

지수가 포함되어 있기 때문에 softmax 계산 시, 굉장히 큰 숫자를 포함하게 될 수 있다. Numeric stability를 개선하기 위해 다음과 같은 방법을 사용할 수 있다고 한다.

# source: https://cs231n.github.io/linear-classify/#softmax-classifier
f = np.array([123, 456, 789]) # example with 3 classes and each having large scores
p = np.exp(f) / np.sum(np.exp(f)) # Bad: Numeric problem, potential blowup

# instead: first shift the values of f so that the highest number is 0:
f -= np.max(f) # f becomes [-666, -333, 0]
p = np.exp(f) / np.sum(np.exp(f)) # safe to do, gives the correct answer

Reference

profile
Keep on dreaming and dreaming

0개의 댓글