RandomFewShot
RandomFewShot
Bases: GreedyOptimizer
Sample among the best predictions to populate the LM's prompt.
Makes the model learn using Few Shot Learning by selecting predictions as examples based on their rewards using the configured sampling strategy.
Example:
import synalinks
import asyncio
async def main():
# ... your program definition
program.compile(
reward=synalinks.rewards.ExactMatch(),
optimizer=synalinks.optimizers.RandomFewShot(
nb_min_examples=1,
nb_max_examples=3,
sampling="softmax",
sampling_temperature=1.0,
),
)
history = await program.fit(...)
References
- DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines (https://arxiv.org/pdf/2310.03714)
- Language Models are Few-Shot Learners (https://arxiv.org/abs/2005.14165)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nb_min_examples
|
int
|
The min number of examples for few-shot learning (Default to 1). |
1
|
nb_max_examples
|
int
|
The max number of examples for few-shot learning (Default to 3). |
3
|
sampling
|
str
|
The method to sample predictions between ['random', 'best', 'softmax']. (Default to 'softmax'). |
'softmax'
|
sampling_temperature
|
float
|
The temperature for softmax sampling.
Used only when |
0.3
|
population_size
|
int
|
The maximum number of best candidates to keep during the optimization process. |
10
|
name
|
str
|
Optional name for the optimizer instance. |
None
|
description
|
str
|
Optional description of the optimizer instance. |
None
|