DSPy: Compilazione di chiamate dichiarative a modelli linguistici in pipeline auto-miglioranti
DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines
October 5, 2023
Autori: 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
Abstract
La comunità del machine learning sta rapidamente esplorando tecniche per il prompting di modelli linguistici (LM) e per la loro organizzazione in pipeline per risolvere compiti complessi. Purtroppo, le pipeline esistenti basate su LM sono tipicamente implementate utilizzando "template di prompt" predefiniti, ovvero stringhe lunghe e complesse scoperte tramite tentativi ed errori. Per un approccio più sistematico allo sviluppo e all'ottimizzazione di pipeline basate su LM, introduciamo DSPy, un modello di programmazione che astrae le pipeline LM come grafi di trasformazione del testo, ovvero grafi computazionali imperativi in cui i LM vengono invocati tramite moduli dichiarativi. I moduli DSPy sono parametrici, il che significa che possono apprendere (creando e raccogliendo dimostrazioni) come applicare composizioni di tecniche di prompting, fine-tuning, aumento dei dati e ragionamento. Progettiamo un compilatore che ottimizza qualsiasi pipeline DSPy per massimizzare una metrica specifica. Condividiamo due casi di studio, dimostrando che programmi DSPy concisi possono esprimere e ottimizzare pipeline LM sofisticate che ragionano su problemi di matematica, affrontano il recupero multi-hop, rispondono a domande complesse e controllano cicli di agenti. In pochi minuti di compilazione, poche righe di DSPy consentono a GPT-3.5 e llama2-13b-chat di auto-avviare pipeline che superano il prompting few-shot standard (generalmente di oltre il 25% e il 65%, rispettivamente) e pipeline con dimostrazioni create da esperti (fino al 5-46% e 16-40%, rispettivamente). Inoltre, i programmi DSPy compilati per LM aperti e relativamente piccoli come T5 con 770 milioni di parametri e llama2-13b-chat sono competitivi con approcci che si basano su catene di prompt scritte da esperti per il proprietario GPT-3.5. DSPy è disponibile all'indirizzo 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