Skip to main content
QUICK REVIEW

[Paper Review] "Mask and Infill" : Applying Masked Language Model to Sentiment Transfer

Xing Wu, Tao Zhang|arXiv (Cornell University)|Aug 21, 2019
Topic ModelingComputer Science21 references15 citations
TL;DR

This paper proposes a two-stage 'Mask and Infill' framework for non-parallel sentiment transfer, leveraging a pre-trained masked language model (BERT) to preserve content while transferring sentiment. By first masking sentiment-bearing tokens and then conditioning infill generation on context and target sentiment via an Attribute-Conditional MLM, the method achieves state-of-the-art performance in both automatic and human evaluations, outperforming prior RNN-based models in content preservation and sentiment accuracy.

ABSTRACT

This paper focuses on the task of sentiment transfer on non-parallel text, which modifies sentiment attributes (e.g., positive or negative) of sentences while preserving their attribute-independent content. Due to the limited capability of RNNbased encoder-decoder structure to capture deep and long-range dependencies among words, previous works can hardly generate satisfactory sentences from scratch. When humans convert the sentiment attribute of a sentence, a simple but effective approach is to only replace the original sentimental tokens in the sentence with target sentimental expressions, instead of building a new sentence from scratch. Such a process is very similar to the task of Text Infilling or Cloze, which could be handled by a deep bidirectional Masked Language Model (e.g. BERT). So we propose a two step approach "Mask and Infill". In the mask step, we separate style from content by masking the positions of sentimental tokens. In the infill step, we retrofit MLM to Attribute Conditional MLM, to infill the masked positions by predicting words or phrases conditioned on the context1 and target sentiment. We evaluate our model on two review datasets with quantitative, qualitative, and human evaluations. Experimental results demonstrate that our models improve state-of-the-art performance.

Motivation & Objective

  • To address the challenge of sentiment transfer in non-parallel text, where no paired examples of same-content, different-sentiment sentences exist.
  • To overcome limitations of RNN-based encoder-decoder models in capturing long-range dependencies and generating fluent, semantically consistent sentences.
  • To improve content preservation and sentiment transfer accuracy by leveraging pre-trained deep bidirectional language models.
  • To develop a method that mimics human-style sentiment conversion—replacing only sentiment markers—rather than rewriting entire sentences from scratch.
  • To integrate attribute conditioning and discriminative constraints into masked language modeling for more accurate and targeted sentiment transfer.

Proposed method

  • The method consists of two stages: first, sentiment tokens are identified and masked using a fused approach combining attention-based classification and frequency-ratio dictionary lookup.
  • In the infill stage, a pre-trained masked language model is retrofitted into an Attribute-Conditional MLM (AC-MLM) by conditioning predictions on both context and target sentiment embeddings.
  • The AC-MLM is further refined using a pre-trained sentiment classifier as a discriminator to ensure generated words align with the target sentiment.
  • Soft-sampling is applied during training to handle the discrete nature of language generation and improve optimization stability.
  • The fusion method dynamically selects between attention-based and frequency-ratio masking when one fails to produce a valid, content-preserving mask.
  • The model is trained end-to-end with a loss function combining reconstruction loss (contextual fluency) and discriminative loss (sentiment accuracy).

Experimental results

Research questions

  • RQ1Can masking and infilling with a pre-trained BERT-based model outperform RNN-based encoder-decoder models in sentiment transfer without parallel training data?
  • RQ2How effectively can a fused method of attention-based and frequency-ratio techniques identify sentiment markers while preserving content?
  • RQ3To what extent does conditioning masked language modeling on target sentiment improve transfer accuracy and content preservation?
  • RQ4How does the integration of a pre-trained sentiment classifier enhance the quality and consistency of generated sentiment words?
  • RQ5What trade-off exists between sentiment accuracy and sentence fluency/diversity, and can it be controlled via loss weighting?

Key findings

  • The AC-MLM-SS model with the fusion-based masking method achieved the highest human evaluation scores: 4.2 for grammaticality, 4.0 for content preservation, and 4.4 for target attribute match on the Yelp dataset.
  • On the Yelp dataset, the AC-MLM-SS model achieved a BLEU score of 4.2, significantly outperforming the previous state-of-the-art DeleteAndRetrieval model (3.6 BLEU).
  • On the Amazon dataset, the AC-MLM-SS model achieved a BLEU score of 4.1, showing consistent improvement over baselines.
  • The model demonstrated strong content preservation, with human annotators rating content similarity at 4.0 on Yelp and 4.0 on Amazon, indicating minimal semantic drift.
  • The ablation study confirmed that the fusion-based masking method outperformed both individual attention-based and frequency-ratio methods, especially on noisier, less structured Amazon data.
  • The trade-off analysis showed that adjusting the hyperparameter η allowed control over the balance between BLEU score and sentiment accuracy, confirming the model's tunable performance.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.