Deep Learning – Summer 2025/26

The objective of this course is to provide a comprehensive introduction to deep neural networks, which have consistently demonstrated superior performance across diverse domains, notably in processing and generating images, text, and speech.

The course focuses both on theory spanning from the basics to the latest advances, as well as on practical implementations in Python and PyTorch (students implement and train deep neural networks performing image classification, image segmentation, object detection, part of speech tagging, lemmatization, speech recognition, reading comprehension, and image generation). Basic Python skills are required, but no previous knowledge of artificial neural networks is needed; basic machine learning understanding is advantageous.

Students work either individually or in small teams on weekly assignments, including competition tasks, where the goal is to obtain the highest performance in the class.

Optionally, you can obtain a micro-credential after passing the course.

About

SIS code: NPFL138
Semester: summer
E-credits: 8
Examination: 3/4 C+Ex
Guarantor: Milan Straka

Timespace Coordinates

  • lectures: Czech lecture is held on Tuesday 13:10 in S5, English lecture on Tuesday 16:30 in S5; first lecture is on Feb 17
  • practicals: there are two parallel practicals, a Czech one on Thursday 9:00 in S5, and an English one on Thursday 10:40 in S5; first practicals are on Feb 19
  • consultations: entirely optional consultations take place on Wednesday 12:20 in S5; first consultations are on Feb 25

All lectures and practicals will be recorded and available on this website.

Lectures

1. Introduction to Deep Learning Slides PDF Slides CZ Lecture CZ UniApprox CZ Practicals EN Lecture EN UniApprox EN Practicals Questions numpy_entropy pca_first mnist_layers_activations

License

Unless otherwise stated, teaching materials for this course are available under CC BY-SA 4.0.

A micro-credential (aka micro-certificate) is a digital certificate attesting that you have gained knowledge and skills in a specific area. It should be internationally recognized and verifiable using an online EU-wide verification system.

A micro-credential can be obtained both by the university students and external participants.

External Participants

If you are not a university student, you can apply to the Deep Learning micro-credential course here and then attend the course along the university students. Upon successfully passing the course, a micro-credential is issued.

The price of the course is 5 000 Kč. If you require a tax receipt, please inform Magdaléna Kokešová within three business days after the payment.

The lectures run for 14 weeks from Feb 17 to May 22, with the examination period continuing until the end of September. Please note that the organization of the course and the setup instructions will be described at the first lecture; if you have already applied, you do not need to do anything else until that time.

University Students

If you have passed the course (in academic year 2024/25 or later) as a part of your study plan, you can obtain a micro-credential by paying only an administrative fee of 300 Kč; if you passed the course but it is not in your study plan, the administrative fee is 500 Kč. Detailed instructions how to get the micro-credential will be sent to the course participants during the examination period.


The lecture content, including references to study materials. The main study material is the Deep Learning Book by Ian Goodfellow, Yoshua Bengio and Aaron Courville, (referred to as DLB).

References to study materials cover all theory required at the exam, and sometimes even more – the references in italics cover topics not required for the exam.

1. Introduction to Deep Learning

 Feb 17 Slides PDF Slides CZ Lecture CZ UniApprox CZ Practicals EN Lecture EN UniApprox EN Practicals Questions numpy_entropy pca_first mnist_layers_activations

  • Random variables, probability distributions, expectation, variance, Bernoulli distribution, Categorical distribution [Sections 3.2, 3.3, 3.8, 3.9.1 and 3.9.2 of DLB]
  • Self-information, entropy, cross-entropy, KL-divergence [Section 3.13 of DLB]
  • Gaussian distribution [Section 3.9.3 of DLB]
  • Machine Learning Basics [Section 5.1-5.1.3 of DLB]
  • History of Deep Learning [Section 1.2 of DLB]
  • Linear regression [Section 5.1.4 of DLB]
  • Challenges Motivating Deep Learning [Section 5.11 of DLB]
  • Neural network basics
    • Neural networks as graphs [Chapter 6 before Section 6.1 of DLB]
    • Output activation functions [Section 6.2.2 of DLB, excluding Section 6.2.2.4]
    • Hidden activation functions [Section 6.3 of DLB, excluding Section 6.3.3]
    • Basic network architectures [Section 6.4 of DLB, excluding Section 6.4.2]
  • Universal approximation theorem

