هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
What the course covers
PyTorch tensors: how to make them, change them and read their shape.
- Datasets and DataLoaders: how data moves into a model.
- Linear regression with
nn.Moduleand gradient descent. - Full training loops: loss, backward pass and optimizer.
- Many inputs and many outputs with
nn.Linear. - Logistic regression for classification, plus a final project.
| Module | Main focus |
|---|---|
| Module 1 · about 3 hours | Exploring Tensors: 1-D and 2-D tensors, operations, shape, dtype, autograd |
| Module 2 · about 1 hour | Building Datasets in PyTorch: Dataset class, __len__, __getitem__, transforms |
| Module 3 · about 3 hours | Linear Regression and Gradient Descent: nn.Module, MSE, learning rate, stopping |
| Module 4 · about 3 hours | Training the PyTorch Way: DataLoader, optimizers, batches, epochs, data splits |
| Module 5 · about 2 hours | Multiple Inputs and Outputs: nn.Linear, weight matrices, vectorized cost |
| Module 6 · about 2 hours | Logistic Regression: sigmoid, cross-entropy, maximum likelihood, regularization |
| Module 7 · about 5 hours | Final Project and Quiz: League of Legends match prediction |
Module 1: Exploring Tensors
Exploring Tensors: 1-D and 2-D tensors, operations, shape, dtype, autograd.
- A tensor is an array of numbers with a shape. A 1-D tensor is a vector; a 2-D tensor is a matrix.
shapegives the size of each dimension.dtypegives the number type.numel()gives the total count.- autograd records the operations on tensors.
backward()fills the.gradfield with gradients.
Module 2: Building Datasets in PyTorch
Building Datasets in PyTorch: Dataset class, __len__, __getitem__, transforms.
- A custom Dataset class needs
__len__(number of rows) and__getitem__(return one row). transforms.Compose([...])chains preprocessing steps. A DataLoader turns a dataset into batches and can shuffle the rows.
Module 3: Applying Linear Regression and Gradient Descent
Linear Regression and Gradient Descent: nn.Module, MSE, learning rate, stopping.
- A model is an
nn.Module. You writeforward()and call the model like a function. state_dict()holds the learned parameters: weights and bias.- MSE is the mean squared error. Gradient descent moves each weight against its gradient.
- The update is
w = w - lr * grad. A big learning rate overshoots; a small one is slow.
Module 4: Training Linear Regression the PyTorch Way
Training the PyTorch Way: DataLoader, optimizers, batches, epochs, data splits.
- One step:
optimizer.zero_grad(),loss.backward(), thenoptimizer.step(). - Batch descent uses all rows, stochastic uses one row, mini-batch uses a small group.
- An epoch is one pass over the training set. Batch size and learning rate change convergence.
- Split the data into train, validation and test. Low train loss with high validation loss is overfitting.
Module 5: Multiple Inputs and Outputs
Multiple Inputs and Outputs: nn.Linear, weight matrices, vectorized cost.
nn.Linear(in_features, out_features)holds a weight matrix and a bias vector. One input gives one weight; many inputs give a matrix.- A multi-output model returns one value per target, and vectorized code trains it in one loop.
Module 6: Applying Logistic Regression for Classification
Logistic Regression: sigmoid, cross-entropy, maximum likelihood, regularization.
- Logistic regression uses the sigmoid to turn a score into a probability from 0 to 1. A threshold (often 0.5) then gives the class.
- Cross-entropy is better than MSE for classification. It comes from maximum likelihood.
nn.Sequentialstacks layers in order. Regularization helps the model generalize.
Module 7: Final Project and Quiz
Final Project and Quiz: League of Legends match prediction.
- The project uses in-game statistics to predict League of Legends match results.
- The steps are the same as in the labs: load data, build the model, train, evaluate. Read the rubric before you submit.
Check yourself
Answer each question first, then open it to check the answer.
1What is a PyTorch tensor? a) A table inside a database · b) A Python list with no type · c) A saved model file · d) An array of numbers with a shape
d) An array of numbers with a shape. A tensor is a multi-dimensional array. It has a shape and a data type.
2Which attribute tells you how many values a tensor holds in total? a) shape · b) dtype · c) numel() · d) grad
c) numel(). numel() counts every value in the tensor, like rows times columns.
3What does backward() do? a) It loads the data · b) It computes gradients for the tracked tensors · c) It saves the model · d) It prints the loss
b) It computes gradients for the tracked tensors. Autograd records the graph, then backward() walks it backwards to get gradients.
4Which two methods must a custom Dataset class provide? a) fit and predict · b) __len__ and __getitem__ · c) forward and backward · d) save and load
b) __len__ and __getitem__. The DataLoader asks the dataset for its size and for one sample at a time.
5What is the job of a DataLoader? a) To build batches from a dataset · b) To compute the gradients · c) To define the loss function · d) To clean the labels by hand
a) To build batches from a dataset. A DataLoader groups samples into batches and can shuffle them.
6What does state_dict() store? a) The learning rate · b) The names of the columns · c) The test rows · d) The model parameters (weights and bias)
d) The model parameters (weights and bias). state_dict() is a dictionary of the weights and biases of the module.
7What happens when the learning rate is far too big? a) Training is always faster and stable · b) The steps overshoot and the loss may grow · c) The model has no parameters · d) The data is shuffled for you
b) The steps overshoot and the loss may grow. Big steps can pass the minimum, so the loss jumps or becomes NaN.
8What is one epoch? a) One pass over all the training data · b) One forward pass on one row · c) One saved checkpoint · d) One layer of the network
a) One pass over all the training data. An epoch is one full pass over the training rows.
9Which order is correct for one PyTorch training step? a) step, backward, zero_grad · b) zero_grad, backward, step · c) backward, step, zero_grad · d) zero_grad, step, backward
b) zero_grad, backward, step. Clear the old gradients, compute new ones, then update the weights.
10nn.Linear(5, 3) maps an input of how many features to how many outputs? a) 3 inputs to 5 outputs · b) 5 inputs to 5 outputs · c) 5 inputs to 3 outputs · d) 3 inputs to 3 outputs
c) 5 inputs to 3 outputs. The first number is the input size, the second is the output size.
11Which function turns a score into a probability between 0 and 1? a) ReLU · b) Sigmoid · c) argmax · d) MSE
b) Sigmoid. Sigmoid maps any score into the range 0 to 1.
12Why is cross-entropy used instead of MSE for classification? a) It punishes confident wrong answers and fits probabilities · b) It needs no labels at all · c) It always gives a loss of zero · d) It works only with numbers
a) It punishes confident wrong answers and fits probabilities. Cross-entropy comes from maximum likelihood and punishes wrong confidence.
Study and exam tips
Know the tensor attributes: shape, dtype, numel and .grad.
- Keep the training order clear: zero the gradients, backward, step.
- Learn what changes with batch size, epochs and learning rate.
- Remember the reason for cross-entropy: probabilities, not plain numbers.