SENSESHIFT: Continuous Sentiment-Controlled Text Generation via Encoder-based Mask Infilling

Shahed Masoudian, Markus Frohmann, Emmanouil Karystinaios, Navid Rekabsaz, Markus SchedlarXiv 2026

TL;DR

While decoder-based large language models dominate text generation, they struggle to modify specific sentences within a longer text to match a precise, fine-grained sentiment target. SENSESHIFT flips the script by using a bidirectional encoder architecture combined with iterative mask infilling to achieve precise sentence-level sentiment control. Despite being a fraction of the size of massive decoder models, SENSESHIFT delivers superior sentiment control and better contextual integration.

What Problem Does This Paper Address?

Most research in controllable text generation (CTG) for sentiment relies on decoder-only language models. These models use causal attention, meaning they generate text strictly from left to right. While excellent for open-ended generation, this architecture is fundamentally mismatched for in-text editing—scenarios where a user wants to rewrite a specific sentence inside an existing document. Because decoders cannot natively look ahead to the posterior context, the rewritten sentences often fail to integrate naturally with the text that follows.

Furthermore, existing methods usually treat sentiment as a coarse binary label (positive vs. negative) or apply a single sentiment control across an entire document. Controlling fine-grained sentiment intensity at the individual sentence level (e.g., shifting a sentence from neutral to mildly positive without breaking the narrative flow) remains an open challenge that prompting-based approaches struggle to solve reliably.

Methods

SENSESHIFT addresses these limitations by utilizing a bidirectional encoder framework (instantiated using ModernBERT-base and large) across three distinct stages:

  1. Automatic Sentiment Signal Construction and Quantization: The authors use VADER to automatically extract continuous sentiment scores ($v_i \in [-1, 1]$) for every sentence in a corpus. These scores are quantized into a discrete grid (with a step size of 0.1) and mapped to unique sentiment tokens (e.g., [0.5]), which are prepended to their respective sentences as local control anchors.
  2. Control-Aware MLM Fine-Tuning: The model undergoes Masked Language Modeling (MLM) training with two key modifications: sentiment tokens are never masked (serving as persistent conditioning anchors), and the masking ratio is bumped up to 40% to force the model to rely heavily on both the surrounding context and the sentiment anchors.
  3. Iterative Mask Infilling: During inference, the target sentence is entirely replaced with [MASK] tokens. Instead of predicting all masked tokens simultaneously—which causes standard encoders to generate repetitive, incoherent text due to conditional independence assumptions—SENSESHIFT predicts tokens sequentially from left to right. It leverages bidirectional attention over the entire past and future context, utilizing beam search with length normalization and a diversity penalty to ensure fluent outputs.
Figure 1: SENSESHIFT VS decoder-based prompting for sentiment CTG. Based on a given text, target sentence and sentiment, SENSESHIFT places sentiment tokens before each sentence. encoder-architecture allows SENSESHIFT to predict masked tokens attending to each target sentiment while distinguishing prior context from posterior.

Datasets

The framework was trained and evaluated on two distinct datasets characterized by dynamic sentiment shifts:

  • TinyStories: A corpus of ~4.5M short, multi-paragraph stories generated by GPT-3.5/4.0 containing diverse narrative arcs and explicit sentiment shifts.
  • Yelp Reviews: Approximately 300K human-written business reviews where sentence-level sentiments frequently fluctuate (e.g., praising the food but criticizing the service).

Key Insights and Ideas

  • The Architectural Advantage of Encoders: For localized text editing, bidirectional attention is structurally superior to causal attention. It allows the model to balance the transition between what came before and what comes after the edited segment.
  • The Necessity of Iterative Infilling: Parallel mask prediction suffers from severe exposure bias. Forcing the encoder to generate token-by-token (mimicking a decoder's autoregressive nature but with full contextual visibility) dramatically improves text fluency and coherence.
  • Efficiency Over Scale: Massive parameter counts aren't always necessary for specialized control tasks. A well-designed 395M parameter encoder can outperform a 120B parameter decoder model on localized attribute steering.

Key Results

  • Superior Sentiment Adherence: SENSESHIFT (ModernBERT-E-0.4B) achieved the lowest sentiment deviation ($\Delta_s = 0.20$ on TinyStories) compared to all baselines, including massive prompting models like OSS-120B ($\Delta_s = 0.30$).
  • Flawless Contextual Fit: SENSESHIFT maintained a calibrated fitness score ($\Delta_f$) at or near zero across both in-domain and out-of-domain evaluations. In contrast, decoder prompting baselines frequently suffered significant drops in contextual fitness, meaning their generated sentences felt out of place.
  • Drastic Perplexity Reductions: Iterative mask infilling reduced generation perplexity by a factor of 5–10× compared to parallel whole-mask prediction (e.g., dropping from 869.9 down to 53.6 for the 0.4B model on TinyStories).
  • Human Preference: In a user study, annotators rated SENSESHIFT as equivalent to or better than a 5× larger Gemma2-2B model (trained with token instruction tuning) in 73.5% of evaluated samples, showing a distinct preference for SENSESHIFT's sentiment alignment.

Limitations and Future Work

  • Sentiment Scorer Bottleneck: The framework relies entirely on VADER for sentiment labeling and evaluation. While VADER is highly efficient, it is a rule-based system that struggles with implicit or highly nuanced emotional expressions.
  • Data Distribution Skew: The training datasets feature very few examples of extreme sentiment values (especially highly negative ones), leading to higher error rates ($\Delta_s$) when targeting extreme values like $s = -1.0$.
  • Contextual Resistance: The authors observed that highly polarized surrounding context can "resist" the target sentiment shift, making it harder to inject a negative sentence into an overwhelmingly positive paragraph. Exploring how surrounding context biases generation remains an open avenue for future research.

Summary updated

BibTeX
@misc{masoudian2026senseshift,
  author = {Shahed Masoudian and Markus Frohmann and Emmanouil Karystinaios and Navid Rekabsaz and Markus Schedl},
  title = {{SENSESHIFT: Continuous Sentiment-Controlled Text Generation via Encoder-based Mask Infilling}},
  year = {2026},
  eprint = {2608.24304},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2608.24304},
}
Figure