Algorithm Search⌘K

Text generation and decoding

Problems

  • Automatic summarization

    Produce a short text that keeps the main content of one or more documents, either by extracting sentences or by writing new ones.

    intro
  • Autoregressive decoding

    Given a model that gives the next token's distribution from a prefix, find the most probable output or draw a sample, one token at a time. Sampling is easy; the exact mode is hard.

    intro

Algorithms

  • Greedy decoding

    At each step emit the single most probable next token, until an end token. Fast, but its output can be far less probable than the most probable sequence.

    O(n (C + V)) worst1 languagesintro
  • Luhn summarization

    Luhn's 1958 extractive method: words of medium frequency are significant, and a sentence scores the best (significant words)^2 / length over its clusters of close significant words.

    O(N + n log n) expected1 languagesintro
  • Incremental algorithm for referring expressions

    Build a description of a target object by adding attributes in a fixed preference order whenever they rule out some distractor.

    O(p m) worst1 languagescore
  • LexRank

    Score sentences by the stationary distribution of a random walk on a graph of idf-weighted cosine similarities above a threshold (0.1), with random jumps, found by the power method.

    O(n N + I n²) expected1 languagescore
  • Nucleus sampling

    Sample from the smallest set of most probable next tokens whose total probability reaches p, so the candidate set adapts to the shape.

    O(V log V) worst1 languagescore
  • TextRank

    Rank sentences or words by weighted PageRank with d = 0.85 on a graph whose edges weigh word overlap or co-occurrence, then extract the top ones. A heuristic with no training.

    O(n N + I n²) expected1 languagescore
  • Top-k sampling

    Keep only the k most probable next tokens, renormalize their probabilities and sample from them.

    O(V + k log k) worst1 languagescore
  • Diverse beam search

    Split the beam into groups and penalize each group for tokens chosen by earlier groups at the same step, to return a varied list.

    O(n B (C + V)) worst1 languagesadvanced
  • Grid beam search

    Beam search with one beam per count of satisfied constraint tokens, so that the output must contain given words or phrases.

    O(n k (c + 1) (M + V + m)) worst1 languagesadvanced
  • Minimum Bayes risk decoding

    Choose the candidate output with the least expected loss under the model, for a loss such as 1 - BLEU or the word error rate, often with the expectation estimated from model samples.

    O(H N L) worst1 languagesadvanced
  • BERTScore

    Score a candidate text against a reference by greedy matching of their contextual token embeddings by cosine, as precision, recall and F1.

    O(n m d) worst1 languagesresearch
  • Contrastive search

    Choose among the top-k tokens by probability minus a penalty for the maximum cosine similarity of its hidden state to earlier ones.

    O(n (k C + V + k (L + n) d)) worst1 languagesresearch
  • Speculative decoding

    A small draft model proposes several tokens. The large model checks them in one pass and accepts each by a rule that keeps its exact distribution.

    O(n (P + k Q + k V)) worst1 languagesresearch
  • Stochastic beam search

    Beam search on Gumbel-perturbed log-probabilities that draws k sequences without replacement exactly from a sequence model.

    O(n k (M + V)) worst1 languagesresearch
  • Typical sampling

    Keep the tokens whose surprisal is closest to the entropy of the next-token distribution, up to mass tau, and sample among them.

    O(V log V) worst1 languagesresearch

Data structures

  • Key-value cache

    Store the attention keys and values of past tokens during decoding, so each new token costs attention time linear in the length, not quadratic.

    O(L (n^2 d + n d^2)) generate1 languagesadvanced

Techniques

  • Temperature sampling

    Sample the next token from softmax(z / T). T below 1 sharpens the distribution toward greedy, T above 1 flattens it toward uniform.

    1 languagesintro
  • Length normalization

    Divide the log probability of each finished beam hypothesis by a function of its length, such as |Y|^alpha, so that beam search does not prefer short outputs.

    1 languagescore
  • Repetition penalty

    Lower the logits of tokens that already occur in the output, by a factor or by an amount per occurrence, to curb loops.

    1 languagesadvanced
  • Scheduled sampling

    During training feed the model its own predicted token instead of the gold one with a probability that grows on a schedule.

    advanced
  • Grammar-constrained decoding

    Mask at each step the tokens that cannot extend the output to a string of a given regular or context-free language, tracked by an automaton.

    research
  • Self-consistency

    Sample many chain-of-thought answers and return the final answer that occurs most often among them.

    research

Concepts

  • Natural language generation pipeline

    The classic split of data-to-text generation into document planning, microplanning with referring expressions, and surface realization.

    core
  • Exposure bias

    A model trained with teacher forcing sees only gold prefixes, but at test time conditions on its own outputs, so errors can compound.

    advanced
  • Inadequacy of the mode

    A measured fact: the most probable output of a neural translation model is often empty or too short, so wider beams and exact search can lower the quality.

    research

Definitions

  • ROUGE

    Recall-oriented summary metrics based on the overlap of n-grams, or the longest common subsequence, between a candidate and reference summaries.

    1 languagescore

Models

  • Pointer-generator network

    An encoder-decoder that at each step mixes generating a word from the vocabulary with copying a source word through its attention weights.

    advanced