Final Review Notes

English translation

These notes help connect the main concepts.

AI Applications uses a handwritten exam in which you complete key parts of provided Python/PyTorch code and work out tensor values, shapes and predictions. Separately practice predicting the results of short code from the existing notebooks before comparing with execution.

1. Start with the Input and Target

Next-character prediction in Weeks 12–13 predicts the next character at each position; sentiment classification in Week 14 assigns one label to a complete sentence. The prediction task determines the target and model-output shapes. Even when classification operations are shared, first identify what each axis represents.

Follow how the data changes from input to internal representation to logits. In these exercises, logits and targets are used to calculate loss, while the class selected by argmax is compared with the target to calculate accuracy. Distinguish the scores used for learning from the class index ultimately selected.

2. Turning Long Text into Training Examples

A window is a short input segment cut from a longer text. For next-character prediction, its target starts one character after the input. Window length determines how many characters an example reads; stride determines where the next example starts. They are different settings.

Overlapping source segments and carrying model state between examples are separate issues. The Week 13 exercise handles each example independently. Distinguish how source segments relate from how the code actually passes state.

3. Distinguish Sequence Output from State

RNNs, LSTMs and GRUs process ordered data using the current input and previous state. RNNs and GRUs maintain hidden state; LSTMs maintain both hidden and cell states. Gates control how much information is incorporated, using parameters learned during training.

The output for all time steps is not the same array as the final state. Even with batch_first=True, the final-state axes do not all adopt the input/output ordering. Inspect the returned values, then identify which tensor is passed to the linear layer for per-character class scores.

4. From Word IDs to Sentence Vectors

A token is a unit of text, an index identifies it in the vocabulary, and an embedding is a learnable vector retrieved with that index. The magnitude of an index is not a word’s meaning or sentiment strength. PAD marks empty positions added to align lengths; UNK represents a token absent from the vocabulary.

The Week 14 model represents a sentence by averaging word vectors while excluding PAD. Mean pooling is simple to compute but does not preserve word order. The roles of the representations introduced in the video remain applicable; the exercise uses preprocessing and a model that run in the current environment to inspect intermediate results.

5. What Can the Training Results Establish?

Loss measures the chosen training objective; accuracy is the fraction of predictions matching their labels. They are different metrics. Fitting short training examples does not by itself establish performance on new text or understanding of long context.

When comparing model metrics, also check the data and training conditions used to obtain them.