Skip to main content
TextGrad: Automatic "Differentiation" via TextMert Yuksekgonul et al.

Objective functions

In numerical optimization and automatic differentiation, the objective function is typically a differentiable function, such as mean squared error or cross entropy. In TEXTGRAD, the objective can be a complex and potentially nondifferentiable function, where the domain and codomain of the function can be unstructured data. This choice adds important generality and flexibility to the framework. For instance, we demonstrate that the objective can be specified in natural language text and computed by prompting a language model (§3.3), an output of a code interpreter running unit tests (§3.1), or outputs of molecular simulation engines (§3.4). For instance, a simple loss function for a code snippet can be the following:

Loss(code,target goal)=LLM(Here is a code snippet:{code}).(13)\mathrm{Loss}(\mathrm{code},\mathrm{target~goal}) = \mathrm{LLM}(\mathrm{Here~is~a~code~snippet:}\{\mathrm{code}\}). \quad (13)

Here is the goal for this snippet: {target goal}\{\mathrm{target~goal}\} Evaluate the snippet for correctness and runtime complexity.),

where we can use this evaluation signal to optimize the code snippet, powered by the well- documented ability of LLMs to simulate human feedback, self- evaluate, and self- improve [10, 28- 33].