BERT as a Teacher: Contextual Embeddings for Sequence-Level Reward

Florian Schmidt, Thomas HofmannarXiv 2020

Introduction

The standard approach for training generative text models, Maximum Likelihood Estimation (MLE), is frequently criticized for "exposure bias." Because the model only observes ground-truth prefixes during training, small errors during inference can compound, leading to poor sequence-level coherence. Reinforcement Learning (RL) offers a path forward by optimizing for full sequences, yet it is often limited by the metrics used for rewards. Traditional $n$-gram based metrics like BLEU or ROUGE are sparse, ignore semantic similarity, and lack the granularity to provide effective per-token feedback.

This paper introduces a novel reward function that leverages the contextual power of BERT to overcome these limitations. By replacing rigid $n$-gram counts with "BERT-grams"—clusters of contextual embeddings—the authors provide a dense and semantically rich signal for RL training.

Methodology: The BERT-gram Reward

The proposed method transforms BERT’s discriminative knowledge into a teacher for generative models. The process involves three main stages:

  1. Corpus Representation: Every word in a large training corpus (e.g., BooksCorpus) is embedded using BERT. Unlike static word vectors, these embeddings are contextual, capturing the specific meaning of a word based on its surroundings.
  2. Clustering: To manage computational complexity, K-means clustering is applied to the resulting embeddings to identify $K$ prototypical "BERT-grams" for each vocabulary item.
  3. Reward Calculation: During RL training via the REINFORCE algorithm, the generator's output tokens are compared to the nearest BERT-gram in the reference set using a Radial Basis Function (RBF) kernel. This provides a continuous reward that recognizes semantic proximity even when exact word matches are absent.

Results and Performance

The effectiveness of the BERT-gram reward was evaluated primarily through unconditional text generation. The quality of the generated text was measured using GPT-2 perplexity, a proxy for naturalness and fluency.

GPT-2 Perplexity over training steps for different models.

As illustrated in the figure above, the BERT-gram model ("OURS") achieves a significantly lower perplexity (118) compared to the $n$-gram RL baseline (224) and the standard MLE approach (944). This suggests that the contextual reward helps the model learn more realistic linguistic patterns. Qualitatively, the model also learned to mimic specific stylistic elements of the BooksCorpus, such as the frequent use of direct speech, which appeared in 95% of generated sequences.

Semantic Sensitivity and Long-Range Coherence

A critical advantage of using BERT is its sensitivity to long-range context. To test this, the authors utilized the DiscoFuse dataset, comparing "real" fused sentences against "fake" ones where the second half of the sentence was randomly swapped.

Reward assigned to real vs. fake sentences relative to the conjunction point.

The results in the figure above show that the BERT-based reward function successfully discriminates between real and fake sentences, assigning significantly higher scores to coherent sequences. This discrimination persists even when the local syntax around the join point is identical, a scenario where traditional $n$-gram metrics typically fail to distinguish any difference. Analysis showed that BERT embeddings are sensitive to perturbations up to 7 words away, far exceeding the 2-4 word window of traditional metrics.

Conclusion and Limitations

By "borrowing" representations from high-quality discriminative models, the BERT-gram approach provides a smoother and more informative learning signal for text generation. However, the method is not without drawbacks. Like many RL-based generative models, it is susceptible to "mode collapse," where the model sacrifices diversity for high-reward "templates." Additionally, the training process is sensitive to hyperparameters such as entropy regularization and requires significant computational overhead due to the repeated forward passes of the BERT model. Future research may explore more efficient ways to integrate continuous semantic rewards while maintaining output variety.

Summary updated

BibTeX
@misc{schmidt2020bert,
  author = {Florian Schmidt and Thomas Hofmann},
  title = {{BERT as a Teacher: Contextual Embeddings for Sequence-Level Reward}},
  year = {2020},
  eprint = {2003.02738},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2003.02738},
}
Figure