Flow-based Text Style Transfer Model - Zihan ZHANG; Jinqiao DAI; Pin YANG (工程科学与技术)
Objective In recent years, numerous style transfer methods in the text style transfer (TST) have relied on semi-supervised and unsupervised learning. The central concept of these methods involves mapping the text into a latent space, enabling the separation of content and style representations and facilitating style transfer. Text style transfer focuses on converting text attributes or styles while preserving the semantic content of the source sentences. Existing methods achieve significant progress in addressing the challenges associated with traditional TST tasks. However, these methods continue to face common limitations, including mismatches between the content and style of the transferred text and difficulties in maintaining the core semantics of the original text. Minimizing textual information loss during the transfer process remains critical to resolving content-style matching issues and preserving core semantics.Method This study introduces a flow-based text style transfer model. It adopts neural spline flows (NSF) as the foundational flow model for the text transfer task using the potential of flows in style transfer tasks. Flows employing affine coupling or autoregressive transformations provide accurate density assessment and sampling. The model comprises a conditional encoder, a series of invertible flows, a style discriminator, and two conditional decoders. The encoder ( $ X\to Z $ <alternatives> </alternatives>) transforms input sentences into the latent space. The forward process of the flow model is represented as $ f:Z\to \hat{Z} $ <alternatives> </alternatives>, abstracts the latent space encoding to a higher dimension, separates content and style, and reconstructs them. The inverse process, denoted as $ {f}^{-1}:\hat{Z}\to Z $ <alternatives> </alternatives>, returns to the latent space. The conditional decoder ( $ Z\to X $ <alternatives> </alternatives>) interprets the latent space’s hidden state into the target sentence required for the TST task. Initially, non-parallel datasets of various styles are partitioned into two domains, labeled as ‘a’ and ‘b’ representing opposing styles to illustrate the task of transferring a sentence from style ‘a’ to style ‘b’. Input sentences $ {x}_{\mathrm{a}}^{\mathrm{s}\mathrm{r}\mathrm{c}} $ <alternatives> </alternatives> and $ {x}_{\mathrm{b}}^{\mathrm{s}\mathrm{r}\mathrm{c}} $ <alternatives> </alternatives>, belonging to different style domains, exhibit non-parallel text content. This research derives their initial latent state space encodings, $ {\boldsymbol{z}}_{\mathrm{a}} $ <alternatives> </alternatives> and $ {\boldsymbol{z}}_{\mathrm{b}} $ <alternatives> </alternatives>, respectively by inputting $ {x}_{\mathrm{a}}^{\mathrm{s}\mathrm{r}\mathrm{c}} $ <alternatives> </alternatives> and $ {x}_{\mathrm{b}}^{\mathrm{s}\mathrm{r}\mathrm{c}} $ <alternatives> </alternatives> into the encoder. $ {\boldsymbol{z}}_{\mathrm{a}} $ <alternatives> </alternatives> is the hidden state sequence obtained by $ {x}_{\mathrm{a}}^{\mathrm{s}\mathrm{r}\mathrm{c}} $ <alternatives> </alternatives> through the encoder, and likewise for $ {\boldsymbol{z}}_{{\mathrm{b}}} $ <alternatives> </alternatives> corresponding to $ {x}_{\mathrm{b}}^{\mathrm{s}\mathrm{r}\mathrm{c}} $ <alternatives> </alternatives>. Then, using the flow, $ {{\textit{z}}}_{\mathrm{a}} $ <alternatives> </alternatives> and $ {\boldsymbol{z}}_{\mathrm{b}} $ <alternatives> </alternatives> are remapped to another distribution space, yielding encodings $ {\hat{\boldsymbol{z}}}_{\mathrm{a}} $ <alternatives> </alternatives> and $ {\hat{\boldsymbol{z}}}_{\mathrm{b}} $ <alternatives> </alternatives>. In the $ \hat{Z} $ <alternatives> </alternatives> space, which is the latent space mapped by the flow, $ {\hat{\boldsymbol{z}}}_{\mathrm{a}} $ <alternatives> </alternatives> is retained to reconstruct content while separating style. This study extends neural spline flows to further process the encoded latent variable $ {\hat{\boldsymbol{z}}}$ <alternatives> </alternatives>. Coupling transformations divide the input $ {\hat{\boldsymbol{z}}}$ <alternatives> </alternatives> into two parts, and compute $ {\boldsymbol{{\theta}} }=\mathrm{N}\mathrm{N}\left({\boldsymbol{z}}_{1:n-1}\right) $ <alternatives> </alternatives>, and $ {\hat{\boldsymbol{z}}}_{i}={f}_{{\theta }_{i}}({\boldsymbol{z}}_{i} $ <alternatives> </alternatives>). Then, set $ {{\hat{\boldsymbol{z}}}_{\mathrm{b}{,1:n-1}}^{{*}}}={{\hat{\boldsymbol{z}}}_{\mathrm{a},1:n-1} }$ <alternatives> </alternatives> and return $ {\hat{\boldsymbol{z}}}_{\mathrm{b}}^{\mathrm{*}}=[{{\hat{\boldsymbol{z}}}_{\mathrm{a},1:n-1}},{{\hat{\boldsymbol{z}}}_{\mathrm{b},n:d}}] $ <alternatives> </alternatives>. This transformation finalizes the conversion from $ {\hat{\boldsymbol{z}}}_{\mathrm{a}} $ <alternatives> </alternatives> to $ {\hat{\boldsymbol{z}}}_{\mathrm{b}}^{\mathrm{*}} $ <alternatives> </alternatives>. NSF proposes monotonic rational-quadratic transforms as an alternative to coupling layers or additive/affine transformations in autoregressive layers. This approach enhances flexibility while preserving precise reversibility. The study employs monotonic rational-quadratic splines and their inverses as building blocks to implement functions $ {f}_{i} $ <alternatives> </alternatives> and $ {f}_{i}^{-1} $ <alternatives> </alternatives>, where a monotonically increasing rational quadratic function defines each interval. Subsequently, the reverse process through the flow is applied to restore $ {\boldsymbol{z}}_{\mathrm{b}}^{\mathrm{*}} $ <alternatives> </alternatives> to the $ Z $ <alternatives> </alternatives> space. In addition, a pre-trained discriminator is employed in the model training process to compare reconstructed stylized $ {\boldsymbol{z}}_{\mathrm{b}}^{\mathrm{*}} $ <alternatives> </alternatives> with its original content source $ {\boldsymbol{z}}_{\mathrm{a}} $ <alternatives> </alternatives> The results are utilized to optimize the decoder. Finally, the conditional decoder $ {p}_{\mathrm{a}\to \mathrm{b}}\left(x|{\boldsymbol{z}}\right) $ <alternatives> </alternatives> is employed to obtain the transferred text $ {x}_{\mathrm{b}}^{\mathrm{r}\mathrm{e}\mathrm{c}} $ <alternatives> </alternatives>. Similarly, for the task of transferring a style ‘b’ sentence to style ‘a’, the reconstruction object is $ {\hat{\boldsymbol{z}}}_{\mathrm{b}} $ <alternatives> </alternatives>, resulting in $ {\boldsymbol{z}}_{\mathrm{a}}^{\mathrm{*}} $ <alternatives> </alternatives>. Another decoder, $ {p}_{\mathrm{b}\to \mathrm{a}}\left(x|{\boldsymbol{z}}\right) $ <alternatives> </alternatives>, is utilized to decode and obtain $ {x}_{\mathrm{a}}^{\mathrm{r}\mathrm{e}\mathrm{c}} $ <alternatives> </alternatives>.Results and DiscussionThe automatic evaluation metrics results indicated that the proposed method achieves the highest scores in terms of transfer accuracy (ACC) and ref–BLEU compared to the baseline models in both sentiment transfer and stance transfer tasks. In the instance analysis, several example sentences are extracted from the outputs of the sentiment transfer task for further comparison. The proposed method outperforms the selected baseline model when processing text containing multiple key pieces of information. The human evaluation results demonstrated that the proposed method performs better overall in text-style transfer tasks than the baseline. In addition, each model performs better in the sentiment transfer task than in the political stance transfer task. This difference is attributed to the subtle and implicit nature of the style information in political stance texts compared to sentiment texts. Effectively extracting these features remains an important research focus for future work. This section introduces a new metric for evaluating content preservation (CP) more comprehensively during the style transfer process to intuitively express the comprehensive performance of the models. The experiment modifies the criteria proposed by Krishna et al. and combines these three scores into a single sum. This combination method supports the evaluation of content preservation by considering the similarity between the reference text and the original text. Hence, a more comprehensive understanding of how well the model preserves the essential content during the text style transfer process is obtained. The proposed method achieves a 3% higher comprehensive score than the suboptimal model in sentiment transfer and a 5% higher score in political stance transfer. These results suggest that employing neural spline flows to handle latent space sequences not only improves content preservation but also balances transfer accuracy on this basis.Conclusion This study proposes a flow-based text style transfer model. It constructs a transformation function based on neural spline flows to address the issue of preserving text content during the TST task. It aims to reduce content and style mismatches after the TST task by jointly training the decoder with recomposed hidden state sequences derived from variations in the initial hidden state sequences. The neural spline flow-based model manipulates latent text sequences with high preservation by adjusting the number of stacked flows to achieve disentanglement effects on different text styles and contents. The flexibility and analytic reversibility of autoregressive transformations in neural spline flows reduce the loss of original content and semantic damage when encoding latent space hidden states.