Modulating Language Models with Emotions

Ruibo Liu, Jason Wei, Chenyan Jia, Soroush Vosoughi

TL;DR

To make conversational AI truly empathetic, models must be able to express fine-grained human emotions. This paper introduces Modulated Layer Normalization (Mod-LN), a plug-and-play technique adapted from computer vision that injects emotional signals (represented by emojis) directly into pre-trained language models like BERT and GPT-2. The resulting models generate highly emotional, fluent, and diverse responses while requiring a fraction of the training data used by traditional baselines.

What Problem Does This Paper Address?

Building interactive systems that understand and express human emotions is a long-standing goal in NLP. A common task here is emotional response generation: given a conversation context, the AI must generate a reply that fits the topic and reflects a specified target emotion.

Past approaches—such as Variational Autoencoders (VAEs) and Generative Adversarial Networks (GANs)—frequently suffer from data scarcity, leading them to generate dull, generic responses. While large-scale language models (LMs) can be trained from scratch to steer text generation, doing so is computationally expensive and particularly difficult for low-resource or rare emotions. The authors address this by finding a simple, lightweight way to inject fine-grained emotional control into existing, pre-trained LMs without rebuilding their architectures.

Methods

The core innovation is Modulated Layer Normalization (Mod-LN), a technique widely used in computer vision generative models (like StyleGAN) but largely unexplored in NLP text generation.

In standard layer normalization, hidden states are normalized using only their internal mean and variance. Mod-LN introduces an external condition—in this case, a target emotion represented by an emoji. Two Multi-Layer Perceptrons (MLPs) dynamically compute scale ($\gamma$) and shift ($\beta$) parameters based on this emotion embedding, shifting the network's hidden states toward the desired emotional tone:

$$\text{Mod-LN}(x) = \text{MLP}_\gamma(c) \cdot \left(\frac{x - \mu}{\sigma + \epsilon}\right) + \text{MLP}_\beta(c)$$

The authors integrate Mod-LN into two distinct encoder-decoder setups:

  1. Mod-LN MLM (BERT-to-BERT): Uses BERT for both encoding and decoding. Because BERT is inherently bi-directional, they modify the decoder's attention mask to be uni-directional to prevent the model from looking ahead during text generation.
  2. Mod-LN ARLM (GPT2-to-GPT2): Uses the autoregressive GPT-2 model for both encoding and decoding.

Datasets

  • MojiTalk: A large Twitter conversation corpus consisting of roughly 700,000 conversation pairs. Responses in this dataset contain one or more of 64 popular emojis, which serve as the ground-truth labels for fine-grained emotions.
  • DeepMoji: A state-of-the-art emoji classification model trained on 1.24 billion tweets. The authors use DeepMoji as an automated judge to evaluate how accurately the generated responses reflect the intended emojis.

Key Insights and Ideas

  • Cross-Domain Synergy: Borrowing conditioning mechanisms from computer vision GANs works remarkably well for language modeling. Modulating the normalization layers acts as an effective, lightweight steering wheel for text generation.
  • Extreme Data Efficiency: By leveraging the rich representations already present in pre-trained LMs, Mod-LN circumvents the data scarcity trap. The model achieves competitive emotional control using just 10% of the available training data.
  • Autoregressive Advantage: The GPT-2 based model consistently outperformed the BERT-based model in emotion control. This suggests that models natively pre-trained with an autoregressive (left-to-right) objective are better suited for this style of conditioned generation.

Key Results

The models were evaluated on emotion control, diversity, and fluency, outperforming the previous state-of-the-art baseline (R-CVAE).

  • Emotion Accuracy: When evaluated by DeepMoji on the Hits@5 metric (whether the target emotion was in the top 5 predicted emotions), Mod-LN GPT-2 achieved 82.5% accuracy, compared to R-CVAE's 53.4%.
  • Data Scarcity Robustness: Remarkably, when trained on just 10% of the data, Mod-LN GPT-2 achieved a Hits@5 accuracy of 64.1%, easily beating the baseline trained on 100% of the data.
  • Fluency: Mod-LN GPT-2 achieved a perplexity score of 36.31, vastly superior to R-CVAE's 92.64, indicating much higher text quality and fluency.
  • Human Evaluation: 120 human annotators rated the generated text on a 7-point scale. Responses from the Mod-LN models showed no statistically significant difference from actual human responses in both emotion control and readability, outperforming vanilla GPT-2 and R-CVAE.

Limitations and Future Work

  • Discrete Emotion Categories: The emotional conditioning relies entirely on discrete emoji classes (64 specific emojis). It does not account for blended emotions or continuous emotional intensities.
  • Architectural Scope: While the authors note that the method is easily extendable to other Transformer-based LMs, this study only explicitly tests BERT and GPT-2.
  • Future Directions: The authors suggest that this plug-and-play modulation technique could be applied to other text-steering tasks beyond emotions, such as controlling persona, style, or specific linguistic attributes.

Summary updated

BibTeX
@inproceedings{liu2021modulating,
  author = {Ruibo Liu and Jason Wei and Chenyan Jia and Soroush Vosoughi},
  title = {{Modulating Language Models with Emotions}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  url = {https://openreview.net/forum?id=r1yxKe0RmGQ},
}
Figure