1. Home
  2. Explore
  3. Computer Science
  4. Transformers and Large Language Models

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Transformers and Large Language Models

  • 65Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Modeling History

How did natural-language processing models in the 2010s typically differ from modern large language models in how they were designed for tasks?

65 questions

  1. 1

    How did natural-language processing models in the 2010s typically differ from modern large language models in how they were designed for tasks?

    Model answer

    The 2010s commonly used a separate, task-specific model for each use case, such as sentiment classification, translation, or named-entity recognition. Modern LLMs can support a wider range of tasks.

    Explanation

    The earlier approach relied on dedicated models rather than one model intended to handle many different tasks.

  2. 2

    Which model architecture was prominent in NLP before transformers, and what does its name mean?

    Model answer

    Recurrent neural networks (RNNs) were prominent; they process sequences recurrently, carrying information forward through a hidden state.

    Explanation

    RNNs process sequence elements one at a time and update a state as they go.

  3. 3

    What architectural development did the 2017 paper “Attention Is All You Need” introduce, and why was it a turning point?

    Model answer

    It introduced the transformer, an architecture based on attention that proved highly scalable and enabled substantial performance gains as models grew.

    Explanation

    The lecture identifies the transformer’s scalability as a key reason it marked a turning point.

  4. 4

    According to the lecture, what factors can be increased to scale a model, and what effect can this have?

    Model answer

    A model can be given more data, more compute, and more parameters; scaling these factors can produce performance gains.

    Explanation

    The lecture describes the transformer paradigm as scaling effectively with all three resources.

  5. 5

    What product-level shift followed the 2022 release of ChatGPT, as described in the lecture?

    Model answer

    ChatGPT helped make interacting with a chatbot familiar to a much broader audience.

    Explanation

    The lecture presents the release as a turning point in how people experienced LLMs, separate from the transformer’s architectural impact.

  6. 6

    What contrast does the lecture draw between traditional token-by-token LLM generation and newer generation approaches?

    Model answer

    Traditional LLMs predict tokens one at a time, while some newer models use different paradigms, including diffusion-based approaches.

    Explanation

    The lecture notes an increasing number of models that do not follow the traditional one-token-at-a-time approach.

  7. 7

    What is tokenization, and why is it needed before a model processes text?

    Model answer

    Tokenization divides text into units called tokens. It is needed because models process numerical representations rather than raw text.

    Explanation

    Each token can subsequently be represented numerically, for example by a vector.

  8. 8

    What is a tokenizer’s vocabulary, and how can vocabulary choice affect a text’s sequence length?

    Model answer

    A vocabulary is the set of tokens the tokenizer is allowed to use. Different vocabularies can divide the same text into different numbers of tokens, changing sequence length.

    Explanation

    Sequence length is the number of tokens used to represent the input.

  9. 9

    What are two advantages of word-level tokenization?

    Model answer

    It is simple to implement by splitting at spaces, and its tokens are relatively interpretable because they correspond to words.

    Explanation

    A token can be directly associated with the word it represents.

  10. 10

    Why can word-level tokenization produce a large vocabulary?

    Model answer

    Words have many forms and variations, such as singular and plural forms, so treating each word as a separate token can greatly increase vocabulary size.

    Explanation

    A separate token may be needed for each variation encountered by the tokenizer.

  11. 11

    Why can word-level tokenization make it difficult to share knowledge between related words?

    Model answer

    Related forms such as “bear” and “bears” are separate tokens, and nothing guarantees that their learned representations will be similar.

    Explanation

    The tokenizer itself does not encode that the two words share a root or meaning.

  12. 12

    What is an out-of-vocabulary problem in word-level tokenization?

    Model answer

    It occurs when an input contains a word absent from the training vocabulary, so the model has no learned representation for that word.

    Explanation

    A word-level tokenizer can encounter a word at inference time that it never encountered during training.

  13. 13

    What are advantages of character-level tokenization?

    Model answer

    It uses a small, fixed set of characters, reduces the risk of out-of-vocabulary words, and can handle casing differences and misspellings more robustly.

    Explanation

    Words are built from characters in the vocabulary, so an unfamiliar or misspelled word need not be an unknown whole-word token.

  14. 14

    What are two drawbacks of character-level tokenization?

    Model answer

    It creates longer sequences, which take more computation to process, and individual character representations are less interpretable than word representations.

    Explanation

    Model complexity and processing time increase with sequence length.

  15. 15

    What is subword tokenization, and how can it help represent related word forms?

    Model answer

    Subword tokenization divides text into units between whole words and individual characters, often based on common letter sequences learned from data. Related forms can share a subword, such as “bear” in both “bear” and “bears.”

    Explanation

    Subwords preserve some word-root information without requiring every full word to be a distinct token.

  16. 16

    What is a drawback of learning a subword tokenizer from a corpus?

    Model answer

    It requires extra training work, and the resulting tokens depend on the corpus used to learn them, so that corpus should suit the intended use.

    Explanation

    A tokenizer trained on data unlike the data it will later process may produce less suitable tokenizations.

  17. 17

    How does byte pair encoding (BPE) build a vocabulary?

    Model answer

    BPE starts with an initial set of tokens, repeatedly finds frequent adjacent pairs in the training data, and adds tokens that merge those pairs until the desired vocabulary size is reached.

    Explanation

    The final subword tokens are learned from recurring patterns in the corpus.

  18. 18

    Why can BPE improve processing efficiency, and what corpus consideration matters when using it for multilingual work?

    Model answer

    Frequent merged sequences can represent text with fewer tokens, shortening sequences. For multilingual work, the training corpus should represent the languages of interest.

    Explanation

    Shorter sequences reduce the amount of text the model must process, while a poorly representative corpus may not produce suitable tokens for all target languages.

  19. 19

    What is an unknown token, and when might a tokenizer use it?

    Model answer

    An unknown token is a special token used to represent text that is not covered by the vocabulary.

    Explanation

    For example, an unseen spelling may be mapped to an unknown token rather than represented as a known word.

  20. 20

    What are beginning-of-sequence and end-of-sequence tokens used for during generation?

    Model answer

    The beginning-of-sequence token signals that generation should start; the end-of-sequence token signals that generation is finished.

    Explanation

    These tokens mark the boundaries of generated text.

  21. 21

    Why might a model use a padding token, and what other role-related special tokens does the lecture mention?

    Model answer

    Padding can make sequences the same length, which can improve computational efficiency. Special tokens can also represent roles such as user and assistant; conventions for special-token names are not universal.

    Explanation

    Equal-sized sequences can be convenient for hardware and tensor operations, while role tokens convey information about who produced text.

  22. 22

    Why are one-hot encodings inadequate as meaningful token representations?

    Model answer

    Different tokens have orthogonal one-hot vectors, so the encoding does not represent how similar or related the tokens are.

    Explanation

    The representation distinguishes tokens but provides no meaningful information about their relationships.

  23. 23

    What should meaningful token representations capture, and why are such representations useful?

    Model answer

    They should reflect relevant similarities between tokens, and they give a model useful numerical inputs for tasks such as generating text or predicting a class.

    Explanation

    Models need numerical inputs that convey information about the text to produce meaningful outputs.

  24. 24

    What is a proxy task, and what proxy tasks did Word2Vec use?

    Model answer

    A proxy task is learned to help achieve a different end goal. Word2Vec used tasks such as predicting a word from its context or predicting surrounding words from a given word.

    Explanation

    Predicting a word from context is the continuous bag-of-words approach; predicting context words is the skip-gram approach.

  25. 25

    In a basic Word2Vec-style network, what are the roles of the input, hidden, and output dimensions?

    Model answer

    The one-hot input and output probability vector have vocabulary size VVV, while the hidden representation has a chosen size DDD, typically smaller than VVV.

    Explanation

    The output has one probability for each vocabulary token, and the hidden layer supplies the learned latent representation.

  26. 26

    How does the training objective in the lecture encourage a model to predict the intended next word?

    Model answer

    The model produces probabilities over the vocabulary, compares them with the target word, and uses a loss such as cross-entropy to update its weights.

    Explanation

    The loss penalizes a prediction that assigns too little probability to the target token.

  27. 27

    What can Word2Vec-style training reveal about the learned hidden representations?

    Model answer

    Similar tokens can have similar representations, and the representations can encode relationships or associations between words.

    Explanation

    The lecture illustrates this with associations such as Paris–France and Berlin–Germany, and with teddy bears being soft.

  28. 28

    What is a limitation of static word embeddings when a word has different meanings in different contexts?

    Model answer

    A word receives the same representation in every context, so the representation does not distinguish meanings such as a river bank and a financial bank.

    Explanation

    The representation is associated with the word itself rather than the particular sentence in which it occurs.

  29. 29

    Why do static word embeddings fail to represent differences in word order?

    Model answer

    They represent the same words the same way even when their order changes, so sentences such as “the child hugs the bear” and “the bear hugs the child” can be indistinguishable to this approach.

    Explanation

    The representations do not encode how the words are arranged in the sentence.

  30. 30

    What is the central idea of an RNN hidden state?

    Model answer

    It is a state updated as the sequence is processed that aims to encode the meaning of the tokens seen so far.

    Explanation

    The state is passed forward and used when processing subsequent tokens or making predictions.

  31. 31

    How can RNNs use sequence information for tasks such as classification, word labeling, and generation?

    Model answer

    They process tokens one at a time and update the hidden state; the state can support a sequence-level prediction, token-level labels, or next-token generation.

    Explanation

    For example, the lecture describes sentiment prediction, noun-versus-verb labeling, and text generation.

  32. 32

    How do RNNs address the word-order limitation of static embeddings?

    Model answer

    Their hidden state changes as tokens arrive, allowing a token’s representation or prediction to depend on the preceding sequence.

    Explanation

    The hidden state carries information about the sequence seen so far, rather than treating each word in isolation.

  33. 33

    What is the long-range dependency problem in RNNs?

    Model answer

    An RNN can have difficulty retaining information about words that occurred far earlier in a sequence because its information is carried through a repeatedly updated hidden state.

    Explanation

    This can make it hard to connect a later word or pronoun to something mentioned much earlier.

  34. 34

    What problem were long short-term memory (LSTM) networks designed to address, and how?

    Model answer

    LSTMs were designed to help retain information over longer spans by maintaining a cell state in addition to the hidden state.

    Explanation

    The cell state was intended to carry information for longer, although LSTMs still have limitations.

  35. 35

    What training and computation limitation follows from an RNN’s sequential processing?

    Model answer

    The model must process tokens one at a time, using the preceding hidden state for each next prediction, which makes processing and training slow.

    Explanation

    Each step depends on the state computed by earlier steps, limiting parallel processing across the sequence.

  36. 36

    How does attention differ from relying only on an RNN hidden state?

    Model answer

    Attention gives a token direct connections to earlier tokens, letting the model learn which past tokens are relevant instead of relying only on information compressed into the hidden state.

    Explanation

    In translation, direct access to a relevant source word can help predict its corresponding target word.

  37. 37

    What does self-attention compute for a token?

    Model answer

    It computes the token’s representation as a function of tokens in the same sequence, rather than only of the token and a recurrent hidden state.

    Explanation

    Each token can use information from other tokens in its sequence to form a context-aware representation.

  38. 38

    In attention, what roles do queries, keys, and values play?

    Model answer

    A query seeks relevant information, keys are compared with the query to determine relevance, and values supply the information combined using those relevance weights.

    Explanation

    The output is a weighted combination of value vectors, with weights determined by query–key similarity.

  39. 39

    How are query, key, and value vectors obtained from token representations?

    Model answer

    Each token representation is projected using learned matrices into query, key, and value spaces.

    Explanation

    The projection matrices allow the model to learn how tokens should be compared and what information they should provide.

  40. 40

    How does a query determine which values contribute most to its attention output?

    Model answer

    It is compared with the keys, commonly using dot products; the resulting scores are normalized into weights that are applied to the corresponding values.

    Explanation

    A high query–key similarity gives the associated value a larger contribution to the weighted sum.

  41. 41

    What does the softmax operation do to attention scores?

    Model answer

    It converts the scores into weights that sum to one, allowing them to function as a normalized weighting over values.

    Explanation

    The attention output uses these weights to combine value vectors.

  42. 42

    What is the scaled dot-product self-attention formula, and what is the purpose of its scaling factor?

    Model answer

    The formula is softmax⁡ ⁣(QK⊤DK)V\operatorname{softmax}\!\left(\frac{QK^\top}{\sqrt{D_K}}\right)Vsoftmax(DK​​QK⊤​)V. The factor DK\sqrt{D_K}DK​​ helps normalize the scores because their variance depends on the key dimension.

    Explanation

    The matrix product QK⊤QK^\topQK⊤ gives query–key similarities, and multiplying by VVV forms weighted value combinations.

  43. 43

    What is the shape and meaning of the matrix QK⊤QK^\topQK⊤ for a sequence of nnn tokens?

    Model answer

    It has shape n×nn \times nn×n; each entry is the similarity between one token’s query and another token’s key.

    Explanation

    Each row corresponds to a query, and each column corresponds to a key in the sequence.

  44. 44

    Why does basic self-attention need additional positional information?

    Model answer

    If tokens interact without position information, the model does not know their order in the sequence.

    Explanation

    The attention connections alone do not indicate where tokens occur relative to one another.

  45. 45

    What was the original transformer designed to do, and what are the encoder and decoder responsible for?

    Model answer

    It was designed for machine translation. The encoder builds meaningful representations of the source text, and the decoder uses those representations to generate the target text.

    Explanation

    The encoder represents the input language; the decoder produces a translation in the target language.

  46. 46

    How are token embeddings and positional embeddings combined at the transformer input?

    Model answer

    The token embedding is added to a positional embedding for that token’s position.

    Explanation

    The token embedding represents token identity, while the positional embedding supplies sequence-location information.

  47. 47

    What are two ways the original transformer approach can represent positions?

    Model answer

    Position embeddings can be learned, or positions can be represented with predefined sine and cosine functions at different frequencies.

    Explanation

    The lecture describes both learned and fixed, frequency-based position representations.

  48. 48

    What limitation can arise with learned position embeddings, and what advantage can predefined positional representations offer?

    Model answer

    Learned embeddings may not represent positions beyond those seen during training. Predefined representations can provide position encodings beyond the learned range.

    Explanation

    For example, a model learned only up to position 500 would not have learned embeddings for later positions.

  49. 49

    What positional relationship can sine- and cosine-based embeddings encode?

    Model answer

    They can make nearby positions similar and positions farther apart less similar.

    Explanation

    Using functions at different frequencies creates position vectors that vary systematically across the sequence.

  50. 50

    What does the encoder’s self-attention layer do to token representations?

    Model answer

    It uses learned query, key, and value projections to make each token’s representation depend on other tokens in the input sequence.

    Explanation

    This produces context-aware representations rather than representations based only on each token individually.

  51. 51

    What is the role of the transformer feed-forward neural network?

    Model answer

    It projects representations through a higher-dimensional layer and an activation function, enabling the model to learn nonlinear transformations.

    Explanation

    In the described transformer, the feed-forward network follows attention within a block.

  52. 52

    What are the encoder’s outputs used for in the decoder’s cross-attention layer?

    Model answer

    They provide the keys and values that decoder representations attend to, allowing generated tokens to use information from the source text.

    Explanation

    The decoder’s query comes from the generated side, while the keys and values come from the encoder.

  53. 53

    How does masked self-attention constrain the decoder?

    Model answer

    It allows each position to attend only to itself and earlier generated tokens, not to tokens that have not been generated yet.

    Explanation

    The mask blocks future positions so generation remains causal.

  54. 54

    How does a transformer decoder generate a sequence from a beginning-of-sequence token?

    Model answer

    It processes the beginning token, predicts a next-token distribution, selects a token, and feeds that token back into the decoder; the process repeats until an end-of-sequence token is produced.

    Explanation

    This repeated next-token procedure is autoregressive generation.

  55. 55

    What is the purpose of the decoder’s final linear layer and softmax?

    Model answer

    They convert the decoder representation into a probability distribution over the vocabulary for predicting the next token.

    Explanation

    This output softmax has a different role from the softmax used to weight attention values.

  56. 56

    What is the difference between the softmax used in attention and the final decoder softmax?

    Model answer

    Attention softmax produces weights over keys or tokens to combine values; the final decoder softmax produces probabilities over vocabulary tokens for next-token prediction.

    Explanation

    Although both use softmax, one weights information and the other predicts the next token.

  57. 57

    For an input of nnn token representations of size DmodelD_{\text{model}}Dmodel​, what dimensions do the query, key, and value projection matrices produce?

    Model answer

    They produce query, key, and value matrices with nnn rows and respectively DQD_QDQ​, DKD_KDK​, and DVD_VDV​ columns.

    Explanation

    The input projection matrices map from the model dimension into the query, key, and value spaces.

  58. 58

    Why must DQD_QDQ​ and DKD_KDK​ be equal in scaled dot-product attention?

    Model answer

    The query and key vectors must have matching dimensions so their dot products can be computed.

    Explanation

    The product QK⊤QK^\topQK⊤ compares each query with each key.

  59. 59

    How does multi-head attention extend a single attention operation?

    Model answer

    It performs attention using multiple independently learned query, key, and value projections, then concatenates the head outputs and projects them back to the model dimension.

    Explanation

    Different heads let the model learn different ways of relating tokens; the final projection is commonly denoted WOW_OWO​.

  60. 60

    How do the transformer’s feed-forward layer and repeated blocks contribute to its representational capacity?

    Model answer

    The feed-forward layer expands representations to a larger hidden dimension and applies nonlinear transformations; repeating attention and feed-forward blocks builds richer representations.

    Explanation

    In the original transformer, the encoder and decoder each used six repeated layers, and the feed-forward hidden dimension was typically larger than the model dimension.

  61. 61

    What is the purpose of residual connections in deep transformer architectures?

    Model answer

    They let a layer pass input features forward directly alongside the layer’s transformation, supporting backpropagation and learning in deep networks.

    Explanation

    The output can be understood as the input plus a learned transformation of that input.

  62. 62

    What role does layer normalization play in a transformer?

    Model answer

    It normalizes activations and can help the model converge during training.

    Explanation

    The lecture identifies layer normalization as a training aid used in the transformer.

  63. 63

    How does dropout help a model generalize?

    Model answer

    During training, dropout removes some units with a chosen probability so the model does not rely too heavily on particular features.

    Explanation

    Reducing reliance on specific units can improve generalization.

  64. 64

    What is label smoothing, and why might it help language-model training?

    Model answer

    Label smoothing assigns most of the target probability to the expected token while distributing some probability across other tokens, reflecting that multiple continuations can be valid and helping generalization.

    Explanation

    For example, instead of requiring the intended next word to have probability 100%, the target can assign it a high but lower probability and spread the remainder over other words.

  65. 65

    Why is label smoothing particularly plausible for machine translation?

    Model answer

    A source sentence can have multiple valid translations, so training need not treat only one target word as absolutely correct.

    Explanation

    The lecture notes that alternative continuations can be valid and that label smoothing improved machine-translation metrics.

1 of 65
Question 1 of 65

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent