A multimodal machine translation method and device based on text-image attention mechanism

By supervising the text-image attention matrix during the text-image generation process, the problem of low training efficiency of the text-image generation model is solved, the efficiency of multi-modal translation is optimized, the text focuses on image information more accurately, and the performance of cross-modal tasks is improved. .

CN118228743BActive Publication Date: 2024-09-20BEIJING LANGUAGE AND CULTURE UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410655980.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-24
Publication Date
2024-09-20
Estimated Expiration
2044-05-24

AI Technical Summary

Technical Problem

The existing text and image attention mechanism lacks supervision during the training process, resulting in low training efficiency of the text and image generation model, which in turn affects the efficiency of multi-modal translation.

Method used

The attention matrix generated during the text and image generation process is used to supervise the text and image attention matrix in the training process. The MSE loss function and bilinear interpolation algorithm are used to unify the matrix size and word granularity and optimize the text and image in cross-modal interaction. attention.

Benefits of technology

It improves the training efficiency of the text and picture generation model and the efficiency of multi-modal translation, allowing the text to more accurately focus on the visual information in the picture, and improving the performance of cross-modal tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118228743B
    Figure CN118228743B
Patent Text Reader

Abstract

The present invention relates to the technical field of machine translation, and in particular to a multimodal machine translation method and device based on a text-image attention mechanism. The method comprises: inputting a source language text into a trained text-image generation model, obtaining a diffuse attention matrix based on the text-image generation process, the text vector of the source language text, and the corresponding generated image; obtaining an attention matrix during the training process according to translation training samples and an initial multimodal machine translation model based on a text-image attention mechanism; using an MSE loss function, calculating a first loss function according to the diffuse attention matrix and the attention matrix during the training process; determining a second loss function according to the predicted output of the multimodal machine translation model and the true value of the output text; and training the initial multimodal machine translation model according to the first loss function and the second loss function. The present invention can improve the efficiency of training a text-image generation model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of machine translation, and in particular to a multimodal machine translation method and device based on a text-image attention mechanism. Background Art

[0002] The text-image attention matrix is ​​generated during cross-modal interaction. It is an attention information matrix that reflects which part of the image the text pays more attention to. The text-image attention matrix in cross-modal interaction determines which information in the image needs to be paid attention to, so as to better utilize visual information. The existing text-image attention matrix is ​​often generated during the training process. As the model training process is continuously optimized, the text pays attention to the corresponding area in the image, thereby integrating the image information into the text model. Although the existing model architecture can fuse text and images and learn the correspondence between text and images, the attention mechanism learned through the training process still has problems such as insufficient attention and incorrect attention areas.

[0003] In order to optimize the text-image attention mechanism and extract more effective visual information, existing technologies have made many attempts to design more reasonable model architectures and filter the noise of visual features. In terms of model architecture, architectures such as Multimodal Transformer, Selective Attention, and Merge-attention are widely used in cross-modal interaction tasks, and have achieved good results in tasks such as multimodal machine translation, cross-modal matching, and hidden image region detection. In terms of filtering visual feature noise, in order to obtain image information that is more relevant to the text, technologies such as modeling semantic information in visual features and masking information in visual features that is not related to the text have also achieved good results.

[0004] Although text-image attention can be optimized by optimizing the model architecture and filtering visual feature noise, it still needs to be learned during the training process and lacks a correct text-image attention mechanism for supervision. Since the training data of the text model and the image pre-training model are different, the learning of the text-image attention mechanism becomes more difficult in the absence of text-image attention mechanism supervision, resulting in low efficiency in training the text-image generation model, and thus low efficiency in multimodal translation. Summary of the invention

[0005] In order to solve the technical problem that the training efficiency of the text-image generation model in the prior art is low, resulting in low efficiency of multimodal translation, the embodiment of the present invention provides a multimodal machine translation method and device based on the text-image attention mechanism. The technical solution is as follows:

[0006] On the one hand, a multimodal machine translation method based on a text-image attention mechanism is provided, the method is implemented by a multimodal machine translation device, and the method includes:

[0007] S1. Build an initial multimodal machine translation model based on text-image attention mechanism;

[0008] S2, obtain the trained text-image generation model and the source language text;

[0009] S3, inputting the source language text into a trained text-image generation model, and obtaining an initial diffuse attention matrix and a generated image corresponding to the source language text based on the text-image generation process of the trained text-image generation model, the text vector of the source language text, and the visual features of the generated image corresponding to the source language text;

[0010] S4, obtaining a translation training sample, wherein the translation training sample includes an input text, an image generated by the input text, and an output text true value;

