In-Context Learning State Vector with Inner and Momentum Optimization

Large Language Models (LLMs) have exhibited an impressive ability to perform In-Context Learning (ICL) from only a few examples. Recent works have indicated that the functions learned by ICL can be represented through compressed vectors derived from the transformer. However, the working mechanisms and optimization of these vectors are yet to be thoroughly explored. In this paper, we address this gap by presenting a comprehensive analysis of these compressed vectors, drawing parallels to the parameters trained with gradient descent, and introduce the concept of state vector. Inspired by the works on model soup and momentum-based gradient descent, we propose inner and momentum optimization methods that are applied to refine the state vector progressively as test-time adaptation. Moreover, we simulate state vector aggregation in the multiple example setting, where demonstrations comprising numerous examples are usually too lengthy for regular ICL, and further propose a divide-and-conquer aggregation method to address this challenge. We conduct extensive experiments using Llama-2 and GPT-J in both zero-shot setting and few-shot setting. The experimental results show that our optimization method effectively enhances the state vector and achieves the state-of-the-art performance on diverse tasks. Code is available at https://github.com/HITsz-TMG/ICL-State-Vector

Paper

References (44)

Scroll for more · 32 remaining

Similar papers

Peer review

Reviewer MvM27/10 · confidence 5/52024-07-12

Summary

This work introduces the novel concept of the state vector. It encapsulates the information of ICL examples from separate tokens as anchors. Drawing inspiration from the duality between transformer attention and gradient descent, the authors implement inner and momentum optimization to generate task-specific state vectors. To address the context length limitation of LLMs, a divide-and-conquer strategy is employed to aggregate information from multiple examples into a single state vector. Experimental results demonstrate that patching the state vector during the inference forward pass outperforms previously proposed task vector and function vectors.

Strengths

1. Although the idea of using vectors to capture in-context learning is not new, the proposed approach of optimizing the state vector using inner/momentum optimization is well-motivated. 2. The paper is well-organized and sound with experiments and ablation studies. 3. The experimental results and the analyses provide some useful insights.

Weaknesses

1. It is not clear whether larger models or more complex datasets can still benefit from this work. Is this work only applicable to relatively small models? 2. It is unclear why a dummy query has to be included when extracting the state vector, whose task is to encapsulate the examples only. What if not? 3. Can we use this vector to align LLMs further, considering encapsulating them into memory/vector bases for reuse and continuous learning of new knowledge?

Questions

## Summary of review In general, the paper presents an interesting concept, and the overall submission is technically sound. Therefore I am positive to this paper at this point. However, I hope the authors can address the several concerns raised in the weakness section by providing extra explanations and discussions regarding the unclear aspects. Also, please response to the additional questions shown as follows. If the authors can well address my concerns/questions, I will keep the positive accept rating. ## Additional questions 1. I would like to know whether the ICL state vector can be used in actual alignment scenarios. If we switch to a long-context version of the model, how will the ICL state vector be different? 2. The previous study demonstrates that the label words are information anchors [1], while this work aggregates the information of separate tokens in the state vector, is there any evidence that the separate tokens can also gather in-context information in a progressive manner? [1]Lean Wang, Lei Li, Damai Dai, Deli Chen, Hao Zhou, Fandong Meng, Jie Zhou, and Xu Sun. 2023. Label Words are Anchors: An Information Flow Perspective for Understanding In-Context Learning. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, pages 9840–9855, Singapore. Association for Computational Linguistics.

Rating

7

Confidence

5

Soundness

3

Presentation

2

Contribution

3

Limitations

n/a

Authorsrebuttal2024-08-12

A follow-up message about the rebuttal for the paper15186

Dear Reviewer `MvM2`, We hope you are doing well. As the discussion period is coming to an end (Aug 13), we wanted to reach out to see if you have any follow-up questions. If so, we would appreciate the opportunity to respond before the discussion period ends. We believe our above messages should have addressed your concerns, and therefore may warrant an increase in score if you find them helpful as well. Would you please let us know if you have any further questions or concerns? We are happy to continue the discussion. Thank you very much again for your thoughtful review and help in improving the paper. We appreciate your time and consideration. Best regards, Paper15186 Authors

Reviewer MvM22024-08-13

Thank you for your response

Thank you for your response to the rebuttal. I appreciate that my concerns have been taken into consideration. I suggest that the authors enhance the paper by integrating feedback from other reviewers, including the use of larger-scale models and addressing presentation issues. As a result, I maintain my acceptance of the paper at this stage.

Authorsrebuttal2024-08-13

Dear Reviewer `MvM2`, We are glad to have addressed your concerns. Please let us know if you have any further questions, as we are happy to continue the discussion.

Reviewer 4gb34/10 · confidence 4/52024-07-13

Summary

The paper presents an in-depth analysis and optimization of In-Context Learning (ICL) within large language models (LLMs). In particular, it proposes inner and momentum-based optimization techniques to increase the performance of in-context learning.

Strengths

1. In-depth analysis of ICL vectors across 12 different datasets (linguistic, translation, and knowledge). The analysis provides insights into ICL vectors and motivates the optimization. 2. The optimization method can be divided into inner and momentum-based stages, each of which has shown promising improvement. 3. The ablation study is abundant. 4. The presentation of the research question is clear to read and follow.

Weaknesses

1. The method itself is somewhat simple. Specifically, the inner optimization is merely a uniform averaging. 2. The definition of state vectors lacks a rigorous theoretical basis, making it difficult to infer the approach's generalizability and reliability across different NLP tasks. 3. The experiments are conducted on Llama-2-7B and GPT-J-6B, which are limited in terms of scale and performance.

Questions

In principle, ICL plays a more significant role in larger models (also with better long-sequence performance). Does this method benefit these models?

Rating

4

Confidence

4

Soundness

3

Presentation

3

Contribution

2

Limitations

NA

Authorsrebuttal2024-08-12

A follow-up message about the rebuttal for the paper15186

Dear Reviewer `4gb3`, We hope you are doing well. As the discussion period is coming to an end (Aug 13), we wanted to reach out to see if you have any follow-up questions. If so, we would appreciate the opportunity to respond before the discussion period ends. We believe our above messages should have addressed your concerns, and therefore may warrant an increase in score if you find them helpful as well. Would you please let us know if you have any further questions or concerns? We are happy to continue the discussion. Thank you very much again for your thoughtful review and help in improving the paper. We appreciate your time and consideration. Best regards, Paper15186 Authors

Reviewer 4gb32024-08-12

Key concerns remain

I thank the authors for this detailed reply. However, regarding my points, the response is not satisfactory. 1. The formalization of state vector is the key point if the authors claim this method "as the first to establish a bridge between the theoretical understanding of ICL's working mechanism and the application of ICL compressed vectors". What is the advance of this method in this perspective? I think this will enhance the theoretical basis. How does this improve the authors' understanding and motivate this simple method? 2. The added experiment in Figure 10 actually raises more questions. Firstly, it looks like the "regular" baseline is missing. Also, for the few shot settings on LIama-2-70B, the method does not generate significant results (near or lower than ICL), especially for the AVG. Does this mean average aggregation is not very effective (given its simple form)? Also, it is quite true for main figure 2. For the 70B results, the D&C is also improving less over AVG. Why does this happen? Improvement on larger/more powerful base models is more concern given the nature of ICL. All in all, I am currently unable to change my score.

Authorsrebuttal2024-08-13

We sincerely appreciate your thoughtful feedback and questions. We are more than happy to engage in a discussion to address the concerns regarding the formalization of the state vector and the addition aggregation experiment on Llama-2-70B. *** ## **The Advantage of State Vector Formalization** We are glad to clarify that our formalization of the state vector contributes to the advancement of research in both the ICL working mechanism and ICL compression vector domains. **ICL Working Mechanism** Previous studies[1, 2, 3] that based on the dual view of ICL and gradient descent have primarily provided evidence from the perspective of attention pattern similarity. In contrast, our research demonstrates that certain optimization algorithms applied to the gradient can also effectively refine the state vector. This finding introduces new evidence from the perspective of ICL compression vector application. Although we acknowledge that this approach does not conclusively establish the ICL mechanism, we argue that our study presents a novel perspective and empirical support that contribute to advancing the understanding of ICL’s underlying mechanism. **ICL Compression Vector** Earlier studies[4, 5] on ICL compression vectors suggested that hidden states or attention activations in transformers contain information related to the ICL task function. However, these studies were largely based on hypotheses and empirical analysis, lacking a solid theoretical foundation. Our work extends this line of inquiry by leveraging the dual view of ICL and gradient descent. We propose that attention activations can be viewed as trained parameters. This offers theoretical justification for the idea that attention activations could store the ICL task function, thereby providing a more robust basis for understanding their role. In summary, we argue that our work provides new insights and evidence that contribute to the advancement of research in both the ICL working mechanism and the application of compression vectors. [1] *Why can gpt learn in-context? language models implicitly perform gradient descent as meta-optimizers* [2] *In-context Learning and Gradient Descent Revisited* [3] *Transformers Learn In-Context by Gradient Descent* [4] *In-context learning creates task vectors* [5] *Function vectors in large language models*

Authorsrebuttal2024-08-13

## **The Experiment result on Figure 10** We sincerely appreciate your insightful observations regarding the experiment in `Figure 10`. Thank you for pointing out the issue with the missing regular baseline. To address this and supplement our analysis, we have provided the original results of the Llama-2-70B aggregation experiment below. We will also revise our tables accordingly. Due to space constraints, we are only presenting the results for the 10 examples and 100 examples settings. We categorize the result into zero-shot and few-shot settings. **Zero-shot**: | | Regular | Avg. 10-examples | Avg. 100-examples | D&C 10-examples | D&C 100-examples | | ----------------- | ------- | ---------------- | ----------------- | --------------- | ---------------- | | Person-Occupation | 0.0 | 7.6 | 18.1 | 0.7 | 31.8 | | Antonym | 0.1 | 61.0 | 63.1 | 51.7 | 64.5 | | English-French | 0.3 | 35.7 | 34.1 | 26.7 | 46.9 | | Product-Company | 0.1 | 11.0 | 17.5 | 32.9 | 34.2 | **Few-shot**: | | ICL baseline | Avg. 10-examples | Avg. 100-examples | D&C 10-examples | D&C 100-examples | | ----------------- | ------------ | ---------------- | ----------------- | ---------------- | ---------------- | | Person-Occupation | 70.4 | 68.7 | 71.1 | 48.0 | 72.6 | | Antonym | 68.1 | 67.7 | 68.3 | 62.2 | 71.7 | | English-French | 82.9 | 82.1 | 82.6 | 77.5 | 84.6 | | Product-Company | 80.1 | 80.2 | 80.9 | 75.5 | 85.1 | As shown in the few-shot results, our D&C aggregation performs worse than the ICL baseline and average aggregation when the number of aggregated examples is small. The primary reason for this is that the conquer stage relies on a limited number of examples (e.g., only 1-shot in the conquer stage of D&C aggregation, compared to 10-shot for average aggregation when using a total of 10 examples). This limitation prevents the model's ability to effectively compress information from the group-specific state vectors into the final D&C aggregated state vector. However, as the number of examples increases, the performance of D&C aggregation improves significantly. At the 100-example setting, it outperforms the ICL baseline across four datasets (**with improvements of 2.2 on Person-Occupation, 3.6 on Antonym, 1.7 on English-French, and 5.0 on Product-Company**). Additionally, in the experiments shown in `Figure 2`, our method also achieves notable improvements (**ranging from 1.4 to 11.3 on Llama-2-7B and from 1.3 to 10.1 on GPT-J**). **We achieved similar improvements on the larger Llama-2-70B model as we did on the smaller Llama-2-7B model**, which demonstrates the effectiveness of our D&C aggregation method. Regarding the average aggregation, we would like to emphasize that **we included the average aggregation as a straightforward and intuitive baseline instead of the proposed method (it's not our main contributions)**. Consistent with your observations, we also found that the averaging aggregation does not yield significant results on Llama-2-70B. We attribute this to the fact that the simple average method, while providing some improvement, is insufficient for state vector aggregation. In contrast, our proposed D&C aggregation surpasses average aggregation under the 100-shot setting, which shows that our method is more effective and offers greater improvement over average aggregation. *** Thank you very much again for your thoughtful review and feedback. Please let us know if you have any further questions, as we are happy to continue the discussion.

Reviewer yzeU4/10 · confidence 4/52024-07-14

Summary

The authors focus on the compressed vectors in In-Context Learning (ICL). They highlights the similarities between the compressed vectors and parameters trained via gradient descent, proposing the formulation of the state vector. Then they applies two optimization algorithm to progressively refine state vector. The proposed method achieves SotA performance on diverse tasks.

Strengths

1.The authors introduce the formulation of state vector that encapsulates the processing state of ICL stored in the attention activations. 2.The proposed two optimization methods for the state vector seem to be effective. 3. The research topic is significant and intriguing

Weaknesses

1.The proposed state vector seems to be benefit from examples (as shown in Eqn. 5), could you explain how it works without demonstration in the zero-shot setting (as shown in Table 1)? 2.As ICL baseline makes predictions conditioned on the demonstrations, could you explain why its performance remains unchanged with different number of examples in Figure 2? 3.The proposed method is mainly draw inspiration from trainable parameters and gradient optimization algorithm. However, the performance of applying other classical gradient optimization algorithms has deteriorated significantly in Table 2. And the authors argue that “The outcome indicates a discrepancy between the state vector and updated parameters with gradient descent.” This confuses me a lot. The authors should state their similarities and differences more clearly and precisely.

Questions

See weakness.

Rating

4

Confidence

4

Soundness

2

Presentation

2

Contribution

2

Limitations

See weakness.

Authorsrebuttal2024-08-12

A follow-up message about the rebuttal for the paper15186

Dear Reviewer `yzeU`, We hope you are doing well. As the discussion period is coming to an end (Aug 13), we wanted to reach out to see if you have any follow-up questions. If so, we would appreciate the opportunity to respond before the discussion period ends. We believe our above messages should have addressed your concerns, and therefore may warrant an increase in score if you find them helpful as well. Would you please let us know if you have any further questions or concerns? We are happy to continue the discussion. Thank you very much again for your thoughtful review and help in improving the paper. We appreciate your time and consideration. Best regards, Paper15186 Authors

Reviewer FZSw7/10 · confidence 4/52024-07-16

Summary

This paper aims to revealing the working mechanism of the compressed state vector in context learning. They first prove the state vectors are similar with parameters trained via gradient descent. Then, they propose three methods to optimize such kind of parameters: (1) inner optimization averaging each vector of the separate token; (2) momentum optimization using momentum-based optimization algorithm; (3) divide-and-conquer strategy aggregating several vector groups. They test these methods on some medium-sized LLMs. Experiments show some improvements against other compressed vector baselines.

Strengths

1. The paper is well written and easy to follow. 2. The contribution of this paper is significant. It attempts to provide understanding of the mechanism of ICL via a gradient descent perspective. The proposed state vector can be viewed as trained parameters so that they can be optimized with future methods. 3. The proposed optimization methods are reasonable. Experiments with these methods support their claims. The performance can be improved in most scenarios.

Weaknesses

A substantive assessment of the weaknesses of the paper. Focus on constructive and actionable insights on how the work could improve towards its stated goals. Be specific, and avoid generic remarks. For example, if you believe the contribution lacks novelty, provide references and an explanation as evidence; if you believe experiments are insufficient, explain why and exactly what is missing, etc. Please keep in mind that the rebuttal period is not necessarily enough to run new experiments. As a result, asking for new results is rather unrealistic.

Questions

1. Does the state vector without optimization actually function the same as the task vector? If not, I think there should be another baseline called state vector (w/o optimization). The authors should claim whether this is a new compressed vector method or just a prove of similarity to gradient descent. 2. Can the authors provide more rationality of optimizing the state vector? I understand the state vector is a compression of previous context, but what it would present after the optimization? 3. Experiments show that the inner optimization and momentum optimization prefer different tasks. Is there a conclusion when to use which? Or is there a combination to adaptively cover all the situations? 4. Can the authors elaborate more on the differences between averaging and D&C? Why D&C is worse when the number of examples equals 10 (Figure 2)? In my understanding, they should be the same since the authors use 10-shot ICL (there should be only 1 group). 5. The authors should check the correctness of the experiment results. For example, in Table 5, they report Llama-2 Zero-shot Regular with six zeros but with an average of 0.2.

Rating

7

Confidence

4

Soundness

3

Presentation

3

Contribution

3

Limitations

See questions

Authorsrebuttal2024-08-12

A follow-up message about the rebuttal for the paper15186

Dear Reviewer `FZSw`, We hope you are doing well. As the discussion period is coming to an end (Aug 13), we wanted to reach out to see if you have any follow-up questions. If so, we would appreciate the opportunity to respond before the discussion period ends. We believe our above messages should have addressed your concerns, and therefore may warrant an increase in score if you find them helpful as well. Would you please let us know if you have any further questions or concerns? We are happy to continue the discussion. Thank you very much again for your thoughtful review and help in improving the paper. We appreciate your time and consideration. Best regards, Paper15186 Authors

Reviewer pJQh6/10 · confidence 3/52024-07-20

Summary

The paper considers the problem of using compressed vectors to replace explicit demonstrations, with potential benefits of providing new perspectives to better understand the mechanism of In-Context Learning (ICL), and addressing the issue of overly long demonstrations by summarizing them into a vector. The main challenge is the drop in accuracy. The paper proposes new methods to enhance compressed vectors, using ideas of ensemble averaging, momentum (though details are insufficient), and Divide-and-Conquer aggregation. Many ablation experiments are conducted to prove the effectiveness and answer different research questions.

Strengths

1. The paper conducts a large number of ablation experiments. 2. The methods proposed are quite novel, including the heuristic approaches and Divide-and-Conquer aggregation. 3. In practice, the methods perform very well on certain tasks. 4. The work provides new perspectives to better understand the mechanism of ICL.

Weaknesses

1. The development is still in its early stages, mostly heuristic, lacking any theoretical guarantees. However, I think this is not a critical issue, as the final performance is good in practice for certain tasks, and a rigorous analysis is very hard due to the complexity of transformers. 2. The presentation needs improvement, e.g., Figure 4 should have a color legend for different positions. The specific parameter $L$ used should be clarified in Section 5.1 3. The strict definition of the momentum gradient optimization algorithm used needs to be clearly stated.

Questions

1. What is the strict definition of the momentum gradient optimization algorithm used as opt? Is it Polyak Momentum or Nesterov momentum? 2. In the code, what do FixOptimizer, OneStepOptimizer, and FixOneStepOptimizer represent respectively? Which one represents momentum? 3. For Divide-and-Conquer aggregation, how does the performance compare to directly averaging the different group-specific state vectors?

Rating

6

Confidence

3

Soundness

3

Presentation

2

Contribution

3

Limitations

1. The presentation needs improvement. 2. It is worth considering larger models, e.g., Llama2-70B. But existing experiments on Llama-2-7B, Llama-2-13B and GPT-J-6B is strong enough. 3. It is worth discussing the performance on more complex ICL tasks, such as math and text summarization.

Reviewer pJQh2024-08-07

Thank you for your detailed response. It answers most of my question. > For Divide-and-Conquer aggregation, how does the performance compare to directly averaging the different group-specific state vectors? My question is not regarding to average aggregation, but for average of group-specific state vectors. My motivation is that the aggregation of group-specific state vectors in this paper seems non-trivial to me, and I was wondering what's the performance if a naive average aggregation of group-specific state vectors are used. I understand this is a new algorithm and implementing it and evaluating it comes with cost, and I think this new experiment is not necessary. Existing experiments are strong enough. > It is worth discussing the performance on more complex ICL tasks, such as math and text summarization > we conducted experiments on the alignment task, which involves aligning LLMs with human preferences and is inherently more complex and diverse Thanks for the additional experiment. I think one fundamental question in this field that is still unclear is why substituting the state vector works. A relevant question is what information can be stored in state vector. Answering these questions would be far beyond the scope of this paper. But since these questions are clear, it would be beneficial to provide more evidence on the state vectors method on tasks of different complexity, even if the state vectors method turn out to perform bad on some cases. I suspect on more complex task, the information stored in state vectors would be not sufficient and performance improvements would diminish. This motivate me to ask the question about more complex ICL tasks. But again, this is not necessary, and I think existing experiments are strong enough. Based on your promise to improve the presentation, I will increase my score.

Authorsrebuttal2024-08-10

Response to Reviewer pJQh

> For Divide-and-Conquer aggregation, how does the performance compare to directly averaging the different group-specific state vectors? Thank you for your question. We apologize for the earlier misunderstanding and value the chance to further discuss the naive average aggregation of state vectors that you have mentioned. However, we are slightly confused, as our understanding is that the averaging aggregation state vector proposed in our work indeed uses the average of group-specific state vectors. We believe this is equivalent to the naive average aggregation of group-specific state vectors that you referred to. Since the naive averaging algorithm is similar to our Inner Optimization approach, we conducted an additional experiment to compare the performance of the averaging state vector with that of the inner optimized state vector. For the naive averaging algorithm, we set up a total of 100 examples, with 10 examples for a group. The results for the naive averaging of group-specific state vectors under this setting are provided below. | | Antonym | English-French | Person-Instrument | | ------------------- | :--------: | :--------------: | :-----------------: | | inner (zero-shot) | 61.0±1.0 | 66.5±1.0 | 67.4±2.6 | | average (zero-shot) | 59.3±1.4 | 67.1±0.8 | 66.7±2.2 | | inner (few-shot) | 66.2±1.6 | 74.6±0.9 | 70.1±4.3 | | average (few-shot) | 65.7±1.1 | 75.1±1.5 | 70.5±3.1 | Our observations indicate that both methods enhance the state vector in a similar manner, leading to comparable improvements in performance and robustness. However, in terms of efficiency, our Inner Optimization approach holds an advantage as it requires only a single forward pass and fewer examples. We hope our response addresses your question. If we have misunderstood your proposed algorithm, we kindly ask you to provide a more detailed description of the difference between your proposed algorithm and our averaging aggregation, as well as specify the experiment results you are interested in. We would be more than happy to continue this discussion with you. *** > It is worth discussing the performance on more complex ICL tasks, such as math and text summarization > we conducted experiments on the alignment task, which involves aligning LLMs with human preferences and is inherently more complex and diverse We sincerely appreciate your thoughtful feedback and your emphasis on the importance of the state vector method in more complex tasks. While our current work focuses on explaining the working mechanism and applying it to several basic tasks, we fully recognize the significance of exploring its application in more complex scenarios. We plan to investigate the performance and applicability of state vectors in these more challenging tasks in our future work. *** Thank you so much for raising the score and your very supportive comments on our paper! We will revise the paper according to your suggestions and comments. Please let us know if you have any further questions, as we are happy to continue the discussion.

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC