Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add icl_sliding_k_retriever.py and update __init__.py #1305

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

cpa2001
Copy link
Contributor

@cpa2001 cpa2001 commented Jul 11, 2024

Motivation

This PR aims to introduce a new Sliding Window Retriever for in-context learning. The goal is to enhance the flexibility and effectiveness of example retrieval in the OpenCompass framework, particularly for scenarios where context relevance varies with the position of test examples.

Modification

This PR introduces two main modifications:

  1. Added a new file icl_sliding_k_retriever.py implementing the SlidingWindowRetriever class.
  2. Updated __init__.py to include the new SlidingWindowRetriever in the package exports.

The SlidingWindowRetriever allows for dynamic selection of in-context examples based on a sliding window approach, which can be particularly useful for tasks where the relevance of context changes as we progress through the dataset.

BC-breaking (Optional)

This modification does not introduce any changes that break backward compatibility. Existing retriever implementations remain unchanged, and this new retriever can be used alongside them without conflicts.

Use cases (Optional)

The SlidingWindowRetriever can be particularly useful in scenarios such as:

  1. Time-series data analysis where recent context is more relevant.
  2. Document processing tasks where context relevance changes throughout the document.
  3. Any task where the order of examples matters and using a fixed set of examples throughout might not be optimal.

To use the new retriever, users can specify it in their configuration files like so:

retriever = dict(type='SlidingWindowRetriever',
                 dataset=dataset,
                 k=5)  # retrieves 5 previous examples

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects.
  • CLA has been signed and all committers have signed the CLA in this PR.

Copy link
Collaborator

@tonysy tonysy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tonysy tonysy merged commit 463231c into open-compass:main Aug 23, 2024
3 checks passed
liushz pushed a commit to liushz/opencompass that referenced this pull request Sep 3, 2024
…-compass#1305)

* Add icl_sliding_k_retriever.py and update __init__.py

* Fix flake8, isort, and yapf issues for Sliding Window Retriever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants