ChatPaper.aiChatPaper

DSPy: 선언적 언어 모델 호출을 자가 개선 파이프라인으로 컴파일하기

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

October 5, 2023
저자: 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

초록

머신러닝 커뮤니티는 언어 모델(LM)을 프롬프팅하고 이를 복잡한 작업을 해결하기 위한 파이프라인으로 구성하는 기술을 빠르게 탐구하고 있습니다. 그러나 기존의 LM 파이프라인은 일반적으로 시행착오를 통해 발견된 긴 문자열인 "프롬프트 템플릿"을 하드코딩하여 구현됩니다. LM 파이프라인을 체계적으로 개발하고 최적화하기 위한 접근법으로, 우리는 DSPy를 소개합니다. DSPy는 LM 파이프라인을 텍스트 변환 그래프, 즉 선언적 모듈을 통해 LM을 호출하는 명령형 계산 그래프로 추상화하는 프로그래밍 모델입니다. DSPy 모듈은 파라미터화되어 있어, 프롬프팅, 파인튜닝, 증강, 추론 기술의 조합을 어떻게 적용할지 학습할 수 있습니다(데모를 생성하고 수집함으로써). 우리는 주어진 메트릭을 최대화하기 위해 DSPy 파이프라인을 최적화하는 컴파일러를 설계했습니다. 두 가지 사례 연구를 통해, 간결한 DSPy 프로그램이 수학 단어 문제를 추론하고, 멀티홉 검색을 처리하며, 복잡한 질문에 답하고, 에이전트 루프를 제어하는 정교한 LM 파이프라인을 표현하고 최적화할 수 있음을 보여줍니다. 컴파일링 후 몇 분 안에, 몇 줄의 DSPy 코드로 GPT-3.5와 llama2-13b-chat이 표준 퓨샷 프롬프팅(일반적으로 각각 25%와 65% 이상)과 전문가가 작성한 데모를 사용한 파이프라인(각각 최대 5-46%와 16-40%)을 능가하는 파이프라인을 자체 부트스트랩할 수 있습니다. 또한, 770M 파라미터 T5와 llama2-13b-chat과 같은 상대적으로 작고 오픈된 LM으로 컴파일된 DSPy 프로그램은 전문가가 작성한 프롬프트 체인에 의존하는 접근법과 비교해도 경쟁력이 있습니다. DSPy는 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