Teacher forcing trains a sequence decoder by feeding the true previous token as the next input instead of the model’s own prediction. That makes decoding easier during training and helps the model learn sequences faster. section 11.3.2 section 11.3.3
In Seq2Seq decoding, the encoder’s last hidden state initializes the decoder, then each step chooses between autoregressive input and teacher forcing. The target sequence must be available during training because the decoder needs the correct next token. section 11.3 section 11.4.1
Typical behavior in this implementation:
- Use the ground-truth token at step t as input for step t + 1 during training. section 11.3.2
- Use autoregressive sampling when teacher forcing is not selected or when predicting new data. section 11.3.3
- Keep the model in autoregressive mode at evaluation time because the answer is unknown. section 11.3.3
Decoder step selection
The forward pass checks training mode, then either sets next_words from target[:, t] or samples from the current prediction; at test time it uses argmax. A figure shows the decoder ignoring its own prediction and feeding the correct previous output instead. section 11.4.1
Figure 11.5 Example of teacher forcing. For the decoder, we ignore the predictions and at step t, we feed in the correct previous output yt − 1. The predictions are still used when the loss is computed.
Shows the decoder input being replaced by the correct prior token while predictions still contribute to the loss. section 11.3.2

