-
Notifications
You must be signed in to change notification settings - Fork 750
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
【Paddle Hackathon No.11】 #5262
Merged
Merged
【Paddle Hackathon No.11】 #5262
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f6dd209
Create MultiMarginLoss_cn.rst
yangguohao cf6ab9f
Create multi_margin_loss_cn.rst
yangguohao 199ad90
Update multi_margin_loss_cn.rst
yangguohao 76119b8
Update Overview_cn.rst
yangguohao 7b79bc6
Update multi_margin_loss_cn.rst
yangguohao e7ddcb3
Update MultiMarginLoss_cn.rst
yangguohao 67d988e
Update MultiMarginLoss_cn.rst
yangguohao addd60e
Update multi_margin_loss_cn.rst
yangguohao a280008
Update MultiMarginLoss_cn.rst
yangguohao ee60f0f
Update docs/api/paddle/nn/functional/multi_margin_loss_cn.rst
yangguohao 7500047
Update MultiMarginLoss_cn.rst
yangguohao 76ad4b9
Update multi_margin_loss_cn.rst
yangguohao a9d8e9c
for punctuation
Ligoml 29f8cf8
for punctuation
Ligoml File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.. _cn_api_paddle_nn_MultiMarginLoss: | ||
|
||
MultiMarginLoss | ||
------------------------------- | ||
|
||
.. py:class:: paddle.nn.MultiMarginLoss(p: int = 1, margin: float = 1.0, weight=None, reduction: str = 'mean', name:str=None) | ||
|
||
创建一个 MultiMarginLoss 的可调用类。通过计算输入 `input` 和 `label` 间的多分类问题的 `hinge loss (margin-based loss)` 损失。 | ||
|
||
损失函数如果在没有权重下计算每一个 mini-batch 的 loss 按照下列公式计算 | ||
|
||
.. math:: | ||
\text{loss}(input_i, label_i) = \frac{\sum_{j} \max(0, \text{margin} - input_i[label_i] + input_i[j])^p}{\text{C}} | ||
|
||
|
||
其中 :math:`0 \leq j \leq \text{C}-1`, 且 :math:`j \neq label_i`, :math:`0 \leq i \leq \text{N}-1` N 为 batch 数量, C 为类别数量。 | ||
|
||
如果含有权重 `weight` 则损失函数按以下公式计算 | ||
|
||
.. math:: | ||
\text{loss}(input_i, label_i) = \frac{\sum_{j} \max(0, weight[label_i] * (\text{margin} - input_i[label_i] + input_i[j]))^p}{\text{C}} | ||
|
||
|
||
参数 | ||
::::::::: | ||
- **p** (int,可选) - 手动指定幂次方指数大小,默认为 1。 | ||
- **margin** (float,可选) - 手动指定间距,默认为 1。 | ||
- **weight** (Tensor,可选) - 权重值,默认为 None。 如果给定权重则形状为 :math:`[C, ]` | ||
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有:``'none'``、``'mean'``、``'sum'``。默认为 ``'mean'``,计算 Loss 的均值;设置为 ``'sum'`` 时,计算 Loss 的总和;设置为 ``'none'`` 时,则返回原始 Loss。 | ||
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
||
调用参数 | ||
::::::::: | ||
- **input** (Tensor) - 数据类型是 float32、float64。 | ||
- **label** (Tensor) - 标签的数据类型为 int32、int64。 | ||
|
||
形状 | ||
::::::::: | ||
- **input** (Tensor) - :math:`[N, C]`,其中 N 是 batch_size, C 是类别数量。 | ||
- **label** (Tensor) - :math:`[N, ]`。 | ||
- **output** (Tensor) - 输出的 Tensor。如果 :attr:`reduction` 是 ``'none'``,则输出的维度为 :math:`[N, ]`。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``,则输出的维度为 :math:`[1]` 。 | ||
|
||
返回 | ||
::::::::: | ||
返回计算 MultiMarginLoss 的可调用对象。 | ||
|
||
代码示例 | ||
::::::::: | ||
COPY-FROM: paddle.nn.MultiMarginLoss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.. _cn_api_paddle_nn_functional_multi_margin_loss: | ||
|
||
multi_margin_loss | ||
------------------------------- | ||
|
||
.. py:function:: paddle.nn.functional.multi_margin_loss(input, label, p:int = 1, margin: float = 1.0, weight=None, reduction: str = 'mean', name:str=None) | ||
|
||
计算输入 `input` 和 `label` 间的多分类问题的 `hinge loss` 损失。 | ||
|
||
|
||
yangguohao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
损失函数如果在没有的权重下计算每一个 mini-batch 的 loss 按照下列公式计算 | ||
|
||
.. math:: | ||
\text{loss}(input_i, label_i) = \frac{\sum_{j} \max(0, \text{margin} - input_i[label_i] + input_i[j])^p}{\text{C}} | ||
|
||
其中 :math:`0 \leq j \leq \text{C}-1`, 且 :math:`j \neq label_i`, :math:`0 \leq i \leq \text{N}-1` N 为 batch 数量, C 为类别数量。 | ||
|
||
如果含有权重 `weight` 则损失函数按以下公式计算 | ||
|
||
.. math:: | ||
\text{loss}(input_i, label_i) = \frac{\sum_{j} \max(0, weight[label_i] * (\text{margin} - input_i[label_i] + input_i[j]))^p}{\text{C}} | ||
|
||
参数 | ||
::::::::: | ||
- **input** (Tensor) - :math:`[N, C]`,其中 N 是 batch_size, `C` 是类别数量。数据类型是 float32、float64。 | ||
- **label** (Tensor) - :math:`[N, ]`。标签 ``label`` 的数据类型为 int32、int64。 | ||
- **p** (int,可选) - 手动指定范数,默认为 1。 | ||
- **margin** (float,可选) - 手动指定间距,默认为 1。 | ||
- **weight** (Tensor,可选) - 权重值,默认为 None。如果给定则形状为 :math:`[C, ]`。 | ||
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有:``'none'``, ``'mean'``, ``'sum'``。默认为 ``'mean'``,计算 Loss 的均值;设置为 ``'sum'`` 时,计算 Loss 的总和;设置为 ``'none'`` 时,则返回原始 Loss。 | ||
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
||
形状 | ||
::::::::: | ||
- **input** (Tensor) - :math:`[N, C ]`,其中 N 是 batch_size,`C` 是类别问题。数据类型是 float32、float64。 | ||
- **label** (Tensor) - :math:`[N, ]`,标签 ``label`` 的数据类型为 int32、int64。 | ||
- **output** (Tensor) - 输出的 Tensor。如果 :attr:`reduction` 是 ``'none'``,则输出的维度为 :math:`[N, ]`,与输入 ``input`` 的形状相同。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``,则输出的维度为 :math:`[1]` 。 | ||
|
||
返回 | ||
::::::::: | ||
返回计算的 Loss。 | ||
|
||
代码示例 | ||
::::::::: | ||
COPY-FROM: paddle.nn.functional.multi_margin_loss |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call parameters 部分好像没有翻译过来?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已添加