当前位置:网站首页>[pytorch] softmax function
[pytorch] softmax function
2022-07-01 09:08:00 【Enzo tried to smash the computer】
Students who have done many classification tasks must know softmax function .softmax function , Also known as normalized exponential function . It's a binary function sigmoid Generalization on multi classification , The purpose is to show the results of multi classification in the form of probability . The following figure shows softmax The calculation method of :

Now let's explain why softmax It's in this form .
First , We know that probability has two properties :1) The probability of prediction is non negative ;2) The sum of the probabilities of various prediction results is equal to 1.
softmax It is to convert the prediction result from negative infinity to positive infinity into probability according to these two steps .
1) Convert the forecast results to non negative numbers
The following figure for y=exp(x) Image , We can know that the value range of the exponential function is from zero to positive infinity .softmax The first step is to transform the prediction results of the model into an exponential function , This ensures that the probability is nonnegative .

2) The sum of the probabilities of various prediction results is equal to 1
To ensure that the sum of the probabilities of each prediction result is equal to 1. We only need to normalize the converted results . The way is Divide the converted results by the sum of all converted results , It can be understood as the percentage of the converted results in the total . So we get the approximate probability .
Here is an example , Suppose the prediction result of the model for a three classification problem is -3、1.5、2.7. We need to use it. softmax Convert model results into probability . Steps are as follows :
1) Convert the forecast results to non negative numbers
y1 = exp(x1) = exp(-3) = 0.05
y2 = exp(x2) = exp(1.5) = 4.48
y3 = exp(x3) = exp(2.7) = 14.88
2) The sum of the probabilities of various prediction results is equal to 1
z1 = y1/(y1+y2+y3) = 0.05/(0.05+4.48+14.88) = 0.0026
z2 = y2/(y1+y2+y3) = 4.48/(0.05+4.48+14.88) = 0.2308
z3 = y3/(y1+y2+y3) = 14.88/(0.05+4.48+14.88) = 0.7666
To sum up softmax How to convert multi classification output into probability , It can be divided into two steps :
1) molecular : By exponential function , Map real output to zero to positive infinity .
2) The denominator : Add all the results , Normalize .
The following picture shows Stanford University CS224n Most softmax The explanation of :

边栏推荐
- 2.2 【pytorch】torchvision.transforms
- I would like to know the process of stock registration and account opening by mobile phone? In addition, is it safe to open a mobile account?
- Win7 pyinstaller reports an error DLL load failed while importing after packaging exe_ Socket: parameter error
- Shell脚本-while循环详解
- Personal decoration notes
- Embedded Engineer Interview Question 3 Hardware
- Shell script -select in loop
- Understanding and implementation of AVL tree
- NiO zero copy
- 【检测技术课案】简易数显电子秤的设计与制作
猜你喜欢

Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month

Embedded Engineer Interview Question 3 Hardware

Football and basketball game score live broadcast platform source code /app development and construction project

What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?

Pain points and solutions of equipment management in large factories

How to manage fixed assets well? Easy to point and move to provide intelligent solutions

Mise en œuvre simple de l'équilibrage de la charge par nacos

2.2 【pytorch】torchvision.transforms

Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)

TV size and viewing distance
随机推荐
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DS18B20 temperature sensor +nodejs local service + MySQL database
Shell脚本-echo命令 转义符
jeecg 重启报40001
How to manage fixed assets efficiently in one stop?
Is it safe to dig up money and make new shares
Nacos - gestion de la configuration
Common interview questions for embedded engineers 2-mcu_ STM32
Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)
Principle and application of single chip microcomputer timer, serial communication and interrupt system
【pytorch】softmax函数
[ESP nanny level tutorial] crazy completion chapter - Case: temperature and humidity monitoring system based on Alibaba cloud, applet and Arduino
What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?
Dynamic proxy
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DHT11 +nodejs local service + MySQL database
Jeecg restart alarm 40001
中小企业固定资产管理办法哪种好?
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + MQ系列 + NodeJs本地服务 + MySql存储
Public network cluster intercom +gps visual tracking | help the logistics industry with intelligent management and scheduling
【pytorch学习】torch.device
Shell脚本-变量的定义、赋值和删除