liveBook · Manning

Recursion

As explained in Natural Language Processing in Action, Second Edition

Recursion is a computational process in which an operation invokes itself or reuses its output as input until a termination condition is reached.

Recursion recycles an operation’s output as input for another step until the computation terminates. A recursive function calls itself; an autoregressive model reuses each predicted token to predict the next one. section 9.1

The technique matters because recycling enables sequential prediction while requiring careful control:

  • Distinguish recursion from recurrence: recurrence specifically describes RNN units recycling outputs into their own inputs, while recursion also includes systems such as transformers. section 9.1
  • Terminate safely by reducing the remaining work at each recycling step; otherwise, recursive computation can continue indefinitely or break a program. section 8.0
  • Apply recursive prediction to next-token generation, real-time transcription and translation, algorithmic trading, and code generation. section 8.0

Autoregressive transformer generation

A transformer runs its network to produce one token embedding, recycles that output into the input, and runs again to predict the next token. Unlike an RNN, it contains no recurrent neurons and does not require inner-layer unrolling. section 9.1

Figure 9.1 Autoregressive transformers “recycle” their outputs into their input.
figure

Trace how an autoregressive transformer recycles generated outputs into successive inputs. section 9.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Defines recursion, distinguishes it from recurrence, and emphasizes termination but stops short of implementing a recursive function.
Examples
Uses recursive token generation, RNN memory, transcription, translation, algorithmic trading, and code generation as examples.
What you can do after
Evaluate recursive NLP architectures and recognize why termination and decreasing work matter for safe repeated computation.
How it connects
Connects recursion with autoregressive models, recurrent neural networks, transformers, convolutional neural networks, and token prediction.

Also explained in

Compare how 23 books explain recursion →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.