Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
9b674db
Update cnn_manual description to mention PyTorch instead of TensorFlow
davidruda Mar 23, 2024
4bce475
Remove obsolete sentence.
foxik Mar 23, 2024
557c470
Add missing torch suubmodule import to cifar10.py
akumm2k Mar 23, 2024
3a6cb5d
Fix cifar10 `Dataset` type hint
akumm2k Mar 23, 2024
2dcd474
Remove unnecessary annotation.
foxik Mar 23, 2024
743dd44
Reflow line longer than 119 characters.
foxik Mar 23, 2024
051deba
Add a question about CutMix.
foxik Mar 25, 2024
2cf184b
Add lecture 6 slides.
foxik Mar 25, 2024
4b420d9
Add link to the recording of Czech lecture 6.
foxik Mar 25, 2024
6487226
Fix link to R-CNN paper.
foxik Mar 25, 2024
9979814
Add link to the recording of English lecture 6.
foxik Mar 26, 2024
4ee4056
Fix error in mnist_ensemble task description.
foxik Mar 26, 2024
3038d28
Move Group Normalization to the list of required topics.
foxik Mar 26, 2024
5ce8590
Add batch size in RPN training.
foxik Mar 26, 2024
9c8050a
Fix a type (the types are evaluated in global scope).
foxik Mar 26, 2024
8349ab5
Provide `transform` also in the `TransformedDataset`.
foxik Mar 26, 2024
8ef8b38
Improve loading of empty values.
foxik Mar 26, 2024
e691c01
Update the ignore file.
foxik Mar 27, 2024
10f1eff
Add assignments of the lecture 6.
foxik Mar 27, 2024
2572453
Mention that next Monday is Easter Monday.
foxik Mar 27, 2024
61034e9
Add link to the recordings of practicals 6.
foxik Mar 27, 2024
27e6bbf
Use correct metric name.
foxik Mar 27, 2024
e5745c2
Fix the huber_loss figure.
foxik Mar 27, 2024
c95da6a
Reformulate the conditions for obtaining regular and bonus points.
foxik Mar 27, 2024
0435c55
Grammar fixes mentioned in #19.
foxik Apr 2, 2024
7dd6814
Change order in verification to bias-kernel-inputs.
foxik Apr 2, 2024
a25b41b
Increase the tolerance during backpropagation verification.
foxik Apr 2, 2024
d1602d7
Add lecture 7 assignment.
foxik Apr 2, 2024
bb63d5e
Make the import sorted.
foxik Apr 2, 2024
5508a17
Fix type annotation.
foxik Apr 2, 2024
770ef78
Fix a typo.
foxik Apr 2, 2024
d1f155b
Add explicit sizes of train/dev/test splits.
foxik Apr 3, 2024
24e1405
Correctly type the TransformedDataset.
foxik Apr 3, 2024
b0ab807
Unpack tuples when calling transform.
foxik Apr 3, 2024
e488e11
Minor formatting improvements and fixes.
foxik Apr 3, 2024
b80b722
Add development version of cags_dataset module.
foxik Apr 3, 2024
d5db482
Add link to recordings of practicals 7.
foxik Apr 3, 2024
5bc873d
Remove unused import.
foxik Apr 3, 2024
94b2b56
Make verification more robust to rounding errors around 0.
foxik Apr 4, 2024
2fcdcf8
Make the instructions less ambiguous by not using pronouns.
foxik Apr 4, 2024
51803a4
Update cags_dataset and svhn_dataset modules.
foxik Apr 5, 2024
3c39967
Remove the development version of cags_dataset.
foxik Apr 5, 2024
42440ce
Add updated version of the CIFAR10 dataset.
foxik Apr 8, 2024
7b16c0d
Add slides for lecture 8.
foxik Apr 8, 2024
fe3bd1c
Add link to the Czech lecture 8 recording.
foxik Apr 8, 2024
376fc7b
Correctly use signed int64 type for the labels.
foxik Apr 8, 2024
1fedee8
Correctly type a generic callable as `Callable[..., Any]`.
foxik Apr 8, 2024
a7cfd54
Correctly type `get_value` and `get_value_of_kind`.
foxik Apr 8, 2024
4ebc353
Add link to the English lecture 8 recording.
foxik Apr 9, 2024
6edbe8b
Add assignments of the lecture 8.
foxik Apr 13, 2024
45f2d60
Fix typos
petrkasp Apr 14, 2024
f6de38f
Merge pull request #21 from petrkasp/master
foxik Apr 14, 2024
5e03a97
The gradient clipping has been implemented since Keras 2.
foxik Apr 14, 2024
849a68c
Let gradient clipping be actually implemented by students.
foxik Apr 14, 2024
fd3e162
Add a forgotten `return inputs`.
foxik Apr 14, 2024
4a32330
Add link to the lecture 8 practicals recording.
foxik Apr 14, 2024
9aa8cf6
Fix an error in the template, causing padding chars to be processed.
foxik Apr 14, 2024
1f51549
Do not use keras.utils.set_random_seed.
foxik Apr 15, 2024
fc34ac5
Add lecture 9 slides.
foxik Apr 15, 2024
0bd26bc
Make ELMO optional.
foxik Apr 15, 2024
cbd517c
Add link to Czech lecture 9 recording.
foxik Apr 15, 2024
8ee415c
Remove BPE and Wordpieces from lecture 9.
foxik Apr 15, 2024
1039731
Remove unused image.
foxik Apr 15, 2024
0b6b501
Add discreet colors in the LSTM and GRU illustrations.
foxik Apr 15, 2024
c5bc7ef
Consistent name of the lecture with slides.
foxik Apr 15, 2024
ececa4e
Move unused questions to lecture 10.
foxik Apr 15, 2024
964ed6d
Fix incorrect index.
foxik Apr 15, 2024
1b099b4
Add a link to recording of English lecture 9.
foxik Apr 16, 2024
ebccee7
Improve TODO note formulation.
foxik Apr 16, 2024
eb3172e
Improve description of the output layer TODO note.
foxik Apr 16, 2024
b41350f
Fixed some typos in tagger_cle.py
LuckaAm Apr 16, 2024
a631891
Merge pull request #22 from LuckaAm/patch-1
foxik Apr 16, 2024
ef94fc7
Improve comments (formatting, a typo).
foxik Apr 16, 2024
e7953bb
Add tensorboard_projector.
foxik Apr 16, 2024
41d961e
Add descriptions of lecture 9 assignments.
foxik Apr 17, 2024
3fcec93
Add link to lecture 9 practicals recordings.
foxik Apr 17, 2024
282d78a
Mentioning that logits are enough.
foxik Apr 18, 2024
51b7519
Rename section to Span Labeling.
foxik Apr 18, 2024
de284f6
Add .gitignore
nimrossum Apr 18, 2024
a9048e3
Add updated version of the CIFAR10 dataset.
foxik Apr 8, 2024
844862f
Add slides for lecture 8.
foxik Apr 8, 2024
1cade00
Add link to the Czech lecture 8 recording.
foxik Apr 8, 2024
18846b8
Correctly use signed int64 type for the labels.
foxik Apr 8, 2024
2c50b48
Correctly type a generic callable as `Callable[..., Any]`.
foxik Apr 8, 2024
b4697b1
Correctly type `get_value` and `get_value_of_kind`.
foxik Apr 8, 2024
fdae69d
Add link to the English lecture 8 recording.
foxik Apr 9, 2024
8e79214
Add assignments of the lecture 8.
foxik Apr 13, 2024
944ec9f
Fix typos
petrkasp Apr 14, 2024
4a45a19
The gradient clipping has been implemented since Keras 2.
foxik Apr 14, 2024
57b6fff
Let gradient clipping be actually implemented by students.
foxik Apr 14, 2024
713b9a5
Add a forgotten `return inputs`.
foxik Apr 14, 2024
62b3331
Add link to the lecture 8 practicals recording.
foxik Apr 14, 2024
021dda6
Fix an error in the template, causing padding chars to be processed.
foxik Apr 14, 2024
992c9ca
Do not use keras.utils.set_random_seed.
foxik Apr 15, 2024
cd3ff64
Add lecture 9 slides.
foxik Apr 15, 2024
008f760
Make ELMO optional.
foxik Apr 15, 2024
a7db031
Add link to Czech lecture 9 recording.
foxik Apr 15, 2024
b3fdaba
Remove BPE and Wordpieces from lecture 9.
foxik Apr 15, 2024
e361e9f
Remove unused image.
foxik Apr 15, 2024
37741de
Add discreet colors in the LSTM and GRU illustrations.
foxik Apr 15, 2024
00a2de3
Consistent name of the lecture with slides.
foxik Apr 15, 2024
bd8328e
Move unused questions to lecture 10.
foxik Apr 15, 2024
0ac55d5
Fix incorrect index.
foxik Apr 15, 2024
5ccab42
Add a link to recording of English lecture 9.
foxik Apr 16, 2024
e8390c9
Improve TODO note formulation.
foxik Apr 16, 2024
c0c4646
Improve description of the output layer TODO note.
foxik Apr 16, 2024
bfd1812
Fixed some typos in tagger_cle.py
LuckaAm Apr 16, 2024
fab6a71
Improve comments (formatting, a typo).
foxik Apr 16, 2024
7636e50
Add tensorboard_projector.
foxik Apr 16, 2024
ea8b053
Add descriptions of lecture 9 assignments.
foxik Apr 17, 2024
d73cc1b
Add link to lecture 9 practicals recordings.
foxik Apr 17, 2024
0f82c2a
Mentioning that logits are enough.
foxik Apr 18, 2024
11ddc7f
Rename section to Span Labeling.
foxik Apr 18, 2024
0831526
Scale the first MFCC for consistency with the dataset.
foxik Apr 18, 2024
f4777d0
Reorder imports.
foxik Apr 18, 2024
1064bab
Reorder imports.
foxik Apr 18, 2024
afac1b3
Simplify types.
foxik Apr 18, 2024
b63e9d2
Use correct type description for int64 values in TFRecords.
foxik Apr 18, 2024
9b2c3c6
Add __iter__ method to morpho_dataset.Vocabulary.
foxik Apr 18, 2024
602d180
Add __iter__ method to common_voice_cs.Vocabulary.
foxik Apr 18, 2024
ff130ac
Allow more finegrained overrides in TrainableModule.
foxik Apr 18, 2024
994e747
Add missing spaces to make pycodestyle happy.
foxik Apr 18, 2024
6adef67
Add template for the tagger_ner assignment.
foxik Apr 18, 2024
ef9b6a4
Fix test and example outputs for tagger_ner.
foxik Apr 19, 2024
8924827
Explain that the transition matrix should not follow data.
foxik Apr 19, 2024
ec2e5cf
Improve the formulation about transition matrix.
foxik Apr 19, 2024
712474f
Explicitly formulate validity of BIO-encoded sequence.
foxik Apr 19, 2024
c3e76e5
Better line break of math formula.
foxik Apr 19, 2024
b4ff423
Describe how to enforce conditions on the border tags.
foxik Apr 19, 2024
3c425ec
Add used but forgotten type.
foxik Apr 19, 2024
ee6b948
Normalize by 1 when the gold tag sequence is empty.
foxik Apr 19, 2024
0d1341d
Add morpho_dataset.py also to labs/09.
foxik Apr 19, 2024
8e16e74
Add missing space in tagger_we.py
milantru Apr 20, 2024
83827c2
Merge pull request #23 from milantru/patch-1
foxik Apr 20, 2024
2ebaffb
Add a missing space also in tagger_cle and tagger_ner.
foxik Apr 20, 2024
29392ed
Add support for ignore_index in EditDistanceMetric.
foxik Apr 21, 2024
9250d95
Correctly load MFCCs in the CommonVoiceCs class.
foxik Apr 21, 2024
2ee7324
Add templates for ctc_loss and speech_recognition assignments.
foxik Apr 21, 2024
1f5edd1
Add link to the speech_recognition template.
foxik Apr 21, 2024
a3dd37a
Fix typo in comment
davidruda Apr 21, 2024
e1f0b42
Merge pull request #24 from Davideck123/master
foxik Apr 22, 2024
29f9298
Add slides for lecture 10.
foxik Apr 22, 2024
67a9218
Merge remote-tracking branch 'upstream/master'
nimrossum Apr 22, 2024
15d1a1f
Solve sequence classification
nimrossum Apr 23, 2024
666281c
Work on tagger_we and tagger_cle and tagger_competition
nimrossum Apr 23, 2024
25cea35
Ignore zip and pkl
nimrossum Apr 23, 2024
536a189
Add attempts at svhn
nimrossum Apr 23, 2024
41da916
Fix tagger_we
nimrossum Apr 23, 2024
a0455ea
Add progress
nimrossum Apr 28, 2024
d0eb61d
Solve tagger_cle
nimrossum Apr 28, 2024
56b30a0
Add tagger_competition
nimrossum Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.venv
logs
*.tfrecord
*.npz
*.zip
*.pkl
90 changes: 90 additions & 0 deletions exam/questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@