[0011] S5, inputting the input text and the image generated by the input text in the translation training sample into the initial multimodal machine translation model based on the text-image attention mechanism, obtaining the attention matrix in the training process based on the text-image attention mechanism and the bilinear interpolation algorithm in the multimodal machine translation model, and extracting the word segmentation results in the training process;

[0012] S6. According to the word segmentation results in the training process, the initial diffuse attention matrix is ​​copied to obtain a diffuse attention matrix;

[0013] S7, using the MSE loss function, calculating a first loss function according to the diffuse attention matrix and the attention matrix during the training process;

[0014] S8, determining a second loss function according to the predicted output of the multimodal machine translation model and the true value of the output text;

[0015] S9. According to the first loss function and the second loss function, the initial multimodal machine translation model based on the text-image attention mechanism is trained to obtain a trained multimodal machine translation model based on the text-image attention mechanism;

[0016] S10. Using the trained multimodal machine translation model based on the text-image attention mechanism, according to the input text to be searched, obtain an image corresponding to the text to be searched.

[0017] On the other hand, a multimodal machine translation device based on a text-image attention mechanism is provided, and the device is applied to a multimodal machine translation method based on a text-image attention mechanism, and the device comprises:

[0018] Construction module, used to build the initial multimodal machine translation model based on the text-image attention mechanism;

[0019] The first acquisition module is used to acquire the trained text-image generation model and the source language text;

[0020] A first determination module is used to input the source language text into a trained text-image generation model, and obtain an initial diffuse attention matrix and a generated image corresponding to the source language text based on the text-image generation process of the trained text-image generation model, the text vector of the source language text, and the visual features of the generated image corresponding to the source language text;

[0021] A second acquisition module is used to acquire a translation training sample, wherein the translation training sample includes an input text, an image generated by the input text, and an output text truth value;

[0022] The second determination module is used to input the input text and the image generated by the input text in the translation training sample into the initial multimodal machine translation model based on the text-image attention mechanism, obtain the attention matrix in the training process based on the text-image attention mechanism and the bilinear interpolation algorithm in the multimodal machine translation model, and extract the word segmentation results in the training process;

[0023] A copy module is used to copy the initial diffuse attention matrix according to the word segmentation results in the training process to obtain a diffuse attention matrix;

[0024] A calculation module, configured to calculate a first loss function according to the diffuse attention matrix and the attention matrix during the training process using an MSE loss function;

[0025] A third determination module, configured to determine a second loss function according to the predicted output of the multimodal machine translation model and the true value of the output text;

[0026] A training module, used for training the initial multimodal machine translation model based on the text-image attention mechanism according to the first loss function and the second loss function, to obtain a trained multimodal machine translation model based on the text-image attention mechanism;

[0027] The search module is used to use the trained multimodal machine translation model based on the text-image attention mechanism to obtain the image corresponding to the text to be searched according to the input text to be searched.

[0028] On the other hand, a multimodal machine translation device is provided, comprising: a processor; a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, any one of the multimodal machine translation methods based on the text-image attention mechanism is implemented.

[0029] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction is stored in the storage medium, and the at least one instruction is loaded and executed by a processor to implement any one of the above-mentioned multimodal machine translation methods based on the text-image attention mechanism.

[0030] The beneficial effects brought about by the technical solution provided by the embodiment of the present invention include at least:

[0031] The embodiment of the present invention proposes to supervise the text-image attention mechanism in the cross-modal training process through the correspondence between the text and visual information in the text-image generation process, and for the first time uses the attention matrix generated in the text-image generation process to supervise the text-image attention matrix in the training process. The MSE loss function is used for supervision, and an alignment method including a unified matrix size and a unified word granularity is proposed to bring the attention matrix generated in the text-image generation process and the attention matrix generated in the translation process closer, optimize the text-image attention in cross-modal interaction, and let the text pay attention to the visual information of the corresponding area in the picture, thereby improving the performance of cross-modal tasks, improving the efficiency of training the text-image generation model, and further improving the efficiency of multimodal translation. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0033] Figure 1 It is a flow chart of a multimodal machine translation method based on a text-image attention mechanism provided by an embodiment of the present invention;

[0034] Figure 2 It is a schematic diagram of the overall framework of a multimodal machine translation method based on a text-image attention mechanism provided by an embodiment of the present invention;

[0035] Figure 3 It is a model architecture diagram of an overall multimodal machine translation method based on a text-image attention mechanism provided by an embodiment of the present invention;

[0036] Figure 4 It is a block diagram of a multimodal machine translation device based on a text-image attention mechanism provided by an embodiment of the present invention;

[0037] Figure 5 It is a structural schematic diagram of a multimodal machine translation device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0038] The technical solution of the present invention is described below in conjunction with the accompanying drawings.

