ImageNet classification with deep convolutional neural networks
Alex Krizhevsky, Ilya Sutskever et al.
0
Citations
0
Influential Citations
—
Venue
2023
Year
A programming model that abstracts LM pipelines as text transformation graphs, i.e. imperative computation graphs where LMs are invoked through declarative modules, optimizing their use through a structured framework of signatures, modules, and teleprompters to automate and enhance text transformation tasks.
For AI practitioners, the daily grind of prompt engineering is a familiar pain. Crafting the perfect few-shot example, tuning instructions, and debugging chain-of-thought prompts often feels more like alchemy than science. DSPy directly tackles this by proposing a programming model that treats LM pipelines as first-class computational graphs, not string templates. This shift from manual prompting to automated optimization is a significant step toward making LM-based systems more reliable, reproducible, and scalable. By abstracting away the brittle details of prompt formatting, DSPy allows developers to focus on the logic of their application, while the system handles the low-level optimization.

DSPy's core insight is to reframe LM pipelines as text transformation graphs. Instead of writing a prompt like "Answer the following question step-by-step," you define a module with a typed signature, such as question -> answer. This declarative approach specifies what the task is, not how to prompt the LM. The framework provides several built-in modules that abstract common prompting techniques:
dspy.Predict: Basic predictor.dspy.ChainOfThought: Teaches the LM to reason step-by-step.dspy.ProgramOfThought: Instructs the LM to output code that determines the response.dspy.ReAct: An agent that can use tools.dspy.MultiChainComparison: Compares multiple chain-of-thought outputs.These modules are parameterized and can be composed into complex pipelines, much like neural network layers. The real magic happens with the DSPy compiler, which takes a program, a few training examples (which can be unlabeled), and a validation metric. The compiler then uses a teleprompter (optimizer) to automatically tune the program's parameters—prompts, demonstrations, and even LM weights—to maximize the metric.
The optimization process is multi-stage. First, candidate generations are created by bootstrapping demonstrations from the program itself. Then, hyperparameter tuning algorithms (like random search or Bayesian optimization) select the best candidates. Finally, higher-order transformations, such as ensembling multiple copies of the program, can be applied. This automated approach replaces the tedious manual trial-and-error of traditional prompt engineering.

The paper evaluates DSPy on the GSM8K math word problem benchmark. The key result is striking: compiling the correct modules instead of using hand-crafted string prompts improves accuracy across different LMs from a range of 4-20% to a consistent 49-88%. This demonstrates that DSPy not only matches but significantly outperforms expert-written prompts, especially for weaker LMs. The framework's ability to adapt to different models automatically is a major advantage in a landscape where new LMs appear frequently.
DSPy's significance lies in its potential to change how we interact with LMs. By making prompt optimization a first-class, automated process, it lowers the barrier to entry for building sophisticated LM applications. Practitioners can now focus on designing the logic of their pipeline (e.g., retrieval-augmented generation, multi-hop reasoning) while the system handles the tedious optimization. This modularity also enables more thorough exploration of complex pipelines, as the compiler can systematically search for the best configuration. While the paper doesn't deeply explore scalability to very large programs or the computational cost of optimization, the core idea is a powerful step toward making LM-based systems more robust and accessible. For the AI community, DSPy offers a principled alternative to the current ad-hoc practices, potentially leading to more reproducible and efficient workflows.
Alex Krizhevsky, Ilya Sutskever et al.
Ashish Vaswani, Noam Shazeer et al.
Douglas M. Bates, Martin Mächler et al.
Diederik P. Kingma, Jimmy Ba