Stanford DSPy Framework
(Redirected from DSPy Framework)
Jump to navigation
Jump to search
A Stanford DSPy Framework is a declarative prompt programming framework that can be used to create language model-powered applications (that support prompt optimization tasks and self-improving language programs).
- AKA: Declarative Self-improving Python Framework.
- Context:
- It can typically define LLM Tasks with signature declarations rather than using traditional prompt engineering.
- It can typically transform programming code into effective instructions for language models.
- It can typically provide a structured approach to optimize language model prompts and language model configurations.
- It can typically utilize Signatures to define task-specific behavior of language models through declarative specifications of input and output behavior.
- It can typically optimize prompt construction through automatic compilation instead of manual prompt tuning.
- It can typically improve LLM behavior using algorithmic optimizers that adjust prompt parameters.
- It can typically compose Declarative Modules into LLM pipelines through Python code.
- It can typically facilitate the systematic assembly and refinement of LM-driven pipelines.
- ...
- It can often generate few-shot examples automatically based on performance metrics.
- It can often create self-improving pipelines that enhance output quality over time.
- It can often compile declarative language model calls into self-improving pipelines.
- It can often integrate with multiple LLM providers through a unified language model interface.
- It can often support modular architecture for building complex AI workflows with reusable components.
- It can often facilitate RAG system development through specialized modules and retrieval integrations.
- It can often require modest labeling efforts for its optimization process, as it can extrapolate intermediate labels from few instances.
- It can often leverage LM-driven algorithms or optimizers that autonomously adjust prompts and weights.
- ...
- It can range from being a Simple DSPy Framework to being a Complex DSPy Framework, depending on its DSPy module count.
- It can range from being a Specialized DSPy Framework to being a General-Purpose DSPy Framework, depending on its DSPy application domain.
- It can range from being a Research-Oriented DSPy Framework to being a Production-Ready DSPy Framework, depending on its DSPy implementation maturity.
- ...
- It can integrate with external tools via tool abstractions for enhanced functionality.
- It can connect with vector databases to power retrieval-based applications.
- It can support local model deployments in addition to cloud API integrations.
- It can compile LLM programs into optimized prompts and weights.
- It can improve performance of both cutting-edge models like GPT-4 and localized models like Llama.
- It can outline an iterative development cycle for task optimization.
- It can systematize prompt engineering with structured modules and algorithmic improvements.
- ...
- Examples:
- DSPy Framework Implementations, such as:
- Stanford DSPy Framework (2023-present), developed by Stanford NLP research team for declarative LLM programming.
- DSPy-AI Library (2024), providing Python package for modular AI development.
- DSPy Framework Applications, such as:
- DSPy-powered RAG Systems, such as:
- DSPy-powered Question Answering Systems, such as:
- Multi-hop QA DSPy Application implementing complex reasoning chains.
- Factual QA DSPy Application ensuring accurate information extraction.
- Extreme Multi-Label Classification DSPy Program (2024) implementing Infer-Retrieve-Rank workflows.
- DSPy-powered Content Generation Systems, such as:
- DSPy Framework Optimizers, such as:
- LabeledFewShot DSPy Optimizer for example-based optimization.
- BootstrapFewShot DSPy Optimizer for self-generated example optimization.
- MIPROv2 DSPy Optimizer for multi-stage prompt optimization.
- BootstrapFinetune DSPy Optimizer for model parameter optimization.
- BetterTogether DSPy Optimizer (2024) for combined fine-tuning and prompt optimization.
- DSPy Framework Modules, such as:
- ChainOfThought DSPy Module for step-by-step reasoning.
- ReAct DSPy Module for reasoning and action combination.
- Predict DSPy Module for basic text completion.
- Retrieve DSPy Module for information retrieval.
- DSPy Assertions Module (2023) for computational constraint implementation.
- ...
- DSPy Framework Implementations, such as:
- Counter-Examples:
- LangChain Framework, which focuses on tool connection and component chaining rather than automatic prompt optimization.
- Traditional Prompt Engineering, which requires manual prompt tuning instead of declarative programming approaches.
- LlamaIndex Framework, which specializes in data indexing and retrieval without integrated prompt optimization.
- Raw LLM API, which provides direct model access without modular components or optimization capabilitys.
- Simple Script that uses hardcoded prompts for a language model without any optimization.
- Machine Learning Pipeline that relies solely on manual prompt engineering without structured programming approach.
- See: Language Model Framework, Self-Improving AI System, Declarative Programming, Prompt Optimization, LLM Pipeline, Natural Language Processing Framework, Foundation Model, Machine Learning Pipeline, Artificial Intelligence.
References
2024
- https://github.com/stanfordnlp/dspy
- NOTES:
- It represents a novel paradigm in leveraging language models (LMs) for complex tasks, emphasizing algorithmic optimization of LM prompts and weights.
- It facilitates the systematic assembly and refinement of LM-driven pipelines, moving away from labor-intensive manual fine-tuning processes.
- It introduces LM-driven algorithms or optimizers that autonomously adjust prompts and weights to enhance task-specific performance and reliability.
- It is versatile enough to improve the performance of both cutting-edge models like GPT-3.5 and GPT-4 and localized models such as T5-base or Llama2-13b.
- It analogizes the simplification of neural network development, where declarative layers and parameter learning replace manual coding and tuning efforts.
- It outlines an iterative development cycle for task optimization, from defining the task and desired outcomes to constructing and refining pipelines with specialized modules and optimizers.
- It is positioned as an evolving framework aimed at systematizing prompt engineering and pipeline optimization with structured modules and algorithmic improvements.
- NOTES:
2024
- (Oosterlinck et al., 2024) ⇒ D'Oosterlinck, Karel, Omar Khattab, François Remy, Thomas Demeester, Chris Develder, and Christopher Potts. (2024). “In-Context Learning for Extreme Multi-Label Classification.” arXiv preprint arXiv:2401.12178
- ABSTRACT: Multi-label classification problems with thousands of classes are hard to solve with in-context learning alone, as language models (LMs) might lack prior knowledge about the precise classes or how to assign them, and it is generally infeasible to demonstrate every class in a prompt. We propose a general program, 𝙸𝚗𝚏𝚎𝚛--𝚁𝚎𝚝𝚛𝚒𝚎𝚟𝚎--𝚁𝚊𝚗𝚔, that defines multi-step interactions between LMs and retrievers to efficiently tackle such problems. We implement this program using the 𝙳𝚂𝙿𝚢 programming model, which specifies in-context systems in a declarative manner, and use 𝙳𝚂𝙿𝚢 optimizers to tune it towards specific datasets by bootstrapping only tens of few-shot examples. Our primary extreme classification program, optimized separately for each task, attains state-of-the-art results across three benchmarks (HOUSE, TECH, TECHWOLF). We apply the same program to a benchmark with vastly different characteristics and attain competitive performance as well (BioDEX). Unlike prior work, our proposed solution requires no finetuning, is easily applicable to new tasks, alleviates prompt engineering, and requires only tens of labeled examples. Our code is public at this https URL.
2023
- (Khattab et al., 2023) ⇒ Omar Khattab, Arnav Singhvi, Paridhi Maheshwari, Zhiyuan Zhang, Keshav Santhanam, Sri Vardhamanan, Saiful Haq et al. (2023). “Dspy: Compiling Declarative Language Model Calls Into Self-improving Pipelines.” arXiv preprint arXiv:2310.03714
2023
- (Singhvi et al., 2023) ⇒ Arnav Singhvi, Manish Shetty, Shangyin Tan, Christopher Potts, Koushik Sen, Matei Zaharia, and Omar Khattab. (2023). “DSPy Assertions: Computational Constraints for Self-Refining Language Model Pipelines.” arXiv preprint arXiv:2312.13382