[0039] In the embodiments of the present invention, words such as "exemplarily" and "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "example" in the present invention should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of the word "example" is intended to present the concept in a specific way. In addition, in the embodiments of the present invention, the meaning expressed by "and / or" can be both, or it can be either of the two.

[0040] In the embodiments of the present invention, "image" and "picture" can sometimes be used interchangeably. It should be noted that when the difference between them is not emphasized, the meanings they intend to express are the same. "of", "corresponding, relevant" and "corresponding" can sometimes be used interchangeably. It should be noted that when the difference between them is not emphasized, the meanings they intend to express are the same.

[0041] In the embodiments of the present invention, sometimes the subscripts such as W 1 It may be written in non-subscript form such as W1. When the difference is not emphasized, the meaning is the same.

[0042] In order to make the technical problems, technical solutions and advantages to be solved by the present invention more clear, a detailed description will be given below with reference to the accompanying drawings and specific embodiments.

[0043] The embodiment of the present invention provides a multimodal machine translation method based on a text-image attention mechanism, which can be implemented by a multimodal machine translation device, which can be a terminal or a server. Figure 1 The flowchart of the multimodal machine translation method based on the text-image attention mechanism is shown in Figure 2 The overall framework diagram of the multimodal machine translation method based on the text-image attention mechanism is shown in Figure 3 The overall model architecture diagram of the multimodal machine translation method based on the text-image attention mechanism is shown in the figure. The processing flow of the method may include the following steps:

[0044] S1. Build an initial multimodal machine translation model based on the text-image attention mechanism.

[0045] S2. Obtain the trained text-image generation model and the source language text.

[0046] S3. Input the source language text into the trained text-image generation model, and obtain the initial diffuse attention matrix and the generated image corresponding to the source language text based on the text-image generation process of the trained text-image generation model, the text vector of the source language text, and the visual features of the generated image corresponding to the source language text.

[0047] Optionally, the trained text-image generation model is a trained Stable Diffusion model.

[0048] The specific execution process of S3 can be described as: input the source language text into the trained Stable Diffusion model, use the diffuse attention technology with attribution graph to obtain the score of the degree to which the pixel is affected by the input source language text, and then obtain the initial diffuse attention matrix and the generated image corresponding to the source language text.

[0049] In a feasible implementation, the Stable Diffusion model uses a cross-attention mechanism to integrate text into the model diffusion process, thereby generating images related to the text. On this basis, Tang et al. proposed a diffusion attention technique with an attribution graph, which can visualize the cross-attention matrix in the text-image generation process. Specifically, based on a large-scale latent vector space diffusion model, the attribution graph-based method can determine which area of ​​the image has the greatest impact on the word. In the diffusion model, the attention mechanism integrates the text vector into the coordinate-aware image latent representation context and outputs the score of each word-image block. The attention scores are normalized to the [0,1] interval. Therefore, in order to obtain a pixel-level attribution graph, these scores can be aggregated in the spatiotemporal dimension, and the attention scores generated by different attention heads, different model layers, and different time steps are added and normalized to obtain the score of the degree of influence of a pixel by the current word, which is the final saved text-image attention matrix.

[0050] In the stable diffusion model, the attention mechanism makes the text vector The coordinate-aware latent space representation of the image generated by the VAE encoder Generate mutual perception. The reason why the attention scores have good interpretability is that they are all normalized to the interval [0,1]. For the pixel-level attribution map, the attention scores of the spatiotemporal dimensions can be aggregated and interpolated into the image. U-Net has good image segmentation performance and is used as a denoising network in Stable Diffusion. Given a two-dimensional latent space vector, the downsampled convolution block outputs a series of vectors. The upsampled block then cyclically expands the downsampled vector arrive In order to make these representations based on word vectors, a multi-headed cross-attention layer is used:

[0051]

[0052]

[0053] in represents the number of downsampling blocks, represents the time step, represent The dimension of , , Is with The mapping matrices of the attention heads are respectively referred to as the first variable to be trained, the second variable to be trained, and the third variable to be trained in this embodiment of the present invention. The same mechanism applies. The attention score arrays generated by upsampling and downsampling are represented as and . and is normalized to [0,1], connecting the kth word to the i-th downsampling block The middle coordinate of the head . Due to the nature of the fully connected convolutional network U-Net (and VAE), the intermediate coordinates can be mapped to surrounding areas that may affect the final image, so the attention score for the coordinates makes a connection between each word and the corresponding image patch. However, different layers produce heat maps at different scales, which requires spatial normalization to produce a single heat map. To do this, all intermediate attention score arrays are reshaped to the original image size using bicubic interpolation, and then added across all heads, layers and time steps:

[0054]

[0055] Where k represents the kth word, because Since is positive and scale-normalized, it can be visualized as a soft heatmap, where higher scores have more attention. To get a hard binary heatmap (whether a pixel is affected or not), As a gate:

[0056]

[0057] in represents the indicator function, Thus, the attention score of each word in the text to the image vector coordinates can be obtained through the denoising generation process of the Stable Diffusion 2.0 model. , concatenate the attention scores of all words to get the final sentence-level attention matrix . Save the score matrix generated for each sentence to obtain the pixel-level text-image attention matrix.

[0058] S4. Obtain translation training samples, where the translation training samples include input text, images generated from the input text, and output text truth values.

[0059] S5. Input the input text in the translation training sample and the image generated by the input text into the initial multimodal machine translation model based on the text-image attention mechanism. Based on the text-image attention mechanism and the bilinear interpolation algorithm in the multimodal machine translation model, the attention matrix in the training process is obtained, and the word segmentation results in the training process are extracted.

[0060] Optionally, the initial multimodal machine translation model based on the text-image attention mechanism includes Efficientnet, Transformer encoder, and selection attention mechanism.

[0061] The specific execution process of S5 may include the following steps S51-S55:

[0062] S51. Encode the input source language text based on the Transformer encoder to obtain a text vector.

[0063] In a feasible implementation, the input source language text is represented as t, and the text vector obtained by Transformer encoding is It can be expressed as:

[0064]

[0065] S52. Encode the generated image corresponding to the source language text based on EfficientNet to obtain visual features.

[0066] S53. Based on a bilinear interpolation algorithm, interpolate the visual features to obtain interpolated visual features.

[0067] Optionally, S53 performs interpolation processing on the visual features based on a bilinear interpolation algorithm to obtain interpolated visual features, including:

[0068] According to the following formula (1), the visual features are interpolated to obtain the interpolated visual features:

[0069] (1)

[0070] in, Represents visual features, represents the bilinear interpolation processing function, Represents the interpolated visual features, and the size of the interpolated visual features is 64×64×1280.

[0071] S54. According to the attention mechanism, the interpolated visual features are selected to obtain the selected visual features.

[0072] Optionally, S54 selects the interpolated visual features according to the attention mechanism to obtain the selected visual features, including:

[0073] The interpolated visual features are selected according to the following formula (2) to obtain the selected visual features:

[0074] (2)

[0075] in, Represents the visual features after selection, represents a text vector, represents the visual features after interpolation, is the first variable to be trained, is the second variable to be trained, is the third variable to be trained, yes Dimension.

[0076] S55. Determine the attention matrix during the training process according to the text vector and the selected visual features.

[0077] Optionally, S55 determines the attention matrix in the training process according to the text vector and the selected visual features, including:

[0078] According to the following formula (3), the attention matrix during training is determined:

[0079] (3)

[0080] in, represents the attention matrix during training, represents a text vector, represents the visual features after interpolation, yes The dimension of is the first variable to be trained, is the second variable to be trained.

[0081] S6. According to the word segmentation results in the training process, the initial diffuse attention matrix is ​​copied to obtain the diffuse attention matrix.

[0082] In a feasible implementation, in order to unify the granularity of words during alignment, the word attention matrix generated in the text-image generation process is converted into the attention matrix of subwords in the model training process. Specifically, all words in a sentence in the text-image generation process are traversed and compared with the word segmentation results used in the model training. If a word is divided into multiple subwords in the model training, the diffuse attention matrix corresponding to the word in the text-image generation process is also copied. For example, the unsegmented text is "two men pretend to be", and the initial diffuse attention matrix includes [two, men, pretend, to, be], which are respectively calculated to obtain the diffuse attention matrix of the unsegmented words. However, the text after word segmentation is "two men pre@@ tend to be", and in order to maintain the consistency of word granularity, the diffuse attention matrix of the unsegmented words is also segmented. Specifically, the matrix calculated by the unsegmented text [pretend] is copied as the matrix calculated by the subwords [pre@@, tend] after word segmentation. The copied diffuse attention matrix includes the diffuse attention matrices calculated by [two, men, pre@@, tend, to, be] respectively.

[0083] S7. Use the MSE loss function to calculate the first loss function based on the diffuse attention matrix and the attention matrix during training.

[0084] Optionally, S7 uses the MSE loss function to calculate a first loss function according to the diffuse attention matrix and the attention matrix during training, including:

[0085] According to the following formula (4), the diffuse attention matrix and the attention matrix during training, the first loss function is determined:

[0086] (4)

[0087] Among them, N represents the total number of words in the source language text after word segmentation. represents the attention matrix of the i-th word on the visual attention during training, represents the diffusion attention matrix obtained by the i-th word in the text-image generation process, Represents the first loss function.

[0088] S8. Determine a second loss function according to the predicted output of the multimodal machine translation model and the true value of the output text.

[0089] In one feasible implementation, the output of Slective Attention is As visual features, the visual features are integrated into the translation model through the Multimodal Transformer method. The specific method is that at each multimodal self-attention layer, the text and visual representations are spliced ​​into a query vector :

[0090]

[0091] The key and value vectors are text vectors , represents the selected visual features, N represents the total number of words in the source language text after word segmentation, represents the real number domain, P represents the length of the selected visual feature, and d represents the dimension of the text and the selected visual feature. Finally, the output of the multimodal self-attention layer is calculated as follows:

[0092]

[0093] in, is the key vector The output of the last layer of the multimodal Transformer encoder layer is fed into the multimodal Transformer decoder to generate the target translation result. The target sentence is represented as , the loss function of the translation task (i.e., the second loss function) can be expressed as:

[0094]

[0095] in, represents the jth word, t represents the input source language text, p represents the probability, and M represents the length of the target sentence.

[0096] S9. According to the first loss function and the second loss function, the initial multimodal machine translation model based on the text-image attention mechanism is trained to obtain a trained multimodal machine translation model based on the text-image attention mechanism.

[0097] In a feasible implementation, the final training goal is:

[0098]

[0099] in, is a hyperparameter that controls the contribution of the MSE loss function.

[0100] S10. Use the trained multimodal machine translation model based on the text-image attention mechanism to obtain the image corresponding to the text to be searched according to the input text to be searched.

[0101] The embodiment of the present invention proposes to supervise the text-image attention mechanism in the cross-modal training process through the correspondence between the text and visual information in the text-image generation process, and for the first time uses the attention matrix generated in the text-image generation process to supervise the text-image attention matrix in the training process. The MSE loss function is used for supervision, and an alignment method including a unified matrix size and a unified word granularity is proposed to bring the attention matrix generated in the text-image generation process and the attention matrix generated in the translation process closer, optimize the text-image attention in cross-modal interaction, and let the text pay attention to the visual information of the corresponding area in the picture, thereby improving the performance of cross-modal tasks, improving the efficiency of training the text-image generation model, and further improving the efficiency of multimodal translation.

[0102] Figure 4 1 is a block diagram of a multimodal machine translation device based on a text-image attention mechanism according to an exemplary embodiment, wherein the device is used in a multimodal machine translation method based on a text-image attention mechanism. Figure 4 , the device comprises:

[0103] A construction module 4010 is used to construct an initial multimodal machine translation model based on a text-image attention mechanism;

[0104] The first acquisition module 4020 is used to acquire the trained text-image generation model and the source language text;

[0105] The first determination module 4030 is used to input the source language text into the trained text-image generation model, and obtain an initial diffuse attention matrix and a generated image corresponding to the source language text based on the text-image generation process of the trained text-image generation model, the text vector of the source language text, and the visual features of the generated image corresponding to the source language text;

[0106] A second acquisition module 4040 is used to acquire a translation training sample, wherein the translation training sample includes an input text, an image generated by the input text, and an output text truth value;

[0107] The second determination module 4050 is used to input the input text and the image generated by the input text in the translation training sample into the initial multimodal machine translation model based on the text-image attention mechanism, obtain the attention matrix in the training process based on the text-image attention mechanism and the bilinear interpolation algorithm in the multimodal machine translation model, and extract the word segmentation results in the training process;

[0108] A copy module 4060 is used to copy the initial diffuse attention matrix according to the word segmentation result in the training process to obtain a diffuse attention matrix;

[0109] A calculation module 4070, configured to calculate a first loss function according to the diffuse attention matrix and the attention matrix during training using an MSE loss function;

[0110] A third determination module 4080, configured to determine a second loss function according to the predicted output of the multimodal machine translation model and the true value of the output text;

[0111] A training module 4090 is used to train the initial multimodal machine translation model based on the text-image attention mechanism according to the first loss function and the second loss function to obtain a trained multimodal machine translation model based on the text-image attention mechanism;

[0112] The search module 4100 is used to use the trained multimodal machine translation model based on the text-image attention mechanism to obtain the image corresponding to the text to be searched according to the input text to be searched.

[0113] Optionally, the trained text-image generation model is a trained Stable Diffusion model;

[0114] The first determining module 4030 is used to:

[0115] The source language text is input into the trained Stable Diffusion model, and the diffuse attention technology with attribution map is used to obtain the score of the degree to which the pixel is affected by the input source language text, and then the initial diffuse attention matrix and the generated image corresponding to the source language text are obtained.

[0116] Optionally, the initial multimodal machine translation model based on the text-image attention mechanism includes Efficientnet, Transformer encoder and selective attention mechanism;

