From b50d2de96a4fc3a891c439f83187f063b5db109d Mon Sep 17 00:00:00 2001 From: huanxiaoling <3174348550@qq.com> Date: Mon, 26 Sep 2022 16:23:15 +0800 Subject: [PATCH] modify files in tutorials --- tutorials/source_en/beginner/autograd.md | 24 ++++++++++---------- tutorials/source_en/beginner/dataset.md | 12 +++++----- tutorials/source_en/beginner/introduction.md | 4 ++-- tutorials/source_en/beginner/model.md | 8 +++---- tutorials/source_en/beginner/quick_start.md | 2 +- tutorials/source_en/beginner/tensor.md | 6 ++--- tutorials/source_en/beginner/train.md | 2 +- tutorials/source_zh_cn/beginner/tensor.ipynb | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tutorials/source_en/beginner/autograd.md b/tutorials/source_en/beginner/autograd.md index 8681853801..ab2b58ecd9 100644 --- a/tutorials/source_en/beginner/autograd.md +++ b/tutorials/source_en/beginner/autograd.md @@ -27,8 +27,8 @@ In this model, $x$ is the input, $y$ is the correct value, and $w$ and $b$ are t ```python x = ops.ones(5, mindspore.float32) # input tensor y = ops.zeros(3, mindspore.float32) # expected output -w = Tensor(np.random.randn(5, 3), mindspore.float32) # weight -b = Tensor(np.random.randn(3,), mindspore.float32) # bias +w = Parameter(Tensor(np.random.randn(5, 3), mindspore.float32), name='w') # weight +b = Parameter(Tensor(np.random.randn(3,), mindspore.float32), name='b') # bias ``` We construct the computing function based on the computing process described by the computing graphs. @@ -44,7 +44,7 @@ Execute the computing functions to get the calculated loss value. ```python z = function(x, y, w, b) -z +print(z) ``` ```text @@ -72,7 +72,7 @@ The gradients corresponding to $w$ and $b$ are obtained by executing the differe ```python grads = grad_fn(x, y, w, b) -grads +print(grads) ``` ```text @@ -87,7 +87,7 @@ grads ## Stop Gradient -Generally, the derivative of the parameter with respect to loss is found, so that the output of the output function is only one term of loss. When we want the function to output more than one term, the differential function will find the derivative of the parameter with respect to all output terms. In this case, if you want to truncate the gradient of an output term or eliminate the effect of a Tensor on the gradient, you need to use Stop Gradient operation. +Generally, the derivative of the parameter with respect to loss is found, so that the output of function is only one term of loss. When we want the function to output more than one term, the differential function will find the derivative of the parameter with respect to all output terms. In this case, if you want to truncate the gradient of an output term or eliminate the effect of a Tensor on the gradient, you need to use Stop Gradient operation. Here we change `function` to `function_with_logits` that outputs both loss and z to obtain the differentiation function and execute it. @@ -101,7 +101,7 @@ def function_with_logits(x, y, w, b): ```python grad_fn = ops.grad(function_with_logits, (2, 3)) grads = grad_fn(x, y, w, b) -grads +print(grads) ``` ```text @@ -126,7 +126,7 @@ def function_stop_gradient(x, y, w, b): ```python grad_fn = ops.grad(function_stop_gradient, (2, 3)) grads = grad_fn(x, y, w, b) -grads +print(grads) ``` ```text @@ -155,7 +155,7 @@ grad_fn = ops.grad(function_with_logits, (2, 3), has_aux=True) ```python grads, (z,) = grad_fn(x, y, w, b) -grads, z +print(grads, z) ``` ```text @@ -180,8 +180,8 @@ First we inherit `nn.Cell` to construct a single-layer linear transform neural n class Network(nn.Cell): def __init__(self): super().__init__() - self.w = Parameter(w, requires_grad=True) - self.b = Parameter(b, requires_grad=True) + self.w = w + self.b = b def construct(self, x): z = ops.matmul(x, self.w) + self.b @@ -209,7 +209,7 @@ def forward_fn(x, y): Once completed, we use the `value_and_grad` interface to obtain the differentiation function for computing the gradient. -Since Cell is used to encapsulate the neural network model and the model parameters are internal properties of Cell, we do not need to use `grad_position` to specify the derivation of the function inputs at this point, so we configure it as `None`. To derive the model parameters, we use the `weights` parameter and use the `model.trainable_params()` method to retrieve the parameters from the Cell that can be derived. +Since Cell is used to encapsulate the neural network model and the model parameters are internal properties of Cell, we do not need to use `grad_position` to specify the derivation of the function inputs at this point, so we configure it as `None`. When derive the model parameters, we use the `weights` parameter and use the `model.trainable_params()` method to retrieve the parameters from the Cell that can be derived. ```python grad_fn = ops.value_and_grad(forward_fn, None, weights=model.trainable_params()) @@ -217,7 +217,7 @@ grad_fn = ops.value_and_grad(forward_fn, None, weights=model.trainable_params()) ```python loss, grads = grad_fn(x, y) -grads +print(grads) ``` ```text diff --git a/tutorials/source_en/beginner/dataset.md b/tutorials/source_en/beginner/dataset.md index e685185563..11d20280ea 100644 --- a/tutorials/source_en/beginner/dataset.md +++ b/tutorials/source_en/beginner/dataset.md @@ -22,7 +22,7 @@ We use the **Mnist** dataset as a sample to introduce the loading method by usin ### Loading a Dataset by Using Vision -The [Vision](https://gitee.com/mindspore/vision/) development library provides dataset encapsulation based on the customized dataset `mindspore.dataset.GeneratorDataset`. We use its interface for loading with the following parameters to be configured. +The [Vision](https://gitee.com/mindspore/vision/) development library provides function encapsulation based on the customized dataset `mindspore.dataset.GeneratorDataset`. We use its interface for loading with the following parameters to be configured. - `path`: the path to save the dataset. - `split`: the dataset category, `train` or `test`. @@ -40,7 +40,7 @@ training_data = dataset.Mnist( Get the dataset from the automatically downloaded and loaded `training_data`, you can see that its data type is `GeneratorDataset`. ```python -type(training_data.dataset) +print(type(training_data.dataset)) ``` ```text @@ -70,7 +70,7 @@ After the compressed file is deleted and loaded directly, you can see that its d ```python train_dataset = MnistDataset(train_path, shuffle=False) -type(train_dataset) +print(type(train_dataset)) ``` ```text @@ -124,7 +124,7 @@ The `map` is the key operation of data preprocessing, which can add data transfo ```python image, label = next(train_dataset.create_tuple_iterator()) -image.shape, image.dtype +print(image.shape, image.dtype) ``` ```text @@ -139,7 +139,7 @@ Comparing the data before and after map, you can see the data type change. ```python image, label = next(train_dataset.create_tuple_iterator()) -image.shape, image.dtype +print(image.shape, image.dtype) ``` ```text @@ -158,7 +158,7 @@ The batched data is increased by one dimension, and the size is `batch_size`. ```python image, label = next(train_dataset.create_tuple_iterator()) -image.shape, image.dtype +print(image.shape, image.dtype) ``` ```text diff --git a/tutorials/source_en/beginner/introduction.md b/tutorials/source_en/beginner/introduction.md index 16ba7691d9..7d0b28e884 100644 --- a/tutorials/source_en/beginner/introduction.md +++ b/tutorials/source_en/beginner/introduction.md @@ -38,7 +38,7 @@ The blue box on the left is the main MindSpore framework, which mainly provides Below the blue box is the MindSpore Data module, which can be used for data preprocessing, including data sampling, data iteration, data format conversion, and other data operations. Many debugging and tuning problems may occur during training. Therefore, the MindSpore Insight module visualizes debugging and tuning data such as the loss curve, operator execution status, and weight parameter variables, facilitating debugging and optimization during training. -The simplest way to ensure AI security is from the perspective of attack and defense. For example, attackers inject malicious data in the training phase to affect the inference capability of AI models. Therefore, MindSpore launches the MindSpore Armour module to provide an AI security mechanism for MindSpore. +The simplest scenario to ensure AI security is from the perspective of attack and defense. For example, attackers inject malicious data in the training phase to affect the inference capability of AI models. Therefore, MindSpore launches the MindSpore Armour module to provide an AI security mechanism for MindSpore. The content above the blue box is closer to algorithm development users, including the AI algorithm model library ModelZoo, development toolkit MindSpore DevKit for different fields, and advanced extension library MindSpore Extend. MindSciences, a scientific computing kit in MindSpore Extend, is worth mentioning. MindSpore is the first to combine scientific computing with deep learning, combine numerical computing with deep learning, and support electromagnetic simulation and drug molecular simulation through deep learning. @@ -48,7 +48,7 @@ After the neural network model is trained, you can export the model or load the - Supporting full-scenario collaboration - MindSpore is an industry-wide best practice. It provides unified model training, inference, and export APIs for data scientists and algorithm engineers. It supports flexible deployment in different scenarios such as the device, edge, and cloud, and promotes the prosperity of domains such as deep learning and scientific computing. + MindSpore is derived from industry-wide best practices. It provides unified model training, inference, and export APIs for data scientists and algorithm engineers. It supports flexible deployment in different scenarios such as the device, edge, and cloud, and promotes the prosperity of domains such as deep learning and scientific computing. - Provideing the Python programming paradigm to simplify AI programming diff --git a/tutorials/source_en/beginner/model.md b/tutorials/source_en/beginner/model.md index a714b2f1fd..cf90b388fa 100644 --- a/tutorials/source_en/beginner/model.md +++ b/tutorials/source_en/beginner/model.md @@ -128,7 +128,7 @@ hidden1.shape ### nn.ReLU -`nn.ReLU` layer, which adds a nonlinear activation function to the network, to help the neural network learn various complex features. +`nn.ReLU` layer adds a nonlinear activation function to the network, to help the neural network learn various complex features. ```python print(f"Before ReLU: {hidden1}\n\n") @@ -154,15 +154,15 @@ Before ReLU: [[-0.04736331 0.2939465 -0.02713677 -0.30988005 -0.11504349 -0.11 After ReLU: [[0. 0.2939465 0. 0. 0. 0. 0.18007928 0.43213072 0.12091967 0. 0.53133243 0.12605792 0.01825903 0.01287796 0.17238477 0. 0. 0. - 0. 0.05171938] + 1. 0.05171938] [0. 0.2939465 0. 0. 0. 0. 0.18007928 0.43213072 0.12091967 0. 0.53133243 0.12605792 0.01825903 0.01287796 0.17238477 0. 0. 0. - 0. 0.05171938] + 1. 0.05171938] [0. 0.2939465 0. 0. 0. 0. 0.18007928 0.43213072 0.12091967 0. 0.53133243 0.12605792 0.01825903 0.01287796 0.17238477 0. 0. 0. - 0. 0.05171938]] + 1. 0.05171938]] ``` ### nn.SequentialCell diff --git a/tutorials/source_en/beginner/quick_start.md b/tutorials/source_en/beginner/quick_start.md index 8127cc9c29..c1eea20856 100644 --- a/tutorials/source_en/beginner/quick_start.md +++ b/tutorials/source_en/beginner/quick_start.md @@ -16,7 +16,7 @@ from mindspore.dataset import vision ## Processing a Dataset -MindSpore provides Pipeline-based [Data Engine](https://www.mindspore.cn/docs/zh-CN/master/design/data_engine.html) and achieves efficient data preprocessing through [Dataset](https://www.mindspore.cn/tutorials/en/master/beginner/dataset.html) and [Transforms](https://www.mindspore.cn/tutorials/en/master/beginner/transforms.html). In addition, MindSpore provides domain-specific development libraries, such as [Text](https://gitee.com/mindspore/text/), [Vision](https://gitee.com/mindspore/vision/), etc. The development libraries provide encapsulation for a large number of datasets and can be downloaded quickly. In this tutorial, we use Vision's dataset as an example. +MindSpore provides Pipeline-based [Data Engine](https://www.mindspore.cn/docs/zh-CN/master/design/data_engine.html) and achieves efficient data preprocessing through [Dataset](https://www.mindspore.cn/tutorials/en/master/beginner/dataset.html) and [Transforms](https://www.mindspore.cn/tutorials/en/master/beginner/transforms.html). In addition, MindSpore provides domain-specific development libraries, such as [Text](https://gitee.com/mindspore/text/), [Vision](https://gitee.com/mindspore/vision/), etc. The development libraries provide encapsulation for a large number of datasets and can be downloaded quickly. In this tutorial, we use Vision to demonstrate the dataset operation. `mindvision.dataset` module includes various CV datasets, such as Mnist, Cifar, ImageNet, etc. In this tutorial, we use the Mnist dataset and pre-process dataset by using the data transformations provided by `mindspore.dataset`, after automatically downloaded. diff --git a/tutorials/source_en/beginner/tensor.md b/tutorials/source_en/beginner/tensor.md index 30a03300c2..a37873ce8e 100644 --- a/tutorials/source_en/beginner/tensor.md +++ b/tutorials/source_en/beginner/tensor.md @@ -277,7 +277,7 @@ The common structure of the sparse tensor is `> D0`. +`RowTensor` is used to compress tensors that are sparse in the dimension 0. If the dimension of `RowTensor` is `[L0, D1, D2, ..., DN ]` and the number of non-zero elements in the dimension 0 is `D0`, then `L0 >> D0`. The meaning of each parameter is as follows: - `indices`: 1-D integer tensor, indicating the position of non-zero elements in the dimension 0 of the sparse tensor. The shape is `[D0]`. diff --git a/tutorials/source_en/beginner/train.md b/tutorials/source_en/beginner/train.md index 1c1ec55f5a..18fed90a06 100644 --- a/tutorials/source_en/beginner/train.md +++ b/tutorials/source_en/beginner/train.md @@ -81,7 +81,7 @@ In the formula, $n$ is the batch size, and $η$ is a learning rate. In addition, - **Batch size**: specifies the size of each batch of data to be read. If the batch size is too small, it takes a long time and the gradient oscillation is serious, which is unfavorable to convergence. If the batch size is too large, the gradient directions of different batches do not change, and the local minimum value is easy to fall into. Therefore, you need to select a proper batch size to effectively improve the model precision and global convergence. -- **Learning rate**: If the learning rate is low, the convergence speed slows down. If the learning rate is high, unpredictable results such as no training convergence may occur. Gradient descent is a parameter optimization algorithm that is widely used to minimize model errors. The gradient descent estimates the parameters of the model by iterating and minimizing the loss function at each step. The learning rate is used to control the learning progress of a model during iteration. +- **Learning rate**: If the learning rate is low, the convergence speed slows down. If the learning rate is high, unpredictable results such as no training convergence may occur. Gradient descent is widely used in parameter optimization algorithms for minimizing model errors. The gradient descent estimates the parameters of the model by iterating and minimizing the loss function at each step. The learning rate is used to control the learning progress of a model during iteration. ```python epochs = 10 diff --git a/tutorials/source_zh_cn/beginner/tensor.ipynb b/tutorials/source_zh_cn/beginner/tensor.ipynb index 0afaeb4a53..94f3e27cee 100644 --- a/tutorials/source_zh_cn/beginner/tensor.ipynb +++ b/tutorials/source_zh_cn/beginner/tensor.ipynb @@ -466,7 +466,7 @@ "\n", "- `values`: 一维张量,表示`CSRTensor`相对应的非零元素的值,与`indices`长度相等。\n", "\n", - "- `shape`: 表示被压缩的稀疏张量的形状,数据类型为`Tuple`,目前仅支持2维`CSRTensor`。\n", + "- `shape`: 表示被压缩的稀疏张量的形状,数据类型为`Tuple`,目前仅支持2维`CSRTensor`。\n", "\n", "> `CSRTensor`的详细文档,请参考[mindspore.CSRTensor](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.CSRTensor.html)。\n", "\n", -- Gitee