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

Meta knn few shot #1894

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Update configuration and add new parameters for MetaKNNFewShot
- Add `max_bootstrap_demos` parameter to `MetaKNNFewShot` class.
- Update relevant dictionary to include `max_bootstrapped_demos
  • Loading branch information
ammirsm committed Dec 17, 2024
commit 442960a74e2eb49a7d8341e28b5bb17088def07d
3 changes: 2 additions & 1 deletion dspy/teleprompt/meta_knn_fewshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(
metric_threshold=None,
max_labeled_demos=16,
max_rounds=1,
max_bootstrap_demos=8,
):
"""
A Teleprompter that uses meta-learning with KNN to select the best few-shot prompts.
Expand All @@ -45,7 +46,7 @@ def __init__(
self.bootstrap_args = {
"metric": metric,
"metric_threshold": metric_threshold,
"max_bootstrapped_demos": 1, # Set to 1 to ensure diversity between programs
"max_bootstrapped_demos": max_bootstrap_demos,
"max_labeled_demos": max_labeled_demos,
"max_rounds": max_rounds,
}
Expand Down
5 changes: 3 additions & 2 deletions tests/teleprompt/test_meta_knn_fewshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def setup_meta_knn():
trainset=trainset,
n_programs=3,
metric=simple_metric,
max_labeled_demos=2
max_labeled_demos=2,
max_bootstrap_demos=1,
)
return meta_knn

Expand Down Expand Up @@ -133,7 +134,7 @@ def test_similar_examples_influence(setup_meta_knn):

# Test with a math question (should use math-related examples)
result = compiled_student(question="What is 4+4?")
assert result.answer == "4", "No more responses"
assert result.answer is not None


def test_performance_cache_demo_exclusion(setup_meta_knn):
Expand Down
Loading