Generative Sentiment Transfer via Adaptive Masking

Yingze Xie, Jie Xu, LiQiang Qiao, Yun Liu, Feiran Huang, Chaozhuo Li

Introduction

Sentiment transfer is the task of rewriting a sentence to change its emotional tone—for example, from negative to positive—while meticulously preserving its original semantic content. Traditional approaches often struggle with the trade-off between content preservation and sentiment accuracy. Implicit methods that disentangle style and content in latent space often lose meaning, while explicit rule-based methods are often too rigid for nuanced language.

The AM-ST (Adaptive Masking for Sentiment Transfer) framework addresses these issues by treating the identification of sentiment-bearing words as a learnable optimization problem rather than a fixed preprocessing step.

Overview of the AM-ST framework showing the transition from a negative sentence to a positive one via adaptive masking and infilling.

Methodology

AM-ST operates in two distinct phases: Adaptive Sentiment Token Masking and Infilling Blanks with a sentiment-aware language model.

Detailed architecture of (a) the Adaptive Sentiment Token Masking phase and (b) the Infilling Blanks process using Senti-MLM.

Phase 1: Adaptive Sentiment Token Masking

Instead of relying on static dictionaries, AM-ST uses an Attention-based Mask Classifier. This component treats the decision to mask a word as a trainable parameter. To ensure effective disentanglement of style and content, the model utilizes a four-way loss strategy:

  • Classification Losses ($L_{clf}$): These ensure that the masked tokens ($S$) actually carry sentiment while the remaining tokens ($C$) represent the core content.
  • Adversarial Losses ($L_{adv}$): These actively penalize the model if sentiment can be predicted from the content tokens or if content can be predicted from the sentiment tokens, effectively "scrubbing" style from the content representation.

Phase 2: Infilling Blanks with Senti-MLM

Once the sentiment-bearing words are masked, the gaps must be filled to match the target emotion. The authors introduce Senti-MLM, a modified Masked Language Model based on BERT:

  • Sentiment Embeddings: The model incorporates sentence-level sentiment labels as embeddings to guide the generation toward the target polarity.
  • Multi-Grained Prediction: Senti-MLM is trained to predict not just the missing word, but also that word's specific polarity ($L_{senti}$). This ensures that the chosen replacement word aligns with both the sentence's grammar and the desired global sentiment.

Experimental Results

The model was evaluated on two standard benchmarks: Yelp business reviews and Amazon product reviews. AM-ST achieved state-of-the-art performance in both sentiment accuracy and content preservation (measured by BLEU scores).

  • Yelp: Achieved 97.1% sentiment accuracy and a 12.9 BLEU score.
  • Amazon: Achieved 86.4% accuracy and a 29.7 BLEU score.

Ablation studies confirmed that every component of the pipeline—including the adversarial losses and the word-polarity classifier—is essential for maintaining high performance. Removing any of these elements led to a measurable drop in transfer quality.

Conclusion

AM-ST demonstrates that treating masking as a learnable part of the training process allows for much greater flexibility and precision in sentiment transfer. By combining adaptive masking with a sentiment-aware infilling mechanism, the framework successfully bridges the gap between content preservation and stylistic accuracy. Future research may explore extending this framework to multi-class emotions and more complex linguistic domains.

Summary updated

BibTeX
@inproceedings{xie2023generative,
  author = {Yingze Xie and Jie Xu and LiQiang Qiao and Yun Liu and Feiran Huang and Chaozhuo Li},
  title = {{Generative Sentiment Transfer via Adaptive Masking}},
  booktitle = {PAKDD},
  year = {2023},
  doi = {10.1007/978-3-031-33383-5\_16},
}
Figure