From e93fa585612d2ce47e357ec400bfeaaa9338ca75 Mon Sep 17 00:00:00 2001 From: hedongdong Date: Fri, 29 Jan 2021 14:37:09 +0800 Subject: [PATCH] [examples] correct failed examples --- mindspore/nn/layer/basic.py | 2 +- mindspore/nn/layer/container.py | 14 +++++++------- mindspore/nn/loss/loss.py | 3 ++- mindspore/ops/composite/clip_ops.py | 7 ++++--- mindspore/ops/composite/math_ops.py | 4 ++-- mindspore/ops/operations/array_ops.py | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/mindspore/nn/layer/basic.py b/mindspore/nn/layer/basic.py index bd6b8b0a89..8bf4693fa9 100644 --- a/mindspore/nn/layer/basic.py +++ b/mindspore/nn/layer/basic.py @@ -129,7 +129,7 @@ class Dropout(Cell): >>> x = Tensor(np.ones([2, 2, 3]), mindspore.float32) >>> net = nn.Dropout(keep_prob=0.8) >>> net.set_train() - Dropout + Dropout >>> output = net(x) >>> print(output.shape) (2, 2, 3) diff --git a/mindspore/nn/layer/container.py b/mindspore/nn/layer/container.py index a9bb8f4f6f..4eb8a5e510 100644 --- a/mindspore/nn/layer/container.py +++ b/mindspore/nn/layer/container.py @@ -42,9 +42,9 @@ class _CellListBase(): The sequential cell may be iterated using the construct method using for-in statement. But there are some scenarios that the construct method built-in does not fit. For convenience, we provide an interface that indicates the sequential - cell may be interpretated as list of cells, so it can be accessed using + cell may be interpreted as list of cells, so it can be accessed using iterator or subscript when a sequential cell instantiate is accessed - by iterator or subscript , it will be interpretated as a list of cells. + by iterator or subscript , it will be interpreted as a list of cells. """ def __init__(self): self.__cell_as_list__ = True @@ -151,7 +151,7 @@ class SequentialCell(Cell): """Appends a given cell to the end of the list. Examples: - >>> conv = nn.Conv2d(3, 2, 3, pad_mode='valid') + >>> conv = nn.Conv2d(3, 2, 3, pad_mode='valid', weight_init="ones") >>> bn = nn.BatchNorm2d(2) >>> relu = nn.ReLU() >>> seq = nn.SequentialCell([conv, bn]) @@ -159,10 +159,10 @@ class SequentialCell(Cell): >>> x = Tensor(np.ones([1, 3, 4, 4]), dtype=mindspore.float32) >>> output = seq(x) >>> print(output) - [[[[0.08789019 0.08789019] - [0.08789019 0.08789019]] - [[0.07690391 0.07690391] - [0.07690391 0.07690391]]]] + [[[[26.999863 26.999863] + [26.999863 26.999863]] + [[26.999863 26.999863] + [26.999863 26.999863]]]] """ if _valid_cell(cell): self._cells[str(len(self))] = cell diff --git a/mindspore/nn/loss/loss.py b/mindspore/nn/loss/loss.py index 1dd7418de5..e035ceaa69 100644 --- a/mindspore/nn/loss/loss.py +++ b/mindspore/nn/loss/loss.py @@ -316,6 +316,7 @@ class SampledSoftmaxLoss(_Loss): ``GPU`` Examples: + >>> mindspore.set_seed(1) >>> loss = nn.SampledSoftmaxLoss(num_sampled=4, num_classes=7, num_true=1) >>> weights = Tensor(np.random.randint(0, 9, [7, 10]), mindspore.float32) >>> biases = Tensor(np.random.randint(0, 9, [7]), mindspore.float32) @@ -323,7 +324,7 @@ class SampledSoftmaxLoss(_Loss): >>> inputs = Tensor(np.random.randint(0, 9, [3, 10]), mindspore.float32) >>> output = loss(weights, biases, labels, inputs) >>> print(output) - [ 4.0181947 46.050743 7.0009117] + [4.6051701e+01 1.4000047e+01 6.1989022e-06] """ def __init__(self, num_sampled, num_classes, num_true=1, diff --git a/mindspore/ops/composite/clip_ops.py b/mindspore/ops/composite/clip_ops.py index fa8221b62e..b970477cc1 100644 --- a/mindspore/ops/composite/clip_ops.py +++ b/mindspore/ops/composite/clip_ops.py @@ -163,10 +163,11 @@ def clip_by_global_norm(x, clip_norm=1.0, use_norm=None): >>> input_x = (Tensor(x1), Tensor(x2)) >>> out = clip_by_global_norm(input_x, 1.0) >>> print(out) - ([[ 2.98142403e-01, 4.47213590e-01], - [ 1.49071202e-01, 2.98142403e-01]], + (Tensor(shape=[2, 2], dtype=Float32, value= + [[ 2.98142403e-01, 4.47213590e-01], + [ 1.49071202e-01, 2.98142403e-01]]), Tensor(shape=[2, 2], dtype=Float32, value= [[ 1.49071202e-01, 5.96284807e-01], - [ 4.47213590e-01, 1.49071202e-01]]) + [ 4.47213590e-01, 1.49071202e-01]])) """ clip_norm = _check_value(clip_norm) diff --git a/mindspore/ops/composite/math_ops.py b/mindspore/ops/composite/math_ops.py index 029d0a1294..1530d3f197 100644 --- a/mindspore/ops/composite/math_ops.py +++ b/mindspore/ops/composite/math_ops.py @@ -144,7 +144,7 @@ def _axes_int_check(x1_shape, x2_shape, axes): def _validate_axes(x1_shape, x2_shape, axes): """ Checks for axes having the correct length according to input, for any value in axis - being out of range with given shape and also checking for compatiable axes values + being out of range with given shape and also checking for compatible axes values with given inputs. """ shapes = [x1_shape, x2_shape] @@ -246,7 +246,7 @@ def tensor_dot(x1, x2, axes): x2_type = F.dtype(x2) axes = _check_axes(axes) _typecheck_input(x1_type, x2_type) - # input compability check & axes format update + # input compatibility check & axes format update axes = _axes_int_check(x1_shape, x2_shape, axes) _validate_axes(x1_shape, x2_shape, axes) x1_reshape_fwd, x1_transpose_fwd, x1_ret = _calc_new_shape(x1_shape, axes, 0) diff --git a/mindspore/ops/operations/array_ops.py b/mindspore/ops/operations/array_ops.py index 94c96e615e..7d820373d3 100644 --- a/mindspore/ops/operations/array_ops.py +++ b/mindspore/ops/operations/array_ops.py @@ -1943,7 +1943,7 @@ class UnsortedSegmentMin(PrimitiveWithCheck): Tensor, set the number of `num_segments` as `N`, the shape is :math:`(N, x_2, ..., x_R)`. Supported Platforms: - ``Ascend`` + ``Ascend`` ``GPU`` Examples: >>> input_x = Tensor(np.array([[1, 2, 3], [4, 5, 6], [4, 2, 1]]).astype(np.float32))