Requirements

To pass the practicals, you need to obtain at least 80 points, excluding the bonus points. Note that all surplus points (both bonus and non-bonus) will be transfered to the exam. In total, assignments for at least 120 points (not including the bonus points) will be available, and if you solve all the assignments (any non-zero amount of points counts as solved), you automatically pass the exam with grade 1.

Environment

The tasks are evaluated automatically using the ReCodEx Code Examiner.

The evaluation is performed using Python 3.11, PyTorch, Python Image Models, HF Transformers, and Gymnasium. You should install the exact version of these packages yourselves.

Teamwork

Solving assignments in teams (of size at most 3) is encouraged, but everyone has to participate (it is forbidden not to work on an assignment and then submit a solution created by other team members). All members of the team must submit in ReCodEx individually, but can have exactly the same sources/models/results. Each such solution must explicitly list all members of the team to allow plagiarism detection using this template.

No Cheating

Cheating is strictly prohibited and any student found cheating will be punished. The punishment can involve failing the whole course, or, in grave cases, being expelled from the faculty. While discussing assignments with any classmate is fine, each team must complete the assignments themselves, without using code they did not write (unless explicitly allowed). Of course, inside a team you are allowed to share code and submit identical solutions. Note that all students involved in cheating will be punished, so if you share your source code with a friend, both you and your friend will be punished. That also means that you should never publish your solutions.

AI Assistance when Solving Assignments

Relying blindly on AI during learning seems to have negative¹ effect² on skill acquisition. Therefore, you are not allowed to directly copy the assignment descriptions to GenAI and you are not allowed to directly use or copy-paste source code generated by GenAI. However, discussing your manually written code with GenAI is fine.

numpy_entropy

 Deadline: Mar 04, 22:00  2 points

The goal of this exercise is to familiarize with Python, NumPy and ReCodEx submission system. Start with the numpy_entropy.py.

Load a file specified in args.data_path, whose lines consist of data points of our dataset, and load a file specified in args.model_path, which describes a model probability distribution, with each line being a tab-separated pair of (data point, probability).

Then compute the following quantities using NumPy, and print them each on a separate line rounded on two decimal places (or inf for positive infinity, which happens when an element of data distribution has zero probability under the model distribution):

  • entropy H(data distribution)
  • cross-entropy H(data distribution, model distribution)
  • KL-divergence DKL(data distribution, model distribution)

Use natural logarithms to compute the entropies and the divergence.

  1. python3 numpy_entropy.py --data_path numpy_entropy_data_1.txt --model_path numpy_entropy_model_1.txt
Entropy: 0.96 nats
Crossentropy: 0.99 nats
KL divergence: 0.03 nats
  1. python3 numpy_entropy.py --data_path numpy_entropy_data_2.txt --model_path numpy_entropy_model_2.txt
Entropy: 0.96 nats
Crossentropy: inf nats
KL divergence: inf nats

Note that your results may be slightly different, depending on your CPU type and whether you use a GPU.

Entropy: 0.96 nats
Crossentropy: 0.99 nats
KL divergence: 0.03 nats
Entropy: 0.96 nats
Crossentropy: inf nats
KL divergence: inf nats
Entropy: 4.15 nats
Crossentropy: 4.23 nats
KL divergence: 0.08 nats
Entropy: 4.99 nats
Crossentropy: 5.03 nats
KL divergence: 0.04 nats

pca_first

 Deadline: Mar 04, 22:00  2 points

The goal of this exercise is to familiarize with PyTorch torch.Tensors, shapes and basic tensor manipulation methods. Start with the pca_first.py template.

In this assignment, you should compute the covariance matrix of several examples from the MNIST dataset, then compute the first principal component, and quantify the explained variance of it. It is fine if you are not familiar with terms like covariance matrix or principal component – the template contains a detailed description of what you have to do.

Finally, you might want to read the Introduction to PyTorch Tensors.

Note that your results may be slightly different, depending on your CPU type and whether you use a GPU.

  1. python3 pca_first.py --examples=1024 --iterations=64
Total variance: 53.12
Explained variance: 9.64%
  1. python3 pca_first.py --examples=8192 --iterations=128
Total variance: 53.05
Explained variance: 9.89%
  1. python3 pca_first.py --examples=55000 --iterations=1024
