class paddle.fluid.dygraph.nn. BilinearTensorProduct ( input1_dim, input2_dim, output_dim, name=None, act=None, param_attr=None, bias_attr=None, dtype='float32' ) [source]

Add Bilinear Tensor Product Layer

This layer performs bilinear tensor product on two inputs. For example:

\[out_{i} = x * W_{i} * {y^\mathrm{T}}, i=0,1,...,size-1\]
In this formula:
  • \(x\): the first input contains M elements, shape is [batch_size, M].

  • \(y\): the second input contains N elements, shape is [batch_size, N].

  • \(W_{i}\): the i-th learned weight, shape is [M, N]

  • \(out_{i}\): the i-th element of out, shape is [batch_size, size].

  • \(y^\mathrm{T}\): the transpose of \(y\).

  • input1_dim (int) – The dimension of each first input.

  • input2_dim (int) – The dimension of each second input.

  • output_dim (int) – The dimension of output of this 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 Name. Default: None.

  • act (str, optional) – Activation to be applied to the output of this layer. The default value is None.

  • param_attr (ParamAttr, optional) – The parameter attribute for the learnable w, parameters/weights of this layer. The default value is None.

  • 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.

  • dtype (str, optional) – Data type, it can be “float32” or “float64”. Default: “float32”.


weight (Parameter): the learnable weights of this layer.

bias (Parameter): the learnable bias of this layer.


A 2-D Tensor of shape [batch_size, size].

Return type



import paddle
import numpy

layer1 = numpy.random.random((5, 5)).astype('float32')
layer2 = numpy.random.random((5, 4)).astype('float32')
bilinearTensorProduct = paddle.nn.BilinearTensorProduct(
    input1_dim=5, input2_dim=4, output_dim=1000)
ret = bilinearTensorProduct(paddle.to_tensor(layer1),
forward ( x, y )

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

  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments