让大模型少看例子仍能高效学习,压缩提示词提升推理速度
Compressing Many-Shots in In-Context Learning
- 分层压缩多示例提示,用更少的软标记保留关键信息
- 在8倍压缩下仍保持90%以上准确率,比基线损失低10%以内
- 适合需要快速推理的大模型应用,如实时问答系统
大型语言模型在不进行显式微调的情况下,可通过上下文学习(ICL)利用多个输入输出示例完成任务。增加示例数量(即“多示例”)虽能提升性能,但带来更高的内存与计算开销。本文研究如何通过压缩多示例提示来提升ICL推理效率。给定含t个标记的多示例提示,目标是生成仅含m个软标记的摘要,其中m < t。我们发现现有提示压缩方法对多示例无效,而直接减少示例数作为基线反而表现强劲。为实现有效压缩,我们提出:(a) 需使用参数更多、更强的压缩模型;(b) 在每层Transformer中分别压缩表示,实现更细粒度的信息提炼。基于此,我们提出MemCom,一种分层压缩方法。我们在不同模型规模(2B和7B)、架构(Gemma与Mistral)、序列长度(3k–6k token)及压缩比(3x–8x)下系统评估。MemCom在多个带大量标签的分类任务中均优于强基线。尤其在高压缩比下,基线性能下降超20%-30%,而MemCom仅降10%以内,保持高准确率。
原文摘要 · Abstract (English)
Large Language Models (LLMs) have been shown to be able to learn different tasks without explicit finetuning when given many input-output examples / demonstrations through In-Context Learning (ICL). Increasing the number of examples, called ``shots'', improves downstream task performance but incurs higher memory and computational costs. In this work, we study an approach to improve the memory and computational efficiency of ICL inference by compressing the many-shot prompts. Given many shots comprising t tokens, our goal is to generate a m soft-token summary, where m < t. We first show that existing prompt compression methods are ineffective for many-shot compression, and simply using fewer shots as a baseline is surprisingly strong. To achieve effective compression, we find that: (a) a stronger compressor model with more trainable parameters is necessary, and (b) compressing many-shot representations at each transformer layer enables more fine-grained compression by providing each layer with its own compressed representation. Based on these insights, we propose MemCom, a layer-wise compression method. We systematically evaluate various compressor models and training approaches across different model sizes (2B and 7B), architectures (Gemma and Mistral), many-shot sequence lengths (3k-6k tokens), and compression ratios (3x to 8x). MemCom outperforms strong baselines across all compression ratios on multiple classification tasks with large label sets. Notably, while baseline performance degrades sharply at higher compression ratios, often by over 20-30%, MemCom maintains high accuracy with minimal degradation, typically dropping by less than 10%.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。