Normal¶
- class paddle.nn.initializer. Normal ( mean=0.0, std=1.0, name=None ) [source]
-
The Random Normal (Gaussian) distribution initializer.
- Parameters
-
mean (float, optional) – mean of the normal distribution. Default is 0.0.
std (float, optional) – standard deviation of the normal distribution. Default 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. Default: None.
- Returns
-
A parameter initialized by Random Normal (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.Normal(mean=0.0, std=2.0)) >>> bias_attr = paddle.framework.ParamAttr( ... name="linear_bias", ... initializer=paddle.nn.initializer.Normal(mean=0.0, std=2.0)) >>> >>> linear = paddle.nn.Linear(2, 2, weight_attr=weight_attr, bias_attr=bias_attr) >>> print(linear.weight) Parameter containing: Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=False, [[ 2.1973135 -2.2697184], [-1.9104223 -1.0541488]]) >>> print(linear.bias) Parameter containing: Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=False, [ 0.7885926 -0.74719954]) >>> res = linear(data) >>> print(res) Tensor(shape=[3, 1, 2], dtype=float32, place=Place(cpu), stop_gradient=False, [[[ 1.0754838 -4.071067 ]], [[ 1.0754838 -4.071067 ]], [[ 1.0754838 -4.071067 ]]])