diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index e7e53bb53dfb872335713971a36dee4fdf5512e1..e95d43cae91f9613532868266533c258db9ec860 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -8063,13 +8063,13 @@ def bilinear_tensor_product(x, For example: .. math:: - y_{i} = x * W_{i} * {y^\mathrm{T}}, i=0,1,...,K-1 + out{i} = x * W_{i} * {y^\mathrm{T}}, i=0,1,...,size-1 In this formular: - - :math:`x`: the first input contains M elements. - - :math:`y`: the second input contains N elements. - - :math:`y_{i}`: the i-th element of y. + - :math:`x`: the first input contains M elements, shape is [batch_size, M]. + - :math:`y`: the second input contains N elements, shape is [batch_size, N]. - :math:`W_{i}`: the i-th learned weight, shape is [M, N] + - :math:`out{i}`: the i-th element of out, shape is [batch_size, size]. - :math:`y^\mathrm{T}`: the transpose of :math:`y_{2}`. The simple usage is: @@ -8079,8 +8079,8 @@ def bilinear_tensor_product(x, tensor = bilinear_tensor_product(x=layer1, y=layer2, size=1000) Args: - x (Variable): 3-D input tensor with shape [N x M x P] - y (Variable): 3-D input tensor with shape [N x M x P] + x (Variable): 2-D input tensor with shape [batch_size, M] + y (Variable): 2-D input tensor with shape [batch_size, N] size (int): The dimension of this layer. act (str, default None): Activation to be applied to the output of this layer. name (str, default None): The name of this layer. diff --git a/python/paddle/fluid/tests/unittests/test_layers.py b/python/paddle/fluid/tests/unittests/test_layers.py index 49ba41e6fc908e9713414120bbeb45ca715042c3..a0d148bb7825a441d1b9f3e5a872d891b50816dc 100644 --- a/python/paddle/fluid/tests/unittests/test_layers.py +++ b/python/paddle/fluid/tests/unittests/test_layers.py @@ -901,6 +901,16 @@ class TestBook(unittest.TestCase): self.assertIsNotNone(data_1) print(str(program)) + def test_bilinear_tensor_product_layer(self): + program = Program() + with program_guard(program): + data = layers.data(name='data', shape=[4], dtype="float32") + + theta = layers.data(name="theta", shape=[5], dtype="float32") + out = layers.bilinear_tensor_product(data, theta, 6) + + print(str(program)) + if __name__ == '__main__': unittest.main()