Skip to main content

Logo of Selective Context

Selective Context for Large Language Models

Selective Context is a novel approach for optimizing the usage of context in Large Language Models (LLMs) by filtering out less informative content. This approach allows LLMs to process long documents and maintain extended conversations more efficiently without compromising their performance on various tasks.

This repository contains the code and data for the paper: Unlocking Context Constraints of LLMs: Enhancing Context Efficiency of LLMs with Self-Information-Based Content Filtering.

Updates!!

Try our demo on Huggingface Space.

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. Clone the repository:

    git clone https://github.com/liyucheng09/Selective_Context.git
    cd Selective_Context
    
  2. Install the required packages:

    pip install -r requirements.txt
    
  3. Run the Selective Context demo:

    python selective_context.py
    
  4. If you prefer to try with web interface, try our streamlit app:

    streamlit run app/app.py
    

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, 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.

Citation

If you find this repository helpful or use our method in your research, please consider citing our paper:

@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}
}

License

This project is licensed under the MIT License.

Metadata

Release files for selective-context 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for selective-context 0.1.0
File Size Uploaded
selective-context-0.1.0.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for selective-context 0.1.0
File Interpreter ABI Platform
selective_context-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / selective-context-0.1.0.tar.gz

Download URL selective-context-0.1.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9647d35cb8b1da4859e8a4bf926868284905e4cf2dc772e60ea5a8241edc4ab7
BLAKE2b-256 checksum
How to use checksums
5db066723ad440230b6f03bf024f4a6dd0a516db7c6c49e9236994a7b4f20850
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / selective_context-0.1.0-py3-none-any.whl

Download URL selective_context-0.1.0-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
801550a8618fb114083ee322531fda8243b5376b045a340b43db2d73da8eb2c2
BLAKE2b-256 checksum
How to use checksums
f27446fd784d0c5148efb2813522954431ca44b37d40de4ed65d14ee136c9e02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release history Release notifications | RSS feed

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page