optimizes the documentation of chinese API of BCEWithLogitsLoss,BatchMatMul,BatchNorm,etc.

This commit is contained in:
zhangfanghe 2022-03-29 17:06:07 +08:00
parent 86b4de336b
commit 08f8660a6c
18 changed files with 41 additions and 41 deletions

View File

@ -3,7 +3,7 @@ mindspore.ops.BCEWithLogitsLoss
.. py:class:: mindspore.ops.BCEWithLogitsLoss(reduction='mean')
使用sigmoid激活函数计算出预测值BCEWithLogitsLoss计算预测值和目标值之间的二值交叉熵损失。
输入经过sigmoid激活函数后作为预测值BCEWithLogitsLoss计算预测值和目标值之间的二值交叉熵损失。
将输入 `logits` 设置为 :math:`X` ,输入 `labels` 设置为 :math:`Y` ,输入 `weight` 设置为 :math:`W` ,输出设置为 :math:`L` 。则,
@ -31,8 +31,8 @@ mindspore.ops.BCEWithLogitsLoss
- **logits** (Tensor)输入预测值任意维度的Tensor。其数据类型为float16或float32。
- **label** (Tensor) 输入目标值shape与 `logits` 相同。数据类型为float16或float32。
- **weight** (Tensor):指定每个批次二值交叉熵的权重。可以广播到shape同 `logits` 的Tensor。数据类型必须为float16或float32。
- **pos_weight** (Tensor):指定正类的权重。为向量,其长度等于分类数。可以进行广播,其shape与 `logits` 的shape保持一致。数据类型必须为float16或float32。
- **weight** (Tensor):指定每个批次二值交叉熵的权重。支持广播使其shape与 `logits` 的shape保持一致。数据类型必须为float16或float32。
- **pos_weight** (Tensor):指定正类的权重。是一个长度等于分类数的向量。支持广播,使其shape与 `logits` 的shape保持一致。数据类型必须为float16或float32。
**输出:**

View File

@ -3,10 +3,10 @@ mindspore.ops.BatchMatMul
.. py:class:: mindspore.ops.BatchMatMul(transpose_a=False, transpose_b=False)
两个批量Tensor之间的矩阵乘法。
两个batch后的Tensor之间的矩阵乘法。
.. math::
\\text{output}[..., :, :]= \\text{matrix}(x[..., :, :])* \\text{matrix}(y[..., :, :])
\text{output}[..., :, :] = \text{matrix}(x[..., :, :]) * \text{matrix}(y[..., :, :])
两个输入Tensor必须具有相同的秩并且秩必须不小于 `3`

View File

@ -3,14 +3,14 @@ mindspore.ops.BatchNorm
.. py:class:: mindspore.ops.BatchNorm(is_training=False, epsilon=1e-5, momentum=0.1, data_format="NCHW")
对输入数据进行归一化(Batch Normalization Layer)和更新参数。
对输入数据进行归一化(Batch Normalization)和更新参数。
批量归一化广泛应用于卷积神经网络中。此运算对输入应用归一化,避免内部协变量偏移,详见论文 `Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift <https://arxiv.org/abs/1502.03167>`_ 。使用mini-batch数据和学习参数进行训练学习的参数见如下公式中
.. math::
y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
其中, :math:`\gamma``scale` :math:`\beta``bias` :math:`\epsilon``epsilon` :math:`mean` 为x的均值 :math:`variance` 为x的方差。
其中, :math:`\gamma``scale` :math:`\beta``bias` :math:`\epsilon``epsilon` :math:`mean` :math:`x` 的均值, :math:`variance` :math:`x` 的方差。
.. warning::
- 如果该运算用于推理,并且输出"reserve_space_1"和"reserve_space_2"可用,则"reserve_space_1"的值与"mean"相同,"reserve_space_2"的值与"variance"相同。
@ -19,9 +19,9 @@ mindspore.ops.BatchNorm
**参数:**
- **is_training** (bool) - 如果 `is_training` 为True则在训练期间计算 `mean``variance`。如果 `is_training` 为False则在推理期间从checkpoint加载。默认值False。
- **epsilon** (float) - 添加的以确保数值稳定性。默认值1e-5。
- **epsilon** (float) - 添加到分母上的值以确保数值稳定性。默认值1e-5。
- **momentum** (float) - 动态均值和动态方差所使用的动量。(例如 :math:`new\_running\_mean = (1 - momentum) * running\_mean + momentum * current\_mean`)。动量值必须为[0, 1]。默认值0.1。
- **data_format** (str) - 输入数据格式,可选值有:'NHWC'或'NCHW'。默认值:"NCHW"
- **data_format** (str) - 输入数据格式,可选值有:'NHWC'或'NCHW'。默认值:'NCHW'
**输入:**
@ -33,7 +33,7 @@ mindspore.ops.BatchNorm
- **mean** (Tensor) - 输入均值shape为 :math:`(C,)` 的Tensor具有与 `scale` 相同的数据类型。
- **variance** (Tensor) - 输入方差shape为 :math:`(C,)` 的Tensor具有与 `scale` 相同的数据类型。
如果 `is_training` 为True`bias``mean``variance`参数
如果 `is_training` 为True`scale``bias` `mean``variance`Parameter
- **input_x** (Tensor) - 数据输入shape为 :math:`(N, C)` 的Tensor数据类型为float16或float32。
- **scale** (Parameter) - 输入Scalarshape为 :math:`(C,)` 的参数数据类型为float16或float32。

