diff --git a/tutorials/source_en/beginner/autograd.md b/tutorials/source_en/beginner/autograd.md index b90d3fe09b22449edde6370c968edddef9d32858..b8b520b2d53662b4089452fe817080bb1bb0f37f 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 64ec05d34b120d7558f1956c8c60b280ebb8abdb..2a29dabb5b9f565e48612d1e297e4bf090f54cf8 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 fc7729373ba76e5ca477623710883312cadb456d..46d5bda049ac7e411590b7b8c6c0099dc0b5fb3a 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 14302176bd2709684d7ca866ba6a66f1cdd4299f..44284b74211be624935fa5224250bdc90610679c 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 2e673103ebb80c5a806d49a8306ffbb17b0baf99..ab97335e77a5e66f7c894559b9d3c3f789d41701 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/r1.9/design/data_engine.html) and achieves efficient data preprocessing through [Dataset](https://www.mindspore.cn/tutorials/en/r1.9/beginner/dataset.html) and [Transforms](https://www.mindspore.cn/tutorials/en/r1.9/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/r1.9/design/data_engine.html) and achieves efficient data preprocessing through [Dataset](https://www.mindspore.cn/tutorials/en/r1.9/beginner/dataset.html) and [Transforms](https://www.mindspore.cn/tutorials/en/r1.9/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 d753c6ed3e0d1c23f7b70f4522b90c11c1200ad0..4dab28edc3b7099f1f679e08d04d97cd4f8cf8a7 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 0fda77427147fc72d2c8041bd73b80ae35240c4a..05c5e14b1b894a92b5098f412d1727cf13461420 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 3da1540afa0197f48c5b51c3ea13dbc34abfb61d..08a281acb6a69cb978564c9572ffaaf503f2e1e7 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/r1.9/api_python/mindspore/mindspore.CSRTensor.html)。\n", "\n",