Total variance: 52.74
Explained variance: 9.71%

mnist_layers_activations

 Deadline: Mar 04, 22:00  2 points

Before solving the assignment, start by playing with example_pytorch_tensorboard.py, in order to familiarize with PyTorch and TensorBoard. After running the example, start TensorBoard in the same directory using tensorboard --logdir logs and open http://localhost:6006 in a browser and explore the generated logs.

Your goal is to modify the mnist_layers_activations.py template such that a user-specified neural network is constructed:

  • A number of hidden layers (including zero) can be specified on the command line using the parameter hidden_layers.
  • Activation function of these hidden layers can be also specified as a command line parameter activation, with supported values of none, relu, tanh and sigmoid.

Note that your results may be slightly different, depending on your CPU type and whether you use a GPU.

  1. python3 mnist_layers_activations.py --recodex --epochs=1 --hidden_layers=0 --activation=none
Epoch 1/1 1.1s loss=0.5340 accuracy=0.8632 dev:loss=0.2762 dev:accuracy=0.9278
  1. python3 mnist_layers_activations.py --recodex --epochs=1 --hidden_layers=1 --activation=none
Epoch 1/1 1.6s loss=0.3791 accuracy=0.8913 dev:loss=0.2372 dev:accuracy=0.9314
  1. python3 mnist_layers_activations.py --recodex --epochs=1 --hidden_layers=1 --activation=relu
Epoch 1/1 1.7s loss=0.3149 accuracy=0.9110 dev:loss=0.1458 dev:accuracy=0.9608
  1. python3 mnist_layers_activations.py --recodex --epochs=1 --hidden_layers=1 --activation=tanh
Epoch 1/1 1.7s loss=0.3333 accuracy=0.9049 dev:loss=0.1613 dev:accuracy=0.9582
  1. python3 mnist_layers_activations.py --recodex --epochs=1 --hidden_layers=1 --activation=sigmoid
Epoch 1/1 1.7s loss=0.4900 accuracy=0.8782 dev:loss=0.2185 dev:accuracy=0.9390
  1. python3 mnist_layers_activations.py --recodex --epochs=1 --hidden_layers=3 --activation=relu
Epoch 1/1 2.1s loss=0.2736 accuracy=0.9194 dev:loss=0.1089 dev:accuracy=0.9676

Note that your results may be slightly different, depending on your CPU type and whether you use a GPU.

  • python3 mnist_layers_activations.py --hidden_layers=0 --activation=none
Epoch  1/10 1.1s loss=0.5374 accuracy=0.8614 dev:loss=0.2768 dev:accuracy=0.9270
Epoch  5/10 1.1s loss=0.2779 accuracy=0.9220 dev:loss=0.2201 dev:accuracy=0.9430
Epoch 10/10 1.1s loss=0.2591 accuracy=0.9278 dev:loss=0.2139 dev:accuracy=0.9432
  • python3 mnist_layers_activations.py --hidden_layers=1 --activation=none
Epoch  1/10 1.7s loss=0.3791 accuracy=0.8922 dev:loss=0.2400 dev:accuracy=0.9290
Epoch  5/10 1.7s loss=0.2775 accuracy=0.9225 dev:loss=0.2217 dev:accuracy=0.9396
Epoch 10/10 1.7s loss=0.2645 accuracy=0.9247 dev:loss=0.2264 dev:accuracy=0.9378
  • python3 mnist_layers_activations.py --hidden_layers=1 --activation=relu
Epoch  1/10 1.7s loss=0.3178 accuracy=0.9104 dev:loss=0.1482 dev:accuracy=0.9566
Epoch  5/10 1.9s loss=0.0627 accuracy=0.9811 dev:loss=0.0827 dev:accuracy=0.9786
Epoch 10/10 1.9s loss=0.0240 accuracy=0.9930 dev:loss=0.0782 dev:accuracy=0.9810
  • python3 mnist_layers_activations.py --hidden_layers=1 --activation=tanh
Epoch  1/10 1.7s loss=0.3318 accuracy=0.9061 dev:loss=0.1632 dev:accuracy=0.9530
Epoch  5/10 1.7s loss=0.0732 accuracy=0.9798 dev:loss=0.0837 dev:accuracy=0.9768
Epoch 10/10 1.8s loss=0.0254 accuracy=0.9943 dev:loss=0.0733 dev:accuracy=0.9790
  • python3 mnist_layers_activations.py --hidden_layers=1 --activation=sigmoid
