A simple explanation of how the Softmax function works
- Andrew Jones
- Nov 23, 2018
- 2 min read
If you're versed in Neural Networks, you probably know the Softmax function as the function that takes your outputs and forces them all to add up to 1. It's extremely useful, and very commonly used in classification tasks.

But how does it work it's magic exactly? It's quite simple when you break it down into it's parts.
Let's assume you have 5 classification scores being output from your Neural Network, one for each of the nodes in your final layer (I'll just make them up):
node_scores = [2.0, 0.1, 0.5, 1.0, 1.5]
What do we need to do to transform them, so they add up to 1 based on the Softmax function?
If we break the equation into two parts, we can follow it through.
The top layer of the equation takes Euler's number 'e' to the the power of each of our node score, i.e. e**2.0, e**0.1 and so on.
Read more about Euler's Number here:
To do this in python we'll need to import numpy, and we can then do a list comprehension to run through the above calculation for each of our node scores.
import numpy as np eulerised_node_scores = [np.exp(i) for i in node_scores] print(eulerised_node_scores) > [7.389, 1.105, 1.648, 2.718, 4.481]
We then want to calculate the sum of our eulerised node scores:
sum_of_eulerised_node_scores = sum(eulerised_node_scores) print(sum_of_eulerised_node_scores) > 17.342919186503536
And finally, we divide each of our eulerised_node_scores by their sum and voila, we have our softmax scores:
softmax_scores = [j/sum_of_eulerised_node_scores for j in eulerised_node_scores] print(softmax_scores) > [0.426, 0.063, 0.095, 0.156, 0.258]
Let's check they add up to 1...
print(sum(softmax_scores)) > 1.0
I hope that was interesting, please do share to anyone else you think might be interested




Hôm nọ, mình vô tình thấy mọi người nhắc đến bongdaso khi đang bàn về các trận đấu bóng đá, nên cũng tò mò vào xem thử. Mình chỉ lướt qua một chút để xem cách mà thông tin và tỷ số được sắp xếp. Nhìn chung, bố cục khá hợp lý, các phần tách biệt rõ ràng, giúp mình dễ dàng nắm bắt thông tin mà không bị rối mắt. Đối với mình, chỉ cần vậy là đủ để hiểu sơ về tình hình bóng đá trên bongdaso.org.
Hôm qua mình có lướt web tìm thông tin về xổ số, tự dưng thấy một cái tên khá lạ là soi cầu 247. Mình mở ra xem thử, cảm giác giao diện khá trực quan, dễ nhìn. Mình có để ý là tốc độ tải trang cũng ổn định, không bị lag như một số trang khác mình đã thử trước đây. Tuy nhiên, thông tin bên trong có vẻ hơi ngắn gọn, mình thì thích chi tiết hơn một chút. Nhưng mà chắc mình sẽ bookmark lại để theo dõi thêm, biết đâu sẽ tìm được những mẹo hay ho.