View File

@ -3,9 +3,9 @@ mindspore.ops.Dropout2D
.. py:class:: mindspore.ops.Dropout2D(keep_prob=0.5)
在训练期间,根据概率 :math:`1 - keep\_prob` 随机的将一些通道设置为0且服从伯努利分布。对于shape为 :math:`(N, C, H, W)` 的四维Tensor通道特征图指的是shape为 :math:`(H, W)` 的二维特征图。)
在训练期间,根据概率 `1 - keep\_prob` 随机的将一些通道设置为0且服从伯努利分布。对于shape为 :math:`(N, C, H, W)` 的四维Tensor通道特征图指的是shape为 :math:`(H, W)` 的二维特征图。)
例如,对于批量输入的第 :math:`i_th` 样本的第:math:`j_th` 通道为二维Tensor即input[i,j]。在前向传播过程中输入样本的每个通道都有可能被置为0置为0的概率为 :math:`1 - keep\_prob`,且服从伯努利分布。
例如,对于批量输入的第 :math:`i_th` 样本的第 :math:`j_th` 通道为二维Tensor即input[i,j]。在前向传播过程中输入样本的每个通道都有可能被置为0置为0的概率为 `1 - keep\_prob`,且服从伯努利分布。
论文 `Dropout: A Simple Way to Prevent Neural Networks from Overfitting <http://www.cs.toronto.edu/~rsalakhu/papers/srivastava14a.pdf>`_ 中提出了该技术,并证明其能有效地减少过度拟合,防止神经元共适应。更多详细信息,请参见 `Improving neural networks by preventing co-adaptation of feature detectors <https://arxiv.org/pdf/1207.0580.pdf>`_
@ -17,7 +17,7 @@ mindspore.ops.Dropout2D
**输入:**
- **x** (Tensor) - shape为 :math:`(N, C, H, W)` 的四维张量其中N是批量大小C是通道数H是特征高度W是特征宽度。数据类型应为int8、int16、int32、int64、float16或float32。
- **x** (Tensor) - shape为 :math:`(N, C, H, W)` 的四维张量其中N是批处理C是通道数H是特征高度W是特征宽度。数据类型应为int8、int16、int32、int64、float16或float32。
**输出:**

View File

@ -5,7 +5,7 @@ mindspore.ops.LogUniformCandidateSampler
使用log-uniform(Zipfian)分布对一组类进行采样。
该操作从整数范围[0, range_max)中随机采样一个采样类sampled_candidates的Tensor。
该操作从整数范围[0, `range_max` )中随机采样一个采样类( `sampled_candidates` )的Tensor。
**参数:**
@ -17,7 +17,7 @@ mindspore.ops.LogUniformCandidateSampler
**输入:**
- **true_classes** (Tensor) - 目标类其数据类型为int64shape为[batch_size, num_true]
- **true_classes** (Tensor) - 目标类其数据类型为int64shape为(batch_size, num_true)
**输出:**

View File

@ -3,7 +3,7 @@ mindspore.ops.MaskedFill
.. py:class:: mindspore.ops.MaskedFill()
掩码为True位置的值将被指定的值填充
将掩码位置为True的位置填充指定的值
`input``mask` 的shape需相同或可广播。
@ -11,7 +11,7 @@ mindspore.ops.MaskedFill
- **input** (Tensor) - 输入Tensor其数据类型为float16、float32、int8、或int32。
- **mask** (Tensor[bool]) - 输入的掩码其数据类型为bool。
- **value** (Union[float, Tensor]) - 用来填充的值只支持0维Tensor或浮点数
- **value** (Union[float, Tensor]) - 用来填充的值只支持0维Tensor或float
**输出:**
@ -20,7 +20,7 @@ mindspore.ops.MaskedFill
**异常:**
- **TypeError** - `input``mask` 不是Tensor。
- **TypeError** - `value` 既不是浮点数也不是Tensor。
- **TypeError** - `value` 既不是float也不是Tensor。
- **TypeError** - `input``value` 的数据类型不是float16、float32、int8、或int32。
- **TypeError** - `value` 的数据类型与 `input` 不同。
- **TypeError** - `mask` 的数据类型不是bool。