[0117] The first determining module 4030 is used to:

[0118] S51, encoding the source language text based on a Transformer encoder to obtain a text vector;

[0119] S52, encoding the generated image corresponding to the source language text based on EfficientNet to obtain visual features;

[0120] S53, performing interpolation processing on the visual features based on a bilinear interpolation algorithm to obtain interpolated visual features;

[0121] S54, selecting the interpolated visual features according to the attention mechanism to obtain the selected visual features;

[0122] S55. Determine an attention matrix during training according to the text vector and the selected visual features.

[0123] Optionally, the first determining module 4030 is configured to:

[0124] According to the following formula (1), the visual feature is interpolated to obtain the interpolated visual feature:

[0125] (1)

[0126] in, Represents visual features, represents the bilinear interpolation processing function, Represents the interpolated visual features, and the size of the interpolated visual features is 64×64×1280.

[0127] Optionally, the first determining module 4030 is configured to:

[0128] The interpolated visual features are selected according to the following formula (2) to obtain the selected visual features:

[0129] (2)

[0130] in, Represents the visual features after selection, represents a text vector, represents the visual features after interpolation, is the first variable to be trained, is the second variable to be trained, is the third variable to be trained, yes Dimension.

[0131] Optionally, the first determining module 4030 is configured to:

[0132] According to the following formula (3), the attention matrix during training is determined:

[0133] (3)

[0134] in, represents the attention matrix during training, represents a text vector, represents the visual features after interpolation, yes The dimension of is the first variable to be trained, is the second variable to be trained.

[0135] Optionally, the calculation module 4060 is used to:

[0136] According to the following formula (4), the diffuse attention matrix and the attention matrix during training, the first loss function is determined:

[0137] (4)

[0138] Among them, N represents the total number of words in the source language text after word segmentation. represents the attention matrix of the visual attention generated by the i-th word during training, represents the diffusion attention matrix obtained by the i-th word in the text-image generation process, Represents the first loss function.

[0139] The embodiment of the present invention proposes to supervise the text-image attention mechanism in the cross-modal training process through the correspondence between the text and visual information in the text-image generation process, and for the first time uses the attention matrix generated in the text-image generation process to supervise the text-image attention matrix in the training process. The MSE loss function is used for supervision, and an alignment method including a unified matrix size and a unified word granularity is proposed to bring the attention matrix generated in the text-image generation process and the attention matrix generated in the translation process closer, optimize the text-image attention in cross-modal interaction, and let the text pay attention to the visual information of the corresponding area in the picture, thereby improving the performance of cross-modal tasks, improving the efficiency of training the text-image generation model, and further improving the efficiency of multimodal translation.

[0140] Figure 5 is a schematic diagram of the structure of a multimodal machine translation device provided by an embodiment of the present invention, such as Figure 5 As shown, the multimodal machine translation device may include the above Figure 4 The multimodal machine translation device based on the text-image attention mechanism is shown. Optionally, the multimodal machine translation device 510 may include a first processor 2001 .

[0141] Optionally, the multimodal machine translation device 510 may further include a memory 2002 and a transceiver 2003 .

[0142] The first processor 2001, the memory 2002 and the transceiver 2003 may be connected via a communication bus.

[0143] Combine the following Figure 5 The components of the multimodal machine translation device 510 are described in detail:

[0144] The first processor 2001 is the control center of the multimodal machine translation device 510, and can be a processor or a general term for multiple processing elements. For example, the first processor 2001 is one or more central processing units (CPUs), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention, such as one or more microprocessors (digital signal processors, DSPs), or one or more field programmable gate arrays (field programmable gate arrays, FPGAs).

[0145] Optionally, the first processor 2001 may perform various functions of the multimodal machine translation device 510 by running or executing a software program stored in the memory 2002 and calling data stored in the memory 2002 .

[0146] In a specific implementation, as an embodiment, the first processor 2001 may include one or more CPUs, such as Figure 5 CPU0 and CPU1 are shown in FIG.

[0147] In a specific implementation, as an embodiment, the multimodal machine translation device 510 may also include multiple processors, such as Figure 5 The first processor 2001 and the second processor 2004 are shown in FIG. Each of these processors may be a single-core processor (single-CPU) or a multi-core processor (multi-CPU). The processor here may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).

[0148] The memory 2002 is used to store the software program for executing the solution of the present invention, and is controlled to be executed by the first processor 2001. The specific implementation method can refer to the above method embodiment, which will not be repeated here.

[0149] Optionally, the memory 2002 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 2002 may be integrated with the first processor 2001, or may exist independently, and may be accessed through the interface circuit ( Figure 5 (not shown) is coupled to the first processor 2001, which is not specifically limited in this embodiment of the present invention.

[0150] The transceiver 2003 is used to communicate with a network device or a terminal device.

[0151] Optionally, the transceiver 2003 may include a receiver and a transmitter ( Figure 5 The receiver is used to implement a receiving function, and the transmitter is used to implement a sending function.

[0152] Optionally, the transceiver 2003 may be integrated with the first processor 2001, or may exist independently and communicate with the first processor 2001 through the interface circuit ( Figure 5 (not shown) is coupled to the first processor 2001, which is not specifically limited in this embodiment of the present invention.

[0153] It should be noted that Figure 5 The structure of the multimodal machine translation device 510 shown in the figure does not constitute a limitation on the router, and the actual knowledge structure recognition device may include more or less components than those shown in the figure, or combine certain components, or arrange the components differently.

[0154] In addition, the technical effects of the multimodal machine translation device 510 can refer to the technical effects of the multimodal machine translation method based on the text-image attention mechanism described in the above method embodiment, which will not be repeated here.

[0155] It should be understood that the first processor 2001 in the embodiment of the present invention may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0156] It should also be understood that the memory in the embodiments of the present invention may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct rambus RAM (DR RAM).

[0157] The above embodiments can be implemented in whole or in part by software, hardware (such as circuits), firmware or any other combination. When implemented by software, the above embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that contains one or more available media sets. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a tape), an optical medium (for example, a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state hard disk.

[0158] It should be understood that the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. A and B can be singular or plural. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship, but it may also indicate an "and / or" relationship. Please refer to the context for specific understanding.

[0159] In the present invention, "at least one" means one or more, and "plurality" means two or more. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can mean: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple.

[0160] It should be understood that in various embodiments of the present invention, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0161] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0162] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described equipment, devices and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0163] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

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

[0165] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0166] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, 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. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program codes.

[0167] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A multimodal machine translation method based on text-image attention mechanism, characterized in that: The method comprises: S1. Build an initial multimodal machine translation model based on text-image attention mechanism; S2, obtain the trained text-image generation model and the source language text; S3, inputting the source language text into a trained text-image generation model, and obtaining an initial diffuse attention matrix and a generated image corresponding to the source language text based on the text-image generation process of the trained text-image generation model, the text vector of the source language text, and the visual features of the generated image corresponding to the source language text; S4, obtaining a translation training sample, wherein the translation training sample includes an input text, an image generated by the input text, and an output text true value; S5, inputting the input text and the image generated by the input text in the translation training sample into the initial multimodal machine translation model based on the text-image attention mechanism, obtaining the attention matrix in the training process based on the text-image attention mechanism and the bilinear interpolation algorithm in the multimodal machine translation model, and extracting the word segmentation results in the training process; S6. According to the word segmentation results in the training process, the initial diffuse attention matrix is ​​copied to obtain a diffuse attention matrix; S7, using the MSE loss function, calculating a first loss function according to the diffuse attention matrix and the attention matrix during the training process; S8, determining a second loss function according to the predicted output of the multimodal machine translation model and the true value of the output text; S9. According to the first loss function and the second loss function, the initial multimodal machine translation model based on the text-image attention mechanism is trained to obtain a trained multimodal machine translation model based on the text-image attention mechanism; S10, using the trained multimodal machine translation model based on the text-image attention mechanism to obtain an image corresponding to the input text to be searched; The initial multimodal machine translation model based on the text-image attention mechanism includes Efficientnet, Transformer encoder and selective attention mechanism; The S5 is based on the text-image attention mechanism and bilinear interpolation algorithm in the multimodal machine translation model to obtain the attention matrix during the training process, including: S51, encoding the source language text based on a Transformer encoder to obtain a text vector; S52, encoding the generated image corresponding to the source language text based on EfficientNet to obtain visual features; S53, performing interpolation processing on the visual features based on a bilinear interpolation algorithm to obtain interpolated visual features; S54, selecting the interpolated visual features according to the attention mechanism to obtain the selected visual features; S55, determining an attention matrix during training according to the text vector and the selected visual features; The step S53 of interpolating the visual features based on a bilinear interpolation algorithm to obtain interpolated visual features includes: According to the following formula (1), the visual feature is interpolated to obtain the interpolated visual feature: (1) in, Represents visual features, represents the bilinear interpolation processing function, Represents the interpolated visual features, and the size of the interpolated visual features is 64×64×1280.

2. The multimodal machine translation method based on text-image attention mechanism according to claim 1, characterized in that: The trained text-image generation model is a trained Stable Diffusion model; The step S3 inputs the source language text into a trained text-image generation model, and obtains an initial diffuse attention matrix and a generated image corresponding to the source language text based on the text-image generation process of the trained text-image generation model, the text vector of the source language text, and the visual features of the generated image corresponding to the source language text, including: The source language text is input into the trained Stable Diffusion model, and the diffuse attention technology with attribution map is used to obtain the score of the degree to which the pixel is affected by the input source language text, and then the initial diffuse attention matrix and the generated image corresponding to the source language text are obtained.

3. The multimodal machine translation method based on text-image attention mechanism according to claim 1, characterized in that: The step S54 selects the interpolated visual features according to the attention mechanism to obtain the selected visual features, including: The interpolated visual features are selected according to the following formula (2) to obtain the selected visual features: (2) in, Represents the visual features after selection, represents a text vector, represents the visual features after interpolation, is the first variable to be trained, is the second variable to be trained, is the third variable to be trained, yes Dimension.

4. The multimodal machine translation method based on text-image attention mechanism according to claim 1, characterized in that: The step S55 of determining the attention matrix during training according to the text vector and the selected visual feature includes: According to the following formula (3), the attention matrix during training is determined: (3) in, represents the attention matrix during training, represents a text vector, represents the visual features after interpolation, yes The dimension of is the first variable to be trained, is the second variable to be trained.

5. The multimodal machine translation method based on text-image attention mechanism according to claim 1, characterized in that: The S7 uses the MSE loss function to calculate a first loss function according to the diffuse attention matrix and the attention matrix during the training process, including: According to the following formula (4), the diffuse attention matrix and the attention matrix during training, the first loss function is determined: (4) Among them, N represents the total number of words in the source language text after word segmentation. represents the attention matrix of the visual attention generated by the i-th word during training, represents the diffusion attention matrix obtained by the i-th word in the text-image generation process, Represents the first loss function.

6. A multimodal machine translation device based on a text-image attention mechanism, wherein the multimodal machine translation device based on a text-image attention mechanism is used to implement the multimodal machine translation method based on a text-image attention mechanism as claimed in any one of claims 1 to 5, characterized in that: The device comprises: Construction module, used to build the initial multimodal machine translation model based on the text-image attention mechanism; The first acquisition module is used to acquire the trained text-image generation model and the source language text; A first determination module is used to input the source language text into a trained text-image generation model, and obtain an initial diffuse attention matrix and a generated image corresponding to the source language text based on the text-image generation process of the trained text-image generation model, the text vector of the source language text, and the visual features of the generated image corresponding to the source language text; A second acquisition module is used to acquire a translation training sample, wherein the translation training sample includes an input text, an image generated by the input text, and an output text truth value; The second determination module is used to input the input text and the image generated by the input text in the translation training sample into the initial multimodal machine translation model based on the text-image attention mechanism, obtain the attention matrix in the training process based on the text-image attention mechanism and the bilinear interpolation algorithm in the multimodal machine translation model, and extract the word segmentation results in the training process; A copy module is used to copy the initial diffuse attention matrix according to the word segmentation results in the training process to obtain a diffuse attention matrix; A calculation module, configured to calculate a first loss function according to the diffuse attention matrix and the attention matrix during the training process using an MSE loss function; A third determination module, configured to determine a second loss function according to the predicted output of the multimodal machine translation model and the true value of the output text; A training module, used for training the initial multimodal machine translation model based on the text-image attention mechanism according to the first loss function and the second loss function, to obtain a trained multimodal machine translation model based on the text-image attention mechanism; A search module, used to use the trained multimodal machine translation model based on the text-image attention mechanism to obtain an image corresponding to the input text to be searched; The initial multimodal machine translation model based on the text-image attention mechanism includes Efficientnet, Transformer encoder and selective attention mechanism; The first determining module 4030 is used to: S51, encoding the source language text based on a Transformer encoder to obtain a text vector; S52, encoding the generated image corresponding to the source language text based on EfficientNet to obtain visual features; S53, performing interpolation processing on the visual features based on a bilinear interpolation algorithm to obtain interpolated visual features; S54, selecting the interpolated visual features according to the attention mechanism to obtain the selected visual features; S55, determining an attention matrix during training according to the text vector and the selected visual feature; Wherein, the first determining module 4030 is used to: According to the following formula (1), the visual feature is interpolated to obtain the interpolated visual feature: (1) in, Represents visual features, represents the bilinear interpolation processing function, Represents the interpolated visual features, and the size of the interpolated visual features is 64×64×1280.

7. A multimodal machine translation device, characterized in that: The multimodal machine translation device comprises: processor; A memory having computer-readable instructions stored thereon, wherein when the computer-readable instructions are executed by the processor, the method according to any one of claims 1 to 5 is implemented.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program codes, which can be called by a processor to execute the method according to any one of claims 1 to 5.