Exploring Context Window of Large Language Models via Decomposed Positional Vectors

Transformer-based large language models (LLMs) typically have a limited context window, resulting in significant performance degradation when processing text beyond the length of the context window. Extensive studies have been proposed to extend the context window and achieve length extrapolation of LLMs, but there is still a lack of in-depth interpretation of these approaches. In this study, we explore the positional information within and beyond the context window for deciphering the underlying mechanism of LLMs. By using a mean-based decomposition method, we disentangle positional vectors from hidden states of LLMs and analyze their formation and effect on attention. Furthermore, when texts exceed the context window, we analyze the change of positional vectors in two settings, i.e., direct extrapolation and context window extension. Based on our findings, we design two training-free context window extension methods, positional vector replacement and attention window extension. Experimental results show that our methods can effectively extend the context window length.

Paper

References (33)

Scroll for more · 21 remaining

Similar papers

Peer review

Reviewer yDA46/10 · confidence 4/52024-07-06

Summary

This paper disentangles positional vectors from the hidden states of a pretrained Transformer language model to facilitate the understanding of length extrapolation. After a series of analyses, this paper proposes two context extending techniques. Experiments show that the proposed methods lower the perplexity on the task of language modeling.

Strengths

It's always good to have a mechanistic interpretability view of the hidden states of language models. The findings presented in this paper might inspire follow-up work along this direction.

Weaknesses

The experiments presented in the current draft are not convincing enough to me. See questions below.

Questions

1. Instead of continue training from the tinyllama model, I think training models from scratch using the 50B tokens budget will make the results in this paper more convincing. This is because you can get rid of the ripple effect of the originally used rope positional embeddings. Maybe your models were trying to unlearn rope during the continue training stage? 2. Apart from testing perplexity scores on the task of language modeling, I highly recommend the authors adding the experiment of needle in a haystack, otherwise I do not know if the models are really using all the tokens. 3. How do you decide the values of alpha and lambda in section 4.1 and 4.2? In addition, the temperature scaling technique was also used in several other places [1, 2] with explanations of how they did temperature selection. [1] YaRN: Efficient Context Window Extension of Large Language Models [2] Attention Alignment and Flexible Positional Embeddings Improve Transformer Length Extrapolation

Rating

6

Confidence

4

Soundness

2

Presentation

3

Contribution

3

Limitations

See above.

Authorsrebuttal2024-08-11

Our methods can keep the long context utilization capactity of LLMs to some extent.

Thank you for your response and valuable suggestion! To assess the long-context utilization capability, we have adopted your recommendation and evaluated the LLMs using ICL. Specifically, we randomly sampled consecutive substrings from the RedPajama dataset, with lengths of 20, 50, and 200 tokens, respectively. These substrings were then repeated to achieve varying lengths, and we evaluated the accuracy of the models' ability to repeat the first tokens of substrings correctly. The results are presented in the following table. | Total Length(L*N) | - | | 1K | | | 2K | | | 4K | | | 8K | | |-------|----|------|------|------|------|------|------|------|------|------|------|------|------| | Text Length(L) | - | 20 | 50 | 200 | 20 | 50 | 200 | 20 | 50 | 200 | 20 | 50 | 200 | | TL-NoPE-Window | original | 0.98 | 0.98 | 0.92 | 0.95 | 0.97 | 0.93 | 0.08 | 0.07 | 0.05 | 0.08 | 0.07 | 0.05 | | | attention window extension(r=2, lambda=1.1) | 0.99 | 0.96 | 0.9 | 0.89 | 0.89 | 0.92 | 0.66 | 0.89 | 0.92 | 0.06 | 0.07 | 0.06 | | | attention window extension(r=4, lambda=1.2) | 0.88 | 0.74 | 0.9 | 0.75 | 0.7 | 0.9 | 0.48 | 0.7 | 0.83 | 0.44 | 0.59 | 0.74 | | TL-NoPE-new | original | 1 | 0.9 | 0.86 | 1 | 0.9 | 0.86 | 0.11 | 0.49 | 0.13 | 0.06 | 0.07 | 0.01 | | | positional vector replacement(r=2.5, alpha=0.8) | 0.51 | 0.66 | 0.74 | 0.46 | 0.68 | 0.73 | 0.69 | 0.82 | 0.74 | - | - | - | | | positional vector replacement(r=5, alpha=0.8 | 0.3 | 0.26 | 0.23 | 0.25 | 0.21 | 0.28 | 0.24 | 0.22 | 0.29 | 0.21 | 0.49 | 0.64 | After exceeding the context window, the performance of models deteriorates significantly, whereas our methods maintain a degree of capability to utilize longer contexts effectively. Specifically, for TL-Window-NoPE, as the substring length increases, the model exhibits slower degradation of performances. For TL-NoPE, with much longer substrings (for example, 200 tokens), the model even demonstrates superior performance at 8K tokens compared to 2K tokens. These enhancements underscore that our models can leverage longer contexts for enhanced performance.

Reviewer yDA42024-08-11

Thank you. I have one more question.

Thank you for the additional experiments. One question: Could you also report the numbers of TL_NoPE with your proposed positional vector replacement method?

Authorsrebuttal2024-08-11

Experiments with TL-NoPE.

Thank you for your response! We have evaluated the continually trained TL-NoPE and observed similar phenomena, with the hyperparameters listed in the second column of the table below. As demonstrated in the table, TL-NoPE with our method can utilize the long context to some extent to repeat the first token. Moreover, longer substrings (200 tokens) enhance the model's performance in in-context learning (ICL) with long contexts, which underscores the effectiveness of our methods in leveraging long contexts. Finally, further expanding the interpolation ratio and times can yield better performance on longer inputs, albeit with a slight degradation in performance on shorter inputs. | Total Length(L*N) | - | | 1K | | | 2K | | | 4K | | | 8K | | |-------------------|-----------------------------------------------|------|------|------|------|------|------|------|------|------|------|------|------| | Text Length(L) | - | 20 | 50 | 200 | 20 | 50 | 200 | 20 | 50 | 200 | 20 | 50 | 200 | | TL-NoPE | original | 1 | 0.99 | 0.94 | 1 | 0.99 | 0.92 | 0.11 | 0.05 | 0.06 | 0.06 | 0.06 | 0.06 | | | positional vector replacement(r=2, alpha=1.1) | 0.97 | 0.97 | 0.91 | 0.95 | 0.95 | 0.93 | 0.67 | 0.74 | 0.68 | - | - | - | | | positional vector replacement(r=5, alpha=1.3) | 0.65 | 0.85 | 0.86 | 0.56 | 0.8 | 0.87 | 0.5 | 0.72 | 0.84 | 0.14 | 0.28 | 0.68 | | | positional vector replacement(r=6, alpha=1.4) | 0.61 | 0.85 | 0.83 | 0.46 | 0.68 | 0.86 | 0.43 | 0.59 | 0.77 | 0.23 | 0.43 | 0.73 |

Reviewer yDA42024-08-11

Thank you for the additional experiments

Thank you for the additional results. It would be great if you can add them to the final revision. In addition, please also add the missing references [1, 2] to the final revision so that the readers are aware of the similar temperature scaling technique explored in the context of other positional embeddings. I increased the score to 6.

Reviewer 1sVW7/10 · confidence 3/52024-07-08

Summary

This paper proposes a mean-based decomposition technique to analyze the formation and effect of positional encodings in LLMs. It then uses these results to propose methods to extend the context window, resulting in models that generalize better to longer texts.

Strengths

1. This paper is very well-written, and the main findings are properly highlighted. 2. This paper not only explains how positional vectors are formed, but also introduces methods to interpolate them based on the findings. 3. Experiments are performed to show that the new methods result in better perplexity scores beyond the context window.

Weaknesses

I believe this contribution is novel and insightful enough, and there is no apparent weakness.

Questions

1. The legends and graphs in Figure 4 overlap.

Rating

7

Confidence

3

Soundness

3

Presentation

4

Contribution

3

Limitations

The authors have adequately addressed the limitations of their work.

Reviewer R24u7/10 · confidence 4/52024-07-17

Summary

This paper dives into the inner workings of how transformer-based language models handle positional information. By decomposing hidden states into semantic and positional vectors, the authors give a series of analysis about how the positional information are encoded and propagated through layers. I believe this work offers valuable insights for understanding the positional information within the transformer architecture.

Strengths

Very detailed and clear analysis about how the positional information is encoded and propagated within the transformer architecture, and to the best of my knowledge, I have not seen similar work before. I particularly enjoyed reading Figure 2 and 3, which shows how positional information is propagated through layers and goes beyond the window size, and shows how the manipulation of the positional embedding causally influence the attention patterns, particularly removing the attention sink.

Weaknesses

There are few points that I would like to suggest here to make the paper even stronger. - Section 4 feels weak and unnecessary. The performance of replacing the positional vector, if my understanding is correct, seems to be much worse than Dynamic NTK. Given the current mainstream approach is modifying the base of Rope (like YaRN), which is much easier than the approach proposed by this work, I do not think this work’s proposed context extension will be accepted by mainstream model builder. - That being said, I think the in-depth analysis of the positional embeddings are strong enough for me to give an acceptance (I learned a lot from it), so **I would strongly suggest removing the content of section 4, and use its space for more experimental analysis of the positional vectors** There are a few important problems that I believe will receive the communities’ attention and worth being addressed: - Although this paper shows the positional information can propagate through layers (Figure 2), in practice, many work found that models with window attention cannot pass the needle in a haystack test, and this is why Mistral 1.5 changed its attention back to full attention. It would be insightful if the authors can discuss the relationships between positional information and needle-in-a-haystack performance (because needle in haystack is what makes long-context models useful), i.e., why window attention cannot pass needle in haystack even it does have the correct positional information? - This paper’s analysis is restricted on TinyLLaMA, but TinyLLaMA is not a widely used open-source model, thus casting the doubt whether this discovery of this paper will hold for other model families, particularly mainstream open-weight models like LLaMA 3, Mistral, QWen or Yi. I would strongly suggest the authors verify the behavior of positional embedding on either LLaMA 3, Mistral, QWen, or Yi. Currently I’m given a borderline accept, and I will consider increasing my scores if the authors could either (1) discuss the relationship between positional vectors v.s. needle-in-a-haystack or (2) verify that the properties of positional vectors hold for LLaMA 3, Mistral, QWen or Yi (any 2 out of the 4).

Questions

see the above weakness section

Rating

7

Confidence

4

Soundness

4

Presentation

3

Contribution

4

Limitations

see the above weakness section

Authorsrebuttal2024-08-10

Hi Reviewers, Can I please know whether our response addresses your questions? We are curious if there are any particular limitations or weaknesses that prevent you from raising your score. If so, we'd like to have the opportunity to address those during this discussion period.

Reviewer yDA42024-08-10

Thank you for the rebuttal

Q1 and Q3: Thank you for addressing the concerns. We are good now. Q2: I believe there should be other methods to test whether the model is truly utilizing long-context information. I would assume TinyLLama still has a decent in-context learning ability given its size. If so, one experiment I can suggest is: Take a segment (S) of natural text with length L. Repeat it N times and concatenate them to form an artificial sequence (A) with a length of L*N. Feed A into your length-extended model and observe the output. If the model learns to use long-context information, it should output the first token of the original short sequence (S[0]). Note that S[0] is not a natural continuation of A; the model will only output S[0] if it leverages the long artificial in-context examples provided. You can then experiment with different values of L and N to demonstrate the model's ability to process long-context information. The experiment above is just one example. Feel free to devise other methods that can effectively demonstrate the long-context processing capabilities of your model.

Reviewer 1sVW2024-08-13

Thanks for the response!

Program Chairsdecision2024-09-25

Decision

Accept (spotlight)

© 2026 NYSGPT2525 LLC