From 5b6b88ab5b7bb9ff4f91e9ab011cf10e3de4cb3d Mon Sep 17 00:00:00 2001 From: Zhou Wei <1183042833@qq.com> Date: Mon, 27 Dec 2021 20:48:31 +0800 Subject: [PATCH] fix english doc of some API (#38468) --- python/paddle/fluid/initializer.py | 9 +++++---- python/paddle/nn/initializer/dirac.py | 7 ++++--- python/paddle/nn/initializer/orthogonal.py | 18 ++++++++++++------ python/paddle/nn/utils/transform_parameters.py | 4 ++-- python/paddle/tensor/random.py | 10 +++++----- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/python/paddle/fluid/initializer.py b/python/paddle/fluid/initializer.py index d9c67653320..32e3377e263 100644 --- a/python/paddle/fluid/initializer.py +++ b/python/paddle/fluid/initializer.py @@ -1148,13 +1148,14 @@ def _global_bias_initializer(): def calculate_gain(nonlinearity, param=None): """ - Get the recommended gain value of some nonlinearity function. + Get the recommended ``gain`` value of some nonlinearity function. ``gain`` value can be used in some + ``paddle.nn.initializer`` api to adjust the initialization value. Args: - nonlinearity(str): name of nonlinearity activation function. If it is a linear function, which is one of - "linear/conv1d/conv2d/conv3d/conv1d_transpose/conv2d_transpose/conv3d_transpose" , 1.0 will be returned. + nonlinearity(str): name of nonlinearity activation function. If it is a linear function, such as: + `linear/conv1d/conv2d/conv3d/conv1d_transpose/conv2d_transpose/conv3d_transpose` , 1.0 will be returned. param(bool|int|float, optional): optional parameter for somme nonlinearity function. Now, it only applies to - 'leaky_relu'. Default: None, it will be calculated as 0.01 in the formula. + 'leaky_relu'. Default: None, it will be calculated as 0.01 in the formula. Returns: A float value, which is the recommended gain for this nonlinearity function. diff --git a/python/paddle/nn/initializer/dirac.py b/python/paddle/nn/initializer/dirac.py index 267d5be5be2..26aa349b5b1 100644 --- a/python/paddle/nn/initializer/dirac.py +++ b/python/paddle/nn/initializer/dirac.py @@ -31,12 +31,13 @@ class Dirac(Initializer): .. math:: - Assuming: N=min(in\_channels, out\_channels) - X[d, d, shape[2]//2, shape[3]//2, ...]=1, \ d=0,1...N + + where, ``N`` is the minimum value of ``in_channels`` and ``out_channels`` Args: - groups(int): 0-dimension of the Tensor will be divided by groups, each group has the same value. + groups(int, optional): 0-dimension of the Tensor will be divided by groups, + each group has the same value. Default: 1. name(str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. diff --git a/python/paddle/nn/initializer/orthogonal.py b/python/paddle/nn/initializer/orthogonal.py index 8a3b9bf0027..8e0acb9ab2d 100644 --- a/python/paddle/nn/initializer/orthogonal.py +++ b/python/paddle/nn/initializer/orthogonal.py @@ -24,18 +24,24 @@ __all__ = [] class Orthogonal(Initializer): """The orthogonal initializer. The initialized tensor is (semi) orthogonal. - Assuming that 'weight' will be initialized, its shape is [M, N]. + It's only applied to Tensor whose dimension is greater than or equal to 2. + + For the Tensor whose dimension is greater than 2, the 0 dimension is seen as ``rows`` , + and the >=1 dimension are flattened as ``cols`` . + + Which can be describe as: .. code-block:: text - if M < N: + rows = shape[0] + cols = shape[1]·shape[2]···shape[N] + + if rows < cols: The rows are orthogonal vectors - elif M > N: + elif rows > cols: The columns are orthogonal vectors - else M = N: + else rows = cols: Both rows and columns are orthogonal vectors - - Only Tensor with 2 or more dimensions can initialized by Orthogonal. Args: gain(float, optional): The multiplication coefficient for initialized tensor. Default: 1.0. diff --git a/python/paddle/nn/utils/transform_parameters.py b/python/paddle/nn/utils/transform_parameters.py index ea7067cb950..03d2fa51486 100644 --- a/python/paddle/nn/utils/transform_parameters.py +++ b/python/paddle/nn/utils/transform_parameters.py @@ -76,10 +76,10 @@ def parameters_to_vector(parameters, name=None): @dygraph_only def vector_to_parameters(vec, parameters, name=None): """ - Transform a Tensor with 1-D shape to the parameters. + Transform a 1-D Tensor to the input ``parameters`` . Args: - vec (Tensor): A Tensor with 1-D shape, which represents the parameters of a Layer. + vec (Tensor): A 1-D Tensor, which will be sliced and copied to the input ``parameters`` . parameters (Iterable[Tensor]): Iterable Tensors that are trainable parameters of a Layer. name(str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. diff --git a/python/paddle/tensor/random.py b/python/paddle/tensor/random.py index 73738bc6ee6..5adb9371183 100644 --- a/python/paddle/tensor/random.py +++ b/python/paddle/tensor/random.py @@ -85,7 +85,7 @@ def poisson(x, name=None): .. math:: - out_i ~ Poisson (x_i) + out_i \sim Poisson (lambda = x_i) Args: x(Tensor): A tensor with rate parameter of poisson Distribution. The data type @@ -101,12 +101,12 @@ def poisson(x, name=None): import paddle paddle.set_device('cpu') - paddle.seed(2021) + paddle.seed(100) x = paddle.uniform([2,3], min=1.0, max=5.0) out = paddle.poisson(x) - # [[2., 1., 4.], - # [4., 5., 1.]] + #[[2., 5., 0.], + # [5., 1., 3.]] """ @@ -994,7 +994,7 @@ def exponential_(x, lam=1.0, name=None): Args: x(Tensor): Input tensor. The data type should be float32, float64. - lam(float): :math:`\lambda` parameter of Exponential Distribution. + lam(float, optional): :math:`\lambda` parameter of Exponential Distribution. Default, 1.0. name(str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. -- GitLab