class paddle.fluid.dygraph.Linear(input_dim, output_dim, param_attr=None, bias_attr=None, act=None, dtype='float32')[source]

Fully-connected linear transformation layer:

\[Out = Act({XW + b})\]

where \(X\) is the input Tensor, \(W\) and \(b\) are weight and bias respectively.

Linear layer takes only one Tensor input. The Linear layer multiplies input tensor with weight matrix and produces an output Tensor of shape [N, *, output_dim], where N is batch size and * means any number of additional dimensions. If bias_attr is not None, a bias variable will be created and added to the output. Finally, if act is not None, it will be applied to the output as well.

System Message: WARNING/2 (/usr/local/lib/python2.7/dist-packages/paddle/fluid/dygraph/ of paddle.fluid.dygraph.Linear, line 9); backlink

Inline emphasis start-string without end-string.

  • input_dim (int) – The number of input units in this layer.

  • output_dim (int) – The number of output units in this layer.

  • param_attr (ParamAttr or list of ParamAttr, optional) – The parameter attribute for learnable weights(Parameter) of this layer. Default: None.

  • bias_attr (ParamAttr or list of ParamAttr, optional) – The attribute for the bias of this layer. If it is set to False, no bias will be added to the output units. If it is set to None, the bias is initialized zero. Default: None.

  • act (str, optional) – Activation to be applied to the output of this layer. Default: None.

  • dtype (str, optional) – Dtype used for weight, it can be “float32” or “float64”. Default: “float32”.


the learnable weights of this layer.




the learnable bias of this layer.


Parameter or None




from paddle.fluid.dygraph.base import to_variable
import paddle.fluid as fluid
from paddle.fluid.dygraph import Linear
import numpy as np

data = np.random.uniform(-1, 1, [30, 10, 32]).astype('float32')
with fluid.dygraph.guard():
    linear = Linear(32, 64)
    data = to_variable(data)
    res = linear(data)  # [30, 10, 64]

Defines the computation performed at every call. Should be overridden by all subclasses.

  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments