Model training method and device, model reasoning method and device and electronic equipment
By using multiple prediction head modules in the one-way autoregressive text generation model for multi-modal word prediction, the problem of efficiency and effectiveness of the one-way AR model in multi-modal input information processing is solved, and more efficient word prediction is achieved. Meta generation.
Patent Information
- Application Number
- CN202410852340.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-10-15
AI Technical Summary
Existing one-way autoregressive text generation models are inefficient and ineffective when generating multi-modal tokens, and cannot effectively handle the bidirectional data format of multi-modal input information.
Multiple prediction head modules of the unidirectional backbone model are used to predict fixed positions and random positions of latent space word segmentation, generate masked latent space word sequences, and combine uniform and random prediction positions to improve the efficiency and effect of word generation.
It improves the model training efficiency and accuracy of the one-way backbone model, and improves the word element prediction efficiency and generation effect of multi-modal input information.
Smart Images

Figure CN118780334A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a model training method, a model reasoning method, a device and an electronic device. Background Art
[0002] For artificial intelligence (AI) large models, the current mainstream AI large model is a unidirectional auto-regressive (AR) text generation model using a Transformer structure. This unidirectional AR text generation model is suitable for the task of gradually generating word units because it uses a unidirectional attention mechanism. However, since the unidirectional AR text generation model is mainly used in the field of text generation and only predicts the next word unit at each step, when multimodal input information such as videos or images needs to generate a large number of word units, the step-by-step word unit prediction will result in very low word unit prediction efficiency. In addition, since the unidirectional attention mechanism cannot process the bidirectional data format of multimodal input information, it will also affect the final word unit prediction generation effect. Summary of the invention
[0003] The present invention provides a model training method, a model reasoning method, a device and an electronic device, which are used to solve the defects of the existing unidirectional AR text generation model in that the efficiency is very low when gradually generating multimodal word unit results and the final word unit prediction generation effect is poor. Not only the word unit prediction efficiency of each step is improved, but also the word unit prediction in different ways in combination with different prediction heads can also improve the final word unit generation effect, thereby greatly improving the model training efficiency of the unidirectional backbone model and the accuracy of the model training results.
[0004] The present invention provides a model training method, comprising the following steps.
[0005] Using the first prediction head module of the unidirectional backbone model, the next word unit is predicted for the latent space word unit segment in the latent space word unit sequence of the multimodal input information to obtain a first word unit prediction result; Based on the latent space word-gram segmentation, using the second prediction head module of the unidirectional backbone model to perform fixed-position word-gram prediction and random-position word-gram prediction in the latent space word-gram sequence to obtain a second word-gram prediction result; Based on the first word-gram prediction result and the second word-gram prediction result, a masked latent space word-gram sequence corresponding to the multimodal input information is determined, and the masked latent space word-gram sequence is determined as a model training result.
[0006] According to a model training method provided by the present invention, based on the latent space word-gram segmentation, the second prediction head module of the unidirectional backbone model is used to perform fixed position word-gram prediction and random position word-gram prediction in the latent space word-gram sequence, including: In the case where the second prediction head module includes a plurality of first head modules for uniform prediction and a plurality of second head modules for random prediction,
[0007] Based on the latent space word-gram segmentation, determining the uniform prediction positions corresponding to each of the plurality of first head modules in the latent space word-gram sequence, and the random prediction positions corresponding to each of the plurality of second head modules in the latent space word-gram sequence; For each first head module, using the first head module to perform first fixed position word prediction on the latent space word segment, the first fixed position being the same as the uniform prediction position corresponding to the first head module; For each second head module, the second head module is used to perform second random position word prediction on the latent space word segment, and the second random position is the same as the random prediction position corresponding to the second head module and is different from each of the first positions to be predicted.
[0008] According to a model training method provided by the present invention, based on the latent space word-unit segmentation, determining the uniform prediction positions corresponding to each of the plurality of first head modules in the latent space word-unit sequence, and the random prediction positions corresponding to each of the plurality of second head modules in the latent space word-unit sequence, comprises: Determining the prediction position intervals between the plurality of first head modules based on a preset word unit training length and the number of latent space word units included in the latent space word unit sequence; Determining each of the uniform prediction positions based on the prediction position interval, the preset word unit training length and the latent space word unit segmentation; Within a random prediction range preset for the latent space word-unit sequence, each of the random prediction positions that is not repeated with each of the uniform prediction positions is determined based on the latent space word-unit segmentation.
[0009] According to a model training method provided by the present invention, determining the masked latent space word-gram sequence corresponding to the multimodal input information based on the first word-gram prediction result and the second word-gram prediction result includes: Determine the first word unit prediction right-shifted result and the second word unit prediction right-shifted result after both the first word unit prediction result and the second word unit prediction result are right-shifted by a preset number of bits; Based on the first word unit prediction right shift result and the second word unit prediction right shift result, determine the masked latent space word unit sequence that has the same number of latent space word units as and is aligned with the latent space word unit sequence.
[0010] According to a model training method provided by the present invention, the determining, based on the first word unit prediction right shift result and the second word unit prediction right shift result, the masked latent space word unit sequence having the same number of latent space word units as and aligned with the latent space word unit sequence comprises: In an initial fully masked sequence corresponding to the latent space word-gram sequence, determining masked positions and non-masked positions in the initial fully masked sequence based on the first word-gram prediction right shift result and the second word-gram prediction right shift result; Performing mask learning on the initial full-mask sequence using a preset random mask learning strategy; The masked latent space word unit sequence is determined based on the mask value corresponding to the mask position, the predicted word unit corresponding to the non-masked position and the mask learning result.
[0011] The present invention also provides a model reasoning method, which includes the following steps.
[0012] Determine the initial state of the demasking model, wherein the initial state is the masked latent space word sequence obtained by the aforementioned model training method; Using the demasking model to perform multi-step demasking reasoning on the initial state to obtain a completely mask-free target latent space output result; Determine a target multimodal output result corresponding to the target latent space output result, and determine the target multimodal output result as a model inference result.
[0013] The present invention also provides a model training device, comprising the following units.
[0014] The first training unit is used to use the first prediction head module of the unidirectional backbone model to perform next word prediction on the latent space word segment in the latent space word sequence of the multimodal input information to obtain a first word prediction result; based on the latent space word segment, use the second prediction head module of the unidirectional backbone model to perform fixed position word prediction and random position word prediction in the latent space word sequence to obtain a second word prediction result; A second training unit is used to determine a masked latent space word-gram sequence corresponding to the multimodal input information based on the first word-gram prediction result and the second word-gram prediction result, and determine the masked latent space word-gram sequence as a model training result
[0015] The present invention also provides a model reasoning device, comprising the following units.
[0016] A state determination unit, used to determine an initial state of the demasking model, wherein the initial state is a masked latent space word sequence obtained by the aforementioned model training method; A model inference unit is used to perform multi-step demasking inference on the initial state using the demasking model to obtain a completely unmasked target latent space output result; determine a target multimodal output result corresponding to the target latent space output result, and determine the target multimodal output result as a model inference result.
[0017] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the processor implements any one of the above-mentioned model training methods or model inference methods.
[0018] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it implements any of the model training methods or model reasoning methods described above.
[0019] The present invention provides a model training method, a model reasoning method, a device and an electronic device, wherein the model training method uses the first prediction head module of the unidirectional backbone model to predict the next word in the latent space word sequence of the multimodal input information, and based on the latent space word segmentation, uses the second prediction head module of the unidirectional backbone model to predict the fixed position word and the random position word in the latent space word sequence, so as to ensure that each step-by-step word prediction can remove as much mask as possible, which not only improves the efficiency of each step word prediction, but also combines different prediction heads to perform word prediction in different ways to improve the final word generation effect, thereby greatly improving the model training efficiency of the unidirectional backbone model and the accuracy of the model training results. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 It is one of the flow charts of the model training method provided by the present invention.
[0022] Figure 2A This is the second flow chart of the model training method provided by the present invention.
[0023] Figure 2B It is a schematic diagram of the position right shift process provided by an embodiment of the present invention.
[0024] Figure 3 It is one of the flow charts of the model reasoning method provided by the present invention.
[0025] Figure 4 This is the second flow chart of the model reasoning method provided by the present invention.
[0026] Figure 5 It is a flowchart of the overall model reasoning method provided by the present invention.
[0027] Figure 6 It is a structural schematic diagram of the model training device provided by the present invention.
[0028] Figure 7 It is a structural schematic diagram of the model reasoning device provided by the present invention.
[0029] Figure 8 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0031] In the embodiments of the present invention, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B may be singular or plural. In the textual description of the present invention, the character " / " generally indicates that the previous and next associated objects are in an "or" relationship. In addition, it should be noted that the serial numbers themselves, such as "first", "second", etc., used to distinguish the objects described in the present invention are only used to distinguish the objects described, and do not have any order or technical meaning.
[0032] The current mainstream AI models are the unidirectional autoregressive text generation model and the Mask Token Model (MTM) text understanding model. Both models use the Transformer structure and the main core is the attention mechanism used to associate information between tokens. Among them, the unidirectional AR text generation model uses a unidirectional attention mechanism, which can be understood as: previous tokens cannot see subsequent tokens and subsequent tokens can see previous tokens; therefore, the unidirectional AR text generation model is suitable for tasks that gradually generate tokens. The MTM text understanding model uses a bidirectional attention mechanism, which can be understood as: previous tokens and subsequent tokens can see each other, so the MTM text understanding model is suitable for language understanding tasks.
[0033] With the continuous development and progress of multimodal AI large models, the model capabilities have gradually expanded from understanding multimodal input information such as images and videos to generating multimodal information such as images and videos; at the same time, the structure of multimodal large models has gradually changed from traditional convolutional networks to the Transformer structure used by large language models, and the generation methods of multimodal information include using a unidirectional AR text generation model or an MTM text understanding model (since multimodal information similar to images is different from text sequences, the MTM text understanding model can use a bidirectional attention mechanism for word generation rather than just word understanding).
[0034] At present, relevant technologies will compress multimodal input information (such as images, videos, etc.) through a vector quantized variational autoencoder (VQ-VAE), convert it to a latent space, and then calculate the backbone model (one-way AR text generation model or MTM text understanding model).
[0035] Exemplarily, the one-way AR text generation model performs step-by-step autoregressive decoding (ie, next token prediction) based on initial tokens (eg, start symbol, text control information, or image control information, etc.) to achieve unconditional or conditional generation of multimodal information prediction results.
[0036] The MTM text understanding model predicts tokens at different positions through a step-by-step demasking operation. Initially, the positions of all tokens are masks, and then the model randomly selects mask positions according to a random strategy to predict multiple tokens, thereby gradually performing demasking reasoning.
[0037] The final multimodal information prediction results generated by the above two methods are usually processed by super-resolution through the VQ-VAE decoder and converted into images or videos in the original pixel space.
[0038] From this, we can understand that the one-way AR text generation model is mainly used in the field of text generation. Each step only predicts the next token (such as an image or video). Therefore, when multimodal input information such as videos or images needs to generate a large number of words, step-by-step word prediction will lead to very low word prediction efficiency. In addition, the one-way AR text generation model cannot use the bidirectional attention mechanism to process natural bidirectional data formats such as images, which will also affect the final word prediction generation effect to a certain extent.
[0039] Since the MTM text understanding model needs to generate an initial state that conforms to the training distribution before it can perform demasking inference iterations, the initial state using a random distribution during training cannot cover all mask positions, resulting in poor prediction results for multimodal outputs such as images or videos generated by the inference iterations.
[0040] In order to solve the above technical problems, the present invention provides a model training method, a model reasoning method, a device and an electronic device, wherein the execution subject of the model training method can be an electronic device or a server deployed with a one-way AR text generation model, and the electronic device can be a personal computer (PC), a portable device, a laptop computer, a smart phone, a tablet computer, a portable wearable device and other devices; the server can refer to a server, or it can be a server cluster composed of multiple servers, a cloud server, etc. The present invention does not specifically limit the specific form of the electronic device or the server. Furthermore, the execution subject of the model training method can also be applied to a model training device arranged in an electronic device or a server, and the model training device can be implemented by software, hardware or a combination of both. The following describes the model training method by taking the execution subject of the model training method as an electronic device deployed with a one-way AR text generation model as an example.
[0041] In order to facilitate understanding of the model training method provided by the embodiment of the present invention, the model training method provided by the present invention will be described in detail below through the following exemplary embodiments. It is understandable that the following exemplary embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0042] Reference Figure 1 , which is one of the flow charts of the model training method provided by the present invention, such as Figure 1 As shown, the model training and analysis method includes the following steps 110 to 140.
[0043] Step 110: Use the first prediction head module of the unidirectional backbone model to predict the next word unit of the latent space word unit segment in the latent space word unit sequence of the multimodal input information to obtain a first word unit prediction result.
[0044] Among them, the multimodal input information can be videos, images, etc.
[0045] The unidirectional backbone model may specifically be a unidirectional AR text generation model.
[0046] The first prediction head module may be a head module for performing single token prediction, and the number of first prediction head modules is usually 1.
[0047] Specifically, the multimodal input information can be processed through latent space conversion to obtain a latent space word sequence, that is, the multimodal input information is compressed using a compression model encoder (such as VQ-VAE), converted to the latent space, and the latent space word sequence of the multimodal input information is obtained.
[0048] The latent space word-gram sequence is a sequence composed of multiple latent space word-grams and each latent space word-gram can be a mask of the word-gram to be predicted.
[0049] The latent space word unit segmentation can be multiple latent space word units selected when the starting position in the latent space word unit sequence is 1, such as y1, y2, ..., y L ; or, it can be multiple latent space tokens selected from non-starting positions, such as y K+1 ,y K+2 , ..., y K+L , K represents the preset right shift length and is an integer ≥0.
[0050] Exemplarily, when the latent space word sequence is recorded as Y and includes N latent space tokens, it can be as shown in formula (1).
[0051] Y=[y1, y2, y3, y4, y5, y6, y7, y8, y9, y 10 ,y 11 ,y 12 ,y 13 ,y 14 ,y 15 ,y 16 ......,y N ] (1).
[0052] In formula (1), y1, y2, ..., y N They represent the 1st, 2nd, ...Nth latent space token respectively, where N is a positive integer greater than 0.
[0053] At this time, the latent space word unit segment Y can be determined based on the preset word unit training length L L , and is represented by Y L =[y1,y2,...,y L ]; then further segment the latent space word unit Y L Perform next word prediction (such as next token prediction) and obtain the first word prediction result Y L+1 .
[0054] For example, when the latent space word segment is Y L =[y1,y2,...,y L ], the first word prediction result can be Y L+1 =[y2,y3,...,Y L+1 ], the corresponding loss function can be expressed as -log p (0) (Y L+1 |Y L ), where p (0) It is the probability predicted by the model main head module (that is, the first prediction head module).
[0055] Step 120: Based on latent space word-gram segmentation, the second prediction head module of the unidirectional backbone model is used to perform fixed-position word-gram prediction and random-position word-gram prediction in the latent space word-gram sequence to obtain a second word-gram prediction result.
[0056] Specifically, the second prediction head module can be a plurality of pre-set model additional head modules, and some of the plurality of head modules will make uniform predictions for fixed position tokens within a uniform range of the latent space word sequence, and the remaining head modules will also make random predictions for other random position tokens in the latent space word sequence. The above uniform predictions and random predictions can be set before training and fixed after training, and are both based on latent space word segmentation for prediction; so as to obtain the second word prediction result after using the second prediction head module to perform fixed position word prediction and random position word prediction.
[0057] Step 130: Determine a masked latent space word-gram sequence corresponding to the multimodal input information based on the first word-gram prediction result and the second word-gram prediction result, and determine the masked latent space word-gram sequence as a model training result.
[0058] Specifically, when the latent space word-unit sequence is used for model training, the initial tokens with the starting position K+1 can be selected from the latent space word-unit sequence as the latent space word-unit segmentation for single or multiple autoregressive inferences to obtain a partially unmasked masked latent space word-unit sequence, and when multiple autoregressive inferences are performed, the first autoregressive inference predicts the number of tokens in {2, k1, k2, k3, ..., kH}+K tokens, and the remaining positions are to be masked. The second autoregressive inference predicts the tokens at {3, k1+1, k2+1, k3+1, ..., k H +1}+K, and the remaining positions are to be masked; and so on, until the cumulative number of iterations reaches the preset number of iterations, the masked latent space word sequence when the iteration stops is used as the model training result. H Represents the predicted position of the next word in the latent space word sequence of each of the H model extra head modules.
[0059] For example, the initial tokens starting at position K+1 can be the starting character <sos>And other control variable tokens, or partial tokens corresponding to the reference image.
[0060] The model training method provided by the embodiment of the present invention uses the first prediction head module of the unidirectional backbone model to predict the next word in the latent space word sequence of the multimodal input information, and based on the latent space word segmentation, uses the second prediction head module of the unidirectional backbone model to perform fixed position word prediction and random position word prediction in the latent space word sequence, thereby ensuring that each step-by-step word prediction can remove as many masks as possible, which not only improves the efficiency of each step word prediction, but also combines different prediction heads to perform word prediction in different ways to improve the final word generation effect, thereby greatly improving the model training efficiency of the unidirectional backbone model and the accuracy of the model training results.
[0061] Based on the above Figure 1 In the model training method shown in FIG. 1 , in an exemplary embodiment, in step 120, based on latent space word-unit segmentation, a second prediction head module of a unidirectional backbone model is used to perform fixed position word-unit prediction and random position word-unit prediction in a latent space word-unit sequence, and the specific process includes: In the case where the second prediction head module includes multiple first head modules for uniform prediction and multiple second head modules for random prediction, based on latent space word-unit segmentation, the uniform prediction positions corresponding to each of the multiple first head modules in the latent space word-unit sequence and the random prediction positions corresponding to each of the multiple second head modules in the latent space word-unit sequence are determined; further, for each first head module, the first head module is used to perform a first fixed-position word-unit prediction on the latent space word-unit segmentation, and the first fixed position is the same as the uniform prediction position corresponding to the first head module; at the same time, for each second head module, the second head module is used to perform a second random-position word-unit prediction on the latent space word-unit segmentation, and the second random position is the same as the random prediction position corresponding to the second head module and is different from each first position to be predicted.
[0062] Specifically, first determine that the second prediction head module includes H model additional head modules and the H model additional head modules are specifically H / 2 first head modules for uniform prediction and H / 2 second head modules for random prediction. For example, when the number of second prediction heads is 16, 8 are first head modules and 8 are second head modules.
[0063] Based on latent space word segmentation Y L Determine the uniform prediction position corresponding to each first head module in the latent space word sequence k i Indicates that the i-th first head module uniformly predicts the fixed positions of the next few words in the latent space word sequence; and based on the latent space word segmentation Y L Determine the random prediction position corresponding to each second head module in the latent space word sequence k j It indicates that the j-th second head module randomly predicts the random positions of the next few words in the latent space word sequence.
[0064] At this time, each first head module can be used to perform word predictions on the latent space word segmentation at the corresponding uniform prediction position, and each second head module can be used to perform word predictions on the latent space word segmentation at the corresponding random prediction position; each uniform prediction position is different from each random prediction position.
[0065] For example, refer to Figure 2A The second flowchart of the model training method shown in Figure 2A In the example, H model extra head modules are used to perform token prediction respectively. For example, model extra head module 1 is based on latent space word segmentation Y L About Location Token prediction is performed and the corresponding loss function can be expressed as where p (1) is the predicted probability of the model's additional head module 1, and the model's additional head module 2 is based on the latent space word segmentation Y L About Location The corresponding loss function for token prediction can be expressed as where p (2) is the predicted probability of the model's additional head module 2; the model's additional head module 3 is based on the latent space word segmentation Y L About Location The corresponding loss function for token prediction can be expressed as where p (3) is the predicted probability of the model's additional head module 3; and so on.
[0066] Based on the above Figure 1 The model training method shown, in an example embodiment, the unidirectional AR text generation model determines the uniform prediction positions corresponding to each of the multiple first head modules in the latent space word-gram sequence, and the random prediction positions corresponding to each of the multiple second head modules in the latent space word-gram sequence based on latent space word-gram segmentation. The specific process may include: determining the prediction position interval between the multiple first head modules based on a preset word-gram training length and the number of latent space word-grams included in the latent space word-gram sequence; determining each uniform prediction position based on the prediction position interval, the preset word-gram training length and the latent space word-gram segmentation; and determining each random prediction position that does not overlap with each uniform prediction position based on the latent space word-gram segmentation within a random prediction range pre-set for the latent space word-gram sequence.
[0067] Specifically, when the preset word unit training length is set to L, the latent space word unit sequence includes N latent space word units, and the second prediction head module includes H model additional head modules, the prediction position interval s=(NL) / (H / 2) between the multiple first head modules can be determined. Exemplarily, when L=4096, N=6144 and H=16, s=(6144-4096) / 8=256.
[0068] For each first head module, it can be determined that the i-th first head module uniformly predicts the fixed position k of the next few words in the latent space word sequence i , k i =i*s; In this way, the word segmentation in the latent space is Y L =[y1,y2,...,y L ], the uniform prediction position corresponding to the i-th first head module in the latent space word sequence can be determined
[0069] For each second head module, a random prediction position that is random and does not overlap with each uniform prediction position within the random prediction range of the latent space word unit sequence predicted by the jth second head module can be determined. The random prediction range is specifically between L+2 and N-1. It should be noted that Uniform{L+2,N-1} means generating random numbers in the range of L+2 to N-1. Indicates not including k j It indicates that the j-th second head module randomly predicts the random positions of the next few words in the latent space word sequence.
[0070] Based on the above Figure 1 In the model training method shown in FIG. 1 , in an exemplary embodiment, in step 130, based on the first word unit prediction result and the second word unit prediction result, a masked latent space word unit sequence corresponding to the multimodal input information is determined, and the specific implementation process includes: First, determine the first word unit prediction right shift result and the second word unit prediction right shift result after both the first word unit prediction result and the second word unit prediction result are right shifted by a preset number of bits; then, based on the first word unit prediction right shift result and the second word unit prediction right shift result, determine a masked latent space word unit sequence that has the same number of latent space word units as and is aligned with the latent space word unit sequence.
[0071] It should be noted that, refer to Figure 2B As shown, for the latent space word segment Y L 、First word prediction result Y L+1 , uniformly predicted position y L +k i and random prediction positions The whole can be shifted right by K positions. If the right shift exceeds the boundary of the latent space word unit sequence, the word unit prediction is performed from the beginning for the latent space word units that exceed the boundary.
[0072] After right shifting K bits, a masked latent space word-unit sequence with the same number of latent space word-units as those in the latent space word-unit sequence and aligned therewith can be determined by aligning the masks used for a preset proportion of the batch with the indexes of multiple model extra head modules and performing mask learning on the masks used for the remaining proportion of the batch.
[0073] Exemplarily, based on the first word unit prediction right shift result and the second word unit prediction right shift result, determining a masked latent space word unit sequence having the same number of latent space word units as the latent space word unit sequence and being aligned, the specific process includes: First, in the initial fully masked sequence corresponding to the latent space word unit sequence, the masked positions and non-masked positions in the initial fully masked sequence are determined based on the first word unit prediction right shift result and the second word unit prediction right shift result; further, the initial fully masked sequence is masked and learned using a preset random mask learning strategy; then, the masked latent space word unit sequence is determined based on the mask values corresponding to the masked positions, the predicted words corresponding to the non-masked positions, and the mask learning results.
[0074] It should be noted that when the initial full mask sequence M corresponding to the latent space word sequence includes N mask elements and a certain proportion of mask positions and non-mask positions in the N mask elements are determined by formula (2).
[0075]
[0076] In formula (2), m q represents the qth mask element in the initial full mask sequence M, the qth mask element m q Can be one of the masked position and the non-masked position, m q =1 indicates that it is a mask position and has a mask value, m q =0 indicates that it is a non-masked position and corresponds to a predicted token.
[0077] Since the value range of q in formula (2) is limited by the right shift result of the first word unit prediction and the right shift result of the second word unit prediction, it cannot cover all the mask elements in the initial full mask sequence. Therefore, for the remaining mask elements that are not covered, a random masking method can be used to enable the model to learn masks of different ratios. The random masking learning process can refer to formula (3).
[0078]
[0079] In formula (3), p = 1, 2, ..., N, g(r) represents a monotonically increasing function in the domain r∈[0, 1], and satisfies g(0)→1, g(0)→0; for example, Or g(r)=cos(0.5*π*r); z, r~(0,1) means that the random variables r and Z are uniformly distributed in the range of (0,1); when m p =1 indicates that it is a non-masked position and has a masked value; when m p =0 indicates that it is a mask position and corresponds to a predicted token.
[0080] So far, through the above formulas (2) and (3), we can determine the masked latent space word sequence shown in formula (4):
[0081]
[0082] In formula (4), d = 1, 2, ..., N, m d represents the masked position or non-masked position determined according to formula (2) or formula (3). For example, the masked latent space word sequence can be specifically [y1, y2, b, y4, b, y6, ..., y N ], b represents the mask value and is usually the dictionary size of the VQ-VAE codebook; this is because the values of all latent space tokens are between 0 and the dictionary size of 1, so the mask value is set to a value outside its range, such as the dictionary size.
[0083] Below, the model reasoning method provided by the present invention is described, wherein the execution subject of the model reasoning method is an electronic device or server deployed with an MTM text understanding model, and may be the same electronic device as the aforementioned electronic device or server deployed with a unidirectional AR text generation model, or may be a different electronic device, or may be the same server, or may be a different server; no specific limitation is made here. In addition, the execution subject of the model reasoning method may also be applied to a model reasoning device provided in an electronic device or server, and the model reasoning device may be implemented by software, hardware, or a combination of the two. Below, the model reasoning method is described by taking the execution subject of the model reasoning method as an electronic device deployed with an MTM text understanding model as an example.
[0084] Reference Figure 3 , which is one of the flow charts of the model reasoning method provided by the present invention, such as Figure 3 As shown, the model reasoning method includes the following steps 310 to 330.
[0085] Step 310: determine the initial state of the demasking model, where the initial state is the masked latent space word sequence obtained by the aforementioned model training method.
[0086] Step 320: Use the demasking model to perform multi-step demasking reasoning on the initial state to obtain a completely mask-free target latent space output result.
[0087] Step 330: determine the target multimodal output result corresponding to the target latent space output result, and determine the target multimodal output result as the model inference result.
[0088] The demasking model may specifically be an MTM text understanding model.
[0089] It should be noted that when the masked latent space word sequence obtained by the aforementioned model training method is determined as the initial state of the MTM text understanding model, the initial state can be input into the MTM text understanding model, so that the MTM text understanding model uses its bidirectional backbone model to perform multiple demasking inferences on the initial state until a completely demasked target latent space output result is obtained. At this time, the compression model decoder can be used to perform super-resolution processing on the target latent space output result to convert the target latent space output result into the original pixel space, thereby obtaining the target multimodal output result corresponding to the target latent space output result.
[0090] Exemplarily, the compression model decoder may be a VQ-VAE decoder.
[0091] For example, refer to Figure 4 The second flowchart of the model reasoning method shown in Figure 4 In the paper, the bidirectional backbone model is specifically the MTM text understanding model; by masking the latent space word sequence Input into the bidirectional backbone model, and use its bidirectional backbone model head module to perform multiple demasking inferences to obtain the fully demasked target latent space output result, and the corresponding loss function can be expressed as Where p is the predicted probability of the bidirectional backbone model.
[0092] For the initial state, the masked latent space word sequence obtained through multi-step autoregressive inference When, the first step of autoregressive inference predicts that {2, k1, k2, k3, ..., k H }+K tokens, and the remaining positions are mask values b; the second step of autoregressive inference predicts the tokens at {3, k1+1, k2+1, k3+1, ..., k H +1}+K{2,k1,k2,k3,...,k H}+K tokens, and the rest of the positions are mask values b; each step of the word-unit reasoning process ignores the tokens that have been reasoned; and so on, until iteration t AR Step 2 to obtain the masked latent space word sequence So far, the total number of tokens predicted by the one-way backbone model through reasoning is N AR =t AR *(1+H)-N skip , where N skip The number of tokens skipped during inference for the unidirectional backbone model.
[0093] In the masked latent space word sequence As the initial state of the demasking model, during the multi-step demasking tokens inference prediction process, the number of tokens predicted in each step of demasking inference can be set to
[0094] r=linspace(start=1, end=0, total_step=t MTM ), linspace means equal division calculation, t MTM Indicates the number of word prediction inferences of the demasking model. Until the cumulative number of word reasoning steps reaches the preset step threshold, the corresponding target latent space output result is obtained.
[0095] The number of unmasked prediction tokens in each step of the bidirectional backbone model is T[i′], i′=1, 2, ..., t MTM , where i′ is the index value of r. It should be noted that in the multi-step demasking inference process of the demasking model, T[T=0]=1 is set to ensure that at least one token is decoded in each step; T[N]→T[N]+(NN AR )-∑ i , T to ensure that the total number of decoded tokens is NN AR If a token that has already been predicted is encountered, the position is skipped.
[0096] The model reasoning method provided in the embodiment of the present invention greatly improves the prediction effect of the bidirectional backbone model by utilizing the masked latent space word sequence generated by a unidirectional backbone model in conjunction with multiple model extra head modules as the initial state for demasked reasoning and prediction, while also being able to maintain the original high reasoning efficiency of the bidirectional backbone model.
[0097] For example, refer to Figure 5 The flowchart of the overall model inference method is shown in Figure 5 As shown, when the first prediction head module is 1 and the second prediction head module includes 4 model additional head modules, a masked latent space word unit sequence after a single autoregressive inference prediction can be obtained, and then the masked latent space word unit sequence after the single autoregressive inference prediction is further subjected to autoregressive inference prediction again. After obtaining the masked latent space word unit sequence after two autoregressive inference predictions, it is used as the initial state of the demasking model and multiple demasking inferences are performed until a target multimodal output result similar to an image or video is obtained.
[0098] The model training device provided by the present invention is described below. The model training device described below and the model training method described above can be referenced to each other.
[0099] Reference Figure 6 , which is a schematic diagram of the structure of the model training device provided by the present invention, such as Figure 6 As shown, the model training device 600 includes: a first training unit 610 and a second training unit 620.
[0100] The first training unit 610 is used to use the first prediction head module of the unidirectional backbone model to predict the next word in the latent space word sequence of the multimodal input information, and obtain a first word prediction result; based on the latent space word segmentation, use the second prediction head module of the unidirectional backbone model to perform fixed position word prediction and random position word prediction in the latent space word sequence to obtain a second word prediction result.
[0101] The second training unit 620 is used to determine a masked latent space word-gram sequence corresponding to the multimodal input information based on the first word-gram prediction result and the second word-gram prediction result, and determine the masked latent space word-gram sequence as a model training result.
[0102] Optionally, the first training unit 610 is specifically used to determine, based on latent space word-gram segmentation, the uniform prediction positions corresponding to each of the multiple first head modules in the latent space word-gram sequence, and the random prediction positions corresponding to each of the multiple second head modules in the latent space word-gram sequence, when the second prediction head module includes multiple first head modules for uniform prediction and multiple second head modules for random prediction; for each first head module, using the first head module to perform a first fixed-position word-gram prediction on the latent space word-gram segmentation, the first fixed position being the same as the uniform prediction position corresponding to the first head module; for each second head module, using the second head module to perform a second random-position word-gram prediction on the latent space word-gram segmentation, the second random position being the same as the random prediction position corresponding to the second head module and being different from each first position to be predicted.
[0103] Optionally, the first training unit 610 is specifically used to determine the prediction position interval between multiple first head modules based on a preset word unit training length and the number of latent space word units included in the latent space word unit sequence; determine each uniform prediction position based on the prediction position interval, the preset word unit training length and the latent space word unit segmentation; and determine each random prediction position that does not overlap with each uniform prediction position based on the latent space word unit segmentation within a random prediction range pre-set for the latent space word unit sequence.
[0104] Optionally, the second training unit 620 is specifically used to determine the first word unit prediction right shift result and the second word unit prediction right shift result after both the first word unit prediction result and the second word unit prediction result are right shifted by a preset number of bits; based on the first word unit prediction right shift result and the second word unit prediction right shift result, determine a masked latent space word unit sequence that has the same number of latent space word units as and is aligned with the latent space word unit sequence.
[0105] Optionally, the second training unit 620 is specifically used to determine, in the initial fully masked sequence corresponding to the latent space word unit sequence, the masked positions and non-masked positions in the initial fully masked sequence based on the first word unit prediction right shift result and the second word unit prediction right shift result; perform mask learning on the initial fully masked sequence using a preset random mask learning strategy; and determine the masked latent space word unit sequence based on the mask value corresponding to the mask position, the predicted word unit corresponding to the non-masked position, and the mask learning result.
[0106] The model reasoning device provided by the present invention is described below. The model reasoning device described below and the model reasoning method described above can be referenced to each other.
[0107] Reference Figure 7 , which is a schematic diagram of the structure of the model reasoning device provided by the present invention, such as Figure 7 As shown, the model reasoning device 700 includes: a state determination unit 710 and a model reasoning unit 720.
[0108] The state determination unit 710 is used to determine the initial state of the demasking model, where the initial state is the masked latent space word sequence obtained by the aforementioned model training method.
[0109] The model inference unit 720 is used to perform multi-step demasking inference on the initial state using the demasking model to obtain a completely unmasked target latent space output result; determine the target multimodal output result corresponding to the target latent space output result, and determine the target multimodal output result as the model inference result.
[0110] Figure 8 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 8 As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication interface 820 and the memory 830 communicate with each other through the communication bus 840. The processor 810 may call the logic instructions in the memory 830 to execute the model training method, which includes: using the first prediction head module of the unidirectional backbone model to predict the next word of the latent space word segment in the latent space word sequence of the multimodal input information, and obtaining a first word prediction result; based on the latent space word segment, using the second prediction head module of the unidirectional backbone model to predict the fixed position word and the random position word in the latent space word sequence, and obtaining a second word prediction result; based on the first word prediction result and the second word prediction result, determining the masked latent space word sequence corresponding to the multimodal input information, and determining the masked latent space word sequence as the model training result.
[0111] Alternatively, a model reasoning method is executed, which includes: determining an initial state of the demasking model, the initial state being a masked latent space word sequence trained by the aforementioned model training method; using the demasking model to perform multi-step demasking reasoning on the initial state to obtain a completely unmasked target latent space output result; determining a target multimodal output result corresponding to the target latent space output result, and determining the target multimodal output result as the model reasoning result.
[0112] In addition, the logic instructions in the above-mentioned memory 830 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0113] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the model training method provided by the above methods, which includes: using the first prediction head module of the unidirectional backbone model to predict the next word of the latent space word segment in the latent space word sequence of the multimodal input information, and obtaining a first word prediction result; based on the latent space word segment, using the second prediction head module of the unidirectional backbone model to perform fixed position word prediction and random position word prediction in the latent space word sequence, and obtain a second word prediction result; based on the first word prediction result and the second word prediction result, determine the masked latent space word sequence corresponding to the multimodal input information, and determine the masked latent space word sequence as the model training result.
[0114] Alternatively, a model reasoning method is executed, which includes: determining an initial state of the demasking model, the initial state being a masked latent space word sequence trained by the aforementioned model training method; using the demasking model to perform multi-step demasking reasoning on the initial state to obtain a completely unmasked target latent space output result; determining a target multimodal output result corresponding to the target latent space output result, and determining the target multimodal output result as the model reasoning result.
[0115] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the model training method provided by the above-mentioned methods, the method comprising: using a first prediction head module of a unidirectional backbone model to predict the next word of a latent space word segment in a latent space word sequence of multimodal input information, and obtaining a first word prediction result; based on the latent space word segment, using a second prediction head module of the unidirectional backbone model to perform fixed-position word prediction and random-position word prediction in the latent space word sequence, and obtaining a second word prediction result; based on the first word prediction result and the second word prediction result, determining a masked latent space word sequence corresponding to the multimodal input information, and determining the masked latent space word sequence as the model training result.
[0116] Alternatively, a model reasoning method is executed, which includes: determining an initial state of the demasking model, the initial state being a masked latent space word sequence trained by the aforementioned model training method; using the demasking model to perform multi-step demasking reasoning on the initial state to obtain a completely unmasked target latent space output result; determining a target multimodal output result corresponding to the target latent space output result, and determining the target multimodal output result as the model reasoning result.
[0117] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0118] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0119] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.< / sos>
Claims
1. A model training method, characterized in that: include: Using the first prediction head module of the unidirectional backbone model, the next word unit is predicted for the latent space word unit segment in the latent space word unit sequence of the multimodal input information to obtain a first word unit prediction result; Based on the latent space word-gram segmentation, using the second prediction head module of the unidirectional backbone model to perform fixed-position word-gram prediction and random-position word-gram prediction in the latent space word-gram sequence to obtain a second word-gram prediction result; Based on the first word-gram prediction result and the second word-gram prediction result, a masked latent space word-gram sequence corresponding to the multimodal input information is determined, and the masked latent space word-gram sequence is determined as a model training result.
2. The model training method according to claim 1, characterized in that: The method of performing fixed position word unit prediction and random position word unit prediction in the latent space word unit sequence based on the latent space word unit segmentation and utilizing the second prediction head module of the unidirectional backbone model comprises: In the case where the second prediction head module includes a plurality of first head modules for uniform prediction and a plurality of second head modules for random prediction, Based on the latent space word-gram segmentation, determine the uniform prediction position corresponding to each of the plurality of first head modules in the latent space word-gram sequence, and the random prediction position corresponding to each of the plurality of second head modules in the latent space word-gram sequence; for each first head module, use the first head module to perform first fixed position word-gram prediction on the latent space word-gram segmentation, the first fixed position being the same as the uniform prediction position corresponding to the first head module; For each second head module, the second head module is used to perform second random position word prediction on the latent space word segment, and the second random position is the same as the random prediction position corresponding to the second head module and is different from each of the first positions to be predicted.
3. The model training method according to claim 2, characterized in that: The determining, based on the latent space word-gram segmentation, the uniform prediction positions corresponding to each of the plurality of first head modules in the latent space word-gram sequence, and the random prediction positions corresponding to each of the plurality of second head modules in the latent space word-gram sequence, comprises: Determining the prediction position intervals between the plurality of first head modules based on a preset word unit training length and the number of latent space word units included in the latent space word unit sequence; Determining each of the uniform prediction positions based on the prediction position interval, the preset word unit training length and the latent space word unit segmentation; Within a random prediction range preset for the latent space word-unit sequence, each of the random prediction positions that is not repeated with each of the uniform prediction positions is determined based on the latent space word-unit segmentation.
4. The model training method according to any one of claims 1 to 3, characterized in that: The determining, based on the first word-gram prediction result and the second word-gram prediction result, a masked latent space word-gram sequence corresponding to the multimodal input information includes: Determine the first word unit prediction right-shifted result and the second word unit prediction right-shifted result after both the first word unit prediction result and the second word unit prediction result are right-shifted by a preset number of bits; Based on the first word unit prediction right shift result and the second word unit prediction right shift result, determine the masked latent space word unit sequence that has the same number of latent space word units as and is aligned with the latent space word unit sequence.
5. The model training method according to claim 4, characterized in that: The determining, based on the first word unit prediction right shift result and the second word unit prediction right shift result, the masked latent space word unit sequence having the same number of latent space word units as and aligned with the latent space word unit sequence comprises: In an initial fully masked sequence corresponding to the latent space word-gram sequence, determining masked positions and non-masked positions in the initial fully masked sequence based on the first word-gram prediction right shift result and the second word-gram prediction right shift result; Performing mask learning on the initial full-mask sequence using a preset random mask learning strategy; The masked latent space word unit sequence is determined based on the mask value corresponding to the mask position, the predicted word unit corresponding to the non-masked position and the mask learning result.
6. A model reasoning method, characterized in that: include: Determine an initial state of the demasking model, wherein the initial state is a masked latent space word sequence obtained by training using the model training method of any one of claims 1 to 5; Using the demasking model to perform multi-step demasking reasoning on the initial state to obtain a completely mask-free target latent space output result; Determine a target multimodal output result corresponding to the target latent space output result, and determine the target multimodal output result as a model inference result.
7. A model training device, characterized in that: include: The first training unit is used to use the first prediction head module of the unidirectional backbone model to perform next word prediction on the latent space word segment in the latent space word sequence of the multimodal input information to obtain a first word prediction result; based on the latent space word segment, use the second prediction head module of the unidirectional backbone model to perform fixed position word prediction and random position word prediction in the latent space word sequence to obtain a second word prediction result; The second training unit is used to determine the masked latent space word-gram sequence corresponding to the multimodal input information based on the first word-gram prediction result and the second word-gram prediction result, and determine the masked latent space word-gram sequence as the model training result.
8. A model reasoning device, characterized in that: include: A state determination unit, used to determine an initial state of the demasking model, wherein the initial state is a masked latent space word sequence obtained by training using the model training method according to any one of claims 1 to 5; A model inference unit, used for performing multi-step demasking inference on the initial state using the demasking model to obtain a completely unmasked target latent space output result; Determine a target multimodal output result corresponding to the target latent space output result, and determine the target multimodal output result as a model inference result.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, it implements the model training method as described in any one of claims 1 to 5, or implements the model reasoning method as described in claim 6.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the model training method as described in any one of claims 1 to 5, or implements the model reasoning method as described in claim 6.