Epoch  1/10 1.7s loss=0.4985 accuracy=0.8788 dev:loss=0.2156 dev:accuracy=0.9382
Epoch  5/10 1.8s loss=0.1249 accuracy=0.9641 dev:loss=0.1077 dev:accuracy=0.9698
Epoch 10/10 1.8s loss=0.0605 accuracy=0.9837 dev:loss=0.0781 dev:accuracy=0.9762
  • python3 mnist_layers_activations.py --hidden_layers=3 --activation=relu
Epoch  1/10 2.1s loss=0.2700 accuracy=0.9213 dev:loss=0.1188 dev:accuracy=0.9680
Epoch  5/10 2.2s loss=0.0477 accuracy=0.9849 dev:loss=0.0787 dev:accuracy=0.9794
Epoch 10/10 2.3s loss=0.0248 accuracy=0.9916 dev:loss=0.1015 dev:accuracy=0.9762
  • python3 mnist_layers_activations.py --hidden_layers=10 --activation=relu
Epoch  1/10 3.4s loss=0.3562 accuracy=0.8911 dev:loss=0.1556 dev:accuracy=0.9598
Epoch  5/10 3.9s loss=0.0864 accuracy=0.9764 dev:loss=0.1164 dev:accuracy=0.9686
Epoch 10/10 4.0s loss=0.0474 accuracy=0.9874 dev:loss=0.0877 dev:accuracy=0.9774
  • python3 mnist_layers_activations.py --hidden_layers=10 --activation=sigmoid
Epoch  1/10 3.1s loss=1.9711 accuracy=0.1803 dev:loss=1.8477 dev:accuracy=0.2148
Epoch  5/10 3.2s loss=0.9947 accuracy=0.5815 dev:loss=0.8246 dev:accuracy=0.6392
Epoch 10/10 3.2s loss=0.4406 accuracy=0.8924 dev:loss=0.4239 dev:accuracy=0.8992

In the competitions, your goal is to train a model, and then predict target values on the given unannotated test set.

Submitting to ReCodEx

When submitting a competition solution to ReCodEx, you can include any number of files of any kind, and either submit them individually or compess them in a .zip file. However, there should be exactly one text file with the test set annotation (.txt) and at least one Python source (.py/ipynb) containing the model training and prediction. The Python sources are not executed, but must be included for inspection.

Competition Evaluation

  • For every submission, ReCodEx checks the above conditions (exactly one .txt, at least one .py/ipynb) and whether the given annotations can be evaluated without error. If not, it will report the corresponding error in the logs.

  • Before the first deadline, ReCodEx prints the exact achieved performance, but only if it is worse than the baseline.

    If you surpass the baseline, the assignment is marked as solved in ReCodEx and you immediately get regular points for the assignment. However, ReCodEx does not print the reached performance.

  • After the first deadline, the latest submission of every user surpassing the required baseline participates in a competition. Additional bonus points are then awarded according to the ordering of the performance of the participating submissions.

  • After the competition results announcement, ReCodEx starts to show the exact performance for all the already submitted solutions and also for the solutions submitted later.

Repeated Participation in Competitions

  • If a participant got non-zero points for a competition task already in previous years, they are treated slightly differently. Namely, every team with one or more returning participants still get competition points, but
    • the returning team results are not shown on the slides on the practicals;
    • the returning team results are shown in italics in ReCodEx;
    • the returning team results are not used to compute the thresholds for competition points.

What Is Allowed

  • You can use only the given annotated data for training and evaluation.
  • You can use the given annotated training data in any way.
  • You can use the given annotated development data for evaluation or hyperparameter tuning, but not for the training itself.
  • Additionally, you can use any unannotated or manually created data for training and evaluation.
  • The test set annotations must be the result of your system (so you cannot manually correct them; but your system can contain other parts than just trained models, like hand-written rules).
  • Do not use test set annotations in any way, if you somehow get access to them.
  • Unless stated otherwise, you can use any architecture to solve the competition task at hand, but the implementation must be created by you and you must understand it fully. You can of course take inspiration from any paper or existing implementation, but please reference it in that case.
    • You can of course use anything from the PyTorch package (but unless not stated otherwise, do not use models from torchvision, timm, torchaudio, …).
    • You can use any data augmentation (even implementations not written by you).
    • You can use any optimizer and any hyperparameter optimization method (even implementations not written by you).
  • If you utilize an already trained model, it must be trained only on the allowed training data, unless stated otherwise.

