mindspore/docs/api/api_python/nn/mindspore.nn.MultiLabelSoft...

33 lines
1.8 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.nn.MultiLabelSoftMarginLoss
======================================
.. py:class:: mindspore.nn.MultiLabelSoftMarginLoss(weight=None, reduction='mean')
基于最大熵计算用于多标签优化的损失。
多标签软间隔损失通常用于多标签分类任务中,输入样本可以属于多个目标类别。
给定输入 :math:`x` 和二元标签 :math:`y` 其shape为 :math:`(N,C)` :math:`N` 表示样本数量, :math:`C` 为样本类别数,损失计算公式如下:
.. math::
\mathcal{loss\left( x , y \right)} = - \frac{1}{N}\frac{1}{C}\sum_{i = 1}^{N}
\sum_{j = 1}^{C}\left(y_{ij}\log\frac{1}{1 + e^{- x_{ij}}} + \left( 1 - y_{ij}
\right)\log\frac{e^{-x_{ij}}}{1 + e^{-x_{ij}}} \right)
其中 :math:`x{ij}` 表示样本 :math:`i`:math:`j` 类别的概率得分。 :math:`y{ij}` 表示样本 :math:`i` 是否属于类别 :math:`j`
:math:`y{ij}=1` 时属于为0时不属于。对于多标签分类任务每个样本可以属于多个类别即标签中含有多个1。
如果 `weight` 不为None将会和每个分类的loss相乘。
参数:
- **weight** (Union[Tensor, int, float]) - 每个类别的缩放权重。默认值None。
- **reduction** (str) - 指定应用于输出结果的计算方式。取值为"mean""sum",或"none"。默认值:"mean"。
输入:
- **x** (Tensor) - shape为(N, C)的TensorN为batch sizeC为类别个数。
- **target** (Tensor) - 目标值数据类型和shape与 `x` 的相同。
输出:
Tensor数据类型和 `x` 相同。如果 `reduction` 为"none"其shape为(N)。否则其shape为0。
异常:
- **ValueError** - `x``target` 的维度不等于2。