An attempt to create an optimizable programmable system for language models. The idea is that users can construct “programs” using large language models by describing desired inputs and outputs of various modules, which can be connected by traditional programming techniques (conditional branching, loops, computation, etc). Then a “compiler” (optimizer) tries to find the best prompt (mostly few-shot demos, but also in some cases wording) given some trainset and devset.
First author is Omar Khattab, at Stanford.
stanfordnlp/dspy: DSPy: The framework for programming—not prompting—foundation models
LabeledFewShot
and BootstrapFewShot
.LabeledFewShot
provides few-shot demos by simply grabbing a random slice of the trainset.BootstrapFewShot
uses a “teacher” program to train a “student” program.LabeledFewShot
on the student program.LabeledFewShot
, or from the validation set.BootstrapFewShot
is designed for boolean metrics. Traces are kept if the metric evaluates to a truthy value. Only a few traces are stored as demos in the resulting program, and no attempt is made to use the traces which had the highest metric value.max_bootstrapped_demos=4
: the number of augmented traces it tries to produce. Execution stops once this many examples have been boostrapped.max_labeled_demos=16
: the number of “raw” demos the synthetic LabeledFewShot
teacher will use; also, the total number of demos desired in the compiled program. When max_labeled_demos
> max_bootstrapped_demos
, extra unaugmented demos will be emitted.max_rounds=1
: the number of times it will attempt to bootstrap each input exampleBootstrapFewShotWithRandomSearch
creates many candidate programs by shuffling the training set, and picks the best one.LabeledFewShot
BootstrapFewShot
BootstrapFewShot
.num_candidate_programs=16
the number of randomly permuted programs to create with BootstrapFewShot
BootstrapFewShot
)