Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/api/paddle/nn/BCEWithLogitsLoss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ BCEWithLogitsLoss

.. py:class:: paddle.nn.BCEWithLogitsLoss(weight=None, reduction='mean', pos_weight=None, name=None)

可用于创建一个 BCEWithLogitsLoss 的可调用类,计算输入的预测值 `logit` 和标签 `label` 间的 `binary cross entropy with logits loss` 损失。
可用于创建一个 BCEWithLogitsLoss 的可调用类,计算输入的预测值 ``logit`` 和标签 ``label`` 间的 ``binary cross entropy with logits loss`` 损失。

计算方式结合了 `sigmoid` 操作和 :ref:`cn_api_paddle_nn_BCELoss` 操作。或者,我们也可以认为计算方式是 ``sigmoid_cross_entrop_with_logits`` 和一些 `reduce` 操作的组合。
计算方式结合了 ``sigmoid`` 操作和 :ref:`cn_api_paddle_nn_BCELoss` 操作。或者,我们也可以认为计算方式是 ``sigmoid_cross_entrop_with_logits`` 和一些 ``reduce`` 操作的组合。

该损失函数衡量了在每个类别相互独立的分类任务中的逐元素概率误差。这可以被视为预测数据点的标签,其中标签不是相互排斥的。例如,一篇新闻文章可以同时关于政治,科技,体育或者同时不包含这些内容。

Expand All @@ -28,21 +28,21 @@ BCEWithLogitsLoss

然后,当 ``weight`` 或 ``pos_weight`` 不为 None 的时候,将会在输出 Out 上乘以相应的权重。Tensor ``weight`` 给 Batch 中的每一条数据赋予不同权重,Tensor ``pos_weight`` 给每一类的正例添加相应的权重。

最后,将会添加 `reduce` 操作到前面的输出 Out 上。当 `reduction` 为 `none` 时,直接返回最原始的 `Out` 结果。当 `reduction` 为 `mean` 时,返回输出的均值 :math:`Out = MEAN(Out)`。当 `reduction` 为 `sum` 时,返回输出的求和 :math:`Out = SUM(Out)` 。
最后,将会添加 ``reduce`` 操作到前面的输出 Out 上。当 ``reduction`` 为 ``none`` 时,直接返回最原始的 ``Out`` 结果。当 ``reduction`` 为 ``mean`` 时,返回输出的均值 :math:`Out = MEAN(Out)`。当 ``reduction`` 为 ``sum`` 时,返回输出的求和 :math:`Out = SUM(Out)` 。

.. note::
因为是二分类任务,所以标签值应该是 0 或者 1。

参数
:::::::::
- **weight** (Tensor,可选) - 手动指定每个 batch 二值交叉熵的权重。如果指定的话,维度必须是一个 batch 的数据的维度。数据类型是 float32, float64。默认值是:None。
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有:``'none'``, ``'mean'``, ``'sum'``。默认为 ``'mean'``,计算 `BCELoss` 的均值;设置为 ``'sum'`` 时,计算 `BCELoss` 的总和;设置为 ``'none'`` 时,则返回原始 loss。
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有:``'none'``, ``'mean'``, ``'sum'``。默认为 ``'mean'``,计算 ``BCELoss`` 的均值;设置为 ``'sum'`` 时,计算 ``BCELoss`` 的总和;设置为 ``'none'`` 时,则返回原始 loss。
- **pos_weight** (Tensor,可选) - 手动指定正类的权重,必须是与类别数相等长度的向量。数据类型是 float32, float64。默认值是:None。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。

形状
:::::::::
- **logit** (Tensor) - 输入的预测值。形状是 :math:`[N, *]`,其中 N 是 batch_size, `*` 是任意其他维度。输入的预测值 ``logit`` 一般是线性层的输出,不需要经过 ``sigmoid`` 层。数据类型是 float32、float64。
- **logit** (Tensor) - 输入的预测值。形状是 :math:`[N, *]`,其中 N 是 batch_size, ``*`` 是任意其他维度。输入的预测值 ``logit`` 一般是线性层的输出,不需要经过 ``sigmoid`` 层。数据类型是 float32、float64。
- **label** (Tensor) - 标签。 形状是 :math:`[N, *]`,标签 ``label`` 的维度、数据类型与输入的预测值 ``logit`` 相同。
- **output** (Tensor) - 输出的 Tensor。 如果 :attr:`reduction` 是 ``'none'``,则输出的维度为 :math:`[N, *]`,与输入 ``logit`` 的形状相同。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``,则输出的维度为 :math:`[]` 。

