
高效压缩上下文技术实现大语言模型处理能力倍增
Selective Context是一种创新上下文压缩技术,能使大语言模型处理内容量提升一倍。该技术利用基础语言模型计算词句自信息,评估信息量,实现长文档和长对话的高效处理。项目提供完整代码实现、数据集和多项实验评估,已获EMNLP 2023会议认可。此上下文压缩技术适用于需要处理大量文本数据的场景,如智能客服、文档分析等。用户可通过pip安装,便捷集成到现有大语言模型项目中,显著提升处理效率。
Selective Context compresses your prompt and context to allows LLMs (such as ChatGPT) to process 2x more content. It is especially useful in dealing with long documents and maintaining long conversations without compromising their performance on various tasks!
This repository contains the code and data for the paper: Compressing Context to Enhance Inference Efficiency of Large Language Models.
Oct 9 2023: This work has been accepted for the main proceedings of EMNLP 2023 :partying_face:. The paper link above is the latest conference version. If you are looking for the previous arxiv version of the paper: :point_right: Unlocking Context Constraints of LLMs.
May 6 2023: Try our demo on Huggingface Space.
To get started, follow these steps:
Install selective-context via Pypi:
pip install selective-context
python -m spacy download en_core_web_sm
If you are processing Chinese, run python -m spacy download zh_core_web_sm as well.
Import SelectiveContext:
from selective_context import SelectiveContext
Compress your prompt and context. The context contains the compressed context:
sc = SelectiveContext(model_type='gpt2', lang='en')
context, reduced_content = sc(text)
You can also adjust the reduce ratio:
context, reduced_content = sc(text, reduce_ratio = 0.5)
If you prefer to try with web interface, try our streamlit app:
streamlit run app/app.py
Or directly visit our Space on Hugging Face Hub.
selective_context.py: A demo for performing context reduction using Selective Context.context_manager.py: The main module for managing context and implementing the Selective Context algorithm.main.py: The main script for running experiments and evaluating the effectiveness of Selective Context.qa_manager.py: A helper module for managing question answering tasks during the experiments.To reproduce the experiments from the paper:
wget https://github.com/liyucheng09/Selective_Context/releases/download/v0.1.0rc1/datasets_dumps.zip
unzip datasets_dumps.zip
python main.py datasets_dumps/arxiv datasets_dumps/news datasets_dump/conversation <output_path_to_save_results> <num_articles> <HF_model_name_or_path>
The dataset used in the paper can be found at:
The datasets are created by ourselves so if you need citation just use the citation of this tool.
If you have trouble accessing Huggingface Hub, download the data via:
wget https://github.com/liyucheng09/Selective_Context/releases/download/v0.1.0rc1/data_dumps.zip
If you find this repository helpful or use our method in your research, please consider citing our paper:
@misc{li2023compressing,
title={Compressing Context to Enhance Inference Efficiency of Large Language Models},
author={Yucheng Li and Bo Dong and Chenghua Lin and Frank Guerin},
year={2023},
eprint={2310.06201},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
The previous version:
@misc{li2023unlocking,
title={Unlocking Context Constraints of LLMs: Enhancing Context Efficiency of LLMs with Self-Information-Based Content Filtering},
author={Yucheng Li},
year={2023},
eprint={2304.12102},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
This project is licensed under the MIT License.


AI一键生成PPT,就用博思AIPPT!
博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。


AI赋能电商视觉革命,一站式智能商拍平台
潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。


企业专属的AI法律顾问
iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。


稳定高效的流量提升解决方案,助力品牌曝光
稳定高效的流量提升解决方案,助力品牌曝光


最新版Sora2模型免费使用,一键生成无水印视频
最新版Sora2模 型免费使用,一键生成无水印视频


实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。


选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。


最强AI数据分析助手
小浣熊家族Raccoon,您的AI智能助手,致力于通过先进的人工智能技术,为用户提供高效、便捷的智能服务。无论是日常咨询还是专业问题解答,小浣熊都能以快速、准确的响应满足您的需求,让您的生活更加智能便捷。


像人一样思考的AI智能体
imini 是一款超级AI智能体,能根据人类指令,自主思考、自主完成、并且交付结果的AI智能体。
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号