Skip to main content
QUICK REVIEW

[Paper Review] TextGrad: Automatic "Differentiation" via Text

Mert Yüksekgönül, Federico Bianchi|arXiv (Cornell University)|Jun 11, 2024
Natural Language Processing TechniquesComputer Science12 citations
TL;DR

TextGrad enables automatic differentiation-like optimization by backpropagating textual feedback from LLMs to improve components of compound AI systems across code, QA, chemistry, and medicine tasks, without changing the framework.

ABSTRACT

AI is undergoing a paradigm shift, with breakthroughs achieved by systems orchestrating multiple large language models (LLMs) and other complex components. As a result, developing principled and automated optimization methods for compound AI systems is one of the most important new challenges. Neural networks faced a similar challenge in its early days until backpropagation and automatic differentiation transformed the field by making optimization turn-key. Inspired by this, we introduce TextGrad, a powerful framework performing automatic ``differentiation'' via text. TextGrad backpropagates textual feedback provided by LLMs to improve individual components of a compound AI system. In our framework, LLMs provide rich, general, natural language suggestions to optimize variables in computation graphs, ranging from code snippets to molecular structures. TextGrad follows PyTorch's syntax and abstraction and is flexible and easy-to-use. It works out-of-the-box for a variety of tasks, where the users only provide the objective function without tuning components or prompts of the framework. We showcase TextGrad's effectiveness and generality across a diverse range of applications, from question answering and molecule optimization to radiotherapy treatment planning. Without modifying the framework, TextGrad improves the zero-shot accuracy of GPT-4o in Google-Proof Question Answering from $51\%$ to $55\%$, yields $20\%$ relative performance gain in optimizing LeetCode-Hard coding problem solutions, improves prompts for reasoning, designs new druglike small molecules with desirable in silico binding, and designs radiation oncology treatment plans with high specificity. TextGrad lays a foundation to accelerate the development of the next-generation of AI systems.

Motivation & Objective

  • Motivate principled automated optimization for compound AI systems built from multiple components.
  • Introduce a framework that uses textual feedback as gradients to update variables in a computation graph.
  • Demonstrate TextGrad across diverse tasks including coding, reasoning, chemistry, and medical planning.

Proposed method

  • Represent the AI system as a computation graph with variables as inputs/outputs.
  • Define a gradient operator that uses LLM-provided natural language feedback to update variables (textual gradients).
  • Use a Textual Gradient Descent (TGD) optimizer to update variables based on textual gradients.
  • Allow objective functions to be arbitrary, including natural language descriptions, code evaluations, or simulations.
  • Support both instance optimization (directly optimizing a solution) and prompt optimization (optimizing prompts for better model performance).
  • Provide out-of-the-box implementation and PyTorch-like abstractions for ease of use.

Experimental results

Research questions

  • RQ1Can textual feedback from LLMs be backpropagated through a computation graph to improve individual components of a compound AI system?
  • RQ2What are the practical performance gains from using TextGrad on diverse tasks such as coding, reasoning, chemistry, and medicine?
  • RQ3How do instance optimization and prompt optimization compare when guided by textual gradients?
  • RQ4What are the effects of batch, constraints, and momentum-style extensions on TextGrad optimization?
  • RQ5Can TextGrad operate without task-specific prompts or extensive hand-tuning across domains?

Key findings

  • Improved LeetCode Hard problem solutions: TextGrad achieves 36% completion on LeetCode Hard without demonstrations, outperforming zero-shot (23%) and Reflexion baselines (31%).
  • Google-proof Question Answering: zero-shot accuracy improved from 51% to 55% with TextGrad on GPT-4o.
  • MMLU benchmarks: Machine Learning subset accuracy improved from 88.4% (TextGrad) vs. 85.7% (CoT); College Physics improved from 95.1% (TextGrad) vs. 91.2% (CoT).
  • Radiotherapy and molecular design demonstrations show improvements when optimizing problem-specific objectives via textual gradients.
  • TextGrad provides a PyTorch-like API, enabling broad accessibility and generality across tasks without framework-level prompts/tuning.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.