NCA-GENL practice question 3 of 15

Why do we need positional encoding in transformer-based models?

Full set: 95 questions

Domain Large Language Models (LLMs)

Answer options
A: To represent the order of elements in a sequence. Correct answer
B: To prevent overfitting of the model.
C: To reduce the dimensionality of the input data.
D: To increase the throughput of the model.
Correct Answer:
A. To represent the order of elements in a sequence.
Explanation

The core mechanism of a transformer model, self-attention, processes all input tokens in parallel. This design makes the model permutation-invariant, meaning it does not inherently recognize the order of elements in a sequence. For example, the sentences "dog bites man" and "man bites dog" would appear identical to the self-attention layer. Positional encoding is a crucial component that injects information about the relative or absolute position of each token into its embedding. This allows the model to learn and utilize the sequential nature of the data, which is essential for understanding context in tasks like natural language processing.

Why Incorrect

B. Techniques like dropout or weight decay are used to prevent overfitting; positional encoding's primary role is to provide sequential information, not regularization.
C. Positional encoding vectors are added to the input embeddings, maintaining the same dimensionality, not reducing it.
D. Throughput relates to processing speed. While transformers are efficient, positional encoding is a functional necessity for sequence awareness, not a feature to increase throughput.

References

1. Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., & Polosukhin, I. (2017). Attention Is All You Need. Advances in Neural Information Processing Systems 30 (NIPS 2017). Section 3.5, "Positional Encoding," Paragraph 1: "Since our model contains no recurrence and no convolution, in order for the model to make use of the order of the sequence, we must inject some information about the relative or absolute position of the tokens in the sequence."

2. Stanford University. (2021). CS224N: Natural Language Processing with Deep Learning, Lecture 9: Self-Attention and Transformers. Slide 58, "Transformers: Positional Embeddings": "This is the main weakness of Self-Attention. There is no notion of word order (permutation invariance)... We need a way to encode position."

3. Alammar, J. (2018). The Illustrated Transformer. GitHub Blog. Section: "Positional Encoding": "One thing that’s missing from the model as we have described it so far is a way to account for the order of the words in the input sequence... To address this, the transformer adds a vector to each input embedding. These vectors follow a specific pattern that the model learns, which helps it determine the position of each word, or the distance between different words in the sequence." (Note: While a blog, this source is widely cited in academic courseware, including by Stanford, for its accurate and clear explanation of the seminal paper).

Scroll to Top