Expand Down
2 changes: 1 addition & 1 deletion docs/api/paddle/nn/CTCLoss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CTCLoss

返回
:::::::::
``Tensor``,输入 ``log_probs`` 和标签 ``labels`` 间的 `ctc loss`。如果 :attr:`reduction` 是 ``'none'``,则输出 loss 的维度为 [batch_size]。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``,则输出 Loss 的维度为 []。数据类型与输入的 ``log_probs`` 一致。
``Tensor``,输入 ``log_probs`` 和标签 ``labels`` 间的 ``ctc loss``。如果 :attr:`reduction` 是 ``'none'``,则输出 loss 的维度为 [batch_size]。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``,则输出 Loss 的维度为 []。数据类型与输入的 ``log_probs`` 一致。

代码示例
:::::::::
Expand Down
8 changes: 4 additions & 4 deletions docs/api/paddle/nn/CosineEmbeddingLoss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CosineEmbeddingLoss

.. py:class:: paddle.nn.CosineEmbeddingLoss(margin=0, reduction='mean', name=None)

该函数计算给定的输入 input1, input2 和 label 之间的 `CosineEmbedding` 损失,通常用于学习非线性嵌入或半监督学习
该函数计算给定的输入 input1, input2 和 label 之间的 ``CosineEmbedding`` 损失,通常用于学习非线性嵌入或半监督学习

如果 label=1,则该损失函数的数学计算公式如下:

Expand All @@ -24,16 +24,16 @@ CosineEmbeddingLoss

参数
:::::::::
- **margin** (float,可选): - 可以设置的范围为[-1, 1],建议设置的范围为[0, 0.5]。其默认为 `0`。
- **reduction** (string,可选): - 指定应用于输出结果的计算方式,可选值有:``'none'``, ``'mean'``, ``'sum'``。默认为 ``'mean'``,计算 `CosineEmbeddingLoss` 的均值;设置为 ``'sum'`` 时,计算 `CosineEmbeddingLoss` 的总和;设置为 ``'none'`` 时,则返回 `CosineEmbeddingLoss`。数据类型为 string。
- **margin** (float,可选): - 可以设置的范围为[-1, 1],建议设置的范围为[0, 0.5]。其默认为 ``0``。
- **reduction** (string,可选): - 指定应用于输出结果的计算方式,可选值有:``'none'``, ``'mean'``, ``'sum'``。默认为 ``'mean'``,计算 ``CosineEmbeddingLoss`` 的均值;设置为 ``'sum'`` 时,计算 ``CosineEmbeddingLoss`` 的总和;设置为 ``'none'`` 时,则返回 ``CosineEmbeddingLoss``。数据类型为 string。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。

形状
:::::::::
- **input1** (Tensor): - 输入的 Tensor,维度是[N, M],其中 N 是 batch size,可为 0,M 是数组长度。数据类型为:float32、float64。
- **input2** (Tensor): - 输入的 Tensor,维度是[N, M],其中 N 是 batch size,可为 0,M 是数组长度。数据类型为:float32、float64。
- **label** (Tensor): - 标签,维度是[N],N 是数组长度,数据类型为:float32、float64、int32、int64。
- **output** (Tensor): - 输入 ``input1`` 、 ``input2`` 和标签 ``label`` 间的 `CosineEmbeddingLoss` 损失。如果 `reduction` 是 ``'none'``,则输出 Loss 的维度为 [N],与输入 ``input1`` 和 ``input2`` 相同。如果 `reduction` 是 ``'mean'`` 或 ``'sum'``,则输出 Loss 的维度为 []。
- **output** (Tensor): - 输入 ``input1`` 、 ``input2`` 和标签 ``label`` 间的 ``CosineEmbeddingLoss`` 损失。如果 ``reduction`` 是 ``'none'``,则输出 Loss 的维度为 [N],与输入 ``input1`` 和 ``input2`` 相同。如果 ``reduction`` 是 ``'mean'`` 或 ``'sum'``,则输出 Loss 的维度为 []。

代码示例
:::::::::
Expand Down
8 changes: 4 additions & 4 deletions docs/api/paddle/nn/CrossEntropyLoss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,19 @@ CrossEntropyLoss

参数
:::::::::
- **weight** (Tensor,可选) - 指定每个类别的权重。其默认为 `None`。如果提供该参数的话,维度必须为 `C` (类别数)。数据类型为 float32 或 float64。
- **weight** (Tensor,可选) - 指定每个类别的权重。其默认为 ``None``。如果提供该参数的话,维度必须为 ``C`` (类别数)。数据类型为 float32 或 float64。
- **ignore_index** (int64,可选) - 指定一个忽略的标签值,此标签值不参与计算,负值表示无需忽略任何标签值。仅在 soft_label=False 时有效。默认值为-100。数据类型为 int64。
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,数据类型为 string,可选值有:`none`, `mean`, `sum`。默认为 `mean`,计算 `mini-batch` loss 均值。设置为 `sum` 时,计算 `mini-batch` loss 的总和。设置为 `none` 时,则返回 loss Tensor。
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,数据类型为 string,可选值有:``none``、``mean``、``sum``。默认为 ``mean``,计算 ``mini-batch`` loss 均值。设置为 ``sum`` 时,计算 ``mini-batch`` loss 的总和。设置为 ``none`` 时,则返回 loss Tensor。
- **soft_label** (bool,可选) – 指明 label 是否为软标签。默认为 False,表示 label 为硬标签;若 soft_label=True 则表示软标签。
- **label_smoothing** (float,可选)- 指定计算损失时的标签平滑度,它应该在 :math:`[0.0,1.0]` 范围内。其中 0.0 表示无平滑。使得平滑后的标签变成原始真实标签和均匀分布的混合,默认值: 0.0。
- **axis** (int,可选) - 进行 softmax 计算的维度索引。它应该在 :math:`[-1,dim-1]` 范围内,而 ``dim`` 是输入 logits 的维度。默认值:-1。
- **use_softmax** (bool,可选) - 指定是否对 input 进行 softmax 归一化。默认值:True。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。
形状
:::::::::
- **input** (Tensor): 输入 `Tensor`,数据类型为 float32 或 float64。其形状为 :math:`[N, C]`,其中 `C` 为类别数。对于多维度的情形下,它的形状为 :math:`[N, d_1, d_2, ..., d_k, C]` ,k >= 1。
- **input** (Tensor): 输入 ``Tensor``,数据类型为 float32 或 float64。其形状为 :math:`[N, C]`,其中 ``C`` 为类别数。对于多维度的情形下,它的形状为 :math:`[N, d_1, d_2, ..., d_k, C]` ,k >= 1。
- **label** (Tensor): 当 soft_label=False 时,输入 input 对应的标签值,数据类型为 int64。其形状为 :math:`[N]`,每个元素符合条件:0 <= label[i] <= C-1。对于多维度的情形下,它的形状为 :math:`[N, d_1, d_2, ..., d_k]` ,k >= 1;当 soft_label=True 且没有指定 label_smoothing 时,要求 label 的维度、数据类型与 input 相同,每个样本的各标签概率和应为 1;当指定了 label_smoothing (label_smoothing > 0.0) 时, 无论 soft_label 是什么值, label 的维度和数据类型可以是前面两种情况中的任意一种。换句话说,如果 label_smoothing > 0.0, label 可以是独热标签或整数标签。
- **output** (Tensor): 计算 `CrossEntropyLoss` 交叉熵后的损失值。
- **output** (Tensor): 计算 ``CrossEntropyLoss`` 交叉熵后的损失值。


代码示例
Expand Down
2 changes: 1 addition & 1 deletion docs/api/paddle/nn/GaussianNLLLoss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ GaussianNLLLoss
返回
:::::::::

- **output** (Tensor) - 输入 :attr:`input`、 :attr:`variance` 和 :attr:`label` 间的 `GaussianNLLLoss` 损失。如果 `reduction` 为 `'none'`,则输出 Loss 形状与输入相同为 `(N, *)`。如果 `reduction` 为 `'sum'` 或者 `'mean'`,则输出 Loss 形状为 `'(1)'` 。
- **output** (Tensor) - 输入 :attr:`input`、 :attr:`variance` 和 :attr:`label` 间的 ``GaussianNLLLoss`` 损失。如果 ``reduction`` 为 ``'none'``,则输出 Loss 形状与输入相同为 ``(N, *)``。如果 ``reduction`` 为 ``'sum'`` 或者 ``'mean'``,则输出 Loss 形状为 ``(1)`` 。


代码示例
Expand Down
12 changes: 6 additions & 6 deletions docs/api/paddle/nn/HingeEmbeddingLoss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ HingeEmbeddingLoss

.. py:class:: paddle.nn.HingeEmbeddingLoss(margin=1.0, reduction='mean', name=None)

创建一个 HingeEmbeddingLoss 的可调用类,HingeEmbeddingLoss 计算输入 input 和标签 label(包含 1 和 -1) 间的 `hinge embedding loss` 损失。
创建一个 HingeEmbeddingLoss 的可调用类,HingeEmbeddingLoss 计算输入 input 和标签 label(包含 1 和 -1) 间的 ``hinge embedding loss`` 损失。

该损失通常用于度量输入 input 和标签 label 是否相似或不相似,例如可以使用 L1 成对距离作为输入 input,通常用于学习非线性嵌入或半监督学习。

Expand All @@ -29,13 +29,13 @@ HingeEmbeddingLoss

参数
:::::::::
- **margin** (float,可选): - 当 label 为 -1 时,该值决定了小于 `margin` 的 input 才需要纳入 `hinge embedding loss` 的计算。默认为 1.0 。
- **reduction** (str,可选): - 指定应用于输出结果的计算方式,可选值有:``'none'``, ``'mean'``, ``'sum'``。默认为 ``'mean'``,计算 `hinge embedding loss` 的均值;设置为 ``'sum'`` 时,计算 `hinge embedding loss` 的总和;设置为 ``'none'`` 时,则返回 `hinge embedding loss`。
- **margin** (float,可选): - 当 label 为 -1 时,该值决定了小于 ``margin`` 的 input 才需要纳入 ``hinge embedding loss`` 的计算。默认为 1.0 。
- **reduction** (str,可选): - 指定应用于输出结果的计算方式,可选值有:``'none'``, ``'mean'``, ``'sum'``。默认为 ``'mean'``,计算 ``hinge embedding loss`` 的均值;设置为 ``'sum'`` 时,计算 ``hinge embedding loss`` 的总和;设置为 ``'none'`` 时,则返回 ``hinge embedding loss``。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。

输入
:::::::::
- **input** (Tensor): - 输入 Tensor,维度是 [N, *],其中 N 是 batch size, `*` 是任意数量的额外维度。数据类型为:float32、float64。
- **input** (Tensor): - 输入 Tensor,维度是 [N, *],其中 N 是 batch size, ``*`` 是任意数量的额外维度。数据类型为:float32、float64。
- **label** (Tensor): - 标签,维度是 [N, *],与 ``input`` 相同,Tensor 中的值应该只包含 1 和 -1。数据类型为:float32、float64。

返回
Expand All @@ -44,9 +44,9 @@ HingeEmbeddingLoss

形状
:::::::::
- **input** (Tensor): - 输入的 Tensor,维度是 [N, *],其中 N 是 batch size, `*` 是任意数量的额外维度。数据类型为:float32、float64。
- **input** (Tensor): - 输入的 Tensor,维度是 [N, *],其中 N 是 batch size, ``*`` 是任意数量的额外维度。数据类型为:float32、float64。
- **label** (Tensor): - 标签,维度是 [N, *],与 ``input`` 相同,应该只包含 1 和 -1。数据类型为:float32、float64。
- **output** (Tensor): - 输入 ``input`` 和标签 ``label`` 间的 `hinge embedding loss` 损失。如果 `reduction` 是 ``'none'``,则输出 Loss 的维度为 [N, *],与输入 ``input`` 相同。如果 `reduction` 是 ``'mean'`` 或 ``'sum'``,则输出 Loss 的维度为 []。
- **output** (Tensor): - 输入 ``input`` 和标签 ``label`` 间的 ``hinge embedding loss`` 损失。如果 ``reduction`` 是 ``'none'``,则输出 Loss 的维度为 [N, *],与输入 ``input`` 相同。如果 ``reduction`` 是 ``'mean'`` 或 ``'sum'``,则输出 Loss 的维度为 []。

代码示例
:::::::::
Expand Down
6 changes: 3 additions & 3 deletions docs/api/paddle/nn/KLDivLoss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ KLDivLoss

.. py:class:: paddle.nn.KLDivLoss(reduction='mean', log_target=False)

创建一个 `KLDivLoss` 类的可调用对象,以计算输入(Input)和输入(Label)之间的 Kullback-Leibler 散度损失。注意其中输入(Input)应为对数概率值,输入(Label)应为概率值。
创建一个 ``KLDivLoss`` 类的可调用对象,以计算输入(Input)和输入(Label)之间的 Kullback-Leibler 散度损失。注意其中输入(Input)应为对数概率值,输入(Label)应为概率值。

若 ``log_target`` 为 ``False``:

Expand Down Expand Up @@ -37,9 +37,9 @@ KLDivLoss
形状
::::::::::::

- **input** (Tensor):输入的 Tensor,维度是[N, *],其中 N 是 batch size, `*` 是任意数量的额外维度。数据类型为:float32、float64。
- **input** (Tensor):输入的 Tensor,维度是[N, *],其中 N 是 batch size, ``*`` 是任意数量的额外维度。数据类型为:float32、float64。
- **label** (Tensor):标签,维度是[N, *],与 ``input`` 相同。数据类型为:float32、float64。
- **output** (Tensor):输入 ``input`` 和标签 ``label`` 间的 kl 散度。如果 `reduction` 是 ``'none'``,则输出 Loss 的维度为 [N, *],与输入 ``input`` 相同。如果 `reduction` 是 ``'batchmean'`` 、 ``'mean'`` 或 ``'sum'``,则输出 Loss 的维度为 []。
- **output** (Tensor):输入 ``input`` 和标签 ``label`` 间的 kl 散度。如果 ``reduction`` 是 ``'none'``,则输出 Loss 的维度为 [N, *],与输入 ``input`` 相同。如果 ``reduction`` 是 ``'batchmean'`` 、 ``'mean'`` 或 ``'sum'``,则输出 Loss 的维度为 []。

代码示例
::::::::::::
Expand Down
14 changes: 7 additions & 7 deletions docs/api/paddle/nn/L1Loss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ L1Loss

.. py:class:: paddle.nn.L1Loss(reduction='mean', name=None)

创建一个 L1Loss 的可调用类,L1Loss 计算输入 input 和标签 label 间的 `L1 loss` 损失。
创建一个 L1Loss 的可调用类,L1Loss 计算输入 input 和标签 label 间的 ``L1 loss`` 损失。

该损失函数的数学计算公式如下:

当 `reduction` 设置为 ``'none'`` 时:
当 ``reduction`` 设置为 ``'none'`` 时:

.. math::
Out = \lvert input - label\rvert

当 `reduction` 设置为 ``'mean'`` 时:
当 ``reduction`` 设置为 ``'mean'`` 时:

.. math::
Out = MEAN(\lvert input - label\rvert)

当 `reduction` 设置为 ``'sum'`` 时:
当 ``reduction`` 设置为 ``'sum'`` 时:

.. math::
Out = SUM(\lvert input - label\rvert)


参数
:::::::::
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有:``'none'``, ``'mean'``, ``'sum'``。默认为 ``'mean'``,计算 `L1Loss` 的均值;设置为 ``'sum'`` 时,计算 `L1Loss` 的总和;设置为 ``'none'`` 时,则返回 `L1Loss`。
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有:``'none'``, ``'mean'``, ``'sum'``。默认为 ``'mean'``,计算 ``L1Loss`` 的均值;设置为 ``'sum'`` 时,计算 ``L1Loss`` 的总和;设置为 ``'none'`` 时,则返回 ``L1Loss``。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。

形状
:::::::::
- **input** (Tensor):输入的 Tensor,维度是[N, *],其中 N 是 batch size, `*` 是任意数量的额外维度。数据类型为:float32、float64、int32、int64。
- **input** (Tensor):输入的 Tensor,维度是[N, *],其中 N 是 batch size, ``*`` 是任意数量的额外维度。数据类型为:float32、float64、int32、int64。
- **label** (Tensor):标签,维度是[N, *],与 ``input`` 相同。数据类型为:float32、float64、int32、int64。
- **output** (Tensor):输入 ``input`` 和标签 ``label`` 间的 `L1 loss` 损失。如果 `reduction` 是 ``'none'``,则输出 Loss 的维度为 [N, *],与输入 ``input`` 相同。如果 `reduction` 是 ``'mean'`` 或 ``'sum'``,则输出 Loss 的维度为 []。
- **output** (Tensor):输入 ``input`` 和标签 ``label`` 间的 ``L1 loss`` 损失。如果 ``reduction`` 是 ``'none'``,则输出 Loss 的维度为 [N, *],与输入 ``input`` 相同。如果 ``reduction`` 是 ``'mean'`` 或 ``'sum'``,则输出 Loss 的维度为 []。

代码示例
:::::::::
Expand Down
4 changes: 2 additions & 2 deletions docs/api/paddle/nn/MSELoss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ MSELoss
.. math::
Out = (input - label)^2

`reduction`为`'mean'`时:
``reduction`` 为 ``'mean'`` 时:

.. math::
Out = \operatorname{mean}((input - label)^2)

`reduction`为`'sum'`时:
``reduction`` 为 ``'sum'`` 时:

.. math::
Out = \operatorname{sum}((input - label)^2)
Expand Down
Loading
Loading