Skip to content

补充GaussianNLLLoss中文文档。;test=docs_preview #5623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 13, 2023
40 changes: 40 additions & 0 deletions docs/api/paddle/nn/GaussianNLLLoss_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. _cn_api_paddle_nn_GaussianNLLLoss:

GaussianNLLLoss
-------------------------------

.. py:class:: paddle.nn.GaussianNLLLoss(full=False, epsilon=1e-6, reduction='mean', name=None)

计算输入 :attr:`input` 和标签 :attr:`label`、 :attr:`variance` 间的 GaussianNLL 损失,
:attr:`label` 被视为高斯分布的样本,其期望和方差由神经网络预测给出。对于一个 :attr:`label` 张量建模为具有高斯分布的张量的期望值 :attr:`input` 和张量的正方差 :attr:`var`,数学计算公式如下:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

总感觉这段话读起来不太通顺..尤其是最后一句 对于一个 label 张量建模为具有高斯分布的张量的期望值 input 和张量的正方差 var ,建议从头开始的整段描述再斟酌、优化一下


.. math::
\text{loss} = \frac{1}{2}\left(\log\left(\text{max}\left(\text{var},
\ \text{epsilon}\right)\right) + \frac{\left(\text{input} - \text{label}\right)^2}
{\text{max}\left(\text{var}, \ \text{epsilon}\right)}\right) + \text{const.}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在英文文档中还有如下描述,在中文文档中确实。按照中英文文档严格一致的要求,请添加相关描述~或者说清楚不一致的原因
image

参数
::::::::::

- **full** (bool,可选) - 是否在损失计算中包括常数项。默认情况下为 False,表示忽略最后的常数项。
- **epsilon** (float,可选) - 用于限制 variance 的值,使其不会导致除 0 的出现。默认值为 1e-6。
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有 ``none``、``mean`` 和 ``sum``。默认为 ``mean``,计算 ``mini-batch`` loss 均值。设置为 ``sum`` 时,计算 ``mini-batch`` loss 的总和。设置为 ``none`` 时,则返回 loss Tensor。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。

形状
::::::::::

- **input** (Tensor):输入 :attr:`Tensor`,其形状为 :math:`(N, *)` 或者 :math:`(*)`,其中 :math:`*` 表示任何数量的额外维度。数据类型为 float32 或 float64。
- **label** (Tensor):输入 :attr:`Tensor`,其形状为 :math:`(N, *)` 或者 :math:`(*)`,形状与 :attr:`input` 相同,或者其中一维的大小为 1,这时会进行 broadcast 操作。数据类型为 float32 或 float64。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“或者”后面的建议描述再清楚些,如 或者形状与input相同但....

- **variance** (Tensor): 输入 :attr:`Tensor`,其形状为 :math:`(N, *)` 或者 :math:`(*)`,形状与 :attr:`input` 相同,或其中一维的大小为 1,或缺少一维,这时会进行 broadcast 操作。数据类型为 float32 或 float64。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 同样的,“或者”后面的描述建议清晰些
  • 或缺少一维 这句话再斟酌一下,会造成误解
  • 英文文档还有 output的形状描述,请统一


返回
:::::::::

Tensor,计算 `GaussianNLLLoss` 后的损失值。若 :attr:`reduction` 为 ``none``,则与输入形状相同。


代码示例
:::::::::

COPY-FROM: paddle.nn.GaussianNLLLoss
26 changes: 26 additions & 0 deletions docs/api/paddle/nn/functional/gaussian_nll_loss_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. _cn_api_nn_functional_gaussian_nll_loss:

gaussian_nll_loss
-------------------------------
.. py:function:: paddle.nn.functional.gaussian_nll_loss(input, label, variance, full=False, epsilon=1e-6, reduction='mean', name=None)

返回 `gaussian negative log likelihood loss`。可在 :ref:`cn_api_paddle_nn_GaussianNLLLoss` 查看详情。

参数
:::::::::
- **input** (Tensor):输入 :attr:`Tensor`,其形状为 :math:`(N, *)` 或者 :math:`(*)`,其中 :math:`*` 表示任何数量的额外维度。将被拟合成为高斯分布。数据类型为 float32 或 float64。
- **label** (Tensor):输入 :attr:`Tensor`,其形状为 :math:`(N, *)` 或者 :math:`(*)`,形状、数据类型和 :attr:`input` 相同,或者其中一维的大小为 1,这时会进行 broadcast 操作。为服从高斯分布的样本。数据类型为 float32 或 float64。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同样的,按上述要求对“或者”后的描述更清晰化一些

- **variance** (Tensor): 输入 :attr:`Tensor`,其形状为 :math:`(N, *)` 或者 :math:`(*)`,形状与 :attr:`input` 相同,或其中一维的大小为 1,或缺少一维,这时会进行 broadcast 操作。正方差样本,可为不同标签对应不同的方差(异方差性),也可以为同一个方差(同方差性)。数据类型为 float32 或 float64。
- **full** (bool,可选) - 是否在损失计算中包括常数项。默认情况下为 False,表示忽略最后的常数项。
- **epsilon** (float,可选) - 用于限制 variance 的值,使其不会导致除 0 的出现。默认值为 1e-6。
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有 ``none``、``mean`` 和 ``sum``。默认为 ``mean``,计算 ``mini-batch`` loss 均值。设置为 `sum` 时,计算 `mini-batch` loss 的总和。设置为 ``none`` 时,则返回 loss Tensor。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。

返回
:::::::::
`Tensor`,返回存储表示 `gaussian negative log likelihood loss` 的损失值。数据类型与:attr:`input`相同。当 reduction 为:attr:`none`时,形状与:attr:`input`相同。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • :attr:input 左右增加空格,该行其他地方也有相同的错误
    image

  • 注意中英文间增加空格,否则代码风格的ci会过不了,尽量用 pre commmit工具自动检查下


代码示例
:::::::::

COPY-FROM: paddle.nn.functional.gaussian_nll_loss