From 827d93e750145b44e8dc946a578ec8aa7a99adba Mon Sep 17 00:00:00 2001 From: huodagu Date: Tue, 25 Oct 2022 17:02:26 +0800 Subject: [PATCH] modify format --- .../mindspore.Tensor.reverse_sequence.rst | 2 +- docs/api/api_python/nn/mindspore.nn.Adam.rst | 4 +- .../nn/mindspore.nn.HingeEmbeddingLoss.rst | 4 +- ...indspore.ops.func_hinge_embedding_loss.rst | 6 +- .../mindspore.train.CosineSimilarity.rst} | 64 ++++++++--------- .../mindspore.train.ROC.rst} | 70 +++++++++---------- mindspore/python/mindspore/nn/loss/loss.py | 10 +-- .../mindspore/ops/function/math_func.py | 8 +-- .../python/mindspore/ops/function/nn_func.py | 4 +- 9 files changed, 86 insertions(+), 86 deletions(-) rename docs/api/api_python/{nn/mindspore.nn.CosineSimilarity.rst => train/mindspore.train.CosineSimilarity.rst} (81%) rename docs/api/api_python/{nn/mindspore.nn.ROC.rst => train/mindspore.train.ROC.rst} (94%) diff --git a/docs/api/api_python/mindspore/Tensor/mindspore.Tensor.reverse_sequence.rst b/docs/api/api_python/mindspore/Tensor/mindspore.Tensor.reverse_sequence.rst index 6b8a432a7b6..7a7f2437066 100644 --- a/docs/api/api_python/mindspore/Tensor/mindspore.Tensor.reverse_sequence.rst +++ b/docs/api/api_python/mindspore/Tensor/mindspore.Tensor.reverse_sequence.rst @@ -1,7 +1,7 @@ mindspore.Tensor.reverse_sequence ================================== -.. py:method:: mindspore.Tensor.reverse_sequce(seq_lengths, seq_dim=0, batch_dim=0) +.. py:method:: mindspore.Tensor.reverse_sequence(seq_lengths, seq_dim=0, batch_dim=0) 对输入序列进行部分反转。 diff --git a/docs/api/api_python/nn/mindspore.nn.Adam.rst b/docs/api/api_python/nn/mindspore.nn.Adam.rst index 0728861836b..e64ab9ccf26 100644 --- a/docs/api/api_python/nn/mindspore.nn.Adam.rst +++ b/docs/api/api_python/nn/mindspore.nn.Adam.rst @@ -51,9 +51,9 @@ mindspore.nn.Adam .. include:: mindspore.nn.optim_note_weight_decay.rst - 当使用Adam时,如果设置`use_lazy`=True,需要注意的是,梯度稀疏时该优化器只更新网络参数的当前的索引位置,稀疏行为不等同于Adam算法。如果想执行稀疏策略,那么需要把target设置为CPU。 + 当使用Adam时,如果设置 `use_lazy` =True,需要注意的是,梯度稀疏时该优化器只更新网络参数的当前的索引位置,稀疏行为不等同于Adam算法。如果想执行稀疏策略,那么需要把target设置为CPU。 - 当使用Adam时,如果设置`use_offload`=True,需要注意的是,此优化器目前仅支持图模式。 + 当使用Adam时,如果设置 `use_offload` =True,需要注意的是,此优化器目前仅支持图模式。 参数: - **params** (Union[list[Parameter], list[dict]]) - 必须是 `Parameter` 组成的列表或字典组成的列表。当列表元素是字典时,字典的键可以是"params"、"lr"、"weight_decay"、"grad_centralization"和"order_params": diff --git a/docs/api/api_python/nn/mindspore.nn.HingeEmbeddingLoss.rst b/docs/api/api_python/nn/mindspore.nn.HingeEmbeddingLoss.rst index a4ec5022f31..ab1c4950f86 100644 --- a/docs/api/api_python/nn/mindspore.nn.HingeEmbeddingLoss.rst +++ b/docs/api/api_python/nn/mindspore.nn.HingeEmbeddingLoss.rst @@ -17,8 +17,8 @@ mindspore.nn.HingeEmbeddingLoss .. math:: \ell(x, y) = \begin{cases} - \operatorname{mean}(L), & \text{if reduction} = \text{`mean`;}\\ - \operatorname{sum}(L), & \text{if reduction} = \text{`sum`.} + \operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\ + \operatorname{sum}(L), & \text{if reduction} = \text{'sum'.} \end{cases} 其中 :math:`L = \{l_1,\dots,l_N\}^\top`。 diff --git a/docs/api/api_python/ops/mindspore.ops.func_hinge_embedding_loss.rst b/docs/api/api_python/ops/mindspore.ops.func_hinge_embedding_loss.rst index bd88bb8b475..101f8110a89 100644 --- a/docs/api/api_python/ops/mindspore.ops.func_hinge_embedding_loss.rst +++ b/docs/api/api_python/ops/mindspore.ops.func_hinge_embedding_loss.rst @@ -1,7 +1,7 @@ mindspore.ops.hinge_embedding_loss =================================== -.. py:function:: mindspore.ops.HingeEmbeddingLoss(inputs, targets, margin=1.0, reduction="mean") +.. py:function:: mindspore.ops.hinge_embedding_loss(inputs, targets, margin=1.0, reduction="mean") Hinge Embedding 损失函数。按输入元素计算输出。衡量输入张量x和标签y(包含1或-1)之间的损失值。通常被用来衡量两个输入之间的相似度。 @@ -17,8 +17,8 @@ mindspore.ops.hinge_embedding_loss .. math:: \ell(x, y) = \begin{cases} - \operatorname{mean}(L), & \text{if reduction} = \text{`mean`;}\\ - \operatorname{sum}(L), & \text{if reduction} = \text{`sum`.} + \operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\ + \operatorname{sum}(L), & \text{if reduction} = \text{'sum'.} \end{cases} 其中 :math:`L = \{l_1,\dots,l_N\}^\top`。 diff --git a/docs/api/api_python/nn/mindspore.nn.CosineSimilarity.rst b/docs/api/api_python/train/mindspore.train.CosineSimilarity.rst similarity index 81% rename from docs/api/api_python/nn/mindspore.nn.CosineSimilarity.rst rename to docs/api/api_python/train/mindspore.train.CosineSimilarity.rst index 8afa8f5b2ae..3b99307d5c3 100644 --- a/docs/api/api_python/nn/mindspore.nn.CosineSimilarity.rst +++ b/docs/api/api_python/train/mindspore.train.CosineSimilarity.rst @@ -1,32 +1,32 @@ -mindspore.nn.CosineSimilarity -============================= - -.. py:class:: mindspore.nn.CosineSimilarity(similarity='cosine', reduction='none', zero_diagonal=True) - - 计算余弦相似度。 - - 参数: - - **similarity** (str) - "dot"或"cosine"。"cosine"表示相似度计算逻辑, "dot"表示矩阵点乘矩阵计算逻辑。默认值:"cosine"。 - - **reduction** (str) - "none"、"sum"或"mean"。默认值:"none"。 - - **zero_diagonal** (bool) - 如果为True,则对角线将设置为零。默认值:True。 - - .. py:method:: clear() - - 重置评估结果。 - - .. py:method:: eval() - - 计算Cosine Similarity矩阵。 - - 返回: - numpy.ndarray,相似度矩阵。 - - 异常: - - **RuntimeError** - 如果没有先调用update方法。 - - .. py:method:: update(*inputs) - - 使用y_pred和y更新内部评估结果。 - - 参数: - - **inputs** (Union[Tensor, list, numpy.ndarray]) - 输入的矩阵。 +mindspore.train.CosineSimilarity +================================= + +.. py:class:: mindspore.train.CosineSimilarity(similarity='cosine', reduction='none', zero_diagonal=True) + + 计算余弦相似度。 + + 参数: + - **similarity** (str) - "dot"或"cosine"。"cosine"表示相似度计算逻辑, "dot"表示矩阵点乘矩阵计算逻辑。默认值:"cosine"。 + - **reduction** (str) - "none"、"sum"或"mean"。默认值:"none"。 + - **zero_diagonal** (bool) - 如果为True,则对角线将设置为零。默认值:True。 + + .. py:method:: clear() + + 重置评估结果。 + + .. py:method:: eval() + + 计算Cosine Similarity矩阵。 + + 返回: + numpy.ndarray,相似度矩阵。 + + 异常: + - **RuntimeError** - 如果没有先调用update方法。 + + .. py:method:: update(*inputs) + + 使用y_pred和y更新内部评估结果。 + + 参数: + - **inputs** (Union[Tensor, list, numpy.ndarray]) - 输入的矩阵。 diff --git a/docs/api/api_python/nn/mindspore.nn.ROC.rst b/docs/api/api_python/train/mindspore.train.ROC.rst similarity index 94% rename from docs/api/api_python/nn/mindspore.nn.ROC.rst rename to docs/api/api_python/train/mindspore.train.ROC.rst index 1ba81c5b12a..4bd1e8b9906 100644 --- a/docs/api/api_python/nn/mindspore.nn.ROC.rst +++ b/docs/api/api_python/train/mindspore.train.ROC.rst @@ -1,35 +1,35 @@ -mindspore.nn.ROC -===================== - -.. py:class:: mindspore.nn.ROC(class_num=None, pos_label=None) - - 计算ROC曲线。适用于求解二分类和多分类问题。在多分类的情况下,将基于one-vs-the-rest的方法进行计算。 - - 参数: - - **class_num** (int) - 类别数。对于二分类问题,此入参可以不设置。默认值:None。 - - **pos_label** (int) - 正类的类别值。二分类问题中,不设置此入参,即 `pos_label` 为None时,正类类别值默认为1;用户可以自行设置正类类别值为其他值。多分类问题中,用户不应设置此参数,因为它将在[0,num_classes-1]范围内迭代更改。默认值:None。 - - .. py:method:: clear() - - 内部评估结果清零。 - - .. py:method:: eval() - - 计算ROC曲线。 - - 返回: - tuple,由 `fpr`、`tpr` 和 `thresholds` 组成。 - - - **fpr** (np.array) - 假正率。二分类情况下,返回不同阈值下的fpr;多分类情况下,则为fpr(false positive rate)的列表,列表的每个元素代表一个类别。 - - **tps** (np.array) - 真正率。二分类情况下,返回不同阈值下的tps;多分类情况下,则为tps(true positive rate)的列表,列表的每个元素代表一个类别。 - - **thresholds** (np.array) - 用于计算假正率和真正率的阈值。 - - 异常: - - **RuntimeError** - 如果没有先调用update方法,则会报错。 - - .. py:method:: update(*inputs) - - 使用 `y_pred` 和 `y` 更新内部评估结果。 - - 参数: - - **inputs** - 输入 `y_pred` 和 `y`。`y_pred` 和 `y` 是Tensor、list或numpy.ndarray。`y_pred` 一般情况下是范围为 :math:`[0, 1]` 的浮点数列表,shape为 :math:`(N, C)`,其中 :math:`N` 是用例数,:math:`C` 是类别数。`y` 为整数值,如果为one-hot格式,shape为 :math:`(N, C)`,如果是类别索引,shape为 :math:`(N,)`。 +mindspore.train.ROC +===================== + +.. py:class:: mindspore.train.ROC(class_num=None, pos_label=None) + + 计算ROC曲线。适用于求解二分类和多分类问题。在多分类的情况下,将基于one-vs-the-rest的方法进行计算。 + + 参数: + - **class_num** (int) - 类别数。对于二分类问题,此入参可以不设置。默认值:None。 + - **pos_label** (int) - 正类的类别值。二分类问题中,不设置此入参,即 `pos_label` 为None时,正类类别值默认为1;用户可以自行设置正类类别值为其他值。多分类问题中,用户不应设置此参数,因为它将在[0,num_classes-1]范围内迭代更改。默认值:None。 + + .. py:method:: clear() + + 内部评估结果清零。 + + .. py:method:: eval() + + 计算ROC曲线。 + + 返回: + tuple,由 `fpr`、`tpr` 和 `thresholds` 组成。 + + - **fpr** (np.array) - 假正率。二分类情况下,返回不同阈值下的fpr;多分类情况下,则为fpr(false positive rate)的列表,列表的每个元素代表一个类别。 + - **tps** (np.array) - 真正率。二分类情况下,返回不同阈值下的tps;多分类情况下,则为tps(true positive rate)的列表,列表的每个元素代表一个类别。 + - **thresholds** (np.array) - 用于计算假正率和真正率的阈值。 + + 异常: + - **RuntimeError** - 如果没有先调用update方法,则会报错。 + + .. py:method:: update(*inputs) + + 使用 `y_pred` 和 `y` 更新内部评估结果。 + + 参数: + - **inputs** - 输入 `y_pred` 和 `y`。`y_pred` 和 `y` 是Tensor、list或numpy.ndarray。`y_pred` 一般情况下是范围为 :math:`[0, 1]` 的浮点数列表,shape为 :math:`(N, C)`,其中 :math:`N` 是用例数,:math:`C` 是类别数。`y` 为整数值,如果为one-hot格式,shape为 :math:`(N, C)`,如果是类别索引,shape为 :math:`(N,)`。 diff --git a/mindspore/python/mindspore/nn/loss/loss.py b/mindspore/python/mindspore/nn/loss/loss.py index 96d35de0496..81e16560bde 100644 --- a/mindspore/python/mindspore/nn/loss/loss.py +++ b/mindspore/python/mindspore/nn/loss/loss.py @@ -2437,16 +2437,16 @@ class HingeEmbeddingLoss(LossBase): .. math:: l_n = \begin{cases} - x_n, & \text{if}\; y_n = 1,\\ - \max \{0, \Delta - x_n\}, & \text{if}\; y_n = -1, + x_n, & \text{if}\; y_n = 1,\\ + \max \{0, \Delta - x_n\}, & \text{if}\; y_n = -1, \end{cases} and the total loss functions is .. math:: \ell(x, y) = \begin{cases} - \operatorname{mean}(L), & \text{if reduction} = \text{`mean';}\\ - \operatorname{sum}(L), & \text{if reduction} = \text{`sum'.} + \operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\ + \operatorname{sum}(L), & \text{if reduction} = \text{'sum'.} \end{cases} where :math:`L = \{l_1,\dots,l_N\}^\top`. @@ -2454,7 +2454,7 @@ class HingeEmbeddingLoss(LossBase): Args: margin (float): Threshold defined by Hinge Embedding Loss :math:`margin`. Represented as :math:`\Delta` in the formula. Default: 1.0. - reduction (string): Specify the computing method to be applied to the outputs: 'none', 'mean', or 'sum'. + reduction (str): Specify the computing method to be applied to the outputs: 'none', 'mean', or 'sum'. Default: 'mean'. Inputs: diff --git a/mindspore/python/mindspore/ops/function/math_func.py b/mindspore/python/mindspore/ops/function/math_func.py index d668255923d..2c54f3c773d 100644 --- a/mindspore/python/mindspore/ops/function/math_func.py +++ b/mindspore/python/mindspore/ops/function/math_func.py @@ -3787,8 +3787,8 @@ def cdist(x, y, p=2.0): ValueError: If `p` is a negative float. ValueError: If dimension of `x` is not the same as `y`. ValueError: If dimension of `x` or `y` is neither 2 nor 3. - ValueError: If the batch shape of 'x' is not the same as the shape of 'y' - ValueError: If the number of columns of 'x' is not the same as the number of 'y' + ValueError: If the batch shape of 'x' is not the same as the shape of 'y'. + ValueError: If the number of columns of 'x' is not the same as the number of 'y'. Supported Platforms: ``Ascend`` ``GPU`` ``CPU`` @@ -6551,11 +6551,11 @@ def cumprod(input, dim, dtype=None): Args: input (Tensor[Number]): The input tensor. - :math:`(N,*)` where :math:`*` means, any number of additional dimensions, its rank should be less than 8. + :math:`(N,*)` where :math:`*` means, any number of additional dimensions, its rank should be less than 8. dim (int): The dimensions to compute the cumulative product. Only constant value is allowed. dtype: The desired data type of output. Default: None. - Outputs: + Returns: Tensor, has the same shape and dtype as the `input` unless `dtype` is specified. Raises: diff --git a/mindspore/python/mindspore/ops/function/nn_func.py b/mindspore/python/mindspore/ops/function/nn_func.py index e9c68094fae..c59d5a4917c 100644 --- a/mindspore/python/mindspore/ops/function/nn_func.py +++ b/mindspore/python/mindspore/ops/function/nn_func.py @@ -2484,8 +2484,8 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'): .. math:: \ell(x, y) = \begin{cases} - \operatorname{mean}(L), & \text{if reduction} = \text{`mean';}\\ - \operatorname{sum}(L), & \text{if reduction} = \text{`sum'.} + \operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\ + \operatorname{sum}(L), & \text{if reduction} = \text{'sum'.} \end{cases} where :math:`L = \{l_1,\dots,l_N\}^\top`.