Paper Reading AI Learner

DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines

2023-10-05 17:37:25
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, Christopher Potts

Abstract

The ML community is rapidly exploring techniques for prompting language models (LMs) and for stacking them into pipelines that solve complex tasks. Unfortunately, existing LM pipelines are typically implemented using hard-coded "prompt templates", i.e. lengthy strings discovered via trial and error. Toward a more systematic approach for developing and optimizing LM pipelines, we introduce DSPy, a programming model that abstracts LM pipelines as text transformation graphs, i.e. imperative computational graphs where LMs are invoked through declarative modules. DSPy modules are parameterized, meaning they can learn (by creating and collecting demonstrations) how to apply compositions of prompting, finetuning, augmentation, and reasoning techniques. We design a compiler that will optimize any DSPy pipeline to maximize a given metric. We conduct two case studies, showing that succinct DSPy programs can express and optimize sophisticated LM pipelines that reason about math word problems, tackle multi-hop retrieval, answer complex questions, and control agent loops. Within minutes of compiling, a few lines of DSPy allow GPT-3.5 and llama2-13b-chat to self-bootstrap pipelines that outperform standard few-shot prompting (generally by over 25% and 65%, respectively) and pipelines with expert-created demonstrations (by up to 5-46% and 16-40%, respectively). On top of that, DSPy programs compiled to open and relatively small LMs like 770M-parameter T5 and llama2-13b-chat are competitive with approaches that rely on expert-written prompt chains for proprietary GPT-3.5. DSPy is available at this https URL

Abstract (translated)

机器学习社区正在迅速探索技巧,以引导语言模型(LMs)并将其堆叠成解决复杂任务的 pipeline。不幸的是,现有的 LM Pipeline 通常是通过硬编码的 "prompt templates" 发现的,即通过试错发现较长的字符串。为了开发并优化 LM Pipeline,我们引入了DSPy,一个抽象 LM Pipeline 为文本转换图,即指令计算图,即通过declarative模块唤起 LMs 的模型。DSPy 模块是参数化的,这意味着它们可以通过创建和收集演示来学习如何应用组合prompt、微调、增强和推理技巧。我们设计了编译器,将优化任何 DSPy Pipeline,以最大化给定度量。我们进行了两个案例研究,表明简洁的DSPy programs 可以表达和优化复杂的 LM Pipeline,处理数学词汇问题,解决多级检索,回答复杂问题,并控制代理循环。在编译后立即可以看到,DSPy 的几行代码可以让 GPT-3.5 和 llama2-13b-chat 自我bootstrap Pipeline,比标准的几次引导( generally by over 25% 和 65%),以及使用专家创建的演示的 Pipeline(分别高达 5-46% 和 16-40%)更有效。此外,DSPy 程序编译为打开且相对小的 LMs,如 770M-参数 T5 和 llama2-13b-chat,与依赖专家编写的引导链为私有 GPT-3.5 开发的方案竞争。DSPy 可以在 this https URL 上找到。

URL

https://arxiv.org/abs/2310.03714

PDF

https://arxiv.org/pdf/2310.03714.pdf


Tags
3D Action Action_Localization Action_Recognition Activity Adversarial Agent Attention Autonomous Bert Boundary_Detection Caption Chat Classification CNN Compressive_Sensing Contour Contrastive_Learning Deep_Learning Denoising Detection Dialog Diffusion Drone Dynamic_Memory_Network Edge_Detection Embedding Embodied Emotion Enhancement Face Face_Detection Face_Recognition Facial_Landmark Few-Shot Gait_Recognition GAN Gaze_Estimation Gesture Gradient_Descent Handwriting Human_Parsing Image_Caption Image_Classification Image_Compression Image_Enhancement Image_Generation Image_Matting Image_Retrieval Inference Inpainting Intelligent_Chip Knowledge Knowledge_Graph Language_Model LLM Matching Medical Memory_Networks Multi_Modal Multi_Task NAS NMT Object_Detection Object_Tracking OCR Ontology Optical_Character Optical_Flow Optimization Person_Re-identification Point_Cloud Portrait_Generation Pose Pose_Estimation Prediction QA Quantitative Quantitative_Finance Quantization Re-identification Recognition Recommendation Reconstruction Regularization Reinforcement_Learning Relation Relation_Extraction Represenation Represenation_Learning Restoration Review RNN Robot Salient Scene_Classification Scene_Generation Scene_Parsing Scene_Text Segmentation Self-Supervised Semantic_Instance_Segmentation Semantic_Segmentation Semi_Global Semi_Supervised Sence_graph Sentiment Sentiment_Classification Sketch SLAM Sparse Speech Speech_Recognition Style_Transfer Summarization Super_Resolution Surveillance Survey Text_Classification Text_Generation Time_Series Tracking Transfer_Learning Transformer Unsupervised Video_Caption Video_Classification Video_Indexing Video_Prediction Video_Retrieval Visual_Relation VQA Weakly_Supervised Zero-Shot