当前位置:网站首页>NLLLoss+log_ SoftMax=CE_ Loss
NLLLoss+log_ SoftMax=CE_ Loss
2022-04-23 09:17:00 【365JHWZGo】
List of articles
subject
NLLLoss+log_SoftMax=CE_Loss
Preface
It hasn't been updated for several days , alas , A little busy recently , Please forgive me ! Today, I finally stole some time to watch B Station video discovery NLLLoss+log_SoftMax=CE_Loss, ha-ha , I've seen it again , So let's take a closer look today !
NLLLoss
chinese
Negative log likelihood loss
function
torch.nn.NLLLoss(
weight=None,
size_average=None,
ignore_index=- 100,
reduce=None,
reduction='mean'
)
Parameters,
Parameters | type | meaning |
---|---|---|
weight | tensor(optional) | Manually readjust the weight proportion of each class |
size_average | bool(optional) Have been abandoned | Loss is a batch The average value of each loss element in |
ignore_index | int(optional) | Ignoring a target value does not affect the gradient of the input |
reduce | bool(optional) Have been abandoned | According to each mini-batch The average size of the loss is divided equally or summarized |
reduction | string(optional) | reuduction Will be applied to the output |
reduction Parameters | explain |
---|---|
none | Expand all |
mean | Add up / Number |
sum | hold none The results add up |
Function input and output
Input | The goal is | Output | |
---|---|---|---|
type | tensor | tensor | tensor |
dimension | ( N , C N,C N,C)/( C C C) | ( N N N)/() | ( N N N)/ ( N , d 1 , d 2 , . . . , d K ) (N, d_1, d_2, ..., d_K) (N,d1,d2,...,dK) |
Code
import torch
# Imitate the output after passing through the model
preds = torch.tensor([[1.5,2.5,3.0]])
# Real label
target = torch.tensor([1])
nllloss = torch.nn.NLLLoss()
print('nllloss:',nllloss(preds,target))
And CE_Loss The difference and connection
difference :
- CE_Loss It's going through first log_softmax after NLLLoss Loss of steps
- NLLLoss It just corresponds to index Of target The value becomes the opposite number
contact :
- There is a certain correlation , after softmax Most of the subsequent values are [0,1] Between , It's going on log After taking the logarithm, the value is distributed in ( − ∞ -\infty −∞,0] Between , and loss It can't be negative , So we need to NLLLoss To make it positive
import torch
# Imitate the output after passing through the model
preds = torch.tensor([[1.5,2.5,3.0]])
# Real label
target = torch.tensor([1])
cross_entropy_loss = torch.nn.CrossEntropyLoss()
log_softmax = torch.nn.LogSoftmax(dim=1)
nllloss = torch.nn.NLLLoss()
cs_loss = cross_entropy_loss(preds,target)
nls_loss = nllloss(log_softmax(preds),target)
print(f' The cross entropy loss function is :{
cs_loss}\n Go first log_softmax after nll The loss function is :{
nls_loss}')
版权声明
本文为[365JHWZGo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230633453332.html
边栏推荐
- [58] length of the last word [leetcode]
- Brush classic topics
- BK3633 规格书
- Installation of data cleaning ETL tool kettle
- Little girl walking
- 【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
- Cross domain configuration error: when allowcredentials is true, allowedorigins cannot contain the special value "*“
- DMP engine work summary (2021, lightsaber)
- Go language self-study series | golang structure pointer
- ATSS(CVPR2020)
猜你喜欢
Open services in the bottom bar of idea
Principle of synchronized implementation
Installation of data cleaning ETL tool kettle
机器学习(六)——贝叶斯分类器
Program, process, thread; Memory structure diagram; Thread creation and startup; Common methods of thread
Arbre de dépendance de l'emballage des ressources
LeetCode_DFS_中等_1254. 统计封闭岛屿的数目
Failed to download esp32 program, prompting timeout
错题汇总1
MySQL小練習(僅適合初學者,非初學者勿進)
随机推荐
政务中台研究目的建设目标,建设意义,技术创新点,技术效果
小女孩行走
valgrind和kcachegrind使用运行分析
kettle实验
Matlab draw five-star red flag
LeetCode396. Rotate array
Applet in wechat and app get current ()
web页面如何渲染
js 原型链的深入
Go language self-study series | golang structure pointer
Write down the post order traversal of the ~ binary tree
[Luke V0] verification environment 2 - Verification Environment components
Summary of common concepts and problems of linear algebra in postgraduate entrance examination
Find the sum of simple types of matrices
GoLand debug go use - white record
Redis Desktop Manager for Mac
[C language] document operation
STM32 and FreeRTOS stack parsing
Taxable income
Share the office and improve the settled experience