forked from mindspore-Ecosystem/mindspore
!36068 add shape and dtype discription for nn.BiDense
Merge pull request !36068 from 吕昱峰(Nate.River)/code_docs_bidense
This commit is contained in:
commit
e2592d81a6
|
@ -8,27 +8,40 @@ mindspore.nn.BiDense
|
|||
公式如下:
|
||||
|
||||
.. math::
|
||||
\text{outputs} = X_{1}^{T} * \text{kernel} * X_{2} + \text{bias},
|
||||
y = x_1^T A x_2 + b,
|
||||
|
||||
其中 :math:`X_{1}` 是第一个输入Tensor,:math:`X_{2}` 是第二个输入Tensor,:math:`\text{kernel}` 是一个权重矩阵,其数据类型与 :math:`X` 相同, :math:`\text{bias}` 是一个偏置向量,其数据类型与 :math:`X` 相同(仅当has_bias为True时)。
|
||||
其中 :math:`x_{1}` 是第一个输入Tensor,:math:`x_{2}` 是第二个输入Tensor,:math:`A` 是一个权重矩阵,其数据类型与 :math:`x_{*}` 相同, :math:`b` 是一个偏置向量,其数据类型与 :math:`x_{*}` 相同(仅当has_bias为True时)。
|
||||
|
||||
**参数:**
|
||||
|
||||
- **in1_channels** (int) - BiDense层第一个输入Tensor的空间维度。
|
||||
- **in2_channels** (int) - BiDense层第二个输入Tensor的空间维度。
|
||||
- **out_channels** (int) - BiDense层输出Tensor的空间维度。
|
||||
- **weight_init** (Union[Tensor, str, Initializer, numbers.Number]) - 权重参数的初始化方法。数据类型与 `x` 相同。str的值引用自函数 `initializer`。默认值:None。
|
||||
- **bias_init** (Union[Tensor, str, Initializer, numbers.Number]) - 偏置参数的初始化方法。数据类型与 `x` 相同。str的值引用自函数 `initializer`。默认值:None。
|
||||
- **weight_init** (Union[Tensor, str, Initializer, numbers.Number]) - 权重参数的初始化方法。str的值引用自函数 `initializer`。默认值:None。
|
||||
- **bias_init** (Union[Tensor, str, Initializer, numbers.Number]) - 偏置参数的初始化方法。str的值引用自函数 `initializer`。默认值:None。
|
||||
- **has_bias** (bool) - 是否使用偏置向量 :math:`\text{bias}` 。默认值:True。
|
||||
|
||||
**输入:**
|
||||
**形状:**
|
||||
|
||||
- **input1** (Tensor) - shape为 :math:`(*,in1\_channels)` 的Tensor。 参数中的 `in1_channels` 应等于输入中的 :math:`in1\_channels` 。
|
||||
- **input2** (Tensor) - shape为 :math:`(*,in2\_channels)` 的Tensor。 参数中的 `in2_channels` 应等于输入中的 :math:`in2\_channels` 。
|
||||
- **input1** - math:`(*, H_{in1})`,其中 :math:`H_{in1}=\text{in1_channels}`,
|
||||
:math:`*` 为任意维度. input1除最后一维外的维度需与其他输入保持一致。
|
||||
- **input2** - math:`(*, H_{in2})`,其中 :math:`H_{in2}=\text{in2_channels}`,
|
||||
:math:`*` 为任意维度. input2除最后一维外的维度需与其他输入保持一致。
|
||||
- **output** - math:`(*, H_{out})`,其中 :math:`H_{out}=\text{out_channels}`,
|
||||
:math:`*` 为任意维度. output除最后一维外的维度需与所有输入保持一致。
|
||||
|
||||
**输出:**
|
||||
**数据类型:**
|
||||
|
||||
shape为 :math:`(*,out\_channels)` 的Tensor。
|
||||
- **input1** (Tensor) - 数据类型必须为float16或float32,且与input1一致。
|
||||
- **input2** (Tensor) - 数据类型必须为float16或float32,且与input2一致。
|
||||
- **output** (Tensor) - 数据类型与输入保持一致。
|
||||
|
||||
**权重:**
|
||||
|
||||
- **weight** (Parameter) - 权重参数,shape为 :math:`(\text{out_channels}, \text{in1_channels}, \text{in2_channels})`。
|
||||
当`weight_init`设为`None`时, 其初始化值服从 :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`,其中 :math:`k = \frac{1}{\text{in1_channels}}`。
|
||||
- **bias** (Parameter) - 偏置参数,shape为 :math:`(\text{out_channels})`。
|
||||
当`has_bias`设为`True`且`bias_init`设为`None`时,其初始化值服从 :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`,其中 :math:`k = \frac{1}{\text{in1_channels}}`。
|
||||
|
||||
**异常:**
|
||||
|
||||
|
|
|
@ -41,31 +41,46 @@ class BiDense(Cell):
|
|||
Applies dense connected layer for two inputs. This layer implements the operation as:
|
||||
|
||||
.. math::
|
||||
\text{outputs} = X_{1}^{T} * \text{kernel} * X_{2} + \text{bias},
|
||||
y = x_1^T A x_2 + b,
|
||||
|
||||
where :math:`X_{1}` is the first input tensor, math:`X_{2}` is the second input tensor
|
||||
, :math:`\text{kernel}` is a weight matrix with the same data type as the :math:`X` created by the layer
|
||||
, and :math:`\text{bias}` is a bias vector with the same data type as the :math:`X` created by the layer
|
||||
where :math:`x_1` is the first input tensor, math:`x_2` is the second input tensor
|
||||
, :math:`A` is a weight matrix with the same data type as the :math:`x_{*}` created by the layer
|
||||
, and :math:`b` is a bias vector with the same data type as the :math:`x_{*}` created by the layer
|
||||
(only if has_bias is True).
|
||||
|
||||
Args:
|
||||
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 dtype
|
||||
is same as `x`. 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 dtype is
|
||||
same as `x`. The values of str refer to the function `initializer`. Default: None.
|
||||
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 a bias vector. Default: True.
|
||||
|
||||
Inputs:
|
||||
- **input1** (Tensor) - Tensor of shape :math:`(*, in1\_channels)`. The `in_channels` in `Args` should be equal
|
||||
to :math:`in1\_channels` in `Inputs`.
|
||||
- **input2** (Tensor) - Tensor of shape :math:`(*, in2\_channels)`. The `in_channels` in `Args` should be equal
|
||||
to :math:`in2\_channels` in `Inputs`.
|
||||
Shape:
|
||||
- **input1** - math:`(*, H_{in1})` where :math:`H_{in1}=\text{in1_channels}` and
|
||||
:math:`*` means any number of additional dimensions including none. All but the last dimension
|
||||
of the inputs should be the same.
|
||||
- **input2** - math:`(*, H_{in2})` where :math:`H_{in2}=\text{in2_channels}` and
|
||||
:math:`*` means any number of additional dimensions including none. All but the last dimension
|
||||
of the inputs should be the same.
|
||||
- **output** - math:`(*, H_{out})` where :math:`H_{out}=\text{out_channels}`
|
||||
and all but the last dimension are the same shape as the inputs.
|
||||
|
||||
Outputs:
|
||||
Tensor of shape :math:`(*, out\_channels)`.
|
||||
Dtype:
|
||||
- **input1** (Tensor) - The dtype must be float16 or float32 and be same as **input2**.
|
||||
- **input1** (Tensor) - The dtype must be float16 or float32 and be same as **input1**.
|
||||
- **output** (Tensor) - With the same dtype as the inputs.
|
||||
|
||||
Parameters:
|
||||
- **weight** (Parameter) - The learnable weights with shape
|
||||
:math:`(\text{out_channels}, \text{in1_channels}, \text{in2_channels})`.
|
||||
When `weight_init` is `None`, the values are initialized from
|
||||
:math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`, where :math:`k = \frac{1}{\text{in1_channels}}`.
|
||||
- **bias** (Parameter) - The learnable bias of shape :math:`(\text{out_channels})`.
|
||||
If `has_bias` is `True` and `bias_init` is `None`, the values are initialized from
|
||||
:math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`, where :math:`k = \frac{1}{\text{in1_channels}}`.
|
||||
|
||||
Raises:
|
||||
TypeError: If `in1_channels`, `in2_channels` or `out_channels` is not an int.
|
||||
|
|
Loading…
Reference in New Issue