View File

@ -7,8 +7,8 @@ mindspore.ops.MaskedSelect
**输入:**
- **x** (Tensor) - 需要进行索引操作的输入Tensor其shape为 :math:`(x_1, x_2, ..., x_R)`
- **mask** (Tensor[bool]) - 要进行索引的布尔掩码其shape为 :math:`(x_1, x_2, ..., x_R)`
- **x** (Tensor) - 输入Tensor其shape为 :math:`(x_1, x_2, ..., x_R)`
- **mask** (Tensor[bool]) - 输入的布尔掩码其shape为 :math:`(x_1, x_2, ..., x_R)`
**输出:**

View File

@ -9,7 +9,7 @@ mindspore.ops.Meshgrid
**参数:**
- **indexing** ('xy', 'ij', optional) - 'xy'或'ij'。默认值:'xy'。以笛卡尔坐标'xy'或者矩阵'ij'索引作为输出。以长度为 `M``N` 的二维输入,取值为'xy'时输出的shape为 `(N, M)` ,取值为'ij'时输出的shape为 `(M, N)` 。以长度为 `M` , `N``P` 的三维输入,取值为'xy'时输出的shape为 `(N, M, P)` ,取值为'ij'时输出的shape为 `(M, N, P)`
- **indexing** ('xy', 'ij', optional) - 'xy'或'ij'。以笛卡尔坐标'xy'或者矩阵'ij'索引作为输出。以长度为 `M``N` 的二维输入,取值为'xy'时输出的shape为 :math:`(N, M)` ,取值为'ij'时输出的shape为 :math:`(M, N)` 。以长度为 `M` , `N``P` 的三维输入,取值为'xy'时输出的shape为 :math:`(N, M, P)` ,取值为'ij'时输出的shape为 :math:`(M, N, P)`默认值:'xy'。
**输入:**

View File

