Model training method and device for random text generation, equipment and medium

By extending the Denoising Flow (DFlow) model to text generation tasks, and using a causal Transformer structure and fully parallel loss function for training, the illusion problem of autoregressive models is solved, improving the efficiency and accuracy of text generation.

CN119204214BActive Publication Date: 2026-07-21PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
PING AN TECH (SHENZHEN) CO LTD
Filing Date
2024-09-05
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Autoregressive models suffer from the illusion problem caused by error accumulation in text generation, and their inference speed is slow. While diffusion models improve the illusion problem, their inference speed is also relatively slow.

Method used

The Denoising Flow (DFlow) model is extended to text generation tasks. It employs the Auxiliary Flow module, Primary Flow module, and Decoder module, utilizes a causal Transformer structure for latent variable computation and text reconstruction, constructs a fully parallel loss function for training, and combines maximum likelihood estimation and cross-entropy loss function to optimize model parameters.

Benefits of technology

It solves the problem of error accumulation leading to illusion in autoregressive models, improves inference speed and efficiency, maintains the advantages of DFlow, and achieves efficient text generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119204214B_ABST
    Figure CN119204214B_ABST
Patent Text Reader

Abstract

The application discloses a model training method and device for random text generation, an equipment and a medium. For an Auxiliary Flow module of a DFlow-T model, training text data input is all visible, and generated hidden variables are all visible for both a Primary Flow module and a Decoder module, so that the model is all parallel processing for input in the operation process, which can improve inference efficiency, eliminate the possibility of error accumulation, and improve the global relevance and integrity of the inference result. The DFlow is extended to a text generation task, the advantages of the DFlow are retained, and the technical problem of "hallucination" caused by error accumulation of an autoregressive model is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of text generation technology, and in particular to a model training method, apparatus, device and medium for random text generation. Background Technology

[0002] In recent years, generative models have shone brightly in various fields. Existing generative frameworks mainly include: Generative Adversarial Networks (GANs) and likelihood-based models, such as Auto-Regressive models (ARs), Normalizing Flow (NFs), and Diffusion models.

[0003] In the field of text generation, the most popular model currently is the GPT model, which is essentially an autoregressive model. However, due to its structural characteristics, autoregressive models face a difficult problem to solve: the "illusion" caused by error accumulation. During inference, the output of an autoregressive model at each step depends on all previous input content. Therefore, if the output of the current step is slightly off, the next step will be generated based on the biased (incorrect) content, making it easy to understand that the probability of the output being incorrect is higher. This leads to the problem of error accumulation. In text generation, this can easily cause the model's output to describe information that does not conform to the facts, which is the so-called "illusion" problem. For autoregressive models, this problem is particularly determined by their structural characteristics and is inherently difficult to solve. In addition, autoregressive models also have the problem of slow inference speed.

[0004] Diffusion models have recently achieved promising results in text generation. Their non-autoregressive structure improves the "illusion problem," significantly enhancing generation quality. However, the diffusion process also leads to slow inference speeds.

[0005] Previous work proposed a novel generative framework: Denoising Flow (DFlow). This architecture cleverly combines a flow model and a denoising autoencoder (DAE), and has already achieved excellent results on audio generation tasks. Compared to other generative frameworks, DFlow has several advantages:

[0006] 1. Efficient Training and Inference: Compared to autoregressive or diffusion models, DFlow's training and inference are both fully parallel, resulting in high computational efficiency. Furthermore, DFlow's low computational cost during training and inference allows for a larger batch size during training, leading to more stable training and faster model convergence. Additionally, the low computational cost means DFlow uses less memory during inference, making it more efficient.

[0007] 2. Due to the integration of DAE, DFlow's generation effect is not only significantly optimized compared to the traditional Flow model, but also greatly improved in terms of model robustness.

[0008] 3. DFlow inherits the characteristic of traditional Flow models having explicit and controllable latent variables, making it easier to connect to various downstream tasks.

[0009] 4. Simple structure and stable training: Compared with the GAN series models, which are prone to mode collapse, the DFlow model is not only simple in structure and highly interpretable, but also very stable in training, making it easy to expand into a large model and making DFlow a very promising generative framework.

[0010] Building upon DFlow, how to extend DFlow to text generation tasks to address the "illusion" caused by error accumulation in autoregressive models, while retaining the advantages of DFlow, is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0011] This application provides a model training method, apparatus, device, and medium for random text generation, which extends DFlow to text generation tasks, retains the advantages of DFlow, and solves the technical problem of "illusion" caused by error accumulation in autoregressive models.

[0012] In view of this, the first aspect of this application provides a model training method for random text generation, the method comprising:

[0013] Step S1: Obtain training text data x;

[0014] Step S2: Input the training text data x into the Auxiliary Flow module of the DFlow-T model to obtain the latent variables. The Auxiliary Flow module uses a causal Transformer structure as the basic structure for implementing Flow;

[0015] Step S3: The Primary Flow module of the DFlow-T model processes the latent variable z.l z is obtained by forward calculation p =g(z) l ), and make z p The distribution conforms to a standard Gaussian distribution. The Primary Flow module uses the Causal Transformer structure as the basic structure for implementing Flow;