- Compare Cutout and DropBlock. [5]

- Describe in detail how is CutMix performed. [5]

- Describe Squeeze and Excitation applied to a ResNet block. [5]

- Draw the Mobile inverted bottleneck block (including explanation of separable
Expand All @@ -119,3 +121,91 @@
channels. Write down (or derive) the equation of transposed convolution
(or equivalently backpropagation through a convolution to its inputs). [5]

#### Questions@:, Lecture 6 Questions
- Describe the differences among semantic segmentation, image classification,
object detection, and instance segmentation, and write down which metrics
are used for these tasks. [5]

- Write down how is $\mathit{AP}_{50}$ computed. [5]

- Considering a Fast-RCNN architecture, draw overall network architecture,
explain what a RoI-pooling layer is, show how the network parametrizes
bounding boxes and write down the loss. Finally, describe non-maximum
suppression and how the Fast-RCNN prediction is performed. [10]

- Considering a Faster-RCNN architecture, describe the region proposal network
(what are anchors, architecture including both heads, how are the coordinates
of proposals parametrized, what does the loss look like). [10]

- Considering Mask-RCNN architecture, describe the additions to a Faster-RCNN
architecture (the RoI-Align layer, the new mask-producing head). [5]

- Write down the focal loss with class weighting, including the commonly used
hyperparameter values. [5]

- Draw the overall architecture of a RetinaNet architecture (the computation of
$C_1, \ldots, C_7$, the FPN architecture computing $P_1, \ldots, P_7$
including the block combining feature maps of different resolutions; the
classification and bounding box generation heads, including their output
size). Write down the losses for both heads. [10]

- Describe GroupNorm, and compare it to BatchNorm and LayerNorm. [5]

#### Questions@:, Lecture 8 Questions
- Write down how the Long Short-Term Memory (LSTM) cell operates, including
the explicit formulas. Also mention the forget gate bias. [10]

- Write down how the Gated Recurrent Unit (GRU) operates, including
the explicit formulas. [10]

- Describe Highway network computation. [5]

- Why the usual dropout cannot be used on recurrent state? Describe
how the problem can be alleviated with variational dropout. [5]

- Describe layer normalization including all its parameters, and write down how
it is computed (be sure to explicitly state over what is being normalized in
case of fully connected layers and convolutional layers). [5]

- Draw a tagger architecture utilizing word embeddings, recurrent
character-level word embeddings (including how are these computed from
individual characters), and two sentence-level bidirectional RNNs (explaining
the bidirectionality) with a residual connection. Where would you put the
dropout layers? [10]

#### Questions@:, Lecture 9 Questions
- In the context of named entity recognition, describe what the BIO encoding
is and why it is used. [5]

- Write down the dynamic programming algorithm for decoding a BIO-tag sequence,
including its asymptotic complexity. [10]

- In the context of CTC loss, describe regular and extended labelings and
write down the algorithm for computing the log probability of a gold label
sequence $\boldsymbol y$. [10]

- Describe how CTC predictions are performed using a beam-search. [5]

- Draw the CBOW architecture from `word2vec`, including the sizes of the inputs
and the sizes of the outputs and used non-linearities. Also make sure to
indicate where the embeddings are being trained. [5]

- Draw the SkipGram architecture from `word2vec`, including the sizes of the
inputs and the sizes of the outputs and used non-linearities. Also make sure
to indicate where the embeddings are being trained. [5]

- Describe the hierarchical softmax used in `word2vec`. [5]

- Describe the negative sampling proposed in `word2vec`, including
the choice of distribution of negative samples. [5]

#### Questions@:, Lecture 10 Questions
- Write down why are subword units used in text processing, and describe the BPE
algorithm for constructing a subword dictionary from a large corpus. [5]

- Write down why are subword units used in text processing, and describe the
WordPieces algorithm for constructing a subword dictionary from a large
corpus. [5]

- Pinpoint the differences between the BPE and WordPieces algorithms, both
during dictionary construction and during inference. [5]
2 changes: 1 addition & 1 deletion labs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ logs/
*.h5
*.keras
*.npz
*.pickle
*.tfrecord
*.zip
3 changes: 2 additions & 1 deletion labs/04/cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def dataset(self, transform: Callable[[dict[str, np.ndarray]], Any] | None = Non
return CIFAR10.TorchDataset(self, transform)

class TorchDataset(torch.utils.data.Dataset):
def __init__(self, dataset: "Dataset", transform: Callable[[dict[str, np.ndarray]], Any] | None) -> None:
def __init__(self, dataset: "CIFAR10.Dataset",
transform: Callable[[dict[str, np.ndarray]], Any] | None) -> None:
self._dataset = dataset
self._transform = transform

Expand Down
99 changes: 99 additions & 0 deletions labs/04/cifar10_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import os
import sys
from typing import Any, Callable, Sequence, TextIO, TypedDict
import urllib.request

import numpy as np
import torch


class CIFAR10:
H: int = 32
W: int = 32
C: int = 3
LABELS: list[str] = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"]

Element = TypedDict("Element", {"image": np.ndarray, "label": np.ndarray})
Elements = TypedDict("Elements", {"images": np.ndarray, "labels": np.ndarray})

_URL: str = "https://ufal.mff.cuni.cz/~straka/courses/npfl138/2324/datasets/cifar10_competition.npz"

class Dataset(torch.utils.data.Dataset):
def __init__(self, data: "CIFAR10.Elements") -> None:
self._data = data
self._data["labels"] = self._data["labels"].ravel()

@property
def data(self) -> "CIFAR10.Elements":
return self._data

def __len__(self) -> int:
return len(self._data["images"])

def __getitem__(self, index: int) -> "CIFAR10.Element":
return {key.removesuffix("s"): value[index] for key, value in self._data.items()}

def transform(self, transform: Callable[["CIFAR10.Element"], Any]) -> "CIFAR10.TransformedDataset":
return CIFAR10.TransformedDataset(self, transform)

class TransformedDataset(torch.utils.data.Dataset):
def __init__(self, dataset: torch.utils.data.Dataset, transform: Callable[..., Any]) -> None:
self._dataset = dataset
self._transform = transform

def __len__(self) -> int:
return len(self._dataset)

def __getitem__(self, index: int) -> Any:
item = self._dataset[index]
return self._transform(*item) if isinstance(item, tuple) else self._transform(item)

def transform(self, transform: Callable[..., Any]) -> "CIFAR10.TransformedDataset":
return CIFAR10.TransformedDataset(self, transform)

def __init__(self, size: dict[str, int] = {}) -> None:
path = os.path.basename(self._URL)
if not os.path.exists(path):
print("Downloading CIFAR-10 dataset...", file=sys.stderr)
urllib.request.urlretrieve(self._URL, filename="{}.tmp".format(path))
os.rename("{}.tmp".format(path), path)

cifar = np.load(path)
for dataset in ["train", "dev", "test"]:
data = {key[len(dataset) + 1:]: cifar[key][:size.get(dataset, None)]
for key in cifar if key.startswith(dataset)}
setattr(self, dataset, self.Dataset(data))

train: Dataset
dev: Dataset
test: Dataset

# Evaluation infrastructure.
@staticmethod
def evaluate(gold_dataset: Dataset, predictions: Sequence[int]) -> float:
gold = gold_dataset.data["labels"]

if len(predictions) != len(gold):
raise RuntimeError("The predictions are of different size than gold data: {} vs {}".format(
len(predictions), len(gold)))

correct = sum(gold[i] == predictions[i] for i in range(len(gold)))
return 100 * correct / len(gold)

@staticmethod
def evaluate_file(gold_dataset: Dataset, predictions_file: TextIO) -> float:
predictions = [int(line) for line in predictions_file]
return CIFAR10.evaluate(gold_dataset, predictions)


if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--evaluate", default=None, type=str, help="Prediction file to evaluate")
parser.add_argument("--dataset", default="dev", type=str, help="Gold dataset to evaluate")
args = parser.parse_args()

if args.evaluate:
with open(args.evaluate, "r", encoding="utf-8-sig") as predictions_file:
accuracy = CIFAR10.evaluate_file(getattr(CIFAR10(), args.dataset), predictions_file)
print("CIFAR10 accuracy: {:.2f}%".format(accuracy))
Loading