Pytorch 代码注释公式格式还原
由于不熟悉语法,在理解公式过程中,出现障碍。
把公式还原,方便阅读,同时也学习公式表示语法:
pytorch BCE损失函数(loss function)代码注释如下:
The loss can be described as:
.. math::
\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)
or in the case of the `weight` argument being specified:
.. math::
\text{loss}(x, class) = weight[class] \left(-x[class] + \log\left(\sum_j \exp(x[j])\right)\right)
The losses are averaged across observations for each minibatch.
对照如下:
参考文献:
https://www.jianshu.com/p/e74eb43960a1
Tips:
看不懂公式时,前后加上$符号,在markdown中即可还原(单个为行内,两个为行间)。
如:
\text{loss}(x, class) = weight[class] \left(-x[class] + \log\left(\sum_j \exp(x[j])\right)\right)加上美元符后显示为: