mindspore.ops.bidense

mindspore.ops.bidense(input1, input2, weight, bias=None)[source]

Applies bilinear dense connected layer for input1 and input2. The bilinear dense function is defined as:

\[output = input1^{T} weight input2 + bias\]

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • input1 (Tensor) – Input Tensor of shape \((*, in1\_channels)\), where \(*\) means any number of additional dimensions. All but the last dimension should be the same with input2.

  • input2 (Tensor) – Input Tensor of shape \((*, in2\_channels)\), where \(*\) means any number of additional dimensions. All but the last dimension should be the same with input1.

  • weight (Tensor) – The weight applied to the input1 and input2. The shape is \((out\_channels, in1\_channels, in2\_channels)\).

  • bias (Tensor, optional) – Additive biases to the output. The shape is \((out\_channels)\) or \(()\). Defaults: None , the bias is 0.

Returns

Tensor, shape \((*, out\_channels)\), where \(*\) means any number of additional dimensions. All but the last dimension should be the same with the input Tensors.

Raises
  • TypeError – If input1 is not Tensor.

  • TypeError – If input2 is not Tensor.

  • TypeError – If weight is not Tensor.

  • TypeError – If bias is not Tensor.

  • ValueError – If dimensions except the last of ‘input1’ are different from ‘input2’ .

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> input1 = mindspore.Tensor([[-1.1283, 1.2603],
...                            [0.0214, 0.7801],
...                            [-1.2086, 1.2849]], mindspore.float32)
>>> input2 = mindspore.Tensor([[-0.4631, 0.3238, 0.4201],
...                            [0.6215, -1.0910, -0.5757],
...                            [-0.7788, -0.0706, -0.7942]], mindspore.float32)
>>> weight = mindspore.Tensor([[[-0.3132, 0.9271, 1.1010],
...                             [0.6555, -1.2162, -0.2987]],
...                            [[1.0458, 0.5886, 0.2523],
...                             [-1.3486, -0.8103, -0.2080]],
...                            [[1.1685, 0.5569, -0.3987],
...                             [-0.4265, -2.6295, 0.8535]],
...                            [[0.6948, -1.1288, -0.6978],
...                             [0.3511, 0.0609, -0.1122]]], mindspore.float32)
>>> output = ops.bidense(input1, input2, weight)
>>> print(output)
[[-2.0612743 0.5581219 0.22383511 0.8667302]
 [1.4476739 0.12626505 1.6552988 0.21297503]
 [0.6003161 2.912046 0.5590313 -0.35449564]]