关于pytorch 交叉熵的个人理解

本文介绍了作者对PyTorch中交叉熵的理解,通过官方文档解析了交叉熵的计算公式,并指出PyTorch的交叉熵是基于softmax后的输出进行计算的,适用于包括2D图像在内的高维输入。总结了在one-hot编码下,真实类别对应的交叉熵损失表达式。
摘要由CSDN通过智能技术生成

title: pytorch 交叉熵的个人理解
date: 2020-01-19 11:54:06
tags:machine learning


关于pytorch 交叉熵的个人理解

最近,查pytorch的官方文档。里面关于交叉熵部分的公式描述不太理解,查了一些资料,简单的写了下公式。大概理解了一下,不过也不知道正确与否。

官方文档描写如下:

This criterion expects a class index in the range [0, C-1][0,C−1] as the target for each value of a 1D tensor of size minibatch; if ignore_index is specified, this criterion also accepts this class index (this index may not necessarily be in the class range).

The loss can be described as:

loss ( x , c l a s s ) = − log ⁡ ( exp ⁡ ( x [ c l a s s ] ) ∑ j exp ⁡ ( x [ j ] ) ) = − x [ c l a s s ] + log ⁡ ( ∑ j exp ⁡ ( x [ j ] ) ) l o s s ( x , c l a s s ) = − l o g ( ∑ j e x p ( x [ j ] ) e x p ( x [ c l a s s ] ) ) = − x [ c l a s s ] + l o g ( j ∑ e x p ( x [ j ] ) ) \text{loss}(x, class) = -\log\left(\frac{\exp(x[class])}{\sum_j \exp(x[j])}\right) \\ = -x[class] + \log\left(\sum_j \exp(x[j])\right)loss(x,class) \\ =−log(∑jexp(x[j])exp(x[class]))=−x[class]+log(j∑exp(x[j])) loss(x,class)=log(j

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值