@ -5,7 +5,7 @@ mindspore.ops.NLLLoss
获取预测值和目标值之间的负对数似然损失。
reduction=none时,负对数似然损失如下:
reduction为'none'时,负对数似然损失如下:
.. math::
\ell(x, t)=L=\left\{l_{1}, \ldots, l_{N}\right\}^{\top},
@ -17,7 +17,7 @@ mindspore.ops.NLLLoss
reduction不为'none'(默认为'mean'),则
.. math::
\ell(x, t)=\left\{\begin{array}{ll}
\ell(x, t)=L=\left\{\begin{array}{ll}
\sum_{n=1}^{N} \frac{1}{\sum_{n=1}^{N} w_{t n}} l_{n}, & \text { if reduction }=\text { 'mean'; } \\
\sum_{n=1}^{N} l_{n}, & \text { if reduction }=\text { 'sum' }
\end{array}\right.
@ -34,10 +34,10 @@ mindspore.ops.NLLLoss
**输出:**
`loss``total_weight` 组成的2个Tensor的元组
`loss``total_weight` 组成的2个Tensor的tuple
- **loss** (Tensor) - 当 `reduction` 为'none'且 `logits` 为2维Tensor时 `loss` 的shape为 :math:`(N,)` 。否则, `loss` 为scalar。数据类型与 `input's` 相同。
- **total_weight** (Tensor) - `total_weight` 是scalar数据类型与 `weight's` 相同。
- **loss** (Tensor) - 当 `reduction` 为'none'且 `logits` 为2维Tensor时 `loss` 的shape为 :math:`(N,)` 。否则, `loss` 为scalar。数据类型与 `logits` 相同。
- **total_weight** (Tensor) - `total_weight` 是scalar数据类型与 `weight` 相同。
**异常:**

View File

@ -6,7 +6,7 @@ mindspore.ops.NotEqual
计算两个Tensor是否不相等。
.. note::
- 输入 `x``y` 遵循隐式类型转换规则,使数据类型保持一致。
- 输入 `x` 和 `y` 遵循 `隐式类型转换规则 <https://www.mindspore.cn/docs/note/zh-CN/master/operator_list_implicit.html>`_ ,使数据类型保持一致。
- 输入必须是两个Tensor或一个Tensor和一个Scalar。
- 当输入是两个Tensor时它们的shape可以广播。
- 当输入是一个Tensor和一个Scalar时Scalar只能是一个常数。

View File

@ -20,14 +20,14 @@ mindspore.ops.ReduceMax
Tensorshape与输入 `x` 相同。
- 如果为()且keep_dims为False则输出一个0维Tensor表示输入Tensor中所有元素的最大值。
- 如果 `axis` 为()且keep_dims为False则输出一个0维Tensor表示输入Tensor中所有元素的最大值。
- 如果为int取值为2并且keep_dims为False则输出的shape为 :math:`(x_1, x_3, ..., x_R)`
- 如果 `axis` 为int取值为2并且keep_dims为False则输出的shape为 :math:`(x_1, x_3, ..., x_R)`
- 如果轴为tuple(int),取值为(2, 3)并且keep_dims为False则输出的shape为 :math:`(x_1, x_4, ..., x_R)`
- 如果 `axis` 为tuple(int)或list(int),取值为(2, 3)并且keep_dims为False则输出的shape为 :math:`(x_1, x_4, ..., x_R)`
**异常:**
- **TypeError** - `keep_dims` 不是bool。
- **TypeError** - `x` 不是tensor。
- **TypeError** - `x` 不是Tensor。
- **TypeError** - `axis` 不是int、tuple或list。

View File

@ -5,7 +5,7 @@ mindspore.ops.ResizeBilinear
使用双线性插值调整图像大小到指定的大小。
调整输入图像的高和宽,且输入图像的数据类型可以不同但输出的数据类型只能是float32.
调整输入图像的高和宽,且可以输入不同数据类型的图像但输出的数据类型只能是float32。
**参数:**

View File

@ -17,7 +17,7 @@ mindspore.ops.ReverseSequence
**输出:**
shape和数据类型与输入相同。
shape和数据类型与输入相同。
**异常:**

View File

@ -3,7 +3,7 @@
.. py:class:: mindspore.ops.Sort(axis=-1, descending=False)
根据指定的维度对输入Tensor的元素进行排序。默认为升序排序。
根据指定的对输入Tensor的元素进行排序。默认为升序排序。
**参数:**

View File

@ -5,7 +5,7 @@
输入Tensor根据步长和索引进行切片提取。
给定一个输入Tensor此操作会插入长度为1的维度。从给定的'input_tensor'中提取大小为(end-begin)/stride的片段。从起始位置开始,根据步长和索引进行提取,直到所有维度都不小于结束位置为止。
给定一个输入Tensor此操作会插入长度为1的维度。从给定的 `input_tensor` 中提取大小为 `(end-begin)/stride` 的片段。从起始位置开始,根据步长和索引进行提取,直到所有维度都不小于结束位置为止。
给定一个 `input_x[m1, m2, ...、mn]``begin``end``strides` 是长度为n的向量。

View File

@ -5,7 +5,7 @@
返回一个表示每个单元的前N个位置的掩码Tensor。内部元素数据类型为bool。
如果lengths的shape为 :math:`[d_1, d_2, ..., d_n]` 则生成的Tensor掩码拥有数据类型其shape为 :math:`[d_1, d_2, ..., d_n, maxlen]` 且mask :math:`[i_1, i_2, ..., i_n, j] = (j < lengths[i_1, i_2, ..., i_n])`
如果 `lengths` 的shape为 :math:`(d_1, d_2, ..., d_n)` 则生成的Tensor掩码拥有数据类型其shape为 :math:`(d_1, d_2, ..., d_n, maxlen)` 且mask :math:`[i_1, i_2, ..., i_n, j] = (j < lengths[i_1, i_2, ..., i_n])`
**参数:**
@ -14,7 +14,7 @@
**输出:**
返回一个Tensorshape为lengths.shape + (maxlen,)。
返回一个Tensorshape为 `lengths.shape + (maxlen,)`
**异常:**

View File

@ -133,8 +133,8 @@ def sequence_mask(lengths, maxlen=None):
"""
Returns a mask tensor representing the first N positions of each cell.
If lengths has shape [d_1, d_2, ..., d_n], then the resulting tensor mask has type and shape
[d_1, d_2, ..., d_n, maxlen], with mask[i_1, i_2, ..., i_n, j] = (j < lengths[i_1, i_2, ..., i_n])
If `lengths` has shape (d_1, d_2, ..., d_n), then the resulting tensor mask has type and shape
(d_1, d_2, ..., d_n, maxlen), with mask[i_1, i_2, ..., i_n, j] = (j < lengths[i_1, i_2, ..., i_n])
Args:
lengths (Tensor): Tensor to calculate the mask for. All values in this tensor should be
@ -143,7 +143,7 @@ def sequence_mask(lengths, maxlen=None):
type as elements in `lengths`. Default is None.
Outputs:
One mask tensor of shape lengths.shape + (maxlen,).
One mask tensor of shape `lengths.shape + (maxlen,)` .
Raises:
TypeError: If `lengths` is not a Tensor.

View File

@ -914,7 +914,7 @@ class ReduceMax(_Reduce):
the output is a 0-D tensor representing the maximum of all elements in the input tensor.
- If axis is int, set as 2, and keep_dims is False,
the shape of output is :math:`(x_1, x_3, ..., x_R)`.
- If axis is tuple(int), set as (2, 3), and keep_dims is False,
- If axis is tuple(int) or list(int), set as (2, 3), and keep_dims is False,
the shape of output is :math:`(x_1, x_4, ..., x_R)`.
Raises: