Wisc NetID for In-class Quiz: @wisc.edu
4-digit Passcode: (anything is okay, use the same one for all lectures or use based on your id)
Save submission to file? File name: (leave it blank to not save anything) 12id,answer_id;token,answer_check;download,answer_download
# Warning: this is a draft and will be updated one day before the lecture.
📗 No recurrent units are used: "attention is all you need": Link, Link, Wikipedia.
📗 Attention units keep track of which parts of the sentence is important and pay attention to, for example, scaled dot product attention units: Wikipedia.
➩ \(a^{\left(h\right)}_{t} = g\left(w^{\left(x\right)} \cdot x_{t} + b^{\left(x\right)}\right)\) is not recurrent.
➩ There are value units \(a^{\left(v\right)}_{t} = w^{\left(v\right)} \cdot a^{\left(h\right)}_{t}\), key units \(a^{\left(k\right)}_{t} = w^{\left(k\right)} \cdot a^{\left(h\right)}_{t}\), and query units \(a^{\left(q\right)}_{t} = w^{\left(q\right)} \cdot a^{\left(h\right)}_{t}\), and attention context can be computed as \(g\left(\dfrac{a^{\left(q\right)}_{s} \cdot a^{\left(k\right)}_{t}}{\sqrt{m}}\right) \cdot a^{\left(v\right)}_{t}\) where \(g\) is the softmax activation: here \(a^{\left(q\right)}_{s}\) represents the first word, \(a^{\left(k\right)}_{t}\) represents the second word, \(a^{\left(q\right)}_{s} \cdot a^{\left(k\right)}_{t}\) is the dot product (which represents the cosine of the angle between the two words, i.e. how similar or related the two words are), and \(a^{\left(v\right)}_{t}\) is the value of the second word to send to the next layer.
➩ The attention matrix is usually masked so that a unit \(a_{t}\) cannot pay attention to another unit in the future \(a_{t+1}, a_{t+2}, a_{t+3}, ...\) by making the \(a^{\left(q\right)}_{s} \cdot a^{\left(k\right)}_{t} = -\infty\) when \(s \geq t\) so that \(e^{a^{\left(q\right)}_{s} \cdot a^{\left(k\right)}_{t}} = 0\) when \(s \geq t\).
➩ There can be multiple parallel attention units called multi-head attention.
📗 [1 points] Compute the attention weights and the context value of the word with \(q_{i} = x_{i} \cdot w_{q}\) = ?
Words
Key \(k_{j} = x_{j} \cdot w_{k}\)
Value \(v_{j} = x_{j} \cdot w_{v}\)
Attention Weights \(\alpha\)
📗 Answer: .
[Note] Use the space to explain the steps or just take notes:
[L12Q1]
In-class Quiz
ID:
📗 [4 points] Compute the context value of the word with \(q_{i} = x_{i} \cdot w_{q}\) = . You can enter the scaled dot products (optional) in the table and use the "Softmax" button to compute the soft attention weights.
Words
Key \(k_{j} = x_{j} \cdot w_{k}\)
Value \(v_{j} = x_{j} \cdot w_{v}\)
Attention Weights \(\alpha\)
:
:
:
:
📗 Answer: .
[Note] Use the space to explain the steps or just take notes:
📗 Positional encoding are used so that embedding vectors contain information about the word token and its position.
➩ Trained weights, or,
➩ Calculated by \(P\left(k, 2 i\right) = \sin\left(\dfrac{k}{n^{2 i / d}}\right)\) and \(P\left(k, 2 i + 1\right) = \cos\left(\dfrac{k}{n^{2 i / d}}\right)\) for word token \(k\) to position \(j \in \left\{2 i, 2 i + 1\right\}\) in the embedding vector: Link.
📗 Composite encoding = word embeddings + position embeddings.
➩ Output \(a^{\left(n\right)}_{i} = \dfrac{a_{i} - \mu_{x}}{\sqrt{\sigma^{2}_{x} + \varepsilon}}\), added \(\varepsilon\) small to prevent \(\sigma\) close to 0.
📗 Encoder-Decoder structure:
➩ Encoder: input sequence to a continuous representation \(z\) (useful for classification).
➩ Decoder: from \(z\), generate output sequence (useful for generation).
📗 GPT Series (Generative Pre-trained Transformer): Wikipedia.
➩ Pre-training: train all the weights on general purpose text dataset to learn contextualized word and sentence representations.
➩ Fine tuning for pre-trained decoder models freezes a subset of the weights (usually in earlier layers) and updates the other weights (usually the later layers) based on new datasets: Wikipedia.
📗 BERT (Bidirectional Encoder Representations from Transformers): Wikipedia.
➩ Fine tuning for pre-training encoder models adds task heads (additional layers at the end) and trains the weights in the task heads (sometimes also updates the pre-trained weights) for specific tasks.
📗 Many other large language models developed by different companies: Link.
➩ Prompt engineering does not alter the weights, and only provides more context (in the form of examples): Link, Wikipedia.
➩ Reinforcement learning from human feedback (RLHF) uses reinforcement learning techniques to update the model based on human feedback (in the form of rewards, and the model optimizes the reward instead of some form of costs): Wikipedia.
📗 Graph Neural Network (GNN) are generalization of CNNs over graphs: Link, Wikipedia.
➩ Images can be viewed as graphs where pixels are nodes and neighboring pixels are connected by edges.
📗 An example of a graph convolution layer is given by: \(a^{\left(l + 1\right)} = g\left(A_{G} w^{\left(l\right)} \cdot a^{\left(l\right)} + b^{\left(l\right)}\right)\) for the graph \(G\) with adjacency matrix with self loops added (add an edge from every node to itself) \(A\) and the corresponding degree matrix \(D\).
➩ An example of \(A_{G} = D^{- \dfrac{1}{2}} A D^{- \dfrac{1}{2}}\).
📗 Pooling layers can be local or global.
➩ Local: downsampling, for example, k-nearest neighbor pooling, top-k pooling.
➩ Global: permutation invariant, for example, sum, mean, maximum.
📗 Comparison between CNN, RNN, GNN:
➩ CNN share weights over space (regions of pixels).
➩ RNN share weights over time (sequences of tokens).
➩ GNN share weights over graph neighborhoods (links or edges in the graph).
📗 If you have questions, please (i) Ask during or after the lecture or the break, (ii) Piazza: Link, (iii) Office hours and discussion sessions. Please do NOT use Canvas mail and use email only to the course instructor (not TAs) for grading issues.
Additional In-class Discussion
📗 Sometimes a question not in the notes will be asked during the lecture, you can submit your answer here:
[Notes] (not visible to other students):
[L12Q3]
Submit your answer to see other students answers (click the submit button to refresh):
Additional In-class Quiz
📗 Sometimes a question not in the notes will be asked during the lecture, you can submit your answer here:
A.
B.
C.
D.
E.
[Notes] (not visible to other students):
[L12Q4]
Submit your answer to see other students answers (click the submit button to refresh):
📗 To get full points on the in-class quizzes for a lecture:
➩ Submit relevant answers to the questions discussed during the lecture: incorrect answers are okay.
➩ Some questions require [notes] to earn the point.
➩ Some questions require special ID (given during the lecture) to earn the point.
➩ Do not submit answers to questions that are not discussed during the lectures. Each such submission will result in a deduction of one point.
➩ The grade on Canvas Assignment W12 is computed as number of points divided by the number of questions asked (and multiplied by 4, out of 4) and updated on Canvas every weekend.
📗 Notes and code adapted from the course taught by Professors Jerry Zhu, Blerina Gkotse, Yudong Chen, Yingyu Liang, Charles Dyer. Some content are generated using Copilot .