표준 정규화와 달리 softmax를 사용하는 이유는 무엇입니까?
신경망의 출력 레이어에서 softmax 함수를 사용하여 확률 분포를 근사화하는 것이 일반적입니다.
지수로 인해 계산 비용이 많이 듭니다. 왜 모든 변환이 양수가되도록 Z 변환을 수행 한 다음 모든 출력을 모든 출력의 합으로 나눠서 정규화하지 않겠습니까?
표준 정규화와 비교할 때 Softmax의 한 가지 좋은 특성이 있습니다.
분포는 다소 균일 한 신경망의 낮은 자극 (흐린 이미지 생각)과 0과 1에 가까운 확률로 높은 자극 (예 : 큰 숫자, 선명한 이미지 생각)에 반응합니다.
표준 정규화는 비율이 동일한 한 신경 쓰지 않습니다.
소프트 맥스가 10 배 더 큰 입력을 가졌을 때 어떤 일이 발생하는지보십시오. 즉, 신경망이 선명한 이미지를 얻었고 많은 뉴런이 활성화되었습니다
>>> softmax([1,2]) # blurry image of a ferret
[0.26894142, 0.73105858]) # it is a cat perhaps !?
>>> softmax([10,20]) # crisp image of a cat
[0.0000453978687, 0.999954602]) # it is definitely a CAT !
그런 다음 표준 정규화와 비교하십시오.
>>> std_norm([1,2]) # blurry image of a ferret
[0.3333333333333333, 0.6666666666666666] # it is a cat perhaps !?
>>> std_norm([10,20]) # crisp image of a cat
[0.3333333333333333, 0.6666666666666666] # it is a cat perhaps !?
나는 몇 달 동안이 질문을했다. softmax를 출력 함수로 영리하게 추측 한 다음 입력을 softmax에 대한 로그 확률로 해석합니다. 당신이 말했듯이, 왜 모든 출력을 그들의 합으로 나눠서 정규화하지 않겠습니까? 6.2.2 절의 Goodfellow, Bengio 및 Courville (2016) 의 딥 러닝 책 에서 답을 찾았습니다 .
마지막 숨겨진 레이어가 z를 활성화로 제공한다고 가정 해 봅시다. 그러면 softmax는 다음과 같이 정의됩니다
아주 짧은 설명
softmax 함수의 exp는 대 엔트로피 손실의 로그를 대략 상쇄하여 z_i에서 손실이 대략 선형이되도록합니다. 이로 인해 모델이 잘못되었을 때 대략 일정한 기울기가 발생하여 빠르게 보정 할 수 있습니다. 따라서 잘못된 포화 소프트 맥스가 사라지는 구배를 유발하지 않습니다.
간단한 설명
신경망을 훈련시키는 가장 보편적 인 방법은 Maximum Likelihood Estimation입니다. 우리는 훈련 데이터의 가능성을 최대화하는 방식으로 매개 변수 세타를 추정합니다 (크기 m). 전체 트레이닝 데이터 세트의 가능성은 각 샘플의 우도의 곱이므로, 최대화하기 쉽다 로그 우도 데이터 집합 및 이에 K로 인덱싱 된 각 샘플의 로그 우도의 합 :
이제 z가 주어진 소프트 맥스에만 초점을 맞 춥니 다.
나는 k 번째 샘플의 올바른 클래스입니다. 이제 softmax의 로그를 가져 와서 샘플의 로그 우도를 계산하면 다음과 같은 결과가 나타납니다.
z의 큰 차이에 대해 대략적으로 대략적인
먼저 선형 구성 요소 z_i를 볼 수 있습니다. 둘째, 두 가지 경우에 대해 max (z)의 동작을 검사 할 수 있습니다.
- 모형이 정확하면 max (z)는 z_i가됩니다. 따라서 로그 우도는 z_i와 z의 다른 항목 사이의 차이가 커짐에 따라 0으로 나타납니다 (즉, 1의 우도).
- 모형이 올바르지 않으면 max (z)는 다른 z_j> z_i입니다. 따라서 z_i를 추가해도 -z_j가 완전히 취소되지 않으며 로그 우도는 대략 (z_i-z_j)입니다. 이것은 로그 가능성을 높이기 위해 z_i를 높이고 z_j를 줄이려면 어떻게해야하는지 모델에 명확하게 알려줍니다.
모델이 잘못된 샘플에 의해 전체 로그 우도가 지배적임을 알 수 있습니다. 또한 모델이 실제로 부정확하더라도 포화 된 softmax가 발생하더라도 손실 함수는 포화되지 않습니다. z_j에서 대략 선형이며, 거의 일정한 기울기를 가짐을 의미합니다. 이를 통해 모델이 빠르게 자체 수정 될 수 있습니다. 예를 들어, 평균 제곱 오류의 경우에는 해당되지 않습니다.
긴 설명
softmax가 여전히 임의의 선택 인 것 같으면 로지스틱 회귀 분석에서 S 자형을 사용하는 데 대한 정당성을 살펴볼 수 있습니다.
softmax는 유사하게 정당화되는 다중 클래스 문제에 대한 S 자형의 일반화입니다.
: 나는 매우 좋은 것으로 여기에 설명을 발견 CS231n : 시각 인식에 대한 길쌈 신경망.
On the surface the softmax algorithm seems to be a simple non-linear (we are spreading the data with exponential) normalization. However, there is more than that.
Specifically there are a couple different views (same link as above):
Information Theory - from the perspective of information theory the softmax function can be seen as trying to minimize the cross-entropy between the predictions and the truth.
Probabilistic View - from this perspective we are in fact looking at the log-probabilities, thus when we perform exponentiation we end up with the raw probabilities. In this case the softmax equation find the MLE (Maximum Likelihood Estimate)
In summary, even though the softmax equation seems like it could be arbitrary it is NOT. It is actually a rather principled way of normalizing the classifications to minimize cross-entropy/negative likelihood between predictions and the truth.
The values of q_i represent log-likelihoods. In order to recover the probability values, you need to exponentiate them.
One reason that statistical algorithms often use log-likelihood loss functions is that they are more numerically stable: a product of probabilities may be represented be a very small floating point number. Using a log-likelihood loss function, a product of probabilities becomes a sum.
Another reason is that log-likelihoods occur naturally when deriving estimators for random variables that are assumed to be drawn from multivariate Gaussian distributions. See for example the Maximum Likelihood (ML) estimator and the way it is connected to least squares.
As a sidenote, I think that this question is more appropriate for the CS Theory or Computational Science Stack Exchanges.
I think one of the reasons can be to deal with the negative numbers and division by zero, since exp(x) will always be positive and greater than zero.
For example for a = [-2, -1, 1, 2]
the sum will be 0, we can use softmax to avoid division by zero.
Suppose we change the softmax function so the output activations are given by
where c
is a positive constant. Note that c=1
corresponds to the standard softmax function. But if we use a different value of c
we get a different function, which is nonetheless qualitatively rather similar to the softmax. In particular, show that the output activations form a probability distribution, just as for the usual softmax. Suppose we allow c
to become large, i.e., c→∞
. What is the limiting value for the output activations a^L_j
? After solving this problem it should be clear to you why we think of the c=1
function as a "softened" version of the maximum function. This is the origin of the term "softmax". You can follow the details from this source (equation 83).
We are looking at a multi-classification problem. The predicted variable y
can take one of k
categories, where k > 2
. In probability theory, this is a multinomial distribution, and multinomial distribution belongs to a big family called exponential family. According to the property of the exponential family distributions, we reconstruct the probability of P(k=?|x)
, it coincides with the softmax formula.
For further information and a formal proof refer to CS229 lecture notes (Softmax Regression).
A useful trick usually performs to softmax: softmax(x) = softmax(x+c), that is, softmax is invariant to constant offsets in the input.
The choice of the softmax function seems somehow arbitrary as there are many other possible normalizing functions. It is thus unclear why the log-softmax loss would perform better than other loss alternatives.
From "An Exploration of Softmax Alternatives Belonging to the Spherical Loss Family" https://arxiv.org/abs/1511.05042
The authors explored some other functions among which are Taylor expansion of exp
and so called spherical softmax and found out that sometimes they might perform better than usual softmax
.
Adding to Piotr Czapla answer, the greater the input values, the greater the probability for the maximum input, for same proportion and compared to the other inputs:
참고 URL : https://stackoverflow.com/questions/17187507/why-use-softmax-as-opposed-to-standard-normalization
'Programing' 카테고리의 다른 글
변수를 설정하고 사용하는 CMake 구문은 무엇입니까? (0) | 2020.07.02 |
---|---|
컨트롤러의 Hibernate / JPA에서 게으른 페치 된 항목을로드하는 방법 (0) | 2020.07.02 |
BigDecimal 세트 스케일 및 라운드 (0) | 2020.07.02 |
C를 사용하여 배열 반환 (0) | 2020.07.02 |
팬더 : 열의 텍스트를 여러 행으로 나누려면 어떻게합니까? (0) | 2020.07.02 |