Selective_Context
data dumps to reproduce the results

选择性上下文会压缩您的提示和上下文,以允许LLM(例如ChatGpt)处理2倍更多内容。它在处理长期文档并保持长时间的对话时特别有用,而不会损害其在各种任务上的表现!
该存储库包含本文的代码和数据:压缩上下文以提高大语模型的推理效率。
2023年10月9日:这项工作已被2023年EMNLP的主要程序接受。上面的纸质链接是最新的会议版本。如果您正在寻找本文的先前ARXIV版本:解锁LLMS的上下文约束。
2023年5月6日:尝试我们在拥抱面空间上的演示。
要开始,请按照以下步骤:
通过pypi安装selective-context :
pip install selective-context
python -m spacy download en_core_web_sm
如果您正在处理中文,请运行python -m spacy download zh_core_web_sm 。
导入SelectiveContext :
from selective_context import SelectiveContext
压缩您的提示和上下文。 context包含压缩上下文:
sc = SelectiveContext(model_type='gpt2', lang='en')
context, reduced_content = sc(text)
您还可以调整减少比率:
context, reduced_content = sc(text, reduce_ratio = 0.5)
如果您喜欢尝试使用Web界面,请尝试我们的简化应用程序:
streamlit run app/app.py
或直接访问我们的拥抱面轮的空间。
selective_context.py :用于使用选择性上下文降低上下文的演示。context_manager.py :用于管理上下文和实现选择性上下文算法的主要模块。main.py :运行实验和评估选择性上下文有效性的主要脚本。qa_manager.py :用于管理实验期间问题的辅助模块。 从论文中重现实验:
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>
可以在论文中使用的数据集找到:
数据集由我们自己创建,因此,如果您需要引用,只需使用该工具的引用即可。
如果您在访问HuggingFace Hub时遇到困难,请通过以下方式下载数据
wget https://github.com/liyucheng09/Selective_Context/releases/download/v0.1.0rc1/data_dumps.zip
如果您发现此存储库有用或在您的研究中使用我们的方法,请考虑引用我们的论文:
@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}
}
以前的版本:
@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}
}
该项目已根据MIT许可获得许可。