Exemplar Selectors
Module for exemplar selectors.
base_exemplar_selector
Base class for exemplar selectors.
BaseExemplarSelector
Bases: ABC
An abstract base class for exemplar selectors.
This class defines the basic interface and common functionality that all exemplar selectors should implement.
Source code in promptolution/exemplar_selectors/base_exemplar_selector.py
__init__(task, predictor, config=None)
Initialize the BaseExemplarSelector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
BaseTask
|
An object representing the task to be performed. |
required |
predictor
|
BasePredictor
|
An object capable of making predictions based on prompts. |
required |
config
|
ExperimentConfig
|
"ExperimentConfig" overwriting the defaults |
None
|
Source code in promptolution/exemplar_selectors/base_exemplar_selector.py
select_exemplars(prompt, n_examples=5)
abstractmethod
Select exemplars based on the given prompt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The input prompt to base the exemplar selection on. |
required |
n_examples
|
int
|
The number of exemplars to select. Defaults to 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A new prompt that includes the original prompt and the selected exemplars. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
This method should be implemented by subclasses. |
Source code in promptolution/exemplar_selectors/base_exemplar_selector.py
random_search_selector
Random search exemplar selector.
RandomSearchSelector
Bases: BaseExemplarSelector
A selector that uses random search to find the best set of exemplars.
This class implements a strategy that generates multiple sets of random examples, evaluates their performance, and selects the best performing set.
Source code in promptolution/exemplar_selectors/random_search_selector.py
select_exemplars(prompt, n_examples=5, n_trials=5)
Select exemplars using a random search strategy.
This method generates multiple sets of random examples, evaluates their performance when combined with the original prompt, and returns the best performing set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The input prompt to base the exemplar selection on. |
required |
n_examples
|
int
|
The number of exemplars to select in each trial. Defaults to 5. |
5
|
n_trials
|
int
|
The number of random trials to perform. Defaults to 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
str |
The best performing prompt, which includes the original prompt and the selected exemplars. |
Source code in promptolution/exemplar_selectors/random_search_selector.py
random_selector
Random exemplar selector.
RandomSelector
Bases: BaseExemplarSelector
A selector that randomly selects correct exemplars.
This class implements a strategy that generates random examples and selects those that are evaluated as correct until the desired number of exemplars is reached.
Source code in promptolution/exemplar_selectors/random_selector.py
__init__(task, predictor, desired_score=1, config=None)
Initialize the RandomSelector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
BaseTask
|
An object representing the task to be performed. |
required |
predictor
|
BasePredictor
|
An object capable of making predictions based on prompts. |
required |
desired_score
|
int
|
The desired score for the exemplars. Defaults to 1. |
1
|
config
|
ExperimentConfig
|
Configuration for the selector, overriding defaults. |
None
|
Source code in promptolution/exemplar_selectors/random_selector.py
select_exemplars(prompt, n_examples=5)
Select exemplars using a random selection strategy.
This method generates random examples and selects those that are evaluated as correct (score == self.desired_score) until the desired number of exemplars is reached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The input prompt to base the exemplar selection on. |
required |
n_examples
|
int
|
The number of exemplars to select. Defaults to 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A new prompt that includes the original prompt and the selected exemplars. |