
Security News
The Nightmare Before Deployment
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.
selective-context
Advanced tools
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
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, run the following command:
python main.py
This will run the experiments on arxiv papers, BBC news articles, and conversation transcripts with four different NLP tasks: summarization, question answering, original context reconstruction, and conversation.
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 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.
FAQs
Compress your prompt and context to let LLMs deal with 2x more content.
We found that selective-context demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.

Research
/Security News
Impostor NuGet package Tracer.Fody.NLog typosquats Tracer.Fody and its author, using homoglyph tricks, and exfiltrates Stratis wallet JSON/passwords to a Russian IP address.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.