-
Notifications
You must be signed in to change notification settings - Fork 823
[Docathon][Update Doc No.29] fix the LossFunction #7227
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7e19f51
fix the loss_function
Echo-Nie 4f1f251
Merge branch 'PaddlePaddle:develop' into No29
Echo-Nie b84df71
Merge branch 'PaddlePaddle:develop' into No29
Echo-Nie 7d56704
del fluid
Echo-Nie 1a6c510
update three to two
Echo-Nie cbaad6e
Merge branch 'PaddlePaddle:develop' into No29
Echo-Nie cf99407
修补line的长度,之前太短了,不能渲染
Echo-Nie fcfbb2c
fix the line 37 :Bullet list ends without a blank line; unexpected un…
Echo-Nie 0a9afc5
Merge branch 'PaddlePaddle:develop' into No29
Echo-Nie a0396c9
Merge branch 'develop' of https://github.com/PaddlePaddle/docs into N…
Echo-Nie 226b6d8
Merge branch 'No29' of https://github.com/Echo-Nie/PaddlePaddleDocs i…
Echo-Nie 1669bc6
update ,del a Fluid
Echo-Nie a63ba3c
修复英文文档渲染
Echo-Nie 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 |
---|---|---|
@@ -1,60 +1,60 @@ | ||
.. _api_guide_loss_function: | ||
|
||
####### | ||
############ | ||
损失函数 | ||
####### | ||
############ | ||
|
||
损失函数定义了拟合结果和真实结果之间的差异,作为优化的目标直接关系模型训练的好坏,很多研究工作的内容也集中在损失函数的设计优化上。 | ||
Paddle Fluid 中提供了面向多种任务的多种类型的损失函数,以下列出了一些 Paddle Fluid 中包含的较为常用的损失函数。 | ||
Paddle 中提供了面向多种任务的多种类型的损失函数,以下列出了一些 Paddle 中包含的较为常用的损失函数。 | ||
|
||
回归 | ||
==== | ||
====== | ||
|
||
平方误差损失(squared error loss)使用预测值和真实值之间误差的平方作为样本损失,是回归问题中最为基本的损失函数。 | ||
API Reference 请参考 :ref:`cn_api_fluid_layers_square_error_cost`。 | ||
API Reference 请参考 :ref:`cn_api_paddle_nn_functional_square_error_cost`。 | ||
|
||
平滑 L1 损失(smooth_l1 loss)是一种分段的损失函数,较平方误差损失其对异常点相对不敏感,因而更为鲁棒。 | ||
API Reference 请参考 :ref:`cn_api_fluid_layers_smooth_l1`。 | ||
API Reference 请参考 :ref:`cn_api_paddle_nn_functional_smooth_l1_loss`。 | ||
|
||
|
||
分类 | ||
==== | ||
====== | ||
|
||
`交叉熵(cross entropy) <https://en.wikipedia.org/wiki/Cross_entropy>`_ 是分类问题中使用最为广泛的损失函数,Paddle Fluid 中提供了接受归一化概率值和非归一化分值输入的两种交叉熵损失函数的接口,并支持 soft label 和 hard label 两种样本类别标签。 | ||
API Reference 请参考 :ref:`cn_api_fluid_layers_cross_entropy` 和 :ref:`cn_api_fluid_layers_softmax_with_cross_entropy`。 | ||
`交叉熵(cross entropy) <https://en.wikipedia.org/wiki/Cross_entropy>`_ 是分类问题中使用最为广泛的损失函数,Paddle 中提供了接受归一化概率值和非归一化分值输入的两种交叉熵损失函数的接口,并支持 soft label 和 hard label 两种样本类别标签。 | ||
API Reference 请参考 :ref:`cn_api_paddle_nn_functional_cross_entropy`。 | ||
|
||
多标签分类 | ||
--------- | ||
对于多标签分类问题,如一篇文章同属于政治、科技等多个类别的情况,需要将各类别作为独立的二分类问题计算损失,Paddle Fluid 中为此提供了 sigmoid_cross_entropy_with_logits 损失函数, | ||
API Reference 请参考 :ref:`cn_api_fluid_layers_sigmoid_cross_entropy_with_logits`。 | ||
--------------------- | ||
对于多标签分类问题,如一篇文章同属于政治、科技等多个类别的情况,需要将各类别作为独立的二分类问题计算损失,Paddle 中为此提供了 binary_cross_entropy 损失函数, | ||
API Reference 请参考 :ref:`cn_api_paddle_nn_functional_binary_cross_entropy`。 | ||
|
||
大规模分类 | ||
--------- | ||
--------------------- | ||
对于大规模分类问题,通常需要特殊的方法及相应的损失函数以加速训练,常用的方法有 `噪声对比估计(Noise-contrastive estimation,NCE) <http://proceedings.mlr.press/v9/gutmann10a/gutmann10a.pdf>`_ 和 `层级 sigmoid <http://www.iro.umontreal.ca/~lisa/pointeurs/hierarchical-nnlm-aistats05.pdf>`_ 。 | ||
|
||
* 噪声对比估计通过将多分类问题转化为学习分类器来判别数据来自真实分布和噪声分布的二分类问题,基于二分类来进行极大似然估计,避免在全类别空间计算归一化因子从而降低了计算复杂度。 | ||
* 层级 sigmoid 通过二叉树进行层级的二分类来实现多分类,每个样本的损失对应了编码路径上各节点二分类交叉熵的和,避免了归一化因子的计算从而降低了计算复杂度。 | ||
这两种方法对应的损失函数在 Paddle Fluid 中均有提供,API Reference 请参考 :ref:`cn_api_fluid_layers_nce` 和 :ref:`cn_api_fluid_layers_hsigmoid`。 | ||
|
||
这两种方法对应的损失函数在 Paddle 中均有提供,API Reference 请参考 :ref:`cn_api_paddle_static_nn_nce` 和 :ref:`cn_api_paddle_nn_functional_hsigmoid_loss`。 | ||
|
||
序列分类 | ||
------- | ||
序列分类可以分为以下三种: | ||
--------------------- | ||
序列分类可以分为以下两种: | ||
|
||
* 序列分类(Sequence Classification)问题,整个序列对应一个预测标签,如文本分类。这种即是普通的分类问题,可以使用 cross entropy 作为损失函数。 | ||
* 序列片段分类(Segment Classification)问题,序列中的各个片段对应有自己的类别标签,如命名实体识别。对于这种序列标注问题,`(线性链)条件随机场(Conditional Random Field,CRF) <http://www.cs.columbia.edu/~mcollins/fb.pdf>`_ 是一种常用的模型方法,其使用句子级别的似然概率,序列中不同位置的标签不再是条件独立,能够有效解决标记偏置问题。Paddle Fluid 中提供了 CRF 对应损失函数的支持,API Reference 请参考 :ref:`cn_api_fluid_layers_linear_chain_crf`。 | ||
* 时序分类(Temporal Classification)问题,需要对未分割的序列进行标注,如语音识别。对于这种时序分类问题,`CTC(Connectionist Temporal Classification) <http://people.idsia.ch/~santiago/papers/icml2006.pdf>`_ 损失函数不需要对齐输入数据及标签,可以进行端到端的训练,Paddle Fluid 提供了 warpctc 的接口来计算相应的损失,API Reference 请参考 :ref:`cn_api_fluid_layers_warpctc`。 | ||
* 时序分类(Temporal Classification)问题,需要对未分割的序列进行标注,如语音识别。对于这种时序分类问题,`CTC(Connectionist Temporal Classification) <http://people.idsia.ch/~santiago/papers/icml2006.pdf>`_ 损失函数不需要对齐输入数据及标签,可以进行端到端的训练,Paddle 提供了 warpctc 的接口来计算相应的损失,API Reference 请参考 :ref:`cn_api_paddle_nn_functional_ctc_loss`。 | ||
|
||
排序 | ||
==== | ||
====== | ||
|
||
`排序问题 <https://en.wikipedia.org/wiki/Learning_to_rank>`_ 可以使用 Pointwise、Pairwise 和 Listwise 的学习方法,不同的方法需要使用不同的损失函数: | ||
|
||
* Pointwise 的方法通过近似为回归问题解决排序问题,可以使用回归问题的损失函数。 | ||
* Pairwise 的方法需要特殊设计的损失函数,其通过近似为分类问题解决排序问题,使用两篇文档与 query 的相关性得分以偏序作为二分类标签来计算损失。Paddle Fluid 中提供了两种常用的 Pairwise 方法的损失函数,API Reference 请参考 :ref:`cn_api_fluid_layers_rank_loss` 和 :ref:`cn_api_fluid_layers_margin_rank_loss`。 | ||
* Pairwise 的方法需要特殊设计的损失函数,其通过近似为分类问题解决排序问题,使用两篇文档与 query 的相关性得分以偏序作为二分类标签来计算损失。Paddle 中提供了一种常用的 Pairwise 方法的损失函数,API Reference 请参考 :ref:`cn_api_paddle_nn_functional_margin_ranking_loss`。 | ||
|
||
更多 | ||
==== | ||
====== | ||
|
||
对于一些较为复杂的损失函数,可以尝试使用其他损失函数组合实现;Paddle Fluid 中提供的用于图像分割任务的 :ref:`cn_api_fluid_layers_dice_loss` 即是使用其他 OP 组合(计算各像素位置似然概率的均值)而成;多目标损失函数也可看作这样的情况,如 Faster RCNN 就使用 cross entropy 和 smooth_l1 loss 的加权和作为损失函数。 | ||
对于一些较为复杂的损失函数,可以尝试使用其他损失函数组合实现;Paddle 中提供的用于图像分割任务的 :ref:`cn_api_paddle_nn_functional_dice_loss` 即是使用其他 OP 组合(计算各像素位置似然概率的均值)而成;多目标损失函数也可看作这样的情况,如 Faster RCNN 就使用 cross entropy 和 smooth_l1 loss 的加权和作为损失函数。 | ||
|
||
**注意**,在定义损失函数之后为能够使用 :ref:`api_guide_optimizer` 进行优化,通常需要使用 :ref:`cn_api_fluid_layers_mean` 或其他操作将损失函数返回的高维 Tensor 转换为 Scalar 值。 | ||
**注意**,在定义损失函数之后为能够使用 :ref:`api_guide_optimizer` 进行优化,通常需要使用 :ref:`cn_api_paddle_mean` 或其他操作将损失函数返回的高维 Tensor 转换为 Scalar 值。 |
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
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.
同学看一下英文文档的 preview
这部分要加一个空行