Skip to main content
QUICK REVIEW

[논문 리뷰] DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines

Omar Khattab, Arnav Singhvi|arXiv (Cornell University)|2023. 10. 05.
Topic ModelingComputer Science인용 수 49
한 줄 요약

DSPy는 LM 파이프라인을 텍스트 변환 그래프로 바꾸는 선언적이고 매개변수화된 모듈과 프롬프팅을 최적화하는 컴파일러(teleprompters)를 통해 프롬프트 구성과 파인튜닝을 개선하고, 자체적으로 향상되는 다단계 NLP 시스템을 가능하게 한다. 사례 연구는 작은 및 대형 LMs를 사용한 수작업 프롬프트에 비해 성능이 크게 향상됨을 보여준다.

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 https://github.com/stanfordnlp/dspy

연구 동기 및 목표

  • 손으로 작성된 프롬프트 템플릿을 넘어 LM 파이프라인 구축에 체계적이고 모듈식 접근법을 촉진한다.
  • DSPy 추상화(시그니처, 모듈, teleprompters)를 도입하고 이를 최적화된 프롬프팅/파인튜닝 전략으로 컴파일하는 방법을 보여준다.
  • 케이스 스터디를 통해 DSPy가 수작업 프롬프트를 능가하고 더 작은 LMs가 더 큰 전문가 설계 접근법과 경쟁할 수 있음을 시연한다.
  • 부트스트랩 데모와 모듈식 설계가 수학 단어 문제나 다중 홉 QA와 같은 다중 단계 NLP 작업의 성능을 향상시킨다는 것을 보여준다.

제안 방법

  • DSPy를 선언적 모듈을 사용하여 LM 파이프라인을 텍스트 변환 그래프로 표현하는 파이썬 기반 프레임워크로 정의한다.
  • 모듈의 입력/출력 동작을 명시하기 위한 자연어 시그니처를 도입하고(예: question -> answer) Predict, ChainOfThought, ReAct와 같은 모듈을 통해 자동 프롬프트 생성/파인튜닝을 가능하게 한다.
  • LM 선택, 프롬프트, 그리고 데모를 부트스트랩할 시연으로 포함하는 모듈의 매개변수화를 설명한다.
  • teleprompters를 컴파일러/최적화기로 제시하여 데모를 생성하고 매개변수를 조정하거나 제어 흐름을 조정해 학습/검증 세트의 특정 지표를 최적화한다.
  • DSPy 컴파일 과정을 세 단계로 설명한다: 후보 생성(모듈 데모 제작), 매개변수 최적화(데모 및 프롬프트 중에서 선택), 고차원 프로그램 최적화(앙상블, 파이프라인).
  • 간단한 Retrieval-Augmented Generation (RAG) 시스템과 GSM8K 수학 단어 문제 파이프라인 등의 예를 통해 서로 다른 모듈 구성들이 성능에 어떻게 영향을 주는지 설명한다.

실험 결과

연구 질문

  • RQ1DSPy가 손으로 작성한 프롬프트 템플릿을 모듈식이고 매개변수화된 LM 호출 구성요소로 대체하되 성능을 희생하지 않을 수 있을까?
  • RQ2프롬프트 기법의 매개변수화와 모듈을 최적화하는 컴파일러의 사용이 전문가가 설계한 프롬프트보다 서로 다른 LM에 더 잘 적응하는가?
  • RQ3DSPy의 모듈식 접근법이 복잡한 다단계 NLP 파이프라인의 탐색과 최적화를 어떻게 가능하게 하는가?
  • RQ4기본 프롬프트 방법과 비교하여 GSM8K 수학 문제 및 다중 홉 QA 등의 작업에서 DSPy로 달성할 수 있는 성능 향상은 어떤가?

주요 결과

  • DSPy로 구동되는 파이프라인은 테스트된 LMs(GPT-3.5 및 llama2-13b-chat 등)에서 표준 few-shot 프롬프트를 크게 능가한다.
  • DSPy 내 부트스트랩 데모는 많은 설정에서 인간이 작성한 추론 체인(CoT)과 맞먹거나 능가할 수 있다.
  • 앙상블과 다단계 추론 모듈(예: reflection, chain-of-thought 변형)이 가장 큰 이점을 제공하며, 컴파일될 때 현저한 개선이 있다.
  • 소형/오픈소스 LM들(예: 770M T5, llama2-13b-chat)은 더 큰 모델에 대해 전문가가 작성한 프롬프트 체인과 경쟁력을 갖게 된다.
  • DSPy 프로그램을 컴파일하는 것(비록 데이터셋이 보통이고 학습 신호가 작아도)으로 상당한 정확도 향상을 달성하며, 예를 들어 특정 구성에서 GSM8K가 33%에서 82%(GPT-3.5), 32%에서 46%(llama2-13b-chat)로 향상된다.
  • DSPy는 고성능 LM 시스템을 광범위한 수작업 프롬프트 없이 모듈식 단위로 구축할 수 있음을 보여주며 파이프라인 설계의 확장 가능한 탐색을 가능하게 한다.

이 논문 읽기

누빈트 뷰어에서 원문을 열고, 읽으면서 궁금한 곳을 바로 물어보세요.

누빈트에서 이 논문 읽기

이 리뷰는 AI가 논문 원문을 바탕으로 만들었습니다. 인용하기 전에 원문을 확인해 주세요.