Install

  • What Python version to use

    The recommended Python version is 3.11. This version is used by ReCodEx to evaluate your solutions. Supported Python versions are 3.11–3.14.

    You can find out the version of your Python installation using python3 --version.

  • Installing to central user packages repository

    You can install all required packages to central user packages repository using python3 -m pip install --user --no-cache-dir --extra-index-url=https://download.pytorch.org/whl/cu128 npfl138.

    On Linux and Windows, the above command installs CUDA 12.8 PyTorch build, but you can change cu128 to:

    • cpu to get CPU-only (smaller) version,
    • cu124 to get CUDA 12.4 build,
    • rocm7.1 to get AMD ROCm 7.1 build (Linux only).

    On macOS, the --extra-index-url has no effect and the Metal support is installed in any case.

    To update the npfl138 package later, use python3 -m pip install --user --upgrade npfl138.

  • Installing to a virtual environment

    Python supports virtual environments, which are directories containing independent sets of installed packages. You can create a virtual environment by running python3 -m venv VENV_DIR followed by VENV_DIR/bin/pip install --no-cache-dir --extra-index-url=https://download.pytorch.org/whl/cu128 npfl138. (or VENV_DIR/Scripts/pip on Windows).

    Again, apart from the CUDA 12.8 build, you can change cu128 on Linux and Windows to:

    • cpu to get CPU-only (smaller) version,
    • cu124 to get CUDA 12.4 build,
    • rocm7.1 to get AMD ROCm 7.1 build (Linux only).

    To update the npfl138 package later, use VENV_DIR/bin/pip install --upgrade npfl138.

  • Windows installation

    • On Windows, it can happen that python3 is not in PATH, while py command is – in that case you can use py -m venv VENV_DIR, which uses the newest Python available, or for example py -3.11 -m venv VENV_DIR, which uses Python version 3.11.

    • If you encounter a problem creating the logs in the args.logdir directory, a possible cause is that the path is longer than 260 characters, which is the default maximum length of a complete path on Windows. However, you can increase this limit on Windows 10, version 1607 or later, by following the instructions.

  • MacOS installation

  • GPU support on Linux and Windows

    PyTorch supports NVIDIA GPU or AMD GPU out of the box, you just need to select appropriate --extra-index-url when installing the packages.

    If you encounter problems loading CUDA or cuDNN libraries, make sure your LD_LIBRARY_PATH does not contain paths to older CUDA/cuDNN libraries.

Git

  • Is it possible to keep the solutions in a Git repository?

    Definitely. Keeping the solutions in a branch of your repository, where you merge them with the course repository, is probably a good idea. However, please keep the cloned repository with your solutions private.

  • On GitHub, do not create a public fork containing your solutions.

    If you keep your solutions in a GitHub repository, please do not create a clone of the repository by using the Fork button; this way, the cloned repository would be public.

    • If you created a public fork and want to make it private, you need to start by pressing Leave fork network in the repository settings; only then you can change the visibility to private.

    Of course, if you want to create a pull request, GitHub requires a public fork and you need to create it, just do not store your solutions in it (so you might end up with two repositories, a public fork for pull requests and a private repo for your own solutions).

  • How to clone the course repository?

    To clone the course repository, run

    git clone https://github.com/ufal/npfl138
    

    This creates the repository in the npfl138 subdirectory; if you want a different name, add it as an additional parameter.

    To update the repository, run git pull inside the repository directory.

  • How to merge the course repository updates into a private repository with additional changes?

    It is possible to have a private repository that combines your solutions and the updates from the course repository. To do that, start by cloning your empty private repository, and then run the following commands in it:

    git remote add course_repo https://github.com/ufal/npfl138
    git fetch course_repo
    git checkout --no-track course_repo/master
    

    This creates a new remote course_repo and a clone of the master branch from it; however, git pull and git push in this branch will operate on the repository your cloned originally.

    To update your branch with the changes from the course repository, run

    git fetch course_repo
    git merge course_repo/master
    

    while in your branch (the command git pull --no-rebase course_repo master has the same effect). Of course, it might be necessary to resolve conflicts if both you and the course repository modified the same lines in the same files.

