1. Home
  2. Explore
  3. Computer Science
  4. Transformer Neural Networks Explained

Study methods

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

Transformer Neural Networks Explained

  • 29Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Word Embedding and Tokenization

What is the primary purpose of word embedding in a Transformer neural network?

29 questions

  1. 1

    What is the primary purpose of word embedding in a Transformer neural network?

    1. A

      To calculate similarity between words

    2. B

      To convert words into numerical vectors

    3. C

      To determine word order in a sentence

    4. D

      To generate output tokens

    Correct answer
    B

    To convert words into numerical vectors

    Explanation

    Word embedding converts each word (or token) into a vector of numbers that can be processed by the neural network.

  2. 2

    In the simple word embedding network described, what happens when an input token's value is 0?

    1. A

      It produces a large output

    2. B

      It multiplies weights by 1

    3. C

      It is ignored entirely

    4. D

      It sends zeros to the activation functions

    Correct answer
    D

    It sends zeros to the activation functions

    Explanation

    When the input value is 0, all products with weights become 0, so only zeros are passed to the activation functions.

  3. 3

    What type of activation function is used in the word embedding example?

    1. A

      Sigmoid function

    2. B

      ReLU function

    3. C

      Tanh function

    4. D

      Identity function

    Correct answer
    D

    Identity function

    Explanation

    The example uses identity activation functions, meaning output equals input.

  4. 4

    How is the word embedding network reused for multiple input tokens?

    1. A

      Different weights are used for each token

    2. B

      A separate network is created for each token

    3. C

      The same weights are used for each token

    4. D

      Weights are randomly sampled for each token

    Correct answer
    C

    The same weights are used for each token

    Explanation

    The transformer reuses the same word embedding weights for every token, allowing flexibility with input length.

  5. 5

    What does a token include in the vocabulary of a Transformer?

    1. A

      Only individual letters

    2. B

      Words, word fragments, and symbols

    3. C

      Only complete words

    4. D

      Only sentence boundaries

    Correct answer
    B

    Words, word fragments, and symbols

    Explanation

    The vocabulary can be a mix of words, word fragments (subwords), and special symbols like EOS.

  6. 6

    Why does a Transformer need positional encoding?

    1. A

      To convert words into numbers

    2. B

      To keep track of word order

    3. C

      To normalize the output

    4. D

      To calculate attention scores

    Correct answer
    B

    To keep track of word order

    Explanation

    Positional encoding adds information about the position of each word in the sequence, since transformers process words in parallel and don't inherently know order.

  7. 7

    How are positional encoding values generated in the described method?

    1. A

      Using the word embedding values themselves

    2. B

      Using a sequence of alternating sine and cosine functions

    3. C

      Using the softmax function

    4. D

      Using random numbers

    Correct answer
    B

    Using a sequence of alternating sine and cosine functions

    Explanation

    Positional encodings are created from sine and cosine functions of different frequencies, one for each embedding dimension.

  8. 8

    What ensures that each word in a sentence gets a unique sequence of positional encoding values?

    1. A

      The sine and cosine squiggles have different frequencies for different embedding positions

    2. B

      The softmax function is applied

    3. C

      The weights are trained

    4. D

      The activation functions are non-linear

    Correct answer
    A

    The sine and cosine squiggles have different frequencies for different embedding positions

    Explanation

    As the embedding dimension increases, the sine/cosine waves become wider, giving each position a unique combination of values.

  9. 9

    When the order of words in a sentence is reversed, what happens to the positional encoding?

    1. A

      The positional values are recalculated using different sine/cosine functions

    2. B

      The positional encoding is no longer needed

    3. C

      The positional values for the first and third words are swapped

    4. D

      The positional values for each word remain the same

    Correct answer
    C

    The positional values for the first and third words are swapped

    Explanation

    Positional values are tied to positions, not words. Swapping words swaps which word gets which position's encoding values.

  10. 10

    What is the purpose of self-attention in a Transformer?

    1. A

      To convert words to numbers

    2. B

      To determine word order

    3. C

      To select the output token

    4. D

      To keep track of relationships between words in the input

    Correct answer
    D

    To keep track of relationships between words in the input

    Explanation

    Self-attention calculates how much each word should influence the encoding of every other word, capturing context.

  11. 11

    In self-attention, what are the three types of vectors created for each token?

    1. A

      Embedding, Position, Context

    2. B

      Input, Output, Hidden

    3. C

      Query, Key, Value

    4. D

      Encoder, Decoder, Loss

    Correct answer
    C

    Query, Key, Value

    Explanation

    Queries, keys, and values are computed from the input using learned weight matrices. They are used to compute attention scores and weighted sums.

  12. 12

    How is the similarity between a query and a key calculated in the basic self-attention described?

    1. A

      Dot product

    2. B

      Euclidean distance

    3. C

      Cosine similarity

    4. D

      Cross-correlation

    Correct answer
    A

    Dot product

    Explanation

    The dot product of the query and key vectors gives a scalar similarity score.

  13. 13

    What is the role of the softmax function in self-attention?

    1. A

      To normalize the output values

    2. B

      To select the maximum similarity score

    3. C

      To convert similarity scores into probabilities that sum to 1

    4. D

      To add non-linearity

    Correct answer
    C

    To convert similarity scores into probabilities that sum to 1

    Explanation

    Softmax converts raw dot products into probabilities (0 to 1, sum=1) that determine how much each value contributes to the output.

  14. 14

    How are the value vectors used in self-attention?

    1. A

      They are scaled by the softmax probabilities and summed to produce the self-attention output

    2. B

      They are directly added to the query vectors

    3. C

      They are ignored

    4. D

      They replace the key vectors

    Correct answer
    A

    They are scaled by the softmax probabilities and summed to produce the self-attention output

    Explanation

    Each value vector is multiplied by its corresponding softmax weight, then all weighted values are summed to form the final self-attention output for that token.

  15. 15

    Why can self-attention calculations be performed in parallel for all tokens?

    1. A

      The tokens are processed sequentially

    2. B

      The positional encoding is done afterwards

    3. C

      The softmax function requires all similarities at once

    4. D

      The same weights are reused for each token, allowing independent computation

    Correct answer
    D

    The same weights are reused for each token, allowing independent computation

    Explanation

    Because the same set of weights is used for every token, the queries, keys, and values for all tokens can be computed simultaneously, enabling parallel processing.

  16. 16

    What is multi-head attention?

    1. A

      Stacking multiple self-attention cells with different weight sets

    2. B

      Using multiple queries per token

    3. C

      Combining encoder and decoder attention

    4. D

      Attention across multiple sentences

    Correct answer
    A

    Stacking multiple self-attention cells with different weight sets

    Explanation

    Multi-head attention runs several self-attention operations in parallel (each with its own weights) to capture different types of relationships.

  17. 17

    How many self-attention cells were stacked in the original Transformer manuscript?

    1. A

      4

    2. B

      16

    3. C

      8

    4. D

      12

    Correct answer
    C

    8

    Explanation

    The original Transformer paper used 8 attention heads (multi-head attention with 8 parallel self-attention cells).

  18. 18

    What is the purpose of residual connections in a Transformer?

    1. A

      To allow each sublayer to focus on its task without preserving all information

    2. B

      To compute positional encoding

    3. C

      To replace softmax

    4. D

      To increase the number of parameters

    Correct answer
    A

    To allow each sublayer to focus on its task without preserving all information

    Explanation

    Residual connections add the input of a sublayer to its output, so the sublayer only needs to learn the residual change, making training easier.

  19. 19

    What is the purpose of encoder-decoder attention in a Transformer?

    1. A

      To normalize the values

    2. B

      To compute self-attention in the encoder

    3. C

      To encode the output sequence

    4. D

      To allow the decoder to keep track of important words in the input

    Correct answer
    D

    To allow the decoder to keep track of important words in the input

    Explanation

    Encoder-decoder attention helps the decoder focus on relevant parts of the input sentence during translation.

  20. 20

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

    1. A

      Queries from the decoder, keys and values from the encoder

    2. B

      Queries from the encoder, keys and values from the decoder

    3. C

      All from the decoder

    4. D

      All from the encoder

    Correct answer
    A

    Queries from the decoder, keys and values from the encoder

    Explanation

    The decoder provides queries, while the encoder provides keys and values. This allows the decoder to attend to the input sequence.

  21. 21

    How does encoder-decoder attention help when translating a sentence like "Don't eat the pizza"?

    1. A

      It focuses on the last word

    2. B

      It ignores unimportant words

    3. C

      It translates each word independently

    4. D

      It emphasizes the word "Don't" to ensure negation is captured

    Correct answer
    D

    It emphasizes the word "Don't" to ensure negation is captured

    Explanation

    By attending to the input, the decoder can give more weight to important words like "Don't" to preserve the meaning.

  22. 22

    In the decoding example shown, which token is used to initialize the decoder?

    1. A

      PAD (Padding)

    2. B

      EOS (End of Sequence)

    3. C

      SOS (Start of Sequence)

    4. D

      UNK (Unknown)

    Correct answer
    B

    EOS (End of Sequence)

    Explanation

    The example uses the EOS token to start decoding, though SOS is also commonly used.

  23. 23

    After the first translated word is selected, what does the decoder do next?

    1. A

      It applies a softmax to the encoder output

    2. B

      It recalculates word embeddings for all input words

    3. C

      It stops immediately

    4. D

      It feeds that word back into the decoder to generate the next word

    Correct answer
    D

    It feeds that word back into the decoder to generate the next word

    Explanation

    The decoder uses the previously generated word as input to produce the next word, repeating until an EOS token is output.

  24. 24

    What determines when the decoding process stops?

    1. A

      After a fixed number of steps

    2. B

      When all input words are translated

    3. C

      When the decoder outputs an EOS token

    4. D

      When the softmax probability is above 0.5

    Correct answer
    C

    When the decoder outputs an EOS token

    Explanation

    The decoder outputs an EOS token to signal the end of the translated sequence.

  25. 25

    How are the weights in a Transformer initially set before training?

    1. A

      Random values

    2. B

      Calculated from word frequency

    3. C

      All zeros

    4. D

      Pre-determined from a dictionary

    Correct answer
    A

    Random values

    Explanation

    Weights are initialized randomly and then optimized through backpropagation during training.

  26. 26

    What process is used to optimize the weights of a Transformer during training?

    1. A

      Gradient ascent

    2. B

      Forward propagation

    3. C

      Random search

    4. D

      Backpropagation

    Correct answer
    D

    Backpropagation

    Explanation

    Backpropagation computes gradients of the loss with respect to weights, and gradient descent updates the weights to minimize the loss.

  27. 27

    What technique did the original Transformer use to prevent values from growing too large?

    1. A

      Early stopping

    2. B

      Weight decay

    3. C

      Normalization after each step

    4. D

      Dropout

    Correct answer
    C

    Normalization after each step

    Explanation

    Layer normalization is applied after each sublayer (e.g., after self-attention and feed-forward networks) to stabilize training.

  28. 28

    How was the dot product similarity scaled in the original Transformer?

    1. A

      Divided by the square root of the number of embedding values per token

    2. B

      Raised to a power

    3. C

      Multiplied by the number of tokens

    4. D

      Added to a bias term

    Correct answer
    A

    Divided by the square root of the number of embedding values per token

    Explanation

    The dot product is divided by sqrtdksqrt{d_k}sqrtdk​ (where dkd_kdk​ is the dimension of keys) to prevent large values in the softmax.

  29. 29

    How can a Transformer be given more capacity to fit complex data?

    1. A

      By increasing the learning rate

    2. B

      By reducing the vocabulary size

    3. C

      By adding additional neural networks with hidden layers

    4. D

      By using only one attention head

    Correct answer
    C

    By adding additional neural networks with hidden layers

    Explanation

    Extra feed-forward layers or more attention heads increase the number of parameters, allowing the model to learn more complex patterns.

Question 1 of 29
Question 1 of 29

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent