Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.nn.BiDense

View Source On Gitee
class mindspore.nn.BiDense(in1_channels, in2_channels, out_channels, weight_init=None, bias_init=None, has_bias=True, dtype=mstype.float32)[source]

The bilinear dense connected layer.

Applies dense connected layer for two inputs. This layer implements the operation as:

y=x1TAx2+b,

where x1 is the first input tensor, x2 is the second input tensor , A is a weight matrix with the same data type as the x created by the layer , and b is a bias vector with the same data type as the x created by the layer (only if has_bias is True ).

Parameters
  • in1_channels (int) – The number of channels in the input1 space.

  • in2_channels (int) – The number of channels in the input2 space.

  • out_channels (int) – The number of channels in the output space.

  • weight_init (Union[Tensor, str, Initializer, numbers.Number]) – The trainable weight_init parameter. The values of str refer to the function initializer. Default: None .

  • bias_init (Union[Tensor, str, Initializer, numbers.Number]) – The trainable bias_init parameter. The values of str refer to the function initializer. Default: None .

  • has_bias (bool) – Specifies whether the layer uses bias vector. Default: True .

  • dtype (mindspore.dtype) – Dtype of Parameters. Default: mstype.float32 .

Shape:
  • input1 - (,Hin1) where Hin1=in1_channels and means any number of additional dimensions including none. All but the last dimension of the inputs should be the same.

  • input2 - (,Hin2) where Hin2=in2_channels and means any number of additional dimensions including none. All but the last dimension of the inputs should be the same.

  • output - (,Hout) where Hout=out_channels and means any number of additional dimensions including none. All but the last dimension are the same shape as the inputs.

Dtype:
  • input1 (Tensor) - The dtype must be float16 or float32 and be same as input2 .

  • input2 (Tensor) - The dtype must be float16 or float32 and be same as input1 .

  • output (Tensor) - With the same dtype as the inputs.

Weights:
  • weight (Parameter) - The learnable weights with shape (out_channels,in1_channels,in2_channels). When weight_init is None , the values are initialized from U(k,k), where k=1in1_channels.

  • bias (Parameter) - The learnable bias of shape (out_channels). If has_bias is True and bias_init is None , the values are initialized from U(k,k), where k=1in1_channels.

Raises
  • TypeError – If in1_channels, in2_channels or out_channels is not an int.

  • TypeError – If has_bias is not a bool.

  • ValueError – If length of shape of weight_init is not equal to 3 or shape[0] of weight_init is not equal to out_channels or shape[1] of weight_init is not equal to in1_channels or shape[2] of weight_init is not equal to in2_channels.

  • ValueError – If length of shape of bias_init is not equal to 1 or shape[0] of bias_init is not equal to out_channels.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, nn
>>> import numpy as np
>>> x1 = Tensor(np.random.randn(128, 20), mindspore.float32)
>>> x2 = Tensor(np.random.randn(128, 30), mindspore.float32)
>>> net = nn.BiDense(20, 30, 40)
>>> output = net(x1, x2)
>>> print(output.shape)
(128, 40)