Update the annotation of layers.py#4158
Update the annotation of layers.py#4158lcy-seso merged 12 commits intoPaddlePaddle:developfrom ranqiu92:r-doc
Conversation
| :param bias_attr: Bias parameter attribute. True if no bias. | ||
| :param bias_attr: The Bias Attribute. If no bias, then pass False or | ||
| something not type of ParameterAttribute. None will get a | ||
| default Bias. |
There was a problem hiding this comment.
- If this parameter is set to False, no bias is defined. If this parameter is set to None, bias with default initialization settings is defined.
- please help to check what is the default setting of the bias parameter and add it into the doc,
| :param input: The first input layer. | ||
| :type input: LayerOutput. | ||
| :param name: The name of this layers. It is not necessary. | ||
| :param name: The name of this layer. It is not necessary. |
There was a problem hiding this comment.
please delete the sentence "It is not necessary."
| :param label: The input label. | ||
| :type input: LayerOutput. | ||
| :param name: The name of this layers. It is not necessary. | ||
| :param name: The name of this layer. It is not necessary. |
There was a problem hiding this comment.
please change the sentence "It is not necessary." into "It is not required."
The same below.
| It is an optional argument. | ||
| :type weight: LayerOutput | ||
| :param name: The name of this layers. It is not necessary. | ||
| :param name: The name of this layer. It is not necessary. |
There was a problem hiding this comment.
please change the sentence "It is not necessary." into "It is not required."
The same below.
| entire list of get gradient. | ||
| :type max_sort_size: int | ||
| :param name: The name of this layers. It is not necessary. | ||
| :param name: The name of this layer. It is not necessary. |
There was a problem hiding this comment.
please change the sentence "It is not necessary." into "It is not required."
The same below.
| :param label: The input label. | ||
| :type input: LayerOutput. | ||
| :param name: The name of this layers. It is not necessary. | ||
| :param name: The name of this layer. It is not necessary. |
There was a problem hiding this comment.
please change the sentence "It is not necessary." into "It is not required."
The same below.
| :param label: The input label. | ||
| :type input: LayerOutput. | ||
| :param name: The name of this layers. It is not necessary. | ||
| :param name: The name of this layer. It is not necessary. |
There was a problem hiding this comment.
please change the sentence "It is not necessary." into "It is not required."
The same below.
|
@lcy-seso Done |
doc/faq/index_cn.rst
Outdated
|
|
||
| def load_parameter(file_name, h, w): | ||
| with open(file_name, 'rb') as f: | ||
| f.read(16) # skip header. |
There was a problem hiding this comment.
- 调整一下16和17的顺序。把17提前。
- 解释一些这里加载的预训练参数格式,保存的模型为什么需要 skip_header?因为并不是所有情况需要这个操作。不要没有任何解释的放在这里。
doc/faq/index_cn.rst
Outdated
| 17. PaddlePaddle存储的参数格式是什么,如何和明文进行相互转化 | ||
| --------------------------------------------------------- | ||
|
|
||
| PaddlePaddle保存的二进制参数文件内容由16位头信息和网络参数两部分组成。头信息中,第一位固定为0,第二位为4,在使用double精度时,第二位为8,第三位记录共有多少个数值。 |
There was a problem hiding this comment.
- 第一位固定为0,第二位为4。文档不能这么写。解释一下这两位。
- 第一位是paddle的版本信息,paddle预留,用户不用修改,一般写0即可。第二位是浮点数占用多少个字节。4 是float 精度,8是double精度。一般由于训练时保存的模型是float精度,第2位通常固定为4。
- 请组织一下上面内容的表述方式,不要直接照抄。
doc/faq/index_cn.rst
Outdated
|
|
||
|
|
||
| 将明文参数转化为PaddlePaddle可加载的模型参数时,先根据参数规模写入头信息,再写入具体网络参数。以下为将随机生成的矩阵转化为PaddlePaddle可加载的模型参数示例: | ||
| 将明文参数转化为PaddlePaddle可加载的模型参数时,先根据数据类型和参数规模写入头信息,再写入具体网络参数。以下为将随机生成的矩阵转化为PaddlePaddle可加载的模型参数示例: |
There was a problem hiding this comment.
第一句话稍作修改为:
将明文参数转化为PaddlePaddle可加载的模型参数时,首先构造头信息,再写入网络参数。下面将随机生成的矩阵转化为可以被PaddlePaddle加载的模型参数。
doc/faq/index_cn.rst
Outdated
| --------------------------------------------------------- | ||
|
|
||
| PaddlePaddle保存的二进制参数文件内容由16位头信息和网络参数两部分组成。头信息中,第一位固定为0,第二位为4,在使用double精度时,第二位为8,第三位记录共有多少个数值。 | ||
| PaddlePaddle保存的模型参数文件内容由16字节头信息和网络参数两部分组成。头信息中,1~4字节表示PaddlePaddle版本信息;5~8字节表示每个参数占用的字节数,当保存的网络参数为float类型时为4,double类型时为8;9~16字节表示保存的参数总个数。 |
There was a problem hiding this comment.
- 1 ~ 4字节表示PaddlePaddle的版本信息,在大多数情况下,可以直接填充0。@luotao 使用MKLDNN时,这个版本信息是如何定义呢?
There was a problem hiding this comment.
使用MKLDNN的时候,与paddle原来的保持一致,也就是直接填0。MKLDNN保存的参数还是paddle原来的格式,转换在程序里面自动做。这样训练出来的���型,可以直接拿着在非MKLDNN版本上用了。
doc/faq/index_cn.rst
Outdated
| PaddlePaddle保存的模型参数文件内容由16字节头信息和网络参数两部分组成。头信息中,1~4字节表示PaddlePaddle版本信息;5~8字节表示每个参数占用的字节数,当保存的网络参数为float类型时为4,double类型时为8;9~16字节表示保存的参数总个数。 | ||
|
|
||
| 将PaddlePaddle保存的二进制参数还原回明文时,先跳过PaddlePaddle模型参数文件的头信息,再提取网络参数,示例如下: | ||
| 将PaddlePaddle保存的模型参数还原回明文时,可以使用相应数据类型的 :code:`numpy.array` 加载具体网络参数,此时需要跳过PaddlePaddle模型参数文件的头信息。一般情况下,PaddlePaddle保存的模型参数数据类型为float,所以在使用 :code:`numpy.array` 时一般设置 :code:`dtype=float32` 。示例如下: |
There was a problem hiding this comment.
- 此时需要跳过-->此时可以跳过
- 一般情况下,PaddlePaddle保存的模型参数数据类型为float,这句话稍作修改为:
- 若在PaddlePaddle编译时,未指定按照double精度编译,默认情况下按照float精度计算,保存的参数也是float类型。这时在使用 :code:
numpy.array时,一般设置 :code:dtype=float32。示例如下:
- 若在PaddlePaddle编译时,未指定按照double精度编译,默认情况下按照float精度计算,保存的参数也是float类型。这时在使用 :code:
doc/faq/index_cn.rst
Outdated
| with open(param_file, "w") as fparam: | ||
| fparam.write(header + param.tostring()) | ||
|
|
||
| 17. 如何加载预训练embedding参数 |
There was a problem hiding this comment.
如何加载预训练embedding参数 --> 如何加载预训练参数
doc/faq/index_cn.rst
Outdated
| 17. 如何加载预训练embedding参数 | ||
| ------------------------------ | ||
|
|
||
| 设置embedding的参数��性 :code:`is_static=True`,使embedding参数在训练过程中保持不变,从模型文件将预训练参数载入 :code:`numpy.array`,在创建parameters后,使用 :code:`parameters.set()` 加载预训练参数。PaddlePaddle保存的模型参数文件前16字节为头信息,用户将参数载入 :code:`numpy.array` 时须从第17字节开始。 |
There was a problem hiding this comment.
- 拆成1, 2 这样的两条,不要放在一大段里面
- 对要加载预训练参数的层,设置
param_attr=***,以embedding层为例,代码如下:
.. code-block:: python
...
doc/faq/index_cn.rst
Outdated
| return np.fromfile(f, dtype=np.float32).reshape(h, w) | ||
|
|
||
|
|
||
| emb_para = paddle.attr.Param(name='emb', initial_std=0., is_static=True) |
There was a problem hiding this comment.
paddle.attr.Param(is_static=True)
其它两个参数不是必须的,这里删掉。
There was a problem hiding this comment.
抱歉,name是必须的。initial_std=0去掉,这一条是讲加载预训练参数,initial_std 没有实际影响,保持文档的简单直接,这里删掉。
doc/faq/index_cn.rst
Outdated
| --------------------------------------------------------- | ||
|
|
||
| PaddlePaddle保存的模型参数文件内容由16字节头信息和网络参数两部分组成。头信息中,1~4字节表示PaddlePaddle版本信息;5~8字节表示每个参数占用的字节数,当保存的网络参数为float类型时为4,double类型时为8;9~16字节表示保存的参数总个数。 | ||
| PaddlePaddle保存的模型参数文件内容由16字节头信息和网络参数两部分组成。头信息中,1~4字节表示PaddlePaddle版本信息,在多数情况下,可以直接填充0;5~8字节表示每个参数占用的字节数,当保存的网络参数为float类型时为4,double类型时为8;9~16字节表示保存的参数总个数。 |
There was a problem hiding this comment.
根据@luotao 的comment,MKLDNN 现在并没有使用版本信息这一位。
“1~4字节表示PaddlePaddle版本信息,在多数情况下,可以直接填充0” 这句话,作为文档,我们不要为用户留下模棱两可的描述,直接改完下面的吧:
1~4字节表示PaddlePaddle版本信息,请直接填充0。
doc/faq/index_cn.rst
Outdated
|
|
||
|
|
||
| 将明文参数转化为PaddlePaddle可加载的模型参数时,先根据数据类型和参数规模写入头信息,再写入具体网络参数。以下为将随机生成的矩阵转化为PaddlePaddle可加载的模型参数示例: | ||
| 将明文参数转化为PaddlePaddle可加载的模型参数时,首先构造头信息,再写入网络参数。下面将随机生成的矩阵转化为可以被PaddlePaddle加载的模型参数。 |
There was a problem hiding this comment.
下面的代码将随机矩阵存储为为可以被PaddlePaddle加载的模型参数。
No description provided.