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.
Write a short string from Week 12 beside a review from Week 14. If you mark what the model must predict next to each input, how do the number and form of the targets differ?
Look side by side at the input, target and logit shapes printed in Week 12. If you choose to change either the number of sequences or their length, can you first predict which dimensions will change?
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.
Choose a short segment from the exercise text. If you write the characters shown to the model alongside their next-character targets, how are the two segments offset?
What changes if you cut segments of the same length more densely or more sparsely from the text? Which code would you inspect to distinguish overlapping segments from carrying model memory between examples?
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.
Sketch how the Week 12 RNN reads a short string character by character. Where in the code can you trace how information from earlier characters contributes to predicting the next character?
Compare the Week 13
outputwith the returned states. Which arrays would you inspect for information at an intermediate character and after reading the full sequence? What additional distinction is needed for an LSTM?
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.
Choose a short sentence from Week 14. What differences would you expect in the index tensor shape and sentence vector when processing it alone versus in a batch with a longer sentence?
For a Week 14 review, consider changing word order or replacing one word with an unfamiliar word. Choose one change: can you predict where differences first appear among the token list, indices and sentence vector?
Week 14 · Converting a sentence to indices · From sentence vectors to sentiment predictions
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.
Imagine entering a new review after obtaining high training accuracy in Week 14. Which sentences would you choose to investigate further what the model has learned?
Suppose one model performs better in the Week 13 RNN/LSTM/GRU comparison. What would you keep fixed and what would you vary to investigate whether the difference comes from model architecture or experimental conditions?