Text style transfer method, device, electronic device and storage medium
By training the vector conversion model and text style transfer model through unsupervised learning, the problems of high labeling cost and low training efficiency in the existing technology are solved, and efficient conversion and accuracy improvement of text style transfer are achieved.
Patent Information
- Application Number
- CN202110691090.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-22
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2041-06-22
AI Technical Summary
In the existing technology, the annotation cost of text style transfer is high, the training efficiency is low, and it is difficult to achieve efficient conversion between different text styles.
An unsupervised learning method is used to train the vector conversion model and the text style conversion model. The first encoder learns the text semantics, and the second decoder learns the text style to achieve text style transfer, avoiding the sample labeling process.
It improves the conversion efficiency and accuracy of text style transfer and reduces the cost and time of model training.
Smart Images

Figure CN113822064B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology and provides a text style transfer method, device, electronic device and storage medium. Background Art
[0002] With the continuous development of science and technology, the field of natural language processing has made great progress. Text style transfer is a hot topic in this field. Text style transfer refers to converting text from one style to another without changing the text's semantics. Text style involves multiple aspects, such as morphology, grammar, sentiment, and tone.
[0003] In related technologies, text style transfer can be performed in the following two ways:
[0004] The first method is to use a conversion model to convert the text style of the text to be converted from the current style to the specified style, wherein the conversion model is trained based on a labeled training dataset.
[0005] However, in the first method, if the training data is labeled, it will lead to high labeling costs and low training efficiency. In addition, a labeled training dataset can only train a text style conversion model. Therefore, if a conversion model for other text styles is to be obtained, the dataset needs to be re-labeled.
[0006] The second method is to use a style removal model to convert the text style of the text to be converted from the current style to a unified style to obtain a unified style text, and then use a conversion model to convert the text style of the unified style text from the current style to the specified style.
[0007] However, in the second method, the training of the style removal model also requires data labeling, so there are also problems of high labeling cost and low training efficiency. Summary of the Invention
[0008] The embodiments of the present application provide a text style transfer method, device, electronic device and storage medium to solve the problems of high labeling cost and low model processing efficiency and accuracy in related technologies.
[0009] In a first aspect, an embodiment of the present application provides a method for text style transfer, comprising:
[0010] In response to a text style conversion request, obtaining style conversion information of the text to be converted and the target text;
[0011] Inputting the text to be converted into a trained vector conversion model to obtain a target semantic vector corresponding to the text to be converted;
[0012] Based on the target text style conversion information, determining a corresponding trained target style conversion model;
[0013] The target semantic vector is input into the trained target style conversion model to obtain the target text style text.
[0014] In a second aspect, an embodiment of the present application provides a text style transfer apparatus, comprising:
[0015] An acquiring unit, configured to acquire style conversion information of the text to be converted and the target text in response to a text style conversion request;
[0016] A vector conversion unit, configured to input the text to be converted into a trained vector conversion model to obtain a target semantic vector corresponding to the text to be converted;
[0017] A determination unit, configured to determine a corresponding trained target style conversion model based on the target text style conversion information;
[0018] The style conversion unit is used to input the target semantic vector into the trained target style conversion model to obtain target text style text.
[0019] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory, wherein the memory stores program code, and when the program code is executed by the processor, the processor performs the steps of the above-mentioned text style transfer method.
[0020] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium comprising a program code. When the program product is run on an electronic device, the program code is used to enable the electronic device to execute the steps of the above-mentioned text style transfer method.
[0021] In the embodiment of the present application, after obtaining the text to be converted, the text to be converted is input into a trained vector conversion model to obtain the target semantic vector of the text to be converted. The target semantic vector is then input into the trained target style conversion model to obtain the text in the target style. In this way, through content conversion and style conversion, the migration between different text styles can be achieved, improving conversion efficiency and accuracy. In addition, the training of the vector conversion model and the target style conversion model does not require sample labeling, which improves model training efficiency.
[0022] Other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present application. The purposes and other advantages of the present application can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0024] Figure 1 A schematic diagram of an application scenario provided in an embodiment of the present application;
[0025] Figure 2 A schematic diagram of a model framework provided in an embodiment of the present application;
[0026] Figure 3A This is a flow chart of the first stage model training method provided in the embodiments of the present application;
[0027] Figure 3B A logical diagram of the first-stage model training method provided in the embodiments of the present application;
[0028] Figure 4A Schematic diagram of the structure of the attention model in the embodiment of the present application;
[0029] Figure 4B A schematic diagram of generating a query vector, a key vector, and a value vector in an embodiment of the present application;
[0030] Figure 4C A schematic diagram of generating a first context vector corresponding to a word vector Y in an embodiment of the present application;
[0031] Figure 4D This is a schematic diagram of the structure of the long short-term memory model implemented in this application;
[0032] Figure 5 This is a flow chart of the second stage model training method provided in the embodiments of the present application;
[0033] Figure 6 This is a logical diagram of the second-stage model training method provided in the embodiments of the present application;
[0034] Figure 7 A flowchart of a text style transfer method provided in an embodiment of the present application;
[0035] Figure 8A A schematic diagram of a human-computer interaction interface provided in an embodiment of the present application;
[0036] Figure 8B This is another schematic diagram of a human-computer interaction interface provided in an embodiment of the present application;
[0037] Figure 8CThis is a schematic diagram of another human-computer interaction interface provided in an embodiment of the present application;
[0038] Figure 9 A schematic diagram of another target text style text provided in an embodiment of the present application;
[0039] Figure 10 This is a schematic diagram of an interface in a machine translation scenario provided in an embodiment of the present application;
[0040] Figure 11 A schematic diagram of the structure of a text style transfer device provided in an embodiment of the present application;
[0041] Figure 12 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;
[0042] Figure 13 A schematic diagram of the hardware structure of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of the technical solutions of this application, but not all of them. Based on the embodiments described in this application document, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the technical solutions of this application.
[0044] The following is an introduction to some of the concepts involved in the embodiments of this application.
[0045] 1. Text style transfer: converting one text style to another specified text style without changing the semantics.
[0046] 2. Bidirectional Encoder Representations from Transformer (BERT). BERT is a natural language processing model that pre-trains deep bidirectional representations by jointly conditioning on context in all layers. Therefore, the pre-trained BERT representations can be fine-tuned with an additional output layer, making it suitable for model building for a wide range of tasks without significantly modifying the model architecture for specific tasks.
[0047] 3. Transformer. Transformer is a language sequence processing model based on the attention mechanism. It uses the attention mechanism to explore the correlation between words in a sentence, allowing the model to learn the context vector of the word, improving the output effect of the model. It can also use the attention mechanism to achieve fast parallelization, improving the shortcoming of slow training of recurrent neural networks (RNNs).
[0048] 4. Unsupervised learning: solving various pattern recognition problems based on training samples of unknown categories (unlabeled). Unsupervised learning algorithms mainly include principal component analysis, isometric mapping, and local linear embedding.
[0049] 5. Supervised learning is the process of adjusting the parameters of a classifier to achieve the required performance using a set of samples with known categories. In supervised learning, each instance consists of an input object (usually a vector) and a desired output value (also called a supervisory signal). The supervised learning algorithm analyzes the training data and produces an inferred function that can be used to map new instances.
[0050] The preferred embodiments of the present application are described below in conjunction with the drawings in the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application and are not used to limit the present application. In addition, the embodiments and features in the embodiments of the present application can be combined with each other if there is no conflict.
[0051] Artificial Intelligence (AI) refers to the theories, methods, techniques, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, to perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that seeks to understand the essence of intelligence and produce new intelligent machines that can respond in a manner similar to human intelligence. AI also studies the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.
[0052] Artificial intelligence (AI) technology is a comprehensive discipline encompassing a wide range of fields, encompassing both hardware and software technologies. Foundational AI technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, speech processing, natural language processing, as well as machine learning / deep learning, autonomous driving, and smart transportation.
[0053] Natural language processing (NLP) is a key area of research in computer science and artificial intelligence. It studies the theories and methods that enable effective communication between humans and computers using natural language. Natural language processing (NLP) integrates linguistics, computer science, and mathematics. Therefore, research in this field involves natural language—the language we use in everyday life—and is closely linked to the study of linguistics. Natural language processing technologies typically include text processing, semantic understanding, machine translation, robotic question answering, and knowledge graphs.
[0054] Machine learning (ML) is a multidisciplinary field that encompasses probability theory, statistics, approximation theory, convex analysis, and algorithmic complexity theory. It specifically studies how computers can simulate or implement human learning behaviors to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is at the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications span all areas of AI. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.
[0055] With the research and progress of artificial intelligence technology, artificial intelligence technology has been studied and applied in many fields, such as common smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, unmanned driving, automatic driving, drones, robots, smart medical care, smart customer service, Internet of Vehicles, automatic driving, smart transportation, etc. It is believed that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.
[0056] The embodiment of the present application adopts a machine learning vector conversion model and a text style conversion model when performing text style transfer. The method for training the vector conversion model and the text style conversion model proposed in the embodiment of the present application can be divided into two parts, including a training part and an application part; wherein, the training part and the application part both involve the technical field of machine learning and the technical field of natural language processing. In the training part, the two technologies of machine learning and natural language processing are combined, and the training data set given in the embodiment of the present application is used to train the vector conversion model and the text style conversion model. Specifically, after the training samples in the training data set are input into the vector conversion model and the text style conversion model, the output results are obtained, and the model parameters are continuously adjusted through the optimization algorithm in combination with the input training samples; the application part is used to use the vector conversion model and the text style conversion model trained in the training part to perform text style transfer. In addition, it should be noted that the vector conversion model and the text style conversion model in the embodiment of the present application can be trained online or offline, and no specific limitation is made here.
[0057] Text style transfer is a hot issue in the field of natural language processing. Text style transfer refers to converting text from one text style to another without changing the semantics of the text. Text style involves multiple aspects, such as morphology, grammar, emotion, tone, etc.
[0058] In related technologies, a conversion model can be used to convert the text style of the text to be converted from the current style to a specified style. The conversion model is trained based on a labeled training dataset. However, labeling training data results in high labeling costs and low training efficiency. Furthermore, a labeled training dataset can only be used to train a conversion model for one text style. Therefore, to obtain a conversion model for a different text style, the dataset must be re-annotated.
[0059] Alternatively, a style removal model can be used to convert the text style of the text to be converted from its current style to a unified style, resulting in a unified style text. The conversion model can then be used to convert the style of the unified style text from its current style to a specified style. However, training a style removal model also requires labeled data, which is costly and inefficient.
[0060] Since supervised learning has the problems of high labeling cost and low training efficiency, in the embodiment of the present application, an unsupervised training method is adopted to train the model. Specifically, the model training process is divided into a first stage and a second stage. Through the training of the first encoder in the first stage, the trained first encoder learns the semantics of the training samples. Through the training of the second decoder in the second stage, the trained second decoder learns the text style.
[0061] During the model's use phase, after acquiring the text to be converted, it is fed into the trained first encoder to obtain the target semantic vector for the text to be converted. This target semantic vector is then fed into the trained second decoder to obtain the target text style. This allows for conversion between different text styles through content learning and style representation, improving conversion efficiency and accuracy. Furthermore, training the first encoder and second decoder eliminates the need for sample labeling, further enhancing model training efficiency.
[0062] The preferred embodiments of the present application are described below in conjunction with the drawings in the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application and are not used to limit the present application. In addition, the embodiments of the present application and the features in the embodiments may be combined with each other if there is no conflict.
[0063] See Figure 1 As shown, it is a schematic diagram of a possible application scenario in an embodiment of the present application.
[0064] The application scenario diagram includes two terminal devices 110 and a server 130. The application operation interface 120 can be logged in through the terminal device 110. The terminal device 110 and the server 130 can communicate with each other through a communication network.
[0065] In an embodiment of the present application, the terminal device 110 is an electronic device used by the user, which may be, but is not limited to, a personal computer, a mobile phone, a tablet computer, a notebook, an e-book reader, a smart home, an intelligent voice interaction device, a vehicle-mounted terminal, etc. Each terminal device 110 communicates with the server 130 through a communication network. In an optional embodiment, the communication network is a wired network or a wireless network, so the terminal device 110 and the server 130 can be directly or indirectly connected via wired or wireless communication, which is not limited in this application. The server 130 can be an independent physical server 130, or a server 130 cluster or distributed system composed of multiple physical servers 130, or a cloud server 130 that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.
[0066] Among them, the vector conversion model and the target style conversion model in the embodiment of the present application can be deployed on the terminal device 110, and can also be deployed on the server 130. When the vector conversion model and the target style conversion model are deployed on the terminal device 110, the terminal device 110 obtains the text to be converted, performs text style conversion on the text to be converted, and presents the target text style text to the user. When the vector conversion model and the target style conversion model are deployed on the server 130, the server 130 obtains the text to be converted, performs text style conversion on the text to be converted, and returns the target text style text to the terminal device 110, so that the terminal device 110 presents the target text style text to the user. The text to be converted can come from a browser web page, text information that matches the query information entered by the user, or a data source such as a public account article, and this application does not limit this.
[0067] The model training process provided in the embodiments of the present application is described below.
[0068] See Figure 2 As shown, it is a schematic diagram of a model architecture provided in an embodiment of the present application. In the embodiment of the present application, the model training process can be divided into two stages: the first stage and the second stage. The first stage involves a first encoder and a first decoder, and the second stage involves a second encoder and a second decoder, wherein the first encoder trained in the first stage is used as the second encoder in the second stage. It should be noted that, in the embodiment of the present application, the first encoder can also be called a vector conversion model, the first decoder can also be called a text restoration model, and the second decoder can also be called a style conversion model.
[0069] For example, the first encoder, the first decoder, the second encoder, and the second decoder may employ, but are not limited to, a BERT model, a Transformer model, a Long Short-Term Memory (LSTM) model, and the like, without limitation. It is readily understood that, compared to an LSTM model, the BERT and Transformer models offer higher performance but lower computational speed.
[0070] See Figure 3A As shown, it is a flow chart of the model training method of the first stage provided in the implementation of this application. The specific process is as follows:
[0071] S301: Acquire a first training data set, where each first training sample in the first training data set is of an initial text style or a target text style.
[0072] It should be noted that, in the embodiment of the present application, the first training data set is an unlabeled training data set.
[0073] Taking the initial text style as the plain text style (the plain text style can also be called the universal text style) and the target text style as the Jin Yong text style as an example, the first training sample of the plain text style is: Thank you, and the first training sample of the Jin Yong text style is: Thank you very much.
[0074] Since the first training data set contains a large number of first training samples, for ease of reading, the first training data set can be divided into multiple batches, and the number of samples contained in each batch is the same. In the embodiment of the present application, after each batch of first training samples is read, it is determined that the vector conversion model has completed a round of iteration.
[0075] S302 : Obtain a first training sample from a first training data set, and input the first training sample into a first encoder to obtain a first semantic vector corresponding to the first training sample.
[0076] The first encoder can learn the features of texts from different data sources, which can improve the accuracy of the model while reducing the number of model parameters.
[0077] S303: Input the first semantic vector into a first decoder corresponding to the first encoder to obtain a first prediction sample.
[0078] S304 : Based on a first loss value between the first prediction sample and a first training sample, adjust parameters of the first encoder, wherein the parameters are shared between the first encoder and the first decoder.
[0079] The first loss value may be calculated using, but not limited to, a cross entropy loss (CE), which is used to measure the similarity between a predicted sample and a corresponding first training sample.
[0080] Optionally, a process of adjusting parameters of the first encoder based on the first loss value is as follows:
[0081] First, the gradient of the parameters on the first encoder is determined using the first loss value;
[0082] Secondly, the parameters of the first encoder are adjusted according to the direction of the gradient.
[0083] In this way, based on the reverse transfer of the first loss value, the parameters of each layer included in the first encoder are adjusted, so that the parameters of the first encoder can be adjusted.
[0084] Since the parameters of the first encoder and the first decoder are shared, during the process of adjusting the parameters of the first encoder, both the parameters of the first encoder and the parameters of the first decoder will be adjusted.
[0085] S305 , determining whether a preset first convergence condition is met, if so, executing S306 ; otherwise, returning to executing S302 .
[0086] The first convergence condition mentioned in S305 can be any of the following:
[0087] The first loss value converges to a preset expected value; or, the set number of iterations is reached; or, all first training samples are read.
[0088] S306: Output the trained first encoder.
[0089] For example, see Figure 3B As shown, assuming that the first training sample is the first sample A: May I ask your honorable name, the first sample A is input into the first encoder to obtain the semantic vector corresponding to the first sample A, and then, the semantic vector corresponding to the first sample A is input into the first decoder to obtain the corresponding predicted sample A': May I ask your honorable name, and then, based on the first loss value between the first sample A and the predicted sample A', the parameters of the first encoder are adjusted.
[0090] The trained first encoder (i.e., the trained vector conversion model) can recognize text data from different text styles. There is no need to train a corresponding conversion model separately for each text style. While improving the conversion accuracy, it also reduces the number of model parameters, making it easier to deploy the trained first encoder in application scenarios.
[0091] In some embodiments, to speed up model training, the structural characteristics of BERT can be utilized to fine-tune BERT parameters to obtain a first encoder and a corresponding first decoder. In other words, the first encoder mentioned in S302 can use BERT pre-trained parameters.
[0092] BERT is a natural language processing model, which includes an input layer, an output layer, and a hidden layer composed of multiple Transformers. That is to say, Transformers are the core modules that make up BERT, and the attention mechanism is the most crucial part of Transformers. Generally speaking, the semantic meaning expressed by a word or term in a text is related to its context. For example, just seeing the character "鹄" may not enable one to understand its meaning, but after seeing its context "鸿鹄之志", one can understand that "鹄" in this sentence means "swan". Therefore, the context information of words or terms helps to enhance their semantic representation. At the same time, different words or terms in the context often play different roles in enhancing semantic representation. Continuing with the example of "鸿鹄之志", the character "鸿" plays the greatest role in understanding the character "鹄", while the character "之" plays a relatively smaller role. So, the attention mechanism is mainly used to distinguish the influence of each input word vector on text style transfer, and focus on a part of the word vectors that have a greater impact on text style transfer.
[0093] First, input the text to be converted into the first encoder, and perform word segmentation and vectorization processing on the text to be converted in sequence to obtain the corresponding word vector matrix.
[0094] Specifically, first clean the text to be converted,剔除 redundant and invalid text information, then use a word segmentation tool to perform word segmentation on the text to be converted, and finally use a random initialization method, or methods such as the bag-of-words method, Word2Vector, etc. to represent the text to be converted in vector form, and obtain the word vector corresponding to each word.
[0095] Secondly, perform semantic mining processing on each word vector based on the first encoder to obtain the corresponding semantic vector, where a semantic vector represents the confidence of a word vector in text style transfer.
[0096] (1) If the encoder of the first encoder adopts an attention model, the semantic mining processing process is as follows:
[0097] First, calculate the first context vector corresponding to each word vector based on the attention model, where the context represents the semantic meaning of the word corresponding to a word vector in a sentence, and a first context vector represents the correlation between the word vector and each word vector belonging to the same sentence;
[0098] Secondly, perform feature extraction on each word vector and the corresponding first context vector to obtain the semantic vector corresponding to each word vector.
[0099] The attention model in the embodiments of this application is Transformer, refer to Figure 4A It should be noted that the Chinese character "剔除" in the original text is directly translated as "剔除" in the English translation for now. If a more accurate English equivalent needs to be found, it can be adjusted according to the specific context. Also, the text may need further refinement and proofreading for better readability and accuracy in a professional context.The Transformer structure diagram shown in the figure shows that Transformer usually consists of four parts: input layer, output layer, encoder and decoder. Among them, the encoder contains two parts: attention mechanism and feedforward neural network, and the decoder contains two parts: attention mechanism and feedforward neural network.
[0100] In the attention mechanism, see Figure 4B As shown, the word vector matrix obtained by converting the same sentence is used as the input matrix, and the linear transformation matrix W is used. Q 、W K 、W V , get the query vector, key vector and value vector corresponding to each word vector. Figure 4C As shown in the figure, taking a word vector Y as an example, the process of determining its corresponding first context vector is to multiply the query vector by each key vector, use the product as the attention weight of word vector Y on each word vector, then multiply each value vector by the corresponding attention weight, and output the product as the first context vector. In the process of generating the first context vector, the value vector of word vector Y and the value vectors of each word vector belonging to the same sentence are weighted and integrated, reflecting the correlation between word vector Y and each word vector belonging to the same sentence.
[0101] (2) If the first encoder uses the long short-term memory model, the semantic mining process is as follows:
[0102] First, the second context vector corresponding to each word vector is calculated based on the long short-term memory model. The context represents the semantics of the word corresponding to a word vector in a sentence, and a second context vector represents the correlation between the corresponding word vector and other word vectors whose second context vectors have been extracted.
[0103] Secondly, feature extraction is performed on each second context vector to obtain the semantic features corresponding to each word vector.
[0104] The long short-term memory model in the embodiment of the present application is LSTM, which is a special recurrent neural network (RNN). Figure 4D As shown in the structural diagram, LSTM includes an input layer, an output layer, and a hidden layer. Multiple neurons are set on each hidden layer, and each word vector corresponds to a neuron. Each neuron includes a forget gate, an input gate, an output gate, and a Tanh layer. The gate structure is used to eliminate or increase the ability of information to the neuron, so that the LSTM can remember long-term information and overcome the long-term dependency (Long-Term Dependencies) problem of traditional RNN.
[0105] RNNs are recurrent neural networks (RNNs), widely used in fields such as computer vision and natural language processing. Their defining characteristic is the integration of both internal feedback and feedforward connections between processing units. Compared to feedforward neural networks, RNNs exhibit greater dynamic behavior and computational power during computation. This characteristic makes RNNs prone to long-term dependencies—meaning that the current system state is influenced not only by the state at the previous moment, but also by states from long periods before. For example, if an RNN is asked to predict the next word from the sentence "Does this rock candy taste real?", it will easily come up with the word "sweet." However, if an RNN is asked to predict the next word from the sentence "He took a bite of the dish, and the spiciness brought tears to his eyes, his face flushing red. A nearby person quickly poured him a glass of cold water, which he gulped down two times before gradually returning to normal. He angrily exclaimed, 'Does this dish taste real?'" it will struggle to predict the word "spicy."
[0106] See Figure 4D The structural diagram shown introduces the use of any LSTM neuron.
[0107] First, the second context vector h output by the previous neuron t-1 And the word vector x of the current neuron input t As input, the memory cell state C of the previous neuron is obtained through the forget gate t-1 The probability of being forgotten f t , f t The calculation method of is shown in formula (1), where 1 means completely retaining, and 0 means completely discarding.
[0108]
[0109] Secondly, the second context vector h output by the previous neuron t-1 And the word vector x of the current neuron input t As input, the memory cell state C' of the current neuron is obtained through the input gate t The probability of being retained i t , and use i t Calculate the memory cell state C' retained by the current neuron t , specifically, i t The calculation formula is shown in formula (2), C' t The calculation formula is shown in formula (3).
[0110]
[0111] C' t =tanh(W C *[ht-1 ,x t ]+b C ) formula (3);
[0112] Using C t-1 and C' t Update the memory cell state of the current neuron. The updated memory cell state is C t , C t The calculation formula is shown in formula (4).
[0113] C t =f t *C t-1 +i t *C' t Formula (4);
[0114] Finally, the second context vector h output by the previous neuron is t-1 And the word vector x of the current neuron input t As input, C is obtained through the output gate t The probability of the memory cell state being preserved is o t , o t The calculation formula is shown in formula (5);
[0115]
[0116] And, C t After being processed by the activation function Tanh and o t Multiply to get the second context vector h of the current neural output t , h t The calculation method of is shown in formula (6).
[0117] h t =o t *tanh(C t ) formula (6);
[0118] See Figure 5 As shown, it is a flow chart of the second stage model training method provided in the implementation of this application. The specific process is as follows:
[0119] S501: Acquire a second training data set, where each second training sample in the second training data set is of a target text style.
[0120] S502 : Obtain a second training sample from the second training data set, and input the second training sample into a second encoder to obtain a second semantic vector corresponding to the second training sample.
[0121] The main purpose of the first stage is to train the first encoder for two text styles to learn the semantics of the text, while the main purpose of the second stage is to train the decoder for different text styles. Therefore, after the first decoder is trained in the first stage, the first encoder trained in the first stage can be directly used as the second encoder in the second stage. In this way, in the second stage, only the parameters of the second decoder need to be adjusted, and the parameters of the second encoder do not need to be adjusted.
[0122] S503: Input the second semantic vector into the second decoder to obtain a second prediction sample corresponding to the second training sample.
[0123] S504 : Adjust parameters of the second decoder based on a second loss value between the second prediction sample and a second training sample.
[0124] Optionally, the process of adjusting parameters of the second decoder based on the second loss value is as follows:
[0125] First, the gradient of the parameters on the second decoder is determined using the second loss value;
[0126] Secondly, the parameters of the second decoder are adjusted according to the direction of the gradient.
[0127] S505 , determining whether a preset second convergence condition is met, if so, executing S506 ; otherwise, returning to executing S502 .
[0128] The second convergence condition mentioned in S505 can be any of the following:
[0129] The second loss value converges to a preset expected value; or, the set number of iterations is reached; or, all second training samples are read.
[0130] S506: Output the trained second decoder.
[0131] For example, see Figure 6 As shown, assuming that the second training sample is the second sample B: May I ask your honorable name, the second sample B is input into the second encoder to obtain the semantic vector corresponding to the second sample B, wherein the second encoder adopts the trained first encoder, and the parameters of the second encoder are fixed. Then, the semantic vector corresponding to the second sample B is input into the second decoder to obtain the corresponding predicted sample B': May I ask your honorable name, and then, based on the second loss value between the second sample B and the predicted sample B', the parameters of the second decoder are adjusted.
[0132] The trained second decoder (i.e., the trained target style conversion model) can convert the semantic vector into text of the corresponding text style after obtaining the corresponding semantic vector. In this way, the corresponding style conversion model is trained separately for each text style, thereby improving the conversion accuracy.
[0133] Below, the text style transfer method provided in the embodiment of the present application is described based on the trained first encoder and the trained second decoder.
[0134] See Figure 7 As shown, a text style transfer method provided in an embodiment of the present application is provided. The method can be applied to a text style transfer device, in which a trained vector conversion model and a trained target style transfer model are deployed. The specific process is as follows:
[0135] S701: The text style transfer apparatus obtains style conversion information of the text to be converted and the target text in response to a text style conversion request.
[0136] For example, in response to a text style conversion request, the text style transfer apparatus obtains the text to be converted and target text style conversion information, wherein the text to be converted is "Thank You" and the target text style conversion information indicates that the target text style is Jin Yong's text style.
[0137] S702: The text style transfer apparatus inputs the text to be converted into a trained vector conversion model to obtain a target semantic vector corresponding to the text to be converted.
[0138] S703: The text style transfer apparatus determines a corresponding trained target style transfer model based on the target text style transfer information.
[0139] In an embodiment of the present application, in the second stage of model training, for each text style, a style conversion model corresponding to each text style is trained. For example, for the naive text style, a style conversion model corresponding to the naive text style is trained; for the Jin Yong text style, a style conversion model corresponding to the Jin Yong text style is trained.
[0140] For example, the target text style conversion information indicates that the target text style is the Jin Yong text style. The text style transfer device determines the target style conversion model as the trained style conversion model corresponding to the Jin Yong text style based on the target text style conversion information.
[0141] S704 , the text style transfer apparatus inputs the target semantic vector into the trained target style transfer model to obtain the target text style text.
[0142] For example, the text style transfer device inputs the target semantic vector into the style transfer model corresponding to the trained Jin Yong text style to obtain the target text style text: Thank you very much.
[0143] In some embodiments, to increase the robot's question-and-answer function, the text style transfer device can respond to an input operation, obtain the input information to be answered and the target text style conversion information; search the designated storage location for the response text corresponding to the information to be answered, and use the response text as the text to be converted. Accordingly, after obtaining the target text style text, the text style transfer device presents the target text style text. Accordingly, after obtaining the target text style text, the text style transfer device presents the target text style text. The types of input operations include but are not limited to voice input, text input, etc.
[0144] Specifically, in order to provide diverse interaction methods, the text style transfer apparatus may present text in the target text style in the following ways, but not limited to:
[0145] The text style transfer device broadcasts the target text style text by voice; or,
[0146] The text style transfer device presents the target text style text through a human-computer interaction interface.
[0147] The following description only takes interaction through the human-computer interaction interface as an example.
[0148] See Figure 8A As shown, the text style transfer device may include an operation interface A, which is used to receive the text to be answered and the target text style information input by the user, wherein the target text style information includes task status information and character setting information. When the user triggers the "click to select task status" button, the text style transfer device is displayed. Figure 8B The character status selection interface shown in the figure includes the following: good mood, happy, sad, drunk, etc. When the user triggers the "click to select character" button, the text style transfer device will display Figure 8C The character selection interface shown in the figure includes Wang Yuyan, Li Bai, Jin Yong, Lin Daiyu, etc. When the user clicks the "Ask a Question" button, the text style transfer device determines that a text style conversion request is triggered.
[0149] For example, the text style migration device can obtain the input information to be answered and the target text style conversion information in response to an input operation, wherein the input is information to be answered A, and the target text style conversion information A indicates that the target text style is "Wang Yuyan in a good mood". Then, the text style migration device searches for the response text A corresponding to the information to be answered A in the designated storage location, and uses the response text A as the text A to be converted.
[0150] The text style migration device responds to the text style conversion request, obtains the text to be converted A and the target text style conversion information, then inputs the text to be converted A into the trained vector conversion model to obtain the target semantic vector A corresponding to the text to be converted A, and then, based on the target text style conversion information A, determines the trained target style conversion model corresponding to "Wang Yuyan in a good mood", and inputs the target semantic vector A into the trained target style conversion model corresponding to "Wang Yuyan in a good mood" to obtain the target text style text A.
[0151] The present application is further described below in conjunction with specific application scenarios.
[0152] Application scenario 1: Robot question and answer.
[0153] Take the vector conversion model and target style conversion model deployed in a mobile phone as an example, see Figure 9 As shown, the mobile phone obtains the input information to be answered B and the target text style conversion information B in response to the input operation, wherein the input information to be answered B is "Which province in China has the best scenery?", and the target text style conversion information B indicates that the target text style is "Drunk Li Bai".
[0154] The mobile phone is equipped with a trained vector conversion model and a trained target style conversion model for the scenario "Drunken Li Bai." After finding the answer text B corresponding to the unanswered message B and using it as the untranslated text B, the mobile phone inputs the trained vector conversion model to obtain the target semantic vector B corresponding to the untranslated text B. Furthermore, the target semantic vector B is input into the trained target style conversion model for the scenario "Drunken Li Bai" to obtain the target text style text B. The target text style text B is {I've seen so much about "Yunnan," but you haven't recommended anything about Yunnan to me? _? (A quick aside, no exaggeration or criticism, the people of Yunnan are genuine, friendly, and long-lasting) --- manually segmented, just returned from Yunnan, angry answer: Yunnan has many things that others don't have because they are unique to Yunnan. Yunnan has Kunming's four-season spring, Yuxi's verdant mountains and clear waters, Gaoligong Mountain's plateau rainbows, Lijiang's ancient city charm... and so on...}.
[0155] Taking the vector conversion model and the target style conversion model deployed in the server as an example, assuming that the terminal device is a smart speaker, the user can use the smart speaker to input the information to be answered B and the target text style conversion information B by voice. The input information to be answered B is "Which province in China has the best scenery?", and the target text style conversion information B indicates that the target text style is "Drunk Li Bai".
[0156] The server obtains the information to be answered B and the target text style conversion information B. After obtaining the answer text B corresponding to the information to be answered B, the answer text B is used as the text to be converted B. Then, based on the text to be converted B, the target text style conversion information B, the trained vector conversion model, and the trained target style conversion model corresponding to the setting of "Drunken Li Bai", the server obtains the target text style text B. The server then returns the target text style text B to the smart speaker, which then announces the target text style text B through voice.
[0157] Application scenario two: machine translation.
[0158] Machine translation refers to the translation of text from one language to another. In machine translation applications, text style is used to characterize the language type of the text.
[0159] Take the vector conversion model and target style conversion model deployed in a mobile phone as an example, see Figure 10 As shown, the terminal device directly obtains the input text to be converted C and the target text style conversion information C in response to the input operation, wherein the text to be converted C is "I read a book on Sunday" and the target text style conversion information C indicates that Chinese is converted into English.
[0160] The terminal device is equipped with a trained vector conversion model and a trained target style conversion model for English. The terminal device inputs the text to be converted, C, into the trained vector conversion model to obtain a target semantic vector, C, corresponding to the text to be converted. The target semantic vector, C, is then input into the trained target style conversion model for English to obtain and present the target text style, C, which is "I read a book Sunday."
[0161] Application scenario three: text generation.
[0162] In the embodiments of the present application, text generation includes but is not limited to question generation, title generation, etc. Among them, question generation refers to generating a question corresponding to the answer based on a given text and a corresponding answer, and title generation refers to generating a title corresponding to a given text based on the text.
[0163] Taking question generation as an example, after the text style transfer device obtains the text to be processed and the corresponding answer, it uses the answer as the text to be converted D. Then, the text to be converted D is input into the trained vector conversion model to obtain the target semantic vector D corresponding to the text to be converted D. Then, the target semantic vector D is input into the trained target style conversion model set for the corresponding question sentence to obtain the target text style text D.
[0164] Taking title generation as an example, after the text style transfer device obtains the text to be processed, it uses the text to be processed as the text to be converted E. Then, the text to be converted E is input into the trained vector conversion model to obtain the corresponding target semantic vector E. Then, the target semantic vector E is input into the trained target style conversion model with the corresponding summary style setting to obtain the target text style text E.
[0165] Based on the same inventive concept, the present application embodiment provides a text style transfer device. Figure 11 As shown, it is a schematic structural diagram of a text style transfer apparatus 1100, which may include:
[0166] An acquiring unit 1101 is configured to acquire style conversion information of the text to be converted and the target text in response to a text style conversion request;
[0167] A vector conversion unit 1102 is configured to input the text to be converted into a trained vector conversion model to obtain a target semantic vector corresponding to the text to be converted;
[0168] A determining unit 1103 is configured to determine a corresponding trained target style conversion model based on the target text style conversion information;
[0169] The style conversion unit 1104 is configured to input the target semantic vector into the trained target style conversion model to obtain a target text style text.
[0170] Optionally, a training unit 1105 is further included, wherein the training unit 1105 is configured to:
[0171] Acquire a first training data set, wherein each first training sample in the first training data set is of an initial text style or a target text style;
[0172] Inputting the first training data set into the vector conversion model for iterative training until a preset first convergence condition is met, and outputting a trained vector conversion model, wherein one iteration process includes:
[0173] Obtaining a first training sample from the first training data set, and inputting the first training sample into the vector conversion model to obtain a first semantic vector corresponding to the first training sample;
[0174] Inputting the first semantic vector into a text restoration model set corresponding to the vector conversion model to obtain a first prediction sample;
[0175] Based on a first loss value between the first prediction sample and the first training sample, parameters of the vector conversion model are adjusted, wherein parameters are shared between the text restoration model and the vector conversion model.
[0176] Optionally, when adjusting parameters of the vector conversion model based on the first loss value between the first prediction sample and the first training sample, the training unit 1105 is specifically configured to:
[0177] Determine a gradient of a parameter on the vector conversion model based on the first loss value;
[0178] Parameters of the vector conversion model are adjusted according to the direction of the gradient.
[0179] Optionally, a training unit 1105 is included, wherein the training unit 1105 is used to:
[0180] Acquire a second training data set, where each second training sample in the second training data set is in a target text style;
[0181] The second training dataset is input into the target style transfer model for iterative training until a preset second convergence condition is met, and the trained target style transfer model is output. One iteration process includes:
[0182] Obtaining a second training sample from the second training data set, and inputting the second training sample into the vector conversion model to obtain a second semantic vector corresponding to the second training sample;
[0183] Inputting the second semantic vector into a target style conversion model to obtain a second predicted sample corresponding to the second training sample;
[0184] Based on a second loss value between the second prediction sample and the one second training sample, parameters of the target style conversion model are adjusted.
[0185] Optionally, before obtaining the style conversion information of the text to be converted and the target text in response to the text style conversion request, the obtaining unit 1101 is further configured to:
[0186] In response to an input operation, obtaining input information to be answered and the target text style conversion information;
[0187] Searching for a response text corresponding to the information to be answered in a designated storage location, and using the response text as the text to be converted;
[0188] After obtaining the target text style, the style conversion unit 1104 is further configured to:
[0189] Present the target text style text.
[0190] Optionally, when presenting the target text style text, the style conversion unit 1104 is specifically configured to:
[0191] Announce the target text style text by voice; or
[0192] The target text style text is presented through a human-computer interaction interface.
[0193] For the convenience of description, the above parts are divided into modules (or units) according to their functions and described separately. Of course, when implementing this application, the functions of each module (or unit) can be implemented in the same or multiple software or hardware.
[0194] Regarding the apparatus in the above embodiment, the specific manner in which each unit executes the request has been described in detail in the embodiment of the method, and will not be elaborated on here.
[0195] Those skilled in the art will appreciate that various aspects of the present application can be implemented as systems, methods, or program products. Therefore, various aspects of the present application can be specifically implemented in the following forms: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation that combines hardware and software aspects, which may be collectively referred to herein as a "circuit," "module," or "system."
[0196] After introducing the text style transfer method and apparatus according to an exemplary embodiment of the present application, an electronic device according to another exemplary embodiment of the present application is introduced next.
[0197] Figure 12 1 is a block diagram of an electronic device 1200 according to an exemplary embodiment. The device includes:
[0198] Processor 1210;
[0199] a memory 1220 for storing instructions executable by the processor 1210;
[0200] The processor 1210 is configured to execute instructions to implement the text style transfer method in the embodiment of the present disclosure, for example Figure 3A 、 Figure 5 or Figure 7 Follow the steps shown in .
[0201] In an exemplary embodiment, a storage medium including operations is further provided, for example, a memory 1220 including operations, and the operations may be executed by the processor 1210 of the electronic device 1200 to perform the above method. Alternatively, the storage medium may be a non-transitory computer-readable storage medium, for example, a read-only memory (ROM), a random access memory (RAM), a portable compact disk read-only memory (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, etc.
[0202] Based on the same inventive concept, see Figure 13 As shown, an embodiment of the present application further provides a terminal device 1300, which includes but is not limited to mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals and other electronic devices.
[0203] The terminal device 1300 includes a display unit 1340, a processor 1380, and a memory 1320. The display unit 1340 includes a display panel 1341 for displaying information input by a user or information provided to a user, as well as various operation interfaces of the terminal device 1300. In the embodiment of the present application, the display panel 1341 is mainly used to display the operation interfaces and shortcut windows of application programs installed in the terminal device 1300. Optionally, the display panel 1341 can be configured in the form of an LCD (Liquid Crystal Display) or an OLED (Organic Light-Emitting Diode).
[0204] The processor 1380 is configured to read a computer program and then execute the method defined by the computer program. For example, the processor 1380 reads an application, thereby running the application on the terminal device 1300 and displaying an operation interface on the display unit 1340. The processor 1380 may include one or more general-purpose processors and may also include one or more DSPs (Digital Signal Processors) to perform related operations to implement the technical solutions provided in the embodiments of the present application.
[0205] The memory 1320 generally includes internal memory and external memory. The internal memory can be RAM, ROM, and cache (CACHE), etc. The external memory can be a hard disk, an optical disk, a USB disk, a floppy disk, or a tape drive, etc. The memory 1320 is used to store computer programs and other data. The computer program includes an application program, etc. The other data may include data generated after the operating system or application program is run, and the data includes system data (such as configuration parameters of the operating system) and user data. In the embodiment of the present application, program instructions are stored in the memory 1320, and the processor 1380 executes the program instructions in the memory 1320 to implement the text style transfer method discussed above.
[0206] In addition, the terminal device 1300 may also include a display unit 1340 for receiving input digital information, character information or contact touch operation / contactless gesture, and generating signal input related to user settings and function control of the terminal device 1300. Specifically, in an embodiment of the present application, the display unit 1340 may include a display panel 1341. The display panel 1341, such as a touch screen, can collect user touch operations on or near it (such as operations performed by the user using a finger, stylus, or any other suitable object or accessory on or on the display panel 1341) and drive the corresponding connection device according to a pre-set program. Optionally, the display panel 1341 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch direction and detects the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device and converts it into touch point coordinates, which are then sent to the processor 1380. It can also receive commands sent by the processor 1380 and execute them. In an embodiment of the present application, if a user selects a control in the operation interface, the touch detection device in the display panel 1341 detects the touch operation, and sends a signal corresponding to the detected touch operation to the touch controller. The touch controller converts the signal into touch coordinates and sends it to the processor 1380. The processor 1380 determines the control selected by the user based on the received touch coordinates.
[0207] The display panel 1341 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the display unit 1340, the terminal device 1300 can also include an input unit 1330, which can include but is not limited to one or more of a physical keyboard, function keys (such as volume control keys, power keys, etc.), a trackball, a mouse, and a joystick. Figure 13 In the figure, the input unit 1330 includes an image input device 1331 and other input devices 1332 as an example.
[0208] In addition to the above, the terminal device 1300 may also include a power supply 1390 for powering other modules, an audio circuit 1360, a near-field communication module 1370, and an RF circuit 1310. The terminal device 1310 may also include one or more sensors 1350, such as an accelerometer, a light sensor, a pressure sensor, etc. The audio circuit 1360 specifically includes a speaker 1361 and a microphone 1362. For example, a user can use voice control. The terminal device 1300 can collect the user's voice through the microphone 1362, can be controlled by the user's voice, and when the user needs to be prompted, a corresponding prompt tone is played through the speaker 1361.
[0209] Based on the same inventive concept, the present application also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the text style transfer method provided in various optional implementations of the above embodiments.
[0210] In some possible implementations, various aspects of the method for generating an audio library provided in the present application may also be implemented in the form of a program product, which includes a computer program. When the program product is run on a computer device, the computer program is used to enable the computer device to perform the steps of the text style transfer method according to various exemplary embodiments of the present application described above in this specification. For example, the computer device may perform the following steps: Figure 3A 、 Figure 5 or Figure 7 Follow the steps shown in .
[0211] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, RAM, ROM, an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a CD-ROM, an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0212] The program product of the embodiments of the present application may be a CD-ROM and include program code, and may be run on a computing device. However, the program product of the present application is not limited thereto. In this document, a readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with a command execution system, apparatus, or device.
[0213] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein a readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with a command execution system, apparatus, or device. Although preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once the basic inventive concepts become known. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0214] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.
Claims
1. A text style transfer method, characterized in that: include: In response to a text style conversion request, obtaining style conversion information of the text to be converted and the target text; Inputting the text to be converted into a trained vector conversion model to obtain a target semantic vector corresponding to the text to be converted; Based on the target text style conversion information, determining a corresponding trained target style conversion model; Inputting the target semantic vector into the trained target style conversion model to obtain target text style text; The training process of the vector conversion model and the target style conversion model is divided into a first stage and a second stage. In the first stage, the vector conversion model and the text restoration model set corresponding to the vector conversion model are trained using a first training data set. In the second stage, the target style conversion model is trained using the vector conversion model trained in the first stage. The first training data set is an unlabeled training data set, and each first training sample in the first training data set is an initial text style or a target text style. The target style transfer model is trained using the following method: Determining a second semantic vector corresponding to each second training sample in the second training data set by the vector conversion model; each second training sample is a target text style; Inputting each second semantic vector into the target style conversion model to obtain a second predicted sample corresponding to each second training sample; Parameters of the target style conversion model are adjusted based on a loss value between each second training sample and the corresponding second prediction sample.
2. The method according to claim 1, wherein The vector conversion model is trained in the following way: Obtaining the first training data set; Inputting the first training data set into the vector conversion model for iterative training until a preset first convergence condition is met, and outputting a trained vector conversion model, wherein one iteration process includes: Obtaining a first training sample from the first training data set, and inputting the first training sample into the vector conversion model to obtain a first semantic vector corresponding to the first training sample; Inputting the first semantic vector into a text restoration model set corresponding to the vector conversion model to obtain a first prediction sample; Based on a first loss value between the first prediction sample and the first training sample, parameters of the vector conversion model are adjusted, wherein parameters are shared between the text restoration model and the vector conversion model.
3. The method according to claim 2, wherein The adjusting parameters of the vector conversion model based on the first loss value between the first prediction sample and the first training sample specifically includes: Determine a gradient of a parameter on the vector conversion model based on the first loss value; Parameters of the vector conversion model are adjusted according to the direction of the gradient.
4. The method according to any one of claims 1 to 3, wherein Before obtaining the style conversion information of the text to be converted and the target text in response to the text style conversion request, the method further includes: In response to an input operation, obtaining input information to be answered and the target text style conversion information; Searching for a response text corresponding to the information to be answered in a designated storage location, and using the response text as the text to be converted; After obtaining the target text style text, the method further includes: Present the target text style text.
5. The method according to claim 4, wherein The presenting of the target text style text includes: Announce the target text style text by voice; or The target text style text is presented through a human-computer interaction interface.
6. A text style transfer device, characterized in that: include: An acquiring unit, configured to acquire style conversion information of the text to be converted and the target text in response to a text style conversion request; A vector conversion unit, configured to input the text to be converted into a trained vector conversion model to obtain a target semantic vector corresponding to the text to be converted; A determination unit, configured to determine a corresponding trained target style conversion model based on the target text style conversion information; A style conversion unit is used to input the target semantic vector into the trained target style conversion model to obtain the target text style text A training unit, configured to train the vector conversion model and the target style conversion model; The training process is divided into a first stage and a second stage. In the first stage, the vector conversion model and the text restoration model set corresponding to the vector conversion model are trained using a first training data set. In the second stage, the vector conversion model trained in the first stage is used to train the target style conversion model. The first training data set is an unlabeled training data set, and each first training sample in the first training data set is an initial text style or a target text style. The target style conversion model is trained by the following method: determining a second semantic vector corresponding to each second training sample in the second training data set through the vector conversion model; each second training sample is a target text style. Inputting each second semantic vector into the target style conversion model to obtain a second prediction sample corresponding to each second training sample; and adjusting parameters of the target style conversion model based on a loss value between each second training sample and the corresponding second prediction sample.
7. The device according to claim 6, characterized in that The training unit is used to: Obtaining the first training data set; Inputting the first training data set into the vector conversion model for iterative training until a preset first convergence condition is met, and outputting a trained vector conversion model, wherein one iteration process includes: Obtaining a first training sample from the first training data set, and inputting the first training sample into the vector conversion model to obtain a first semantic vector corresponding to the first training sample; Inputting the first semantic vector into a text restoration model set corresponding to the vector conversion model to obtain a first prediction sample; Based on a first loss value between the first prediction sample and the first training sample, parameters of the vector conversion model are adjusted, wherein parameters are shared between the text restoration model and the vector conversion model.
8. The device according to claim 7, wherein When adjusting the parameters of the vector conversion model based on the first loss value between the first prediction sample and the first training sample, the training unit is specifically configured to: Determine a gradient of a parameter on the vector conversion model based on the first loss value; Parameters of the vector conversion model are adjusted according to the direction of the gradient.
9. The device according to any one of claims 6 to 8, characterized in that Before obtaining the style conversion information of the text to be converted and the target text in response to the text style conversion request, the obtaining unit is further configured to: In response to an input operation, obtaining input information to be answered and the target text style conversion information; Searching for a response text corresponding to the information to be answered in a designated storage location, and using the response text as the text to be converted; After obtaining the target text style text, the style conversion unit is further used to: Present the target text style text.
10. The device according to claim 9, wherein When presenting the target text style text, the style conversion unit is specifically used to: Announce the target text style text by voice; or The target text style text is presented through a human-computer interaction interface.
11. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor is enabled to perform the steps of any one of the methods of claims 1 to 5.
12. A computer-readable storage medium, characterized in that The method comprises a computer program. When the computer program is run on an electronic device, the computer program is used to enable the electronic device to execute the steps of any one of the methods of claims 1 to 5.
Citation Information
Patent Citations
Controllable style-based text transformation
CN111797597A