[0016] Step S4: The Decoder module of the DFlow-T model determines the latent variable z. l The training text data x is reconstructed to obtain the training reconstructed text data. The Decoder module uses a multi-layered CausalTransformer structure as the basic structure for implementing Flow;

[0017] Step S5: Construct the loss function of the DFlow-T model. The loss function includes an input loss function based on maximum likelihood estimation and the training text data x calculated based on cross entropy and the training reconstructed text data. Reconstruction loss function between;

[0018] Step S6: Update the parameters of the AuxiliaryFlow module, the PrimaryFlow module, and the Decoder module of the DFlow-T model based on the loss function until the loss function converges, and obtain the trained DFlow-T model.

[0019] Optionally, the AuxiliaryFlow module and the PrimaryFlow module are reversible flow networks;

[0020] The AuxiliaryFlow module and the PrimaryFlow module constitute the Flow structure.

[0021] Optionally, the AuxiliaryFlow module and the Decoder module constitute the AE structure.

[0022] Optionally, the input loss function based on maximizing likelihood estimation is specifically:

[0023] log p(x)=log(p(z p )+log det|J(f)|+log det|J(g)|

[0024] Where p(x) is the probability density function, representing the likelihood of x occurring, and z p The distribution conforms to a standard Gaussian distribution. det|J(f)| and det|J(g)| denote the Jacobian matrix determinants of f and g, respectively.

[0025] Optionally, the training text data x calculated based on cross entropy and the training reconstructed text data The reconstruction loss function between them is as follows:

[0026] Optionally, step S1 specifically includes:

[0027] The training text content is obtained, preprocessed, and then converted into vector-type training text data x.

[0028] A second aspect of this application provides a method for generating random text, using a DFlow-T model trained using the model training method for random text generation provided in the first aspect of this application, the method comprising:

[0029] A point z is randomly sampled from a standard Gaussian distribution. p As input, it is fed into the PrimaryFlow module of the DFlow-T model;

[0030] The PrimaryFlow module of the DFlow-T model applies to the point z. p Perform the inverse operation to obtain the hidden variable z. l =g -1 (z p );

[0031] The Decoder module of the DFlow-T model processes the latent variable z. l Perform text generation to generate random text data.

[0032] A third aspect of this application provides a model training apparatus for random text generation, the apparatus comprising:

[0033] The acquisition unit is used to acquire training text data x;

[0034] The first processing unit is used to input the training text data x into the Auxiliary Flow module of the DFlow-T model to obtain the latent variables. The Auxiliary Flow module uses a causal Transformer structure as the basic structure for implementing Flow;

[0035] The second processing unit is used by the PrimaryFlow module of the DFlow-T model to process the latent variable z.l z is obtained by forward calculation p =g(z) l ), and make z p The distribution conforms to a standard Gaussian distribution. The Primary Flow module uses the Causal Transformer structure as the basic structure for implementing Flow;

[0036] The third processing unit, used by the Decoder module of the DFlow-T model, processes the latent variable z. l The training text data x is reconstructed to obtain the training reconstructed text data. The Decoder module uses a multi-layered CausalTransformer structure as the basic structure for implementing Flow;

[0037] The loss function construction unit is used to construct the loss function of the DFlow-T model. The loss function includes an input loss function based on maximum likelihood estimation and the training text data x calculated based on cross entropy and the training reconstructed text data. Reconstruction loss function between;

[0038] The parameter update unit is used to update the parameters of the AuxiliaryFlow module, the PrimaryFlow module, and the Decoder module of the DFlow-T model based on the loss function until the loss function converges to obtain the trained DFlow-T model.

[0039] Optionally, the Auxiliary Flow module and the Primary Flow module are reversible flow networks;

[0040] The AuxiliaryFlow module and the PrimaryFlow module constitute the Flow structure.

[0041] Optionally, the Auxiliary Flow module and the Decoder module constitute the AE structure.

[0042] Optionally, the input loss function based on maximizing likelihood estimation is specifically:

[0043] log p(x)=log(p(z p )+log det|J(f)|+log det|J(g)|

[0044] Where p(x) is the probability density function, representing the likelihood of x occurring, and z pThe distribution conforms to a standard Gaussian distribution. det|J(f)| and det|J(g)| denote the Jacobian matrix determinants of f and g, respectively.

[0045] A fourth aspect of this application provides a model training device for random text generation, the device comprising a processor and a memory:

[0046] The memory is used to store program code and transmit the program code to the processor;

[0047] The processor is configured to execute, according to instructions in the program code, the steps of the method for training a model for random text generation as described in the first aspect above.

[0048] A fifth aspect of this application provides a computer-readable storage medium for storing program code for performing the method described in the first aspect above.

[0049] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:

[0050] This application provides a model training method, apparatus, device, and medium for random text generation. For the Auxiliary Flow module of the DFlow-T model, the input training text data is fully visible, and the generated latent variables are fully visible as both the Primary Flow module and the Decoder module. This allows the model to process the input in full parallel during the computation process, which can improve inference efficiency and eliminate the possibility of error accumulation. The inference results have better global correlation and completeness, thus extending DFlow to text generation tasks, retaining the advantages of DFlow, and solving the technical problem of "illusion" caused by error accumulation in autoregressive models. Attached Figure Description

[0051] Figure 1 This is a network architecture diagram of the DFlow-T model;

[0052] Figure 2 This is a flowchart of a model training method for random text generation in an embodiment of this application;

[0053] Figure 3 This is a schematic diagram of the structure of the model training device for random text generation in the embodiments of this application;

[0054] Figure 4 This is a schematic diagram of the structure of a model training device for random text generation in an embodiment of this application. Detailed Implementation

[0055] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.

[0056] This application designs a model training method, apparatus, device, and medium for random text generation, which extends DFlow to text generation tasks, retains the advantages of DFlow, and solves the technical problem of "illusion" caused by error accumulation in autoregressive models.

[0057] This application provides a DFlow-T model, such as Figure 1 As shown, Figure 1 The diagram shows the network architecture of the DFlow-T model, where solid lines represent the training process and dashed lines represent the inference process. The DFlow-T model includes:

[0058] Auxiliary Flow module 101, Primary Flow module 102, and Decoder module 103;

[0059] Among them, the AuxiliaryFlow module 101 adopts a causal Transformer structure as the basic structure for implementing Flow, the Primary Flow module 102 adopts a CausalTransformer structure as the basic structure for implementing Flow, and the Decoder module 103 adopts a multi-layered Causal Transformer structure as the basic structure for implementing Flow.

[0060] It should be noted that, in order to extend the powerful structure of DFlow to the field of NLP and apply it to the task of text slice generation, as follows... Figure 1 As shown, the DFlow-T model maintains the original three-module structure in its overall structure: AuxiliaryFlow f, PrimaryFlow g, and Decoder m.

[0061] For each module, we have made specific structural optimizations and improvements. The following are the details of the improvements and the design principles:

[0062] The AuxiliaryFlow module 101, whose operation is represented by f, is a non-volume-preserving flow. Compared to volume-preserving flows, non-volume-preserving flows are more expressive and require fewer network layers. To adapt to text generation tasks, the AuxiliaryFlow module 101 uses a causal Transformer structure as the basic structure for implementing the flow. The core of the Transformer structure lies in its self-attention mechanism, which has a very strong content capture capability. Based on the causal Transformer structure, when calculating self-attention for a text sequence, the current text is only related to the previous text and not to the subsequent text. This design is consistent with the logic of human language. At the same time, for the AuxiliaryFlow module 101, during training, all the input text data is visible. Therefore, when operating on each character, the causal Transformer structure generates latent variables based on all known inputs, avoiding the error accumulation that easily occurs in the character-by-character inference process of autoregressive models.

[0063] Primary Flow module 102, its operation process is represented as g: This module is a volume invariant flow, the purpose of which is to preserve the implicit variable z. l Regularization is applied to ensure the model's training stability. However, its internal structure has been changed to a Causal Transformer structure to guarantee the model's ability to learn and generate content.

[0064] The Decoder module 103's operation process is represented as m: In text generation tasks, text features are discrete features. Therefore, unlike image or audio generation, text generation does not need to consider the problem of "detail generation." Thus, the Decoder module, through the use of a multi-layered CausalTransformer structure, endows the model with the ability to generate content.

[0065] For easier understanding, please refer to Figure 2 , Figure 2 This is a flowchart of the model training method for random text generation in the embodiments of this application, such as... Figure 2 As shown, specifically:

[0066] Step S1: Obtain training text data x;

[0067] It should be noted that the training text data x is usually preprocessed and is not directly composed of a piece of text, but rather the text is converted into vector-type input data. Specifically:

[0068] Collect text data for training the model;

[0069] The collected text is cleaned, including noise removal and text standardization.

[0070] Convert the text into numerical data that the model can process, which may include word embeddings or sentence embeddings.

[0071] Step S2: Input the training text data x into the Auxiliary Flow module of the DFlow-T model to obtain the latent variable z. l = f(x), the Auxiliary Flow module uses a causal Transformer structure as the basic structure for implementing Flow;

[0072] It should be noted that the purpose of the Auxiliary Flow module is to convert input vector data into latent variables. Its computation process is related to its network structure and parameters, and the corresponding parameters will be optimized according to the loss function during training. f() specifically represents the neural network computation process of Auxiliary Flow.

[0073] Step S3: The Primary Flow module of the DFlow-T model processes the latent variable z. l z is obtained by forward calculation p =g(z) l ), and make z p The distribution conforms to a standard Gaussian distribution. The Primary Flow module uses the CausalTransformer structure as the basic structure for implementing Flow;

[0074] It should be noted that during training, the latent variables output by the AuxiliaryFlow module are used to perform forward computation of z using the Primary Flow module. p =g(z) l The purpose of training is to make z p The distribution conforms to a standard Gaussian distribution. This allows for the random sampling of a point that conforms to a standard Gaussian distribution during the inference phase, which can then be used as input for random text generation. g() specifically represents the neural network computation process of Primary Flow.

[0075] Step S4: The Decoder module of the DFlow-T model calculates the latent variable z. l Reconstruct the training text data x to obtain the training reconstructed text data. The Decoder module uses a multi-layered Causal Transformer structure as the basic structure for implementing Flow;

[0076] It should be noted that during training, the Decoder module reconstructs text based on the latent variables output by the AuxiliaryFlow module. Its goal is to reconstruct text data that increasingly approximates the original input training text data, with optimal consistency being the best. m() specifically represents the neural network computation process of the Decoder.