ReCodEx

  • What files can be submitted to ReCodEx?

    You can submit multiple files of any type to ReCodEx. There is a limit of 20 files per submission, with a total size of 20MB.

  • What file does ReCodEx execute and what arguments does it use?

    Exactly one file with py suffix must contain a line starting with def main(. Such a file is imported by ReCodEx and the main method is executed (during the import, __name__ == "__recodex__").

    The file must also export an argument parser called parser. ReCodEx uses its arguments and default values, but it overwrites some of the arguments depending on the test being executed; the template always indicates which arguments are set by ReCodEx and which are left intact.

  • What are the time and memory limits?

    The memory limit during evaluation is 1.5GB. The time limit varies, but it should be at least 10 seconds and at least twice the running time of my solution.

TensorBoard

  • Should TensorFlow be installed when using TensorBoard?

    When TensorBoard starts, it warns about a reduced feature set because of missing TensorFlow, notably

    TensorFlow installation not found - running with reduced feature set.
    

    Do not worry about the warning, there is no need to install TensorFlow.

  • Cannot start TensorBoard after installation

    If you cannot run the tensorboard command after installation, it is most likely not in your PATH. You can either:

    • start tensorboard using python3 -m tensorboard.main --logdir logs, or
    • add the directory with pip installed packages to your PATH (that directory is either bin/Scripts in your virtual environment if you use a virtual environment, or it should be ~/.local/bin on Linux and %UserProfile%\AppData\Roaming\Python\Python311 and %UserProfile%\AppData\Roaming\Python\Python311\Scripts on Windows).
  • What can be logged in TensorBoard? See the documentation of the SummaryWriter. Common possibilities are:

    • scalar values:
      summary_writer.add_scalar(name like "train/loss", value, step)
      
    • tensor values displayed as histograms or distributions:
      summary_writer.add_histogram(name like "train/output_layer", tensor, step)
      
    • images as tensors with shape [num_images, h, w, channels], where channels can be 1 (grayscale), 2 (grayscale + alpha), 3 (RGB), 4 (RGBA):
      summary_writer.add_images(name like "train/samples", images, step, dataformats="NHWC")
      
      Other dataformats are "HWC" (shape [h, w, channels]), "HW", "NCHW", "CHW".
    • possibly large amount of text (e.g., all hyperparameter values, sample translations in MT, …) in Markdown format:
      summary_writer.add_text(name like "hyperparameters", markdown, step)
      
    • audio as tensors with shape [1, samples] and values in [1,1][-1,1] range:
      summary_writer.add_audio(name like "train/samples", clip, step, [sample_rate])
      
    • traced modules using:
      summary_writer.add_graph(module, example_input_batch)
      

Requirements

To pass the practicals, you need to obtain at least 80 points, excluding the bonus points. Note that all surplus points (both bonus and non-bonus) will be transfered to the exam. In total, assignments for at least 120 points (not including the bonus points) will be available, and if you solve all the assignments (any non-zero amount of points counts as solved), you automatically pass the exam with grade 1.

To pass the exam, you need to obtain at least 60, 75, or 90 points out of 100-point exam to receive a grade 3, 2, or 1, respectively. The exam consists of 100-point-worth questions from the list below (the questions are randomly generated, but in such a way that there is at least one question from every but the first lecture). In addition, you can get surplus points from the practicals and at most 10 points for community work (i.e., fixing slides or reporting issues) – but only the points you already have at the time of the exam count. You can take the exam without passing the practicals first.

Exam Questions

Lecture 1 Questions

  • Considering a neural network with DD input neurons, a single hidden layer with HH neurons, KK output neurons, hidden activation ff and output activation aa, list its parameters (including their size) and write down how the output is computed. [5]

  • List the definitions of frequently used MLP output layer activations (the ones producing parameters of a Bernoulli distribution and a categorical distribution). Then write down three commonly used hidden layer activations (sigmoid, tanh, ReLU). [5]

  • Formulate the Universal approximation theorem. [5]