Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Compress your input to ChatGPT or other LLMs, to let them process 2x more content and save 40% memory and GPU time.
| Date | Stars |
|---|---|
| 2026-07-31 | 424 |
| 2026-08-03 | 424 |
| 2026-08-06 | 424 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
<p align="center">
<img src="https://github.com/liyucheng09/Selective_Context/blob/main/results/sc.png" alt="Logo of Selective Context" width="auto" height="150" />
</p>
# Selective Context for LLMs
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](https://arxiv.org/abs/2310.06201).
### Updates!!
- **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](https://arxiv.org/abs/2304.12102).
- **May 6 2023**: Try our demo on [Huggingface Space](https://huggingface.co/spaces/liyucheng/selective_context).
## Key Features
- **Efficient Context Management**: Selective Context maximizes the utility of fixed context length in LLMs, allowing them to process long documents and extended conversations more efficiently.
- **Informativeness Evaluation**: Our method employs a base language model to compute self-information for lexical units (sentences, phrases, or tokens) in a context and use it to evaluate their informativeness.
- **Extensive Evaluation**: We provide extensive evaluations of Selective Context on three data sources (arxiv papers, BBC news articles, and conversation transcripts) and four different NLP tasks (summarization, question answering, original context reconstruction, and conversation).
## Getting Started
To get started, follow these steps:
1. 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.
2. Import `SelectiveContext`:
```
from selective_context import SelectiveContext
```
3. Compress your prompt and context. The `context` contains the compressed context:
```
sc = SelectiveContext(model_type='gpt2', lang='en')
context, reduced_content = sc(text)
```
4. You can also adjust the reduce ratio:
```
context, reduced_content = sc(text, reduce_ratio = 0.5)
```
5. If you prefer to try with web interface, try our streamlit app:
```
streamlit run app/app.py
```
Or directly visit our [Space](https://huggingface.co/spaces/liyucheng/selective_context) on Hugging Face Hub.
## Code Structure
- `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.
## Experiments
To reproduce the experiments from the paper:
1. First, you download the datasets required in the experiments:
```
wget https://github.com/liyucheng09/Selective_Context/releases/download/v0.1.0rc1/datasets_dumps.zip
unzip datasets_dumps.zip
```
2. You run:
```
python main.py datasets_dumps/arxiv datasets_dumps/news datasets_dump/conversation <output_path_to_save_results> <num_articles> <HF_model_name_or_path>
```
## Dataset in the paper
The dataset used in the paper can be found at:
- Arxiv: [HF Hub](https://huggingface.co/datasets/liyucheng/arxiv-march-2023)
- BBC News: [HF Hub](https://huggingface.co/datasets/liyucheng/bbc_new_2303)
- ShareGPT.com: [HF Hub](https://huggingface.co/datasets/liyucheng/sharegpt-500)
The datasets are created by ourselves so if you need citation just use the citation of this tool.
If you have trouble accessing Excerpt of 4,964 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:d5700acb32f4dc70, llm:description: 'Compress your input to ChatGPT or other LLMs, to let them process 2x more content and save 40% memory and GPU time.' topics: chatgpt, llms, nlp
matched fp:d5700acb32f4dc70, llm:description: 'Compress your input to ChatGPT or other LLMs, to let them process 2x more content and save 40% memory and GPU time.' topics: chatgpt, llms, nlp
matched fp:d5700acb32f4dc70, llm:description: 'Compress your input to ChatGPT or other LLMs, to let them process 2x more content and save 40% memory and GPU time.' topics: chatgpt, llms, nlp