TruncatedNormal

class paddle.nn.initializer. TruncatedNormal ( mean=0.0, std=1.0, name=None ) [source]

The Random TruncatedNormal (Gaussian) distribution initializer.

Parameters
  • mean (float, optional) – mean of the normal distribution. The default value is 0.0.

  • std (float, optional) – standard deviation of the normal distribution. The default value is 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 Name.

Returns

A parameter initialized by Random TruncatedNormal (Gaussian) distribution.

Examples

import paddle

data = paddle.ones(shape=[3, 1, 2], dtype='float32')
weight_attr = paddle.framework.ParamAttr(
    name="linear_weight",
    initializer=paddle.nn.initializer.TruncatedNormal(mean=0.0, std=2.0))
bias_attr = paddle.framework.ParamAttr(
    name="linear_bias",
    initializer=paddle.nn.initializer.TruncatedNormal(mean=0.0, std=2.0))
linear = paddle.nn.Linear(2, 2, weight_attr=weight_attr, bias_attr=bias_attr)
# linear.weight:  [[-1.0981836  1.4140984]
#                  [ 3.1390522 -2.8266568]]
# linear.bias:  [-2.1546738 -1.6570673]

res = linear(data)
# res:  [[[-0.11380529 -3.0696259 ]]
#        [[-0.11380529 -3.0696259 ]]
#        [[-0.11380529 -3.0696259 ]]