# BilinearTensorProduct¶

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

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

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

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, size].

Return type

Variable

Examples

import paddle.fluid as fluid
import numpy

with fluid.dygraph.guard():
layer1 = numpy.random.random((5, 5)).astype('float32')
layer2 = numpy.random.random((5, 4)).astype('float32')
bilinearTensorProduct = fluid.dygraph.nn.BilinearTensorProduct(
input1_dim=5, input2_dim=4, output_dim=1000)
ret = bilinearTensorProduct(fluid.dygraph.base.to_variable(layer1),
fluid.dygraph.base.to_variable(layer2))

forward(x, y)

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

Parameters
• *inputs (tuple) – unpacked tuple arguments

• **kwargs (dict) – unpacked dict arguments