Skip to content
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

update FAQ. #4379

Merged
merged 7 commits into from
Sep 26, 2017
Merged

update FAQ. #4379

merged 7 commits into from
Sep 26, 2017

Conversation

peterzhang2029
Copy link
Contributor

@peterzhang2029 peterzhang2029 commented Sep 26, 2017

resolve #2020 #3070 #4024

主要的解决办法是减小学习率或者对数据进行归一化处理。
这里有两种有效的解决方法:

* 对梯度的值进行限制,可以通过设置 :code:`optimizer` 中的 :code:`gradient_clipping_threshold` 来预防梯度爆炸,具体可以参考 `nmt_without_attention <https://github.com/PaddlePaddle/models/tree/develop/nmt_without_attention>`_ 示例。
Copy link
Contributor

Choose a reason for hiding this comment

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

  • 对梯度的值进行限制 --> 对梯度值进行硬截断:设置截断阈值 a,当梯度落在 [-a, a] 区间内,取值不变,否则按照区间端点值进行截断。
  • 可以通过在 :code:optimizer 中设置 `:code:`gradient_clipping_threshold 参数来实现,下面的代码片段将梯度截断的阈值设置为 x :
  • 请给一个精确到代码行的链接,否则依然很难了解到参考哪里。https://github.com/PaddlePaddle/models/blob/develop/nmt_without_attention/train.py#L35 但我建议,请给出一个上下文完整的代码片段,否则代码变动难免忘记更新文档。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


* 对梯度的值进行限制,可以通过设置 :code:`optimizer` 中的 :code:`gradient_clipping_threshold` 来预防梯度爆炸,具体可以参考 `nmt_without_attention <https://github.com/PaddlePaddle/models/tree/develop/nmt_without_attention>`_ 示例。

* 由于最终的损失函数关于每一层输出对应的梯度都会遵循链式法则进行反向传播,因此,可以通过对每一层要传输的梯度大小进行限制来预防浮点数溢出。具体可以对特定的网络层的属性进行设置::code:`layer_attr=paddle.attr.ExtraAttr(error_clipping_threshold=10.0)` 。完整代码可以参考示例 `machine translation <https://github.com/PaddlePaddle/book/tree/develop/08.machine_translation>`_ 。
Copy link
Contributor

Choose a reason for hiding this comment

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

  • 第一句话严重不通顺。请用简洁的短句,而不是复杂的从句。
  • 既然是两种方法,请以序号 1, 2 表示。

  • 我的建议请给一个上下文清晰的代码片段,不要这样没有任何上下文的贴一句代码。
  • 不要直接引用整个目录,使用者非常难以定位到需要参考那里。请给出清晰的,应该参考的哪个片段。

@@ -512,3 +518,69 @@ PaddlePaddle目前支持8种learning_rate_schedule,这8种learning_rate_schedu

出现该错误的原因一般是用户对不同layer的参数 :code:`name` 设置了相同的取值。遇到该错误时,先找出参数 :code:`name` 取值相同的layer,然后将这些layer的参数 :code:`name` 设置为不同的值。

24. PaddlePaddle V2 API中,调用infer接口时输出多个层的计算结果
--------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

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

请让这条 ”--------------------“ 长于标题。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

24. PaddlePaddle V2 API中,调用infer接口时输出多个层的计算结果
--------------------------------------------------

用户在使用多个中间网络层进行预测时,需要先将指定的网络层进行拼接,并作为 :code:`paddle.inference.Inference` 接口中 :code:`output_layer` 属性的输入, 然后调用infer接口来获取多个层对应的计算结果。 示例代码如下:
Copy link
Contributor

Choose a reason for hiding this comment

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

  • “需要先将指定的网络层进行拼接” 这句话不明所以。


用户在使用多个中间网络层进行预测时,需要先将指定的网络层进行拼接,并作为 :code:`paddle.inference.Inference` 接口中 :code:`output_layer` 属性的输入, 然后调用infer接口来获取多个层对应的计算结果。 示例代码如下:

.. code-block:: bash
Copy link
Contributor

Choose a reason for hiding this comment

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

  • 这里不是bash,是python


上述不同的recurrent layer可以归纳为2类:

* 由recurrent_group实现的recurrent layer:
Copy link
Contributor

Choose a reason for hiding this comment

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


* 由recurrent_group实现的recurrent layer:

* 用户在使用这一类recurrent layer时,可以访问由recurrent unit在一个time step里计算得到的中间值(例如:hidden states, input-to-hidden mapping, memory cells等);
Copy link
Contributor

Choose a reason for hiding this comment

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

  • 什么是 recurrent_unit ?

* list 中每个元素是一个layer的输出结果矩阵,类型是numpy的ndarray;
* 每一个layer输出矩阵的高度,在非序列输入时:等于样本数;序列输入时等于:输入序列中元素的总数;宽度等于配置中layer的size;

25. PaddlePaddle 中不同的 recurrent layer 之间的差异
Copy link
Contributor

Choose a reason for hiding this comment

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

PaddlePaddle 中不同 recurrent layer 的区别


此时可以在调用infer接口时通过设置 :code:`flatten_result=False` , 跳过“拼接”步骤,来解决上面的问题。这时,infer接口的返回值是一个python list:

* list元素的个数等于网络中输出层的个数;
Copy link
Contributor

Choose a reason for hiding this comment

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

list 中元素的个数

上述不同的recurrent layer可以归纳为2类:

* 由recurrent_group实现的recurrent layer:

Copy link
Contributor

Choose a reason for hiding this comment

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

  • 我们把这一段的行为逻辑组织成:结论 - 详细介绍的方式吧。
  • 围绕下面的三个问题:
  1. PaddlePaddle 中的RNN分为两类:使用recurrent_group实现的自定义RNN,作为一个独立 layer;
  2. 如何选择应该使用哪一种RNN;
  3. 注意事项:
    • paddle.layer.lstmemory 带 peephole connection,和 paddle.networks.lstmemory_group 不等价
    • paddle.networks.lstmemory_unit 不是 Recurrent layer,作为recurrent_group的单步函数使用。

@@ -519,17 +559,17 @@ PaddlePaddle目前支持8种learning_rate_schedule,这8种learning_rate_schedu
出现该错误的原因一般是用户对不同layer的参数 :code:`name` 设置了相同的取值。遇到该错误时,先找出参数 :code:`name` 取值相同的layer,然后将这些layer的参数 :code:`name` 设置为不同的值。

24. PaddlePaddle V2 API中,调用infer接口时输出多个层的计算结果
Copy link
Contributor

Choose a reason for hiding this comment

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

19 和 24 问题和文字都重复了?合并在一起把。把重复文字删掉。

@@ -316,7 +316,34 @@ Paddle二进制在运行时捕获了浮点数异常,只要出现浮点数异
* 模型一直不收敛,发散到了一个数值特别大的地方。
* 训练数据有问题,导致参数收敛到了一些奇异的情况。或者输入数据尺度过大,有些特征的取值达到数百万,这时进行矩阵乘法运算就可能导致浮点数溢出。

主要的解决办法是减小学习率或者对数据进行归一化处理。
这里有两种有效的解决方法:

Copy link
Contributor

Choose a reason for hiding this comment

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

这里的1和2 改为:

  1. 设置 gradient_clipping_threshold参数;
  2. 设置 error_clipping_threshold 参数;

下文再详细展开两者的不同,放在标题里面解释不清楚。

  1. 两者都是对梯度的截断,但截断时机不同,前者在 optimzier 更新网络参数时应用;后者在激活函数反向计算时被调用;
  2. 截断对象不同:前者截断可学习参数的梯度,后者截断回传给前层的梯度。

@@ -405,9 +437,28 @@ PaddlePaddle保存的模型参数文件内容由16字节头信息和网络参数

.. code-block:: python

out = inferer.infer(input=data_batch, flatten_result=False, field=["value"])
out = inferer.infer(input=data_batch, field=["value"])
Copy link
Contributor

Choose a reason for hiding this comment

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

  • 427 行需要改一下:“如何调用 infer 接口输出多个layer的预测结果”。
  • 帮忙再改一下,21 的标题:两种使用 drop_out 的方法有何区别?
  • 帮忙检查一下标题下方的横向和标题一样长。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

lcy-seso
lcy-seso previously approved these changes Sep 26, 2017
Copy link
Contributor

@lcy-seso lcy-seso left a comment

Choose a reason for hiding this comment

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

LGTM, thank you.

lcy-seso
lcy-seso previously approved these changes Sep 26, 2017
Copy link
Contributor

@lcy-seso lcy-seso left a comment

Choose a reason for hiding this comment

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

LGTM, thank you.

@lcy-seso lcy-seso changed the title add diff of recurrent layer in faq update FAQ. Sep 26, 2017
@lcy-seso lcy-seso merged commit aef71a6 into PaddlePaddle:develop Sep 26, 2017
@peterzhang2029 peterzhang2029 deleted the faq_update branch November 10, 2017 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants