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.mint.nn.Linear

View Source On Gitee
class mindspore.mint.nn.Linear(in_features, out_features, bias=True, weight_init=None, bias_init=None, dtype=None)[source]

The linear connected layer.

Applies linear connected layer for the input. This layer implements the operation as:

outputs=Xkernel+bias

Warning

On the Ascend platform, if bias is False , the x cannot be greater than 6D in PYNATIVE or KBK mode.

where X is the input tensors, kernel is a weight matrix with the same data type as the X created by the layer, and bias is a bias vector with the same data type as the X created by the layer (only if the parameter bias is True).

Warning

In PyNative mode, if bias is False , the x cannot be greater than 6D.

Parameters
  • in_features (int) – The number of features in the input space.

  • out_features (int) – The number of features in the output space.

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

  • weight_init (Union[Tensor, str, Initializer, numbers.Number], optional) – The trainable weight_init parameter. The dtype is same as x. The values of str refer to the function initializer. Default: None , weight will be initialized using HeUniform.

  • bias_init (Union[Tensor, str, Initializer, numbers.Number], optional) – The trainable bias_init parameter. The dtype is same as x. The values of str refer to the function initializer. Default: None , bias will be initialized using Uniform.

  • dtype (mindspore.dtype, optional) – Data type of Parameter. Default: None . If dtype is None , dtype is set to mstype.float32 when initializing the method. When weight_init is Tensor, Parameter has the same data type as weight_init , in other cases, Parameter has the same data type as dtype, the same goes for bias_init.

Inputs:
  • x (Tensor) - Tensor of shape (,in_features). The in_features in Args should be equal to in_features in Inputs.

Outputs:

Tensor of shape (,out_features).

Raises
  • TypeError – If in_features or out_features is not an int.

  • TypeError – If bias is not a bool.

  • ValueError – If length of shape of weight_init is not equal to 2 or shape[0] of weight_init is not equal to out_features or shape[1] of weight_init is not equal to in_features.

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

  • RuntimeError – On the Ascend platform, if bias is False and x is greater than 6D in PYNATIVE or KBK mode.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> from mindspore import Tensor
>>> from mindspore import mint
>>> import numpy as np
>>> x = Tensor(np.array([[180, 234, 154], [244, 48, 247]]), mindspore.float32)
>>> net = mint.nn.Linear(3, 4)
>>> output = net(x)
>>> print(output.shape)
(2, 4)