ChatPaper.aiChatPaper

DSPy: Kompilierung deklarativer Sprachmodellaufrufe in sich selbst verbessernde Pipelines

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

October 5, 2023
papers.authors: 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
cs.AI

papers.abstract

Die ML-Community erforscht derzeit intensiv Techniken für das Prompting von Sprachmodellen (LMs) und deren Integration in Pipelines zur Lösung komplexer Aufgaben. Leider werden bestehende LM-Pipelines typischerweise mit fest kodierten „Prompt-Vorlagen“ implementiert, d. h. langen Zeichenketten, die durch Versuch und Irrtum entdeckt wurden. Um einen systematischeren Ansatz für die Entwicklung und Optimierung von LM-Pipelines zu ermöglichen, stellen wir DSPy vor, ein Programmiermodell, das LM-Pipelines als Texttransformationsgraphen abstrahiert, d. h. imperative Berechnungsgraphen, in denen LMs durch deklarative Module aufgerufen werden. DSPy-Module sind parametrisiert, was bedeutet, dass sie lernen können (durch das Erstellen und Sammeln von Demonstrationen), wie sie Kompositionen von Prompting, Finetuning, Augmentierung und Reasoning-Techniken anwenden. Wir entwickeln einen Compiler, der jede DSPy-Pipeline optimiert, um ein gegebenes Metrikziel zu maximieren. Wir führen zwei Fallstudien durch, die zeigen, dass prägnante DSPy-Programme anspruchsvolle LM-Pipelines ausdrücken und optimieren können, die mathematische Textaufgaben lösen, Multi-Hop-Retrieval bewältigen, komplexe Fragen beantworten und Agentenschleifen steuern. Innerhalb weniger Minuten nach der Kompilierung ermöglichen einige Zeilen DSPy GPT-3.5 und llama2-13b-chat, selbstgesteuerte Pipelines zu erstellen, die Standard-Few-Shot-Prompting (in der Regel um über 25 % bzw. 65 %) und Pipelines mit von Experten erstellten Demonstrationen (um bis zu 5–46 % bzw. 16–40 %) übertreffen. Darüber hinaus sind DSPy-Programme, die für offene und relativ kleine LMs wie den 770M-Parameter-T5 und llama2-13b-chat kompiliert werden, wettbewerbsfähig mit Ansätzen, die auf von Experten geschriebene Prompt-Ketten für proprietäre GPT-3.5 angewiesen sind. DSPy ist verfügbar unter https://github.com/stanfordnlp/dspy.
English
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 https://github.com/stanfordnlp/dspy
PDF352December 15, 2024