当前位置:网站首页>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
边栏推荐
- MYCAT configuration
- What is monitoring intelligent playback and how to use intelligent playback to query video recording
- Summary of common concepts and problems of linear algebra in postgraduate entrance examination
- PCTP考试经验分享
- STM32 and FreeRTOS stack parsing
- Open services in the bottom bar of idea
- Using JS to realize a thousandth bit
- tsdf +mvs
- 2021 Li Hongyi's adaptive learning rate of machine learning
- valgrind和kcachegrind使用運行分析
猜你喜欢

Introduction to matlab

《数字电子技术基础》3.1 门电路概述、3.2 半导体二极管门电路

Kettle experiment (III)

MySQL小練習(僅適合初學者,非初學者勿進)

论文阅读《Multi-View Depth Estimation by Fusing Single-View Depth Probability with Multi-View Geometry》

npm ERR! network

Four pictures to understand some basic usage of Matplotlib

npm ERR! network

A must see wechat applet development guide 1 - basic knowledge
![[in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)](/img/c9/43a63f526068ef6a3e4964a22c5a1f.png)
[in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)
随机推荐
RSA encryption and decryption signature verification
调包求得每个样本的k个邻居
kettle实验
Data visualization: use Excel to make radar chart
Go language self-study series | golang structure pointer
npm ERR! network
Go language self-study series | initialization of golang structure
NPM reports an error: operation not allowed, MKDIR 'C: \ program files \ node JS \ node_ cache _ cacache’
Applet in wechat and app get current ()
Applet error: should have URL attribute when using navigateto, redirectto or switchtab
npm ERR! network
node安装
Find the sum of simple types of matrices
What is monitoring intelligent playback and how to use intelligent playback to query video recording
[C language] document operation
Distributed message oriented middleware framework selection - Digital Architecture Design (7)
Write down the post order traversal of the ~ binary tree
错题汇总1
三、6【Verilog HDL】基础知识之门级建模
2021 Li Hongyi's adaptive learning rate of machine learning