-
Notifications
You must be signed in to change notification settings - Fork 508
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
Exemplar Selection (in context learning) API #1055
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add an example of user's code, in test or documentation?
key + ": " + str(context[key]) for key in key_order[:-1] | ||
] | ||
) | ||
few_shot_prompt += "\n" + key_order[-1] + ": " + "\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use format string here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any benefits to use format string?
} | ||
|
||
@classmethod | ||
def get_few_shot_template(cls, train_data, method=None, few_shot_template=None, method_params=None, template_params=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing selection method into exemplar_selector, maybe it would be easier to implement exemplar_selector with different methods?
BTW I'm not too familiar with pythonic-way of abstract class so I'm just make up pattern here.
abstract class ExemplarSelector:
def construct_template(context) -> str;
pass
# random_exemplar_selector
class RandomExemplarSelector(ExemplarSelector):
def __init__(self, train_data, k):
# initialize
def construct_template(context):
# select `k` examples from train_data and render template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add the abstract class to exemplar_selector.py
test/autogen/oai/test_selection.py
Outdated
|
||
def test_case_existing_method_default_template(self): | ||
# Most cases should use the default template and existing methods | ||
prompt_fn = oai.ExemplarSelector.get_few_shot_template(self.exemplars, method="random", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should ExemplarSelector
be under oai
? It doesn't look right. What about autogen/icl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to autogen/icl
test/autogen/oai/test_selection.py
Outdated
def test_case_existing_method_default_template(self): | ||
# Most cases should use the default template and existing methods | ||
prompt_fn = oai.ExemplarSelector.get_few_shot_template(self.exemplars, method="random", | ||
method_params={"k": 3}, template_params={"key_order": self.key_order}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, the field to predict in the context is not necessarily the last key. Also, the number of such fields is not necessarily 1. Make sure the prompt_fn
does not depend on such assumptions.
@@ -1,6 +1,6 @@ | |||
import unittest | |||
import datasets | |||
from flaml import oai | |||
from flaml import icl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from flaml import icl | |
from flaml.autogen.icl import ExemplarSelector |
@feiran-jia please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Why are these changes needed?
Produced for in-context learning user cases.
For example:
Related issue number
Automate example selection in LLM few-shot learning microsoft/autogen#448
Checks