DSPy: Programming—not prompting—Foundation Models

DSPy: Programming—not prompting—Foundation Models#

Note

Hey guys, this is my personal reading note. I am not sure there might be some mistakes in my understanding. Please feel free to correct me (hsiangjenli@gmail.com) if you find any. Thanks!

Full name of DSPy is DSPy “Declarative Self-improving Language Programs (in Python)”

Developed by Stanford NLP

  • DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines [3]

  • Demonstrate-Search-Predict: Composing Retrieval and Language Models for Knowledge-Intensive {NLP} [2]

Contributions#

  1. separate program from parameters

  2. new optimizer, which is LM-driven and can be used to optimize prompt and weights

How to use DSPy [1]#

  1. Define your task

  2. Define your pipeline

  3. Explore a few examples (Simply run the code and see the results)

  4. Define data

  5. Define metric

  6. Collect data

  7. Set up the optimizer

  8. Train

Reference#

[1]

Using DSPy in 8 Steps | DSPy — dspy-docs.vercel.app. https://dspy-docs.vercel.app/docs/building-blocks/solving_your_task. [Accessed 13-10-2024].

[2]

Omar Khattab, Keshav Santhanam, Xiang Lisa Li, David Hall, Percy Liang, Christopher Potts, and Matei Zaharia. Demonstrate-search-predict: composing retrieval and language models for knowledge-intensive NLP. arXiv preprint arXiv:2212.14024, 2022.

[3]

Omar Khattab, Arnav Singhvi, Paridhi Maheshwari, Zhiyuan Zhang, Keshav Santhanam, Sri Vardhamanan, Saiful Haq, Ashutosh Sharma, Thomas T. Joshi, Hanna Moazam, Heather Miller, Matei Zaharia, and Christopher Potts. Dspy: compiling declarative language model calls into self-improving pipelines. arXiv preprint arXiv:2310.03714, 2023.