1. Home
  2. Explore
  3. Computer Science
  4. Transformer Attention Mechanism

Study methods

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

Transformer Attention Mechanism

  • 25Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Transformer Basics

What is the primary goal of a transformer model as described?

25 questions

  1. 1

    What is the primary goal of a transformer model as described?

    1. A

      Classify text sentiment

    2. B

      Translate languages

    3. C

      Generate random text

    4. D

      Predict the next word in a sequence

    Correct answer
    D

    Predict the next word in a sequence

    Explanation

    The text explicitly states 'The goal of the model that you and I are studying is to take in a piece of text and predict what word comes next.'

  2. 2

    How are tokens defined in the context of this transformer explanation?

    1. A

      Words or pieces of words

    2. B

      Subword units like bytes

    3. C

      Only whole words

    4. D

      Characters

    Correct answer
    A

    Words or pieces of words

    Explanation

    The text says tokens are 'words or pieces of words' but simplifies to words for examples.

  3. 3

    What does an initial embedding represent?

    1. A

      A context-independent vector for the word

    2. B

      A vector enriched by surrounding context

    3. C

      A dictionary definition of the word

    4. D

      Only the position of the word

    Correct answer
    A

    A context-independent vector for the word

    Explanation

    Initial embeddings are described as 'effectively a lookup table with no reference to the context'.

  4. 4

    In the attention mechanism, what is the purpose of the query vector?

    1. A

      To provide information to be added to other embeddings

    2. B

      To 'ask' which other tokens are relevant to this token

    3. C

      To normalize the attention scores

    4. D

      To compute the final output embedding

    Correct answer
    B

    To 'ask' which other tokens are relevant to this token

    Explanation

    The query is described as encoding a question like 'are there any adjectives sitting in front of me?'

  5. 5

    What is the dimension of the key/query space relative to the embedding dimension in GPT-3?

    1. A

      Exactly the same

    2. B

      Variable depending on the head

    3. C

      Larger (e.g., 15000)

    4. D

      Smaller (128 vs 12288)

    Correct answer
    D

    Smaller (128 vs 12288)

    Explanation

    The text specifies the query vector has 'much smaller dimension' (128) compared to the embedding dimension (12288).

  6. 6

    How is relevance between tokens measured in attention?

    1. A

      By computing cosine similarity

    2. B

      By using a small neural network

    3. C

      By computing the dot product between key and query vectors

    4. D

      By computing Euclidean distance

    Correct answer
    C

    By computing the dot product between key and query vectors

    Explanation

    The text states 'you compute a dot product between each possible key-query pair'.

  7. 7

    After computing dot products, what operation normalizes the attention scores for each column?

    1. A

      Normalization by dividing by sum

    2. B

      ReLU

    3. C

      Softmax

    4. D

      Sigmoid

    Correct answer
    C

    Softmax

    Explanation

    The text says 'We compute a softmax along each one of these columns to normalize the values.'

  8. 8

    Why is masking applied in self-attention during training?

    1. A

      To ignore unimportant tokens

    2. B

      To reduce computational cost

    3. C

      To make the attention pattern symmetric

    4. D

      To prevent later tokens from influencing earlier ones

    Correct answer
    D

    To prevent later tokens from influencing earlier ones

    Explanation

    Masking ensures 'later tokens to influence earlier ones' are forced to zero to avoid giving away the answer.

  9. 9

    How is masking implemented before softmax?

    1. A

      Multiplying by a mask matrix of zeros

    2. B

      Removing those entries from the computation

    3. C

      Setting those entries to negative infinity

    4. D

      Setting those entries to zero

    Correct answer
    C

    Setting those entries to negative infinity

    Explanation

    The text says 'before applying softmax, you set all of those entries to be negative infinity.'

  10. 10

    What does the size of the attention pattern scale with?

    1. A

      The number of attention heads

    2. B

      The number of layers

    3. C

      The embedding dimension

    4. D

      The square of the context size

    Correct answer
    D

    The square of the context size

    Explanation

    The text states 'its size is equal to the square of the context size.'

  11. 11

    In the value matrix factoring, what is the purpose of the 'value down' matrix?

    1. A

      To produce the final value vector

    2. B

      To combine all attention heads

    3. C

      To map embeddings from the large space to a smaller space

    4. D

      To compute the attention pattern

    Correct answer
    C

    To map embeddings from the large space to a smaller space

    Explanation

    The value down matrix maps 'the large embedding vectors down to a much smaller space.'

  12. 12

    How are the proposed changes from multiple attention heads combined for a given position?

    1. A

      Averaged

    2. B

      Concatenated and linearly transformed

    3. C

      Selected by a gating mechanism

    4. D

      Summed together

    Correct answer
    D

    Summed together

    Explanation

    The text says 'you sum together all of those proposed changes, one for each head, and you add the result to the original embedding.'

  13. 13

    In practice, the value up matrices from all heads are often combined into a single matrix called:

    1. A

      The projection matrix

    2. B

      The combination matrix

    3. C

      The output matrix

    4. D

      The merged matrix

    Correct answer
    C

    The output matrix

    Explanation

    The text mentions 'these value up matrices for each head appear stapled together in one giant matrix that we call the output matrix.'

  14. 14

    What is the approximate number of parameters in a single attention head of GPT-3 (including all four matrices)?

    1. A

      1.5 million

    2. B

      6.3 million

    3. C

      150 million

    4. D

      600 million

    Correct answer
    B

    6.3 million

    Explanation

    The text calculates 'about 6.3 million parameters for one attention head.'

  15. 15

    How many attention heads are used per block in GPT-3?

    1. A

      96

    2. B

      12

    3. C

      12288

    4. D

      128

    Correct answer
    A

    96

    Explanation

    The text states 'GPT-3 for example uses 96 attention heads inside each block.'

  16. 16

    How many layers (blocks) does GPT-3 have?

    1. A

      96

    2. B

      12

    3. C

      175

    4. D

      128

    Correct answer
    A

    96

    Explanation

    The text says 'GPT-3 includes 96 distinct layers.'

  17. 17

    What is the total number of parameters devoted to attention in GPT-3?

    1. A

      175 billion

    2. B

      600 million

    3. C

      58 billion

    4. D

      6.3 million

    Correct answer
    C

    58 billion

    Explanation

    The text computes 'just under 58 billion distinct parameters devoted to all of the attention heads.'

  18. 18

    What fraction of GPT-3's total parameters come from the attention mechanism?

    1. A

      About one half

    2. B

      Almost all

    3. C

      About two thirds

    4. D

      About one third

    Correct answer
    D

    About one third

    Explanation

    The text says 'it's only about a third of the 175 billion that are in the network in total.'

  19. 19

    What distinguishes cross-attention from self-attention?

    1. A

      Keys and queries come from different data sets

    2. B

      Only a single head is used

    3. C

      No softmax is applied

    4. D

      Masks are never used

    Correct answer
    A

    Keys and queries come from different data sets

    Explanation

    In cross-attention, 'the key and query maps act on different data sets.' Self-attention uses the same data.

  20. 20

    Why is the attention mechanism highly parallelizable?

    1. A

      It does not require sequential processing of tokens

    2. B

      It only involves simple arithmetic operations

    3. C

      It uses matrix multiplications that can be computed simultaneously on GPUs

    4. D

      Both of the above

    Correct answer
    D

    Both of the above

    Explanation

    The text highlights 'extremely parallelizable, meaning that you can run a huge number of computations in a short time using GPUs.'

  21. 21

    In training, how do transformers use each input sequence efficiently?

    1. A

      By using data augmentation on the input

    2. B

      By using contrastive learning with negative samples

    3. C

      By predicting the next token for every possible initial subsequence

    4. D

      By masking random tokens and predicting them

    Correct answer
    C

    By predicting the next token for every possible initial subsequence

    Explanation

    The text describes that you simultaneously predict every possible next token following each initial subsequence, making each training example act as many.

  22. 22

    What happens to the embedding of 'mole' in the initial step of a transformer?

    1. A

      It is replaced by a contextual embedding immediately

    2. B

      It is set to a zero vector

    3. C

      It becomes context-dependent based on the surrounding words

    4. D

      It is the same for all three phrases (e.g., 'American shrew mole', 'one mole of CO2')

    Correct answer
    D

    It is the same for all three phrases (e.g., 'American shrew mole', 'one mole of CO2')

    Explanation

    The initial token embedding is a lookup table with no context, so 'the vector that's associated with mole would be the same in all of these cases.'

  23. 23

    After the attention block, what is the embedding of a word like 'creature' in 'a fluffy blue creature' expected to represent?

    1. A

      The position of the word in the sentence

    2. B

      The word plus context from relevant words like 'fluffy' and 'blue'

    3. C

      A generic concept of an animal

    4. D

      Only the word 'creature' without context

    Correct answer
    B

    The word plus context from relevant words like 'fluffy' and 'blue'

    Explanation

    The attention block updates embeddings so that nouns 'ingest the meaning from their corresponding adjectives.'

  24. 24

    What is the dimension of the embedding space in GPT-3?

    1. A

      128

    2. B

      175

    3. C

      12288

    4. D

      96

    Correct answer
    C

    12288

    Explanation

    The text mentions the embedding dimension as 12,288 (e.g., '12,288 columns' for key/query matrices).

  25. 25

    What is the role of the value matrix in attention?

    1. A

      To produce a vector that is added to other embeddings

    2. B

      To normalize the attention scores

    3. C

      To compute which tokens attend to which

    4. D

      To compress the embeddings into a smaller space

    Correct answer
    A

    To produce a vector that is added to other embeddings

    Explanation

    The value matrix produces a vector that 'you add to the embedding of the second word.'

Question 1 of 25
Question 1 of 25

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent