# SeqGAN: Sequence Generative Adversarial Nets with Policy Gradient

SeqGAN trains text generators with policy gradients instead of GAN gradients

Lantao Yu, Weinan Zhang, Jun Wang, Yong Yu · arXiv · 2016-9-18

- **Problem** GAN gradients fail for discrete tokens, because a small change to a token choice has no matching token. The discriminator also scores only finished sequences, not partial ones.
- **Method** SeqGAN treats the token generator as a stochastic policy. It uses the discriminator's score on a finished sequence as the reward, estimates partial sequence values by Monte Carlo rollouts, and updates the generator by policy gradient.
- **Results** On a synthetic oracle task, SeqGAN reaches an NLLoracle of 8.736, against 9.038 for the MLE-trained generator, where lower is better.

## Why GANs struggle with discrete tokens

Recurrent generators trained by maximum likelihood predict each token from the true prefix, but at inference they condition on their own earlier outputs, which the training data may never have contained. This exposure bias compounds along the sequence. Scheduled sampling reduces the mismatch by feeding the model its own generated tokens during training, yet a later analysis cited by the authors argues that it is an inconsistent strategy that does not fix the problem at its root.

A GAN pairs a discriminator that separates real data from generated data with a generator that tries to fool it, and this has worked well for natural images. For tokens the approach breaks down. The discriminator's gradient tells the generator how to nudge a continuous output, but a small nudge to a choice from a finite vocabulary has no matching token, so the signal carries little meaning.

A second obstacle is timing. The discriminator judges only a complete sequence, so a partial prefix has no direct score, and it is unclear how its current quality should be weighed against the quality of whatever follows it.

## The generator as a stochastic policy

SeqGAN recasts generation as a sequence of decisions. The state at step t is the prefix generated so far, the action is the next token, and the generator G\_θ(y\_t \| Y\_{1:t-1}) is a stochastic policy that picks that token. Choosing a token deterministically appends it to the prefix, so the state transition itself carries no randomness. The randomness lives entirely in the policy's choice of action.

The only reward is given after the last token: the discriminator's estimated probability that the finished sequence came from real data, D\_φ(Y\_{1:T}). Intermediate steps receive no direct reward. Because the policy parameters are updated directly, the discrete token choice never needs to be differentiated through, which is the point where the usual GAN gradient fails for text.

## Estimating action values and updating the generator

For an intermediate prefix Y\_{1:t}, the action value is the average discriminator score over N completions. Each completion Y^n\_{t+1:T} is sampled from a roll-out policy G\_β conditioned on the prefix. The formula is \\( Q(Y\_{1:t-1}, y\_t) = \\frac{1}{N}\\sum\_{n=1}^{N} D\_\\phi(Y^n\_{1:T}) \\) for t \< T, and \\( Q = D\_\\phi(Y\_{1:T}) \\) at t = T. The roll-out policy is set equal to the generator in these experiments, with a simpler roll-out allowed when speed matters more.

Averaging over N completions reduces the variance of the estimate.

The gradient is approximated on one sampled episode as \\( \\nabla\_\\theta J(\\theta) \\simeq \\sum\_{t=1}^{T}\\sum\_{y\_t} \\nabla\_\\theta G\_\\theta(y\_t\|Y\_{1:t-1})\\, Q(Y\_{1:t-1},y\_t) \\), which can be rewritten as an expectation of the log-probability gradient weighted by Q. The parameters are then moved by \\( \\theta \\leftarrow \\theta + \\alpha\_h \\nabla\_\\theta J(\\theta) \\).

Adam and RMSprop can replace the plain step. The Monte Carlo estimates are recomputed for each generated sequence, so the update always uses the current discriminator.

## Alternating generator and discriminator training

Training starts by fitting the generator with maximum likelihood on the real sequences, then fitting the discriminator by minimizing cross entropy with negative examples drawn from that generator. The authors found the signal from this pre-trained discriminator informative for adjusting the generator.

Each round has g-steps of generator updates by policy gradient, followed by d-steps in which the discriminator is retrained. The retraining uses the same real sequences as positives and freshly generated sequences as negatives, with equal counts of each. Reusing the same positives with different sets of negatives acts like bootstrapping and reduces the variance of the discriminator's estimates.

The discriminator objective is \\\[\\min\_\\phi -\\mathbb{E}\_{Y\\sim p\_{data}}\[\\log D\_\\phi(Y)\] - \\mathbb{E}\_{Y\\sim G\_\\theta}\[\\log(1-D\_\\phi(Y))\]\\\], which is the cross entropy between the labels and the predicted probability. Each d-step trains the discriminator for k epochs on this loss.

## Generator and discriminator networks

The generator is a recurrent network whose hidden state is updated as h\_t = g(h\_{t-1}, x\_t), with the LSTM cell implementing g. A softmax layer over a bias c and a weight matrix V gives the distribution over the next token. The authors note that other recurrent variants, such as the GRU and attention, could serve as the generator without changing the framework.

The discriminator is a convolutional network over the token embeddings concatenated into a matrix. Each kernel slides over a window of l tokens and produces a feature map, and max-over-time pooling keeps the strongest response per kernel. A highway layer then mixes the pooled features with a transformed copy through a transform gate, and a fully connected sigmoid output gives the probability that the input is real.

The generated sequence has a fixed length T.

## Synthetic oracle comparison

A randomly initialized LSTM serves as the oracle and generates 10,000 training sequences of length 20. Each model then draws 100,000 samples, and their NLLoracle under the oracle is averaged, with lower values indicating better sequences. The baselines are random token generation, an MLE-trained LSTM, scheduled sampling and PG-BLEU, which scores finished samples with BLEU.

For scheduled sampling the curriculum rate decreases by 0.002 per epoch.

Random generation reaches an NLLoracle of 10.310 and MLE 9.038. Scheduled sampling reaches 8.985 and PG-BLEU 8.946, while SeqGAN reaches 8.736.

In the learning curves, MLE and scheduled sampling settle at a relatively high NLLoracle after about 150 epochs, while SeqGAN keeps improving the same generator structure. The authors read the gap to PG-BLEU as evidence that a discriminator signal guides the policy better than a predefined score such as BLEU.

## How the training schedule affects stability

Four settings are shown: g-steps=100 with d-steps=1 and k=10; g-steps=30 with d-steps=1 and k=30; g-steps=1 with d-steps=1 and k=10; and g-steps=1 with d-steps=5 and k=3.

When the generator takes many steps per discriminator update, convergence is fast, but the generator improves faster than the discriminator can follow. The discriminator then gives misleading signals gradually. Training the discriminator for more epochs reduces this instability.

Updating the discriminator after a single generator epoch, before it is fooled, lets the run learn stably. Using five d-steps per round, so the discriminator sees several different negative sets for the same positives, improves overall performance with good stability. The authors tie this to the theorem in the original GAN work.

## Poem and Obama speech generation

The poem corpus contains 16,394 Chinese quatrains of four lines of twenty characters. The Obama corpus contains 11,092 paragraphs from political speeches. BLEU-2 is used for poems because most words in classical Chinese poems have one or two characters, while BLEU-3 and BLEU-4 are used for the speeches. BLEU compares against the whole test set rather than against a specific line.

For the human judgement, 20 real poems and 20 each from SeqGAN and MLE were mixed, and 70 experts judged 60 poems. A poem counted one point when judged human-written. The mean human score is 0.4165 for MLE, 0.5356 for SeqGAN and 0.6011 for real poems, with a p-value of 0.0034 for MLE against the reference. The authors describe SeqGAN as performing comparably to real human poems in this judgement.

## Piano-key music generation

The training data are the solo tracks of 695 Nottingham folk tunes in MIDI format. Pitches are mapped to 88 numbers, sampled every 0.4 s, and cut into sequences of length 32. BLEU is used for the discrete piano keys, and mean squared error for the continuous pitch patterns, where a lower error is better.

## Limitations

The convergence analysis assumes the discriminator can reach its optimum for a given generator. Only then is its signal meaningful and the adversarial training stable, so the analysis does not cover a discriminator that stays weak.

The exact oracle evaluation exists only for the synthetic task. The poem, speech and music results depend on BLEU against reference texts, and the poem human judgement uses 70 experts on 60 poems. The main text reports one value per model in its tables, with no spread across runs.

The generated sequence length is fixed for the discriminator, and variable-length discrimination is mentioned only as a possibility. The authors state that SeqGAN is the first work to extend GANs to generate sequences of discrete tokens; this is their own claim of priority.

## Paper info

- **Authors**: Lantao Yu, Weinan Zhang, Jun Wang, Yong Yu
- **Venue**: arXiv · Preprint
- **First published**: 2016-9-18
- **Added**: 2026-11-12
- **Updated**: 2017-8-25
- **Version**: v6
- **arXiv**: 1609.05473
- **Category**: cs.LG · cs.AI
- **Original paper terms**: [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1609.05473v6) · [PDF ↗](https://arxiv.org/pdf/1609.05473v6)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Lantao Yu, Weinan Zhang, Jun Wang, Yong Yu (2016). SeqGAN: Sequence Generative Adversarial Nets with Policy Gradient. arXiv:1609.05473v6. https://arxiv.org/abs/1609.05473v6

**BibTeX**

```
@misc{yu2016seqgan,
  title = {{SeqGAN: Sequence Generative Adversarial Nets with Policy Gradient}},
  author = {Lantao Yu and Weinan Zhang and Jun Wang and Yong Yu},
  year = {2016},
  eprint = {1609.05473},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1609.05473v6}
}
```

## Other paper commentary

- [Tutorial on Variational Autoencoders](https://refivu.com/en/papers/51a9cfc2-6285-4935-b55a-3d6450af8eff-tutorial-on-variational-autoencoders.md)
- [Social GAN: Socially Acceptable Trajectories with Generative Adversarial Networks](https://refivu.com/en/papers/134b8b94-f72a-441a-8ec1-4b871085c3e5-social-gan-socially-acceptable-trajectories-with-generative.md)
- [Unsupervised Anomaly Detection with Generative Adversarial Networks to Guide Marker Discovery](https://refivu.com/en/papers/62959e97-b421-4e00-897e-8709c817c9fb-unsupervised-anomaly-detection-with-generative-adversarial.md)
- [Generative Adversarial Text to Image Synthesis](https://refivu.com/en/papers/e3b168a4-0572-44b9-b18e-ca2f31dfdc4a-generative-adversarial-text-to-image-synthesis.md)
- [Adversarial Autoencoders](https://refivu.com/en/papers/8e20edb4-f017-4781-86f9-478c6059260f-adversarial-autoencoders.md)
- [Stable Video Diffusion: Scaling Latent Video Diffusion Models to Large Datasets](https://refivu.com/en/papers/82291bd9-5c41-4b81-bfde-a025a948f4b9-stable-video-diffusion-scaling-latent-video-diffusion-models.md)
- [Deep Learning for Person Re-identification: A Survey and Outlook](https://refivu.com/en/papers/d4bdc05a-ddac-43ad-93f5-95986e1858a4-deep-learning-for-person-re-identification-a-survey.md)
- [Qwen2.5-Coder Technical Report](https://refivu.com/en/papers/8282ea88-f013-4a5f-832a-687a740c2ff3-qwen2-5-coder-technical-report.md)
- [Generating Sentences from a Continuous Space](https://refivu.com/en/papers/921b1922-5f2e-49a8-80cd-9df917da7fe7-generating-sentences-from-a-continuous-space.md)
- [EMNIST: an extension of MNIST to handwritten letters](https://refivu.com/en/papers/c0f15d57-13ab-41d2-b5f0-6b120e9504c7-emnist-an-extension-of-mnist-to-handwritten-letters.md)
- [PV-RCNN: Point-Voxel Feature Set Abstraction for 3D Object Detection](https://refivu.com/en/papers/698bbbfa-a9d9-4163-aa75-907d42df6ab3-pv-rcnn-point-voxel-feature-set-abstraction-for.md)
- [PoseCNN: A Convolutional Neural Network for 6D Object Pose Estimation in Cluttered Scenes](https://refivu.com/en/papers/66e8eadd-21d7-4e03-a7bb-1fbeda963ac8-posecnn-a-convolutional-neural-network-for-6d-object.md)

## Terms in this paper

- [LSTM](https://refivu.com/en/terms/ba10547646d9-lstm)
- [BLEU](https://refivu.com/en/terms/42cd9b97719e-bleu)
- [CNN](https://refivu.com/en/terms/06880f5198e6-cnn)
- [policy gradient](https://refivu.com/en/terms/abaf88e7ce4d-policy-gradient)
- [GAN](https://refivu.com/en/terms/ae488c240045-gan)
- [RNN](https://refivu.com/en/terms/cd8552d9273e-rnn)
- [Oracle](https://refivu.com/en/terms/3ff0e5f5c4ee-oracle)
- [synthetic data](https://refivu.com/en/terms/d3b9fabe1cf0-synthetic-data)
- [exposure bias](https://refivu.com/en/terms/a9919ad9c1df-exposure-bias)
- [REINFORCE algorithm](https://refivu.com/en/terms/12bb061df8dd-reinforce-algorithm)
- [scheduled sampling](https://refivu.com/en/terms/ae12f4276c72-scheduled-sampling)
- [Generative model](https://refivu.com/en/terms/c856d6d2ec9a-generative-model)
- [action-value function](https://refivu.com/en/terms/bf0ed12cb911-action-value-function)
- [Discriminative Model](https://refivu.com/en/terms/86c375ed4197-discriminative-model)
- [maximum likelihood estimation](https://refivu.com/en/terms/fce2bab02a9b-maximum-likelihood-estimation)
- [Nottingham](https://refivu.com/en/terms/9b7dcaa7beab-nottingham)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/29153239-a1df-4102-9df1-abd1ba2a9c96-seqgan-sequence-generative-adversarial-nets-with-policy)
