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

  • 66Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: NLP Tasks

What does natural language processing (NLP) study?

66 questions

  1. 1

    What does natural language processing (NLP) study?

    Model answer

    NLP is the field concerned with manipulating and computing with text.

    Explanation

    NLP methods process language as data for tasks such as classification, translation, and generation.

  2. 2

    What are the three broad categories of NLP tasks described in the lecture?

    Model answer

    The categories are classification, multi-classification, and generation.

    Explanation

    They differ in what a system predicts: a label, multiple labels, or output text.

  3. 3

    How does a text classification task differ from a text generation task?

    Model answer

    Classification maps input text to a prediction such as a label, while generation produces output text, often of variable length.

    Explanation

    Sentiment prediction is classification; translation and question answering are examples of generation.

  4. 4

    Give two examples of text classification tasks and identify what each predicts.

    Model answer

    Sentiment analysis predicts whether text is positive, negative, or neutral; intent detection predicts the user's intended action, such as creating an alarm.

    Explanation

    Both tasks assign a prediction to an input text rather than generating a passage of text.

  5. 5

    What does named entity recognition do, and what kinds of labels can it assign?

    Model answer

    Named entity recognition identifies and labels specific words or spans, for example as locations or times.

    Explanation

    It makes predictions for parts of a text rather than assigning only one label to the whole sentence.

  6. 6

    Name two linguistic tasks other than named entity recognition that involve labeling or analyzing parts of text.

    Model answer

    Part-of-speech tagging labels words as nouns, verbs, and other grammatical categories; parsing analyzes syntactic relationships, such as dependency or constituency structure.

    Explanation

    These tasks analyze grammatical roles or structure within language.

  7. 7

    What is the difference between precision and recall in classification?

    Model answer

    Precision is the proportion of positive predictions that are correct; recall is the proportion of actual positive cases that the model correctly identifies.

    Explanation

    Precision focuses on the correctness of predicted positives, while recall focuses on finding the true positives.

  8. 8

    What does the F1 score summarize, and how is it related to precision and recall?

    Model answer

    The F1 score combines precision and recall using their harmonic mean.

    Explanation

    It provides one measure that reflects both the correctness and coverage of positive predictions.

  9. 9

    Why can accuracy be misleading when a dataset is highly imbalanced?

    Model answer

    A model can achieve high accuracy by predicting only the majority class, even if it fails to identify the minority class.

    Explanation

    For example, predicting the positive class for every case in a dataset that is mostly positive can look accurate while missing all negative cases.

  10. 10

    At what levels can named entity recognition performance be evaluated, and how can the metrics be organized?

    Model answer

    It can be evaluated at the token level or entity-type level, with metrics aggregated for categories such as locations.

    Explanation

    This evaluates how well the system labels the relevant words or entity categories rather than treating each sentence as one prediction.

  11. 11

    Why is machine translation evaluation difficult, and what limitation do BLEU and ROUGE share?

    Model answer

    A translation can be expressed in many valid ways, making comparison difficult. BLEU and ROUGE compare output with reference text, so they require labeled reference translations.

    Explanation

    Producing reference translations takes time and money, and one reference may not capture every acceptable translation.

  12. 12

    What does perplexity measure, and which direction indicates a better score?

    Model answer

    Perplexity quantifies how surprised a model is by text based on the probabilities it assigns; lower perplexity is better.

    Explanation

    Unlike BLEU and ROUGE, perplexity is based on the model's probabilities rather than comparison with a reference text.

  13. 13

    What is tokenization, and what is a token?

    Model answer

    Tokenization divides text into units that a model can process; each unit is called a token.

    Explanation

    A token can be defined at different levels, such as a word, a subword, or a character.

  14. 14

    What is one limitation of word-level tokenization?

    Model answer

    It treats related forms such as “bear” and “bears” as separate tokens instead of directly sharing their common root.

    Explanation

    The model must learn separate representations for word forms that are similar.

  15. 15

    What does out of vocabulary (OOV) mean in language processing?

    Model answer

    An OOV token is a token encountered at inference time that was not present in the training vocabulary.

    Explanation

    A word-level system may need to mark such an unseen word as unknown.

  16. 16

    How does subword tokenization reduce the risk of OOV tokens?

    Model answer

    It breaks words into reusable parts, allowing an unseen word to be represented using subword units that may have appeared during training.

    Explanation

    Shared roots and word fragments make it less likely that an entire input item is unknown.

  17. 17

    What is a benefit and a cost of subword tokenization?

    Model answer

    It can leverage shared word roots and reduce OOV risk, but it may create longer token sequences.

    Explanation

    The longer sequence can require more computation because the model processes more tokens.

  18. 18

    What is a benefit and a cost of character-level tokenization?

    Model answer

    It can handle misspellings and casing variations, but it produces long sequences and character representations can be difficult to interpret meaningfully.

    Explanation

    Longer sequences increase processing time, while an individual character carries less direct meaning than a word or subword.

  19. 19

    Why does sequence length affect the computational cost of processing text?

    Model answer

    A model must process the tokens in its input, so a longer token sequence generally takes more time and computation.

    Explanation

    This is why the long sequences produced by character-level tokenization can be costly.

  20. 20

    What approximate vocabulary sizes were described for single-language and multilingual tokenizers?

    Model answer

    A single-language vocabulary may be on the order of tens of thousands of tokens, while a multilingual vocabulary may be on the order of hundreds of thousands.

    Explanation

    Multilingual and code-capable systems may need to cover more kinds of text.

  21. 21

    What is a one-hot encoding of a token, and what is its key limitation for representing similarity?

    Model answer

    A one-hot encoding assigns each token a vector with one entry set to one and the others set to zero. Different one-hot vectors are orthogonal, so they do not express that some tokens are more similar than others.

    Explanation

    For example, one-hot encoding alone does not make “teddy bear” more similar to “soft” than to “book.”

  22. 22

    How can cosine similarity be interpreted when comparing token vectors?

    Model answer

    Cosine similarity compares the angle between vectors: vectors pointing in similar directions have high similarity, while orthogonal vectors have similarity near zero.

    Explanation

    The measure focuses on vector direction rather than treating differences in vector magnitude as the main signal.

  23. 23

    What kind of relationship should useful token embeddings capture?

    Model answer

    Tokens with similar meanings or uses should have similar representations, while unrelated tokens should be less similar.

    Explanation

    A representation might place “teddy bear” closer to “soft” than to an unrelated word such as “book.”

  24. 24

    What was Word2vec designed to learn, and why were its embeddings considered interpretable?

    Model answer

    Word2vec learned meaningful word embeddings from text. Its vector relationships could capture associations such as king-to-queen and Paris-to-France.

    Explanation

    These relationships offered an intuitive way to inspect what information the embeddings encoded.

  25. 25

    What is the objective of continuous bag of words, or CBOW?

    Model answer

    CBOW uses surrounding words as context to predict a target word.

    Explanation

    The context words provide information from which the missing or target word can be inferred.

  26. 26

    What is the objective of skip-gram, and how does it contrast with CBOW?

    Model answer

    Skip-gram uses a target word to predict its surrounding words; CBOW instead uses surrounding words to predict the target.

    Explanation

    The two methods reverse the direction of prediction while using context from text.

  27. 27

    Why are Word2vec's prediction objectives called proxy tasks?

    Model answer

    They train a model to predict words as a means of learning useful representations; the main goal is meaningful embeddings, not merely completing that prediction task.

    Explanation

    Predicting words encourages the model to encode useful language relationships in its representations.

  28. 28

    In a simple next-word prediction network, what is the role of the vocabulary-sized input and the smaller hidden layer?

    Model answer

    The input represents a token, often as a vocabulary-sized one-hot vector, and the smaller hidden layer provides its learned representation.

    Explanation

    The hidden dimension is typically much smaller than the vocabulary size, making it a compact representation.

  29. 29

    How does training a next-word prediction model update its parameters?

    Model answer

    The model's prediction is compared with the true next token using a loss such as cross-entropy, and backpropagation updates the weights to reduce the loss.

    Explanation

    Repeating this process over training examples improves the model's predictions and teaches its hidden representations.

  30. 30

    How can a trained prediction network provide an embedding for a token?

    Model answer

    The token is represented as a one-hot vector and multiplied by the learned input-to-hidden weights; the resulting hidden representation serves as its embedding.

    Explanation

    The embedding is taken from the learned hidden representation rather than from the one-hot vector itself.

  31. 31

    What factors influence the choice of embedding dimension?

    Model answer

    The complexity of the downstream task and constraints such as latency and computation cost influence the choice.

    Explanation

    Larger vectors can encode richer information but generally require more computation.

  32. 32

    What is a common way to decide when to stop training a model on a proxy task?

    Model answer

    One approach is to monitor the proxy-task loss over training and stop when it converges, while also checking whether the representations suit the downstream task.

    Explanation

    Convergence provides a practical stopping signal, but the proxy objective is not necessarily the final goal.

  33. 33

    Why can averaging token embeddings be inadequate as a sentence representation?

    Model answer

    A simple average loses word order and can discard meaning that depends on how the words are arranged.

    Explanation

    It also combines token-specific representations without making them sensitive to their context in the sentence.

  34. 34

    How does a recurrent neural network process a sequence?

    Model answer

    An RNN processes tokens one at a time and updates a hidden state that represents the sequence seen so far.

    Explanation

    At each step, the new token is combined with the previous hidden state.

  35. 35

    What does the hidden state of an RNN represent, and what other names may be used for it?

    Model answer

    It represents the sequence processed so far and may also be called an activation or context vector.

    Explanation

    The state carries information from earlier tokens into later processing steps.

  36. 36

    How can an RNN be used for sentence classification, token labeling, and generation?

    Model answer

    For sentence classification, the final hidden state can be projected to label predictions; for token labeling, a token's representation can be projected to labels; for generation, the encoded source state can help predict output text.

    Explanation

    The representation used depends on whether the prediction concerns a whole sentence, an individual token, or generated text.

  37. 37

    What long-sequence problem affects basic RNNs?

    Model answer

    RNNs can have difficulty preserving information from far earlier in a sequence, a problem described as long-range dependency or forgetting.

    Explanation

    Information from the past must pass through successive hidden states to influence later predictions.

  38. 38

    What does an LSTM add to an RNN, and what is the purpose of that addition?

    Model answer

    An LSTM adds a cell state alongside the hidden state to help track information that is important to retain.

    Explanation

    The cell state is intended to improve the handling of information from earlier in the sequence.

  39. 39

    Why can gradients vanish or explode when training recurrent models over long sequences?

    Model answer

    Backpropagation through time involves products of quantities across sequential steps; repeated multiplication by values below one can shrink gradients toward zero, while values above one can make them grow.

    Explanation

    Vanishing gradients make it difficult to update earlier computations, while exploding gradients become excessively large.

  40. 40

    Why can RNN training be slow on long sequences?

    Model answer

    To process a later token, an RNN must first compute the hidden states for the preceding tokens in sequence.

    Explanation

    This sequential dependency limits how much of the sequence can be processed at once.

  41. 41

    What problem is attention intended to address when processing long sequences?

    Model answer

    Attention creates direct links between a prediction and relevant parts of the input, helping the model use information from far earlier in a sequence.

    Explanation

    It reduces reliance on carrying all useful information through a chain of recurrent hidden states.

  42. 42

    What is self-attention, and how does it make token representations context-dependent?

    Model answer

    Self-attention lets each token use information from other tokens in the same sequence to form its representation.

    Explanation

    A token can therefore receive different representations depending on the context in which it appears.

  43. 43

    How can self-attention distinguish a word that has different meanings in different contexts?

    Model answer

    It computes a token's representation using the other tokens in its sequence, so the same word can receive different representations in different contexts.

    Explanation

    For example, the context around “bank” can indicate whether it refers to a riverbank or a financial institution.

  44. 44

    In attention, what roles do the query, key, and value play?

    Model answer

    The query is compared with keys to determine which elements are relevant, and the corresponding values provide the information that is combined.

    Explanation

    The query-key comparison determines the weights used to form a weighted combination of values.

  45. 45

    How are query, key, and value vectors obtained in a transformer?

    Model answer

    They are produced by learned projection matrices applied to the input representations.

    Explanation

    The model learns these projections during training rather than using fixed query, key, and value vectors.

  46. 46

    Why is attention naturally expressed with matrix operations?

    Model answer

    Queries, keys, and values for an entire sequence can be combined in matrix form, allowing the attention computation to be performed efficiently on hardware suited to matrix operations.

    Explanation

    This makes it possible to compute attention for many tokens in parallel.

  47. 47

    What is the purpose of the softmax step in scaled dot-product attention?

    Model answer

    Softmax turns query-key compatibility scores into weights that determine how much each value contributes to the result.

    Explanation

    More relevant keys receive larger weights, and their associated values contribute more to the weighted sum.

  48. 48

    Why are query-key dot products scaled by the square root of the key dimension?

    Model answer

    The dot products tend to grow as the key and query dimension grows, so dividing by the square root of that dimension normalizes their scale.

    Explanation

    Scaling prevents the scores from becoming unnecessarily large before softmax.

  49. 49

    What does multi-head attention do, and why use multiple heads?

    Model answer

    It performs attention several times in parallel using different learned projections, allowing the model to represent different relationships between tokens.

    Explanation

    The outputs of the heads are combined, giving the model more ways to relate elements in a sequence.

  50. 50

    How are multiple attention-head outputs combined in the described transformer?

    Model answer

    The head outputs are concatenated and then passed through a learned output projection that maps them back to the embedding dimension.

    Explanation

    The output projection combines the head representations into a single sequence representation of the expected size.

  51. 51

    Why do transformer inputs need positional information?

    Model answer

    Self-attention alone does not encode the order of tokens, so positional information is added to indicate each token's position in the sequence.

    Explanation

    Without position information, the model would not directly know which token came first or later.

  52. 52

    How did the original transformer encode position in its input representations?

    Model answer

    It added sine- and cosine-based positional encodings element-wise to the token embeddings.

    Explanation

    This provides position information while keeping it combined with each token's representation.

  53. 53

    What are the two main parts of the original transformer architecture, and what do they process in translation?

    Model answer

    The encoder processes the source-language input, and the decoder generates the target-language output.

    Explanation

    For translation, the encoder represents the input sentence and the decoder uses those representations to produce the translation.

  54. 54

    What does the encoder's self-attention layer compute?

    Model answer

    It computes each input token's representation as a function of the other tokens in the input sequence.

    Explanation

    This gives the encoder context-aware representations of the source text.

  55. 55

    What is the role of the feedforward network in transformer encoder and decoder blocks?

    Model answer

    It transforms the attention representations further, giving the model additional capacity to learn useful features.

    Explanation

    The feedforward network provides another learned transformation after attention.

  56. 56

    How does decoder masked self-attention differ from encoder self-attention?

    Model answer

    Masked decoder self-attention lets a position attend to itself and preceding output tokens, but not to future tokens that have not yet been generated.

    Explanation

    This prevents the decoder from using information about the answer it is supposed to predict.

  57. 57

    In decoder cross-attention, where do the queries, keys, and values come from?

    Model answer

    The decoder supplies the queries, while the encoder's output representations supply the keys and values.

    Explanation

    This lets the decoder use its current output context to retrieve relevant information from the source input.

  58. 58

    What information does decoder cross-attention provide during translation?

    Model answer

    It lets the decoder determine which parts of the encoded source sentence are relevant to the output token being generated.

    Explanation

    The decoder's query is compared with keys from the encoder, and the associated values provide source information.

  59. 59

    Why does the transformer use stacked encoder and decoder blocks?

    Model answer

    The architecture applies multiple encoder and decoder layers in succession to build richer representations and generate output.

    Explanation

    The encoder's final representations are supplied to the decoder's cross-attention layers.

  60. 60

    How does a transformer turn its final decoder representation into a next-token prediction?

    Model answer

    A linear projection produces scores over the vocabulary, and softmax converts them into a probability distribution for the next token.

    Explanation

    The model can then select or sample a token using those probabilities.

  61. 61

    How does autoregressive decoding proceed, and what signals that generation should stop?

    Model answer

    The decoder begins with a beginning-of-sequence token, predicts one token at a time, and feeds generated tokens back into the decoder. Generation stops when it produces the end-of-sequence token.

    Explanation

    The decoder uses the output generated so far to predict each subsequent token.

  62. 62

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

    Model answer

    The beginning-of-sequence token marks the start of a sequence or generation, and the end-of-sequence token marks its completion.

    Explanation

    These special tokens give the model explicit signals about sequence boundaries.

  63. 63

    What is label smoothing, and how does it change a one-hot training label?

    Model answer

    Label smoothing makes the target less certain by assigning most probability to the correct token and a small amount across the other vocabulary items, instead of using a strict one-hot target.

    Explanation

    This reflects that more than one continuation may be plausible in language.

  64. 64

    Why can label smoothing be useful for language generation?

    Model answer

    It discourages the model from treating one reference continuation as the only possible correct answer, since language often has multiple valid continuations.

    Explanation

    The lecture notes that this technique can improve translation-related metrics such as BLEU.

  65. 65

    What historical developments helped make modern large language models possible?

    Model answer

    Earlier ideas included recurrent models from the 1980s and LSTMs from the 1990s; Word2vec later advanced meaningful embeddings, and the 2017 transformer architecture enabled further progress as compute and training data scaled.

    Explanation

    Earlier models faced limits in available internet-scale data and computational resources, while later advances supported larger models.

  66. 66

    Why could earlier language-model approaches not reach the scale of modern models?

    Model answer

    They were limited by the lack of large internet-scale data and sufficient computational resources.

    Explanation

    More data and compute later allowed models based on newer architectures to be scaled up.

1 of 66
Question 1 of 66

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent