Bilinear¶
- class paddle.nn. Bilinear ( in1_features, in2_features, out_features, weight_attr=None, bias_attr=None, name=None ) [source]
-
This layer performs bilinear on two inputs.
\[ \begin{align}\begin{aligned}out_{i} = x1 * W_{i} * {x2^\mathrm{T}}, i=0,1,...,outfeatures-1\\out = out + b\end{aligned}\end{align} \]- In this formula:
-
\(x1\): the first input contains in1_features elements, shape is [batch_size, in1_features].
\(x2\): the second input contains in2_features elements, shape is [batch_size, in2_features].
\(W_{i}\): the i-th learned weight, shape is [in1_features, in2_features], and learned weight’s shape is [out_features, in1_features, in2_features].
\(out_{i}\): the i-th element of out, shape is [batch_size], and out’s shape is [batch_size, out_features].
\(b\): the learned bias, shape is [1, out_features].
\(x2^\mathrm{T}\): the transpose of \(x2\).
- Parameters
-
in1_features (int) – The dimension of each first input(x1).
in2_features (int) – The dimension of each second input(x2).
out_features (int) – The dimension of output of this layer.
weight_attr (ParamAttr, optional) – The parameter attribute for the learnable w, parameters/weights of
None. (this layer. The default value is) –
bias_attr (ParamAttr, optional) – The parameter 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. The default value is None.
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.
- Attribute:
-
weight (Parameter): the learnable weights of this layer.
bias (Parameter): the learnable bias of this layer.
- Returns
-
A 2-D Tensor of shape [batch_size, out_features].
- Return type
-
Tensor
Examples
>>> import paddle >>> layer1 = paddle.rand((5, 5)).astype('float32') >>> layer2 = paddle.rand((5, 4)).astype('float32') >>> bilinear = paddle.nn.Bilinear(in1_features=5, ... in2_features=4, ... out_features=1000) >>> result = bilinear(layer1,layer2) >>> print(result.shape) [5, 1000]
-
forward
(
x1,
x2
)
forward¶
-
Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
-
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments
-
extra_repr
(
)
extra_repr¶
-
Extra representation of this layer, you can have custom implementation of your own layer.