dspy icon indicating copy to clipboard operation
dspy copied to clipboard

Meta knn few shot

Open ammirsm opened this issue 2 months ago • 2 comments

This pull request introduces a new MetaKNNFewShot class for the dspy.teleprompt module and adds comprehensive testing for this new functionality. The most important changes include the addition of the MetaKNNFewShot class, updates to the __init__.py file to include this new class, and the creation of new test files to ensure the functionality works as expected.

New functionality:

  • dspy/teleprompt/meta_knn_fewshot.py: Introduced the MetaKNNFewShot class, which implements meta-learning with KNN for few-shot prompt selection. This class includes methods for compiling programs, generating multiple programs using bootstrap, building a performance cache, and selecting the best program based on performance.

Updates to existing files:

  • dspy/teleprompt/__init__.py: Added an import statement for the new MetaKNNFewShot class.

Testing:

  • testing/meta_knn_tester.py: Added a new tester script to test the MetaKNNFewShot optimizer. This script includes loading environment variables, initializing the teleprompter, and running tests on specified datasets.
  • tests/teleprompt/test_meta_knn_fewshot.py: Added a comprehensive test suite for the MetaKNNFewShot class. This includes tests for initialization, compilation, performance caching, similar example influence, demo exclusion in performance calculations, and best program selection with NaN values.

Refactoring:

  • testing/optimizer_tester.py: Refactored the load_dataset method to import task modules dynamically based on the dataset name, and made minor formatting changes for consistency. [1] [2] [3] [4] [5]

ammirsm avatar Dec 06 '24 01:12 ammirsm