dspy
dspy copied to clipboard
Meta knn few shot
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 theMetaKNNFewShot
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 newMetaKNNFewShot
class.
Testing:
-
testing/meta_knn_tester.py
: Added a new tester script to test theMetaKNNFewShot
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 theMetaKNNFewShot
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 theload_dataset
method to import task modules dynamically based on the dataset name, and made minor formatting changes for consistency. [1] [2] [3] [4] [5]