[0077] Step S5: Construct the loss function of the DFlow-T model. The loss function includes the input loss function based on maximum likelihood estimation and the training text data x calculated based on cross entropy and the training reconstructed text data. Reconstruction loss function between;

[0078] Step S6: Update the parameters of the Auxiliary Flow module, Primary Flow module, and Decoder module of the DFlow-T model based on the loss function until the loss function converges, and obtain the trained DFlow-T model.

[0079] It should be noted that the model parameters are iteratively updated based on the loss function. When the loss function reaches a low value or stabilizes, the updates stop, resulting in the trained and parameter-optimized DFlow-T model.

[0080] Furthermore, the Auxiliary Flow module and the Primary Flow module are reversible flow networks;

[0081] The Auxiliary Flow module and the Primary Flow module together constitute the Flow structure.

[0082] Furthermore, the Auxiliary Flow module and the Decoder module constitute the AE structure.

[0083] It should be noted that the AE structure consists of AuxiliaryFlow and Decoder.

[0084] It's worth noting that, unlike the original DFLow, this paper replaces the original DAE structure with an AE structure to adapt to text generation tasks. AE structure stands for auto-encoder.

[0085] In image or audio generation tasks, the model's input and output are both continuous signals, so the model needs to simultaneously achieve both content generation and detail generation capabilities. Denoising autoencoders effectively ensure detail generation capabilities while also improving the model's robustness.

[0086] However, in text generation tasks, the model's input is a discrete signal, and the generated signal is also a discrete signal. Therefore, the model needs to focus on content generation without considering the issue of detail generation. In this case, we do not need to perform "noise-adding processing" on the model's input similar to that of the original text.

[0087] On the other hand, some text generation frameworks (such as BERT) endow their models with the ability to learn content by adding masks (adding masks can also be understood as a way of adding noise). However, these two types of models lack the ability to generate instructions, that is, they lack the ability to generate subsequent content based on prompts, which greatly limits the scope of their application. In contrast, autoregressive models like GPT, with their instruction-based generation capabilities, allow for a wide range of applications. The essence of autoregressive models is to utilize a causal network structure. During training, since the inputs at each time step are known (the entire input sequence is visible), parallel computation is possible. However, during inference, the computation at the next time step depends on the output of the previous time step, thus requiring an autoregressive approach. Furthermore, the causal structure can also be understood as a noise-adding scheme, that is, masking the content after the current time step.

[0088] Furthermore, the input loss function based on maximum likelihood estimation is specifically as follows:

[0089] log p(x)=log(p(z p )+log det|J(f)|+log det|J(g)|

[0090] Where p(x) is the probability density function, representing the likelihood of x occurring, and z p The distribution conforms to a standard Gaussian distribution. det|J(f)| and det|J(g)| denote the Jacobian matrix determinants of f and g, respectively.

[0091] It should be noted that the log-likelihood of the input x during training can be calculated using the following formula:

[0092] log p(x)=log(p(z p )+log det|J(f)|+log det|J(g)|

[0093] in det|J(f)| and det|J(g)| denote the Jacobian matrix determinants of f and g, respectively.

[0094] During training, we will use the maximum likelihood estimation as the loss function for this part. mle .

[0095] The DFlow-T model in this application utilizes a causal + self-attention network structure, endowing the model with powerful content learning and generation capabilities, as well as instruction-based generation capabilities. Furthermore, thanks to the ingenious structural design of DFlow-T, the entire network is fully parallel during both training and inference phases. During training, x is fully visible, therefore z... l The computation is completely parallel, and therefore The computation is also fully parallel. We also trained another network, PrimaryFlow, for parallel inference of z. l Specifically, during inference, we first randomly sample a z from a standard Gaussian distribution. p In calculating z using PrimaryFlow l time z p It is fully visible, therefore z l The computation is parallel, thus the entire inference process is parallel. This not only solves the problem of slow inference in the GPT model or diffusion model, but also addresses the fatal weakness of the GPT model, which is prone to error accumulation leading to "illusions".

[0096] This application also provides a method for generating random text, using a DFlow-T model trained by the model training method for random text generation provided in this application. The method includes:

[0097] A point z is randomly sampled from a standard Gaussian distribution. p As input, it is fed into the PrimaryFlow module of the DFlow-T model;

[0098] The Primary Flow module of the DFlow-T model for point z p Perform the inverse operation to obtain the hidden variable z. l =g -1 (z p );

[0099] The Decoder module of the DFlow-T model handles the latent variable z. l Perform text generation to generate random text data.

[0100] It should be noted that when random text generation is required, the DFlow-T model trained using the embodiments of this application can randomly sample a point z from a standard Gaussian distribution. p As input to the Primary Flow module, the latent variable z can be obtained through inverse operation. l The Decoder module, on the other hand, is based on the input's implicit variable z. l Reconstruct the text to generate corresponding random sampling points z. p Random text data

[0101] As a text generation method, random sampling can improve the variability of text generation.

[0102] Please see Figure 3 , Figure 3 This is a schematic diagram of the structure of the model training device for random text generation in the embodiments of this application, as shown below. Figure 3 As shown, specifically:

[0103] Acquisition unit 301 is used to acquire training text data x;

[0104] It should be noted that the training text data x is usually preprocessed and is not directly composed of a piece of text, but rather the text is converted into vector-type input data. Specifically:

[0105] Collect text data for training the model;

[0106] The collected text is cleaned, including noise removal and text standardization.

[0107] Convert the text into numerical data that the model can process, which may include word embeddings or sentence embeddings.

[0108] The first processing unit 302 is used to input the training text data x into the AuxiliaryFlow module of the DFlow-T model to obtain the latent variable z. l = f(x), the AuxiliaryFlow module uses a causal Transformer structure as the basic structure for implementing Flow;

[0109] It should be noted that the purpose of the Auxiliary Flow module is to convert the input vector data into latent variables. Its operation process is related to its network structure and parameters. During training, the corresponding parameters will be optimized according to the loss function.

[0110] The second processing unit 303 is used in the Primary Flow module of the DFlow-T model to process the latent variable z. lz is obtained by forward calculation p =g(z) l ), and make z p The distribution conforms to a standard Gaussian distribution. The PrimaryFlow module uses the CausalTransformer structure as the basic structure for implementing Flow;

[0111] It should be noted that during training, the latent variables output by the AuxiliaryFlow module are used to perform forward computation of z using the Primary Flow module. p =g(z) l The purpose of training is to make z p The distribution conforms to a standard Gaussian distribution. This allows for the random sampling of a point that conforms to a standard Gaussian distribution to serve as input for random text generation during the inference phase.

[0112] The third processing unit 304, used by the Decoder module of the DFlow-T model, determines the latent variable z based on the... l Reconstruct the training text data x to obtain the training reconstructed text data. The Decoder module uses a multi-layered CausalTransformer structure as the basic structure for implementing Flow;

[0113] It should be noted that during training, the Decoder module reconstructs text based on the latent variables output by the AuxiliaryFlow module. Its goal is to reconstruct text data that is as close as possible to the original input training text data, with the best result being that the reconstructed text data is consistent with the original input training text data.

[0114] Loss function building unit 305 is used to construct the loss function of the DFlow-T model. The loss function includes an input loss function based on maximum likelihood estimation and training text data x and training reconstructed text data calculated based on cross entropy. Reconstruction loss function between;

[0115] The parameter update unit 306 is used to update the parameters of the AuxiliaryFlow module, PrimaryFlow module and Decoder module of the DFlow-T model based on the loss function until the loss function converges to obtain the trained DFlow-T model.

[0116] It should be noted that the model parameters are iteratively updated based on the loss function. When the loss function reaches a low value or stabilizes, the updates stop, resulting in the trained and parameter-optimized DFlow-T model.

[0117] Furthermore, the Auxiliary Flow module and the Primary Flow module are reversible flow networks;

[0118] The AuxiliaryFlow module and the PrimaryFlow module together form the Flow structure.

[0119] Furthermore, the AuxiliaryFlow module and the Decoder module constitute the AE structure.

[0120] It should be noted that the AE structure consists of AuxiliaryFlow and Decoder.

[0121] It is worth mentioning that, unlike the original DFLow, this paper replaces the original DAE structure with an AE structure in order to adapt to the text generation task.

[0122] In image or audio generation tasks, the model's input and output are both continuous signals, so the model needs to simultaneously achieve both content generation and detail generation capabilities. Denoising autoencoders effectively ensure detail generation capabilities while also improving the model's robustness.

[0123] However, in text generation tasks, the model's input is a discrete signal, and the generated signal is also a discrete signal. Therefore, the model needs to focus on content generation without considering the issue of detail generation. In this case, we do not need to perform "noise-adding processing" on the model's input similar to that of the original text.

[0124] On the other hand, some text generation frameworks (such as BERT) endow their models with the ability to learn content by adding masks (adding masks can also be understood as a way of adding noise). However, these two types of models lack the ability to generate instructions, that is, they lack the ability to generate subsequent content based on prompts, which greatly limits the scope of their application. In contrast, autoregressive models like GPT, with their instruction-based generation capabilities, allow for a wide range of applications. The essence of autoregressive models is to utilize a causal network structure. During training, since the inputs at each time step are known (the entire input sequence is visible), parallel computation is possible. However, during inference, the computation at the next time step depends on the output of the previous time step, thus requiring an autoregressive approach. Furthermore, the causal structure can also be understood as a noise-adding scheme, that is, masking the content after the current time step.

[0125] Furthermore, the input loss function based on maximum likelihood estimation is specifically as follows:

[0126] log p(x)=log(p(z p)+log det|J(f)|+log det|J(g)|

[0127] Where p(x) is the probability density function, representing the likelihood of x occurring, and z p The distribution conforms to a standard Gaussian distribution. det|J(f)| and det|J(g)| denote the Jacobian matrix determinants of f and g, respectively.

[0128] It should be noted that the log-likelihood of the input x during training can be calculated using the following formula:

[0129] log p(x)=log(p(z p )+log det|J(f)|+log det|J(g)|

[0130] Where p(x) is the probability density function, representing the likelihood of x occurring, and z p The distribution conforms to a standard Gaussian distribution. det|J(f)| and det|J(g)| denote the Jacobian matrix determinants of f and g, respectively.

[0131] During training, we will use the maximum likelihood estimation as the loss function for this part. mle .

[0132] The DFlow-T model in this application utilizes a causal + self-attention network structure, endowing the model with powerful content learning and generation capabilities, as well as instruction-based generation capabilities. Furthermore, thanks to the ingenious structural design of DFlow-T, the entire network is fully parallel during both training and inference phases. During training, x is fully visible, therefore z... l The computation is completely parallel, and therefore The computation is also fully parallel. We also trained another network, PrimaryFlow, for parallel inference of z. l Specifically, during inference, we first randomly sample a z from a standard Gaussian distribution. p In calculating z using PrimaryFlow l time z p It is fully visible, therefore z l The computation is parallel, thus the entire inference process is parallel. This not only solves the problem of slow inference in the GPT model or diffusion model, but also addresses the fatal weakness of the GPT model, which is prone to error accumulation leading to "illusions".

[0133] This application also provides another model training device for random text generation, such as... Figure 4 As shown, for ease of explanation, only the parts related to the embodiments of this application are shown. For specific technical details not disclosed, please refer to the method section of the embodiments of this application. The terminal can be any terminal device including mobile phones, tablets, personal digital assistants (PDAs), point-of-sales terminals (POS), in-vehicle computers, etc. Taking a mobile phone as an example:

[0134] Figure 4 This is a block diagram illustrating a portion of the structure of a mobile phone related to the terminal provided in the embodiments of this application. (Reference) Figure 4 The mobile phone includes: a radio frequency (RF) circuit 1010, a memory 1020, an input unit 1030, a display unit 1040, a sensor 1050, an audio circuit 1060, a wireless fidelity (WiFi) module 1070, a processor 1080, and a power supply 1090, etc. Those skilled in the art will understand that... Figure 4 The mobile phone structure shown does not constitute a limitation on the mobile phone and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0135] The following is combined Figure 4 A detailed introduction to each component of a mobile phone:

[0136] The RF circuit 1010 can be used for receiving and transmitting signals during information transmission or calls. Specifically, it receives downlink information from the base station and processes it with the processor 1080; additionally, it transmits uplink data to the base station. Typically, the RF circuit 1010 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier (LNA), a duplexer, etc. Furthermore, the RF circuit 1010 can also communicate wirelessly with networks and other devices. The aforementioned wireless communications may use any communication standard or protocol, including but not limited to Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, and Short Messaging Service (SMS).

[0137] The memory 1020 can be used to store software programs and modules. The processor 1080 executes various mobile phone functions and data processing by running the software programs and modules stored in the memory 1020. The memory 1020 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory 1020 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0138] The input unit 1030 can be used to receive input numerical or character information, and to generate key signal inputs related to user settings and function control of the mobile phone. Specifically, the input unit 1030 may include a touch panel 1031 and other input devices 1032. The touch panel 1031, also known as a touch screen, can collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel 1031), and drive the corresponding connection devices according to a pre-set program. Optionally, the touch panel 1031 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 1080, and can also receive and execute commands sent by the processor 1080. In addition, the touch panel 1031 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch panel 1031, the input unit 1030 may also include other input devices 1032. Specifically, other input devices 1032 may include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.

[0139] The display unit 1040 can be used to display information input by the user or information provided to the user, as well as various menus of the mobile phone. The display unit 1040 may include a display panel 1041, which may optionally be configured as a Liquid Crystal Display (LCD), Organic Light-Emitting Diode (OLED), or similar display panel 1041. Further, a touch panel 1031 may cover the display panel 1041. When the touch panel 1031 detects a touch operation on or near it, it transmits the information to the processor 1080 to determine the type of touch event. Subsequently, the processor 1080 provides corresponding visual output on the display panel 1041 according to the type of touch event. Although in Figure 4 In this embodiment, the touch panel 1031 and the display panel 1041 are two separate components to realize the input and output functions of the mobile phone. However, in some embodiments, the touch panel 1031 and the display panel 1041 can be integrated to realize the input and output functions of the mobile phone.

[0140] The mobile phone may also include at least one sensor 1050, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 1041 according to the ambient light level, and the proximity sensor can turn off the display panel 1041 and / or the backlight when the phone is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity and can be used for applications that recognize the phone's posture (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition-related functions (such as pedometer, taps), etc. Other sensors that may be configured in the mobile phone, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, will not be described in detail here.

[0141] The audio circuit 1060, speaker 1061, and microphone 1062 provide an audio interface between the user and the mobile phone. The audio circuit 1060 converts the received audio data into electrical signals and transmits them to the speaker 1061, where the speaker 1061 converts them into sound signals for output. On the other hand, the microphone 1062 converts the collected sound signals into electrical signals, which are then received by the audio circuit 1060, converted into audio data, and then processed by the processor 1080 before being transmitted via the RF circuit 1010 to, for example, another mobile phone, or the audio data can be output to the memory 1020 for further processing.

[0142] WiFi is a short-range wireless transmission technology. Through the WiFi module 1070, mobile phones can help users send and receive emails, browse web pages, and access streaming media, providing users with wireless broadband internet access. Although Figure 4 The WiFi module 1070 is shown, but it is understood that it is not an essential component of a mobile phone and can be omitted as needed without changing the essence of the invention.

[0143] The processor 1080 is the control center of the mobile phone, connecting various parts of the phone through various interfaces and lines. It executes software programs and / or modules stored in the memory 1020 and calls data stored in the memory 1020 to perform various functions and process data, thereby providing overall monitoring of the phone. Optionally, the processor 1080 may include one or more processing units; preferably, the processor 1080 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 1080.

[0144] The mobile phone also includes a power supply 1090 (such as a battery) that supplies power to various components. Preferably, the power supply can be logically connected to the processor 1080 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system.

[0145] Although not shown, mobile phones may also include a camera, Bluetooth module, etc., which will not be described in detail here.

[0146] In this embodiment of the application, the processor 1080 included in the terminal also has the following functions:

[0147] Step S1: Obtain training text data x;

[0148] It should be noted that the training text data x is usually preprocessed and is not directly composed of a piece of text, but rather the text is converted into vector-type input data. Specifically:

[0149] Collect text data for training the model;

[0150] The collected text is cleaned, including noise removal and text standardization.

[0151] Convert the text into numerical data that the model can process, which may include word embeddings or sentence embeddings.

[0152] Step S2: Input the training text data x into the Auxiliary Flow module of the DFlow-T model to obtain the latent variable z. l = f(x), the Auxiliary Flow module uses a causal Transformer structure as the basic structure for implementing Flow;

[0153] It should be noted that the purpose of the Auxiliary Flow module is to convert the input vector data into latent variables. Its operation process is related to its network structure and parameters. During training, the corresponding parameters will be optimized according to the loss function.

[0154] Step S3: The Primary Flow module of the DFlow-T model processes the latent variable z. l z is obtained by forward calculation p =g(z) l ), and make z p The distribution conforms to a standard Gaussian distribution. The Primary Flow module uses the CausalTransformer structure as the basic structure for implementing Flow;

[0155] It should be noted that during training, the latent variables output by the AuxiliaryFlow module are used to perform forward computation of z using the Primary Flow module. p =g(z) l The purpose of training is to make z p The distribution conforms to a standard Gaussian distribution. This allows for the random sampling of a point that conforms to a standard Gaussian distribution to serve as input for random text generation during the inference phase.

[0156] Step S4: The Decoder module of the DFlow-T model calculates the latent variable z. l Reconstruct the training text data x to obtain the training reconstructed text data. The Decoder module uses a multi-layered Causal Transformer structure as the basic structure for implementing Flow;

[0157] It should be noted that during training, the Decoder module reconstructs text based on the latent variables output by the AuxiliaryFlow module. Its goal is to reconstruct text data that is as close as possible to the original input training text data, with the best result being that the reconstructed text data is consistent with the original input training text data.

[0158] Step S5: Construct the loss function of the DFlow-T model. The loss function includes the input loss function based on maximum likelihood estimation and the training text data x calculated based on cross entropy and the training reconstructed text data. Reconstruction loss function between;

[0159] Step S6: Update the parameters of the Auxiliary Flow module, Primary Flow module, and Decoder module of the DFlow-T model based on the loss function until the loss function converges, and obtain the trained DFlow-T model.

[0160] It should be noted that the model parameters are iteratively updated based on the loss function. When the loss function reaches a low value or stabilizes, the updates stop, resulting in the trained and parameter-optimized DFlow-T model.

[0161] Furthermore, the Auxiliary Flow module and the Primary Flow module are reversible flow networks;

[0162] The Auxiliary Flow module and the Primary Flow module together constitute the Flow structure.

[0163] Furthermore, the Auxiliary Flow module and the Decoder module constitute the AE structure.

[0164] It should be noted that the AE structure consists of AuxiliaryFlow and Decoder.

[0165] It is worth mentioning that, unlike the original DFLow, this paper replaces the original DAE structure with an AE structure in order to adapt to the text generation task.

[0166] In image or audio generation tasks, the model's input and output are both continuous signals, so the model needs to simultaneously achieve both content generation and detail generation capabilities. Denoising autoencoders effectively ensure detail generation capabilities while also improving the model's robustness.

[0167] However, in text generation tasks, the model's input is a discrete signal, and the generated signal is also a discrete signal. Therefore, the model needs to focus on content generation without considering the issue of detail generation. In this case, we do not need to perform "noise-adding processing" on the model's input similar to that of the original text.

[0168] On the other hand, some text generation frameworks (such as BERT) endow their models with the ability to learn content by adding masks (adding masks can also be understood as a way of adding noise). However, these two types of models lack the ability to generate instructions, that is, they lack the ability to generate subsequent content based on prompts, which greatly limits the scope of their application. In contrast, autoregressive models like GPT, with their instruction-based generation capabilities, allow for a wide range of applications. The essence of autoregressive models is to utilize a causal network structure. During training, since the inputs at each time step are known (the entire input sequence is visible), parallel computation is possible. However, during inference, the computation at the next time step depends on the output of the previous time step, thus requiring an autoregressive approach. Furthermore, the causal structure can also be understood as a noise-adding scheme, that is, masking the content after the current time step.

[0169] Furthermore, the input loss function based on maximum likelihood estimation is specifically as follows:

[0170] log p(x)=log(p(z p )+log det|J(f)|+log det|J(g)|

[0171] Where p(x) is the probability density function, representing the likelihood of x occurring, and z p The distribution conforms to a standard Gaussian distribution. det|J(f)| and det|J(g)| denote the Jacobian matrix determinants of f and g, respectively.

[0172] This application also provides a computer-readable storage medium for storing program code that executes any one of the implementation methods for a model training method for random text generation described in the foregoing embodiments.

[0173] This application provides a model training method, apparatus, device, and medium for random text generation. For the AuxiliaryFlow module of the DFlow-T model, the input training text data is fully visible, and the generated latent variables are fully visible as both the Primary Flow module and the Decoder module. This allows the model to process the input in full parallel during the computation process, which can improve inference efficiency and eliminate the possibility of error accumulation. The inference results have better global correlation and completeness, thus extending DFlow to text generation tasks, retaining the advantages of DFlow, and solving the technical problem of "illusion" caused by error accumulation in autoregressive models.

[0174] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0175] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0176] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0177] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.

[0178] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0179] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0180] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.

[0181] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A model training method for random text generation, characterized in that, include: Step S1: Obtain training text data x; Step S2: Input the training text data x into the Auxiliary Flow module of the DFlow-T model to obtain the latent variable z. l = f(x), the Auxiliary Flow module adopts a causal Transformer structure as the basic structure for implementing Flow; Step S3: The Primary Flow module of the DFlow-T model processes the latent variable z. l z is obtained by forward calculation p =g(z) l ), and make z p The distribution conforms to a standard Gaussian distribution. The Primary Flow module uses the CausalTransformer structure as the basic structure for implementing Flow; Step S4: The Decoder module of the DFlow-T model determines the latent variable z. l The training text data x is reconstructed to obtain the training reconstructed text data. The Decoder module uses a multi-layered CausalTransformer structure as the basic structure for implementing Flow; Step S5: Construct the loss function of the DFlow-T model. The loss function includes an input loss function based on maximum likelihood estimation and the training text data x calculated based on cross entropy and the training reconstructed text data. Reconstruction loss function between; Step S6: Update the parameters of the Auxiliary Flow module, the Primary Flow module, and the Decoder module of the DFlow-T model based on the loss function until the loss function converges, and obtain the trained DFlow-T model.

2. The model training method for random text generation according to claim 1, characterized in that, The Auxiliary Flow module and the Primary Flow module are reversible flow networks; The Auxiliary Flow module and the Primary Flow module constitute the Flow structure.

3. The model training method for random text generation according to claim 2, characterized in that, The Auxiliary Flow module and the Decoder module constitute the AE structure.

4. The model training method for random text generation according to claim 1, characterized in that, The input loss function based on maximum likelihood estimation is specifically as follows: logp(x)=log p(z p )+log it|J(f)|+log it|J(g)| Where p(x) is the probability density function, representing the likelihood of x occurring, and z p The distribution conforms to a standard Gaussian distribution. det|J(f)| and det|J(g)| denote the Jacobian matrix determinants of f and g, respectively.

5. The model training method for random text generation according to claim 1, characterized in that, The training text data x obtained based on cross entropy calculation and the training reconstructed text data The reconstruction loss function between them is as follows:

6. The model training method for random text generation according to claim 1, characterized in that, Step S1 specifically includes: The training text content is obtained, preprocessed, and then converted into vector-type training text data x.

7. A method for generating random text, characterized in that, The DFlow-T model trained using the model training method for random text generation according to any one of claims 1 to 6, wherein the random text generation method comprises: A point z is randomly sampled from a standard Gaussian distribution. p As input, it is fed into the PrimaryFlow module of the DFlow-T model; The Primary Flow module of the DFlow-T model applies to the point z. p Perform the inverse operation to obtain the hidden variable z. l =g -1 (z p ); The Decoder module of the DFlow-T model processes the latent variable z. l Perform text generation to generate random text data.

8. A model training device for random text generation, characterized in that, include: The acquisition unit is used to acquire training text data x; The first processing unit is used to input the training text data x into the AuxiliaryFlow module of the DFlow-T model to obtain the latent variables. The Auxiliary Flow module uses a causal Transformer structure as the basic structure for implementing Flow; The second processing unit is used by the Primary Flow module of the DFlow-T model to process the latent variable z. l z is obtained by forward calculation p =g(z) l ), and make z p The distribution conforms to a standard Gaussian distribution. The Primary Flow module uses the Causal Transformer structure as the basic structure for implementing Flow; The third processing unit, used by the Decoder module of the DFlow-T model, processes the latent variable z. l The training text data x is reconstructed to obtain the training reconstructed text data. The Decoder module uses a multi-layered Causal Transformer structure as the basic structure for implementing Flow; The loss function construction unit is used to construct the loss function of the DFlow-T model. The loss function includes an input loss function based on maximum likelihood estimation and the training text data x calculated based on cross entropy, along with the training reconstructed text data. Reconstruction loss function between; The parameter update unit is used to update the parameters of the Auxiliary Flow module, the Primary Flow module, and the Decoder module of the DFlow-T model based on the loss function until the loss function converges to obtain the trained DFlow-T model.

9. A model training device for random text generation, characterized in that, The device includes a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is configured to execute the model training method for random text generation as described in any one of claims 1-4 according to the instructions in the program code.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store program code for executing the model training method for random text generation according to any one of claims 1-4.