BilinearTensorProduct

class paddle.fluid.dygraph.BilinearTensorProduct(name_scope, size, name=None, act=None, param_attr=None, bias_attr=None)[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\).

Parameters
  • name_scope (str) – The name of this class.

  • size (int) – The dimension of this layer.

  • name (str) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

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

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(
           'BilinearTensorProduct', size=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