Construction method and application of cross-modal retrieval model based on multi-layer attention mechanism
By introducing a multi-layer attention mechanism into the cross-modal retrieval model, learning global and local information of image and text features, optimizing model parameters, solving the problem of failing to effectively utilize multi-modal semantic information in the existing technology, and significantly improving improve the accuracy and performance of cross-modal retrieval.
Patent Information
- Application Number
- CN202110995974.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-27
- Publication Date
- 2024-09-10
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing cross-modal retrieval methods fail to fully utilize the semantic information in multi-modal data and fail to effectively consider the semantic relationships between different modalities, resulting in low retrieval accuracy.
A cross-modal retrieval model based on a multi-layer attention mechanism is used to learn the global feature correspondence and fine-grained contextual local information between image and text features through the cascaded feature extraction module, multi-modal fusion module and common representation module. , calculate the loss function between different modes and within the mode, and optimize the model parameters to improve the retrieval accuracy.
Through the multi-layer attention mechanism model, the semantic information of multi-modal data is fully utilized to improve the accuracy of cross-modal retrieval, retain the discriminability of different semantic data and eliminate the differences between modalities, improving retrieval. performance.
Smart Images

Figure CN113779361B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of data retrieval technology, and more specifically, relates to a construction method and application of a cross-modal retrieval model based on a multi-layer attention mechanism. Background Art
[0002] General search engines on the Internet, such as Google, Baidu, and Yahoo, only accept text-based retrieval methods and can only provide services that use text keywords as retrieval content, but do not support services that use multimodal information for retrieval. Using only text for querying often cannot accurately obtain the query results we want, and because the text keywords entered by users are usually subjective, it is difficult to accurately and comprehensively describe multimedia information, which greatly affects the user experience of using search engines.
[0003] Compared with traditional retrieval methods, cross-modal retrieval tasks mainly search for data of different modalities, inputting data of one modality as query conditions to find related data of another modality. With the rapid development of information technology, multimodal data has become the main form of big data, and how to enable computers to understand multimodal data has become an important topic worthy of research. Multimodal data is diverse and semantically rich. Different modal data describe the characteristics of objects from different angles. Therefore, the method of using multimodal data to perceive the external world is often closer to the main form of human understanding of the world. The semantic understanding and knowledge representation of multimodal data requires computers to be able to perceive and understand real data scenarios, and to further reason about the perceived knowledge. However, it is very difficult for computers to process different forms of multimedia information such as dynamic video, audio and other forms of data. Therefore, this topic has a very broad research significance.
[0004] On the other hand, cross-modal retrieval services in massive data have a wide range of application scenarios. Cross-modal retrieval has promoted the development of traditional search engines and proposed a novel search method. Users can use different data forms to retrieve information at will, such as using pictures to search for audio songs or using text news to search for videos. Cross-modal retrieval also plays an important role in some special information query scenarios, such as searching for relevant facial images of criminals in videos based on the portrait information of criminals provided by witnesses, and submitting photos of scenic spots when traveling to retrieve the corresponding text descriptions of the scenic spots.
[0005] At present, data retrieval based on a single modality has been widely and deeply studied. They can be divided into keyword-based retrieval and content-based retrieval methods, such as text retrieval, image retrieval, and video retrieval. Due to the rapid growth of different types of data such as pictures, texts, and videos, multimodal data has greatly promoted the development of cross-modal retrieval technology and put forward higher requirements for retrieval between different modal data. Cross-modal retrieval can help users obtain comprehensive information about target events, so it has great application value in the real world and has attracted widespread attention from industry and academia in recent years.
[0006] The main challenge of cross-modal retrieval is to retain the semantic information between different modalities and calculate the similarity between different modal data. First of all, the data between different modalities have different dimensions. How to reduce the heterogeneity between different modalities and represent the data of different modalities in a unified way is a very important issue. At the same time, how to cover the semantic information of each modal data itself as much as possible in the final representation of multimodal data without losing important semantics is also a challenging problem. Many methods have been proposed to solve the above problems, but they all have some shortcomings, specifically:
[0007] (1) Methods based on statistical correlation analysis. In order to eliminate the heterogeneity between different modalities, methods based on statistical correlation analysis calculate the similarity between different modal data by learning a common subspace. Although this method has high learning efficiency and is easy to operate, it is difficult to fully simulate the complex correlation of cross-media data in the real world through linear projection alone, and most methods can only simulate two media types.
[0008] (2) Methods based on cross-modal hashing. Existing cross-modal hashing methods map data of different modalities to the same space for calculation by learning one or more hash functions. However, since the similarities between heterogeneous data containing rich semantic information are ignored, many cross-modal hashing methods cannot obtain strong hash codes, resulting in poor retrieval performance.
[0009] (3) Methods based on deep learning. Methods based on deep learning can well preserve the differences between samples with different semantics and learn discriminative features by minimizing the discriminative loss of samples in the label space and the common representation space. However, most previous methods embed images and texts separately into a common space to compare their similarities, and rarely consider the relationship between images and texts. Summary of the invention
[0010] In response to the above defects or improvement needs of the prior art, the present invention provides a method for constructing and applying a cross-modal retrieval model based on a multi-layer attention mechanism, so as to solve the technical problem that the existing cross-modal retrieval method does not fully utilize the semantic information in the original data, only considers the relationship of a single modality, and does not consider the semantic relationship within each modality and between different modalities, resulting in low retrieval accuracy.
[0011] In order to achieve the above objectives, in a first aspect, the present invention provides a method for constructing a cross-modal retrieval model based on a multi-layer attention mechanism, comprising the following steps:
[0012] S1. Build a cross-modal retrieval model; the cross-modal retrieval model includes a cascaded feature extraction module, a multimodal fusion module and a common representation module;
[0013] In the training phase, the feature extraction module is used to extract features from the image modality and text modality data of each image-text data pair in the pre-collected image-text data set, respectively, to obtain text features and image features of each image-text data pair; wherein the image-text data set includes a plurality of image-text data pairs and their corresponding semantic label vectors; the image-text data pair includes image modality data and its corresponding text modality data;
[0014] The multimodal fusion module is used to learn the fine-grained contextual local information in the text features and image features of each image-text data pair based on the multi-layer attention mechanism, as well as the global feature correspondence between the text features and image features, so as to further extract the text features and image features and output them to the common representation module;
[0015] The common representation module is used to map the text features and image features input by the multimodal fusion module to the common representation space respectively, and obtain the semantic representation vector of each image-text data pair; the semantic representation vector of the image-text data pair includes the semantic representation vector of the image modality data and the semantic representation vector of the text modality data;
[0016] The feature extraction module includes a first input terminal and a second input terminal, the image modality data is input into the cross-modal retrieval model via the first input terminal, and the text modality data is input into the cross-modal retrieval model via the second input terminal; the common representation module includes a first output terminal and a second output terminal, the semantic representation vector of the image-text data pair is output from the cross-modal retrieval model via the first output terminal, and the semantic representation vector of the text modality data is output from the cross-modal retrieval model via the second output terminal;
[0017] S2. Based on the semantic label vector and semantic representation vector of each image-text data pair, calculate the invariance loss between the image modality and the text modality, the label space loss, and the discrimination loss between different modalities and within each modality in the common representation space, and add different weights to obtain the loss function of the cross-modal retrieval model;
[0018] S3. Train the cross-modal retrieval model by minimizing the loss function of the cross-modal retrieval model to obtain a trained cross-modal retrieval model.
[0019] Further preferably, the multimodal fusion module includes a plurality of cascaded MCA layers and a dimension reduction unit located after the last MCA layer;
[0020] The MCA layer is used to learn the global feature correspondence between text features and image features based on the collaborative attention mechanism, and to learn the fine-grained contextual local information within text features and image features based on the self-attention mechanism;
[0021] The dimension reduction unit is used to reduce the dimension of the text features and image features input by the multimodal fusion module respectively.
[0022] Further preferably, the MCA layer includes a first self-attention unit, a first fully connected layer, a second self-attention unit, a collaborative attention unit, and a second fully connected layer; the output end of the first self-attention unit is connected to the input end of the first fully connected layer; the output end of the second self-attention unit is connected to the input end of the collaborative attention unit; the output end of the collaborative attention unit is connected to the input end of the second fully connected layer;
[0023] The first self-attention unit is used to extract the latent semantic relationship within the text modality based on the self-attention mechanism to learn the fine-grained local context information within the text features, thereby further extracting the text features;
[0024] The second self-attention unit is used to extract the latent semantic relationship within the image modality based on the self-attention mechanism to learn the fine-grained contextual local information within the image features, thereby further extracting the image features;
[0025] The collaborative attention unit is used to extract the semantic relationship between the image modality and the text modality based on the collaborative attention mechanism, realize the learning process of the text features guiding the image features, and thus learn the global feature correspondence between the text features and the image features to fuse the text features into the image features.
[0026] Further preferably, for a non-last-level MCA layer, the output end of its first fully connected layer is respectively connected to the input end of the collaborative attention unit and the input end of the first self-attention unit of the next-level MCA layer; the output end of the second fully connected layer is connected to the input end of the second self-attention unit of the next-level MCA layer;
[0027] For the last-level MCA layer, the output end of its first fully connected layer is connected to the input end of the collaborative attention unit and the input end of the dimension reduction unit respectively; the output end of the second fully connected layer is connected to the input end of the dimension reduction unit.
[0028] Further preferably, for a non-last-level MCA layer, the output end of its first fully connected layer is connected to the input end of the first self-attention unit of the next-level MCA layer; the output end of the second fully connected layer is connected to the input end of the second self-attention unit of the next-level MCA layer;
[0029] For the last-level MCA layer, the output end of its first fully connected layer is respectively connected to the input end of the collaborative attention unit of each level before it and the input end of the dimension reduction unit; the output end of the second fully connected layer is connected to the input end of the dimension reduction unit.
[0030] In a second aspect, the present invention provides a cross-modal retrieval method based on a multi-layer attention mechanism, comprising:
[0031] After mapping the target query data to a common representation space based on the cross-modal retrieval model constructed by the above-mentioned cross-modal retrieval model construction method, a semantic representation vector of the target query data is obtained, and the similarity between the target query data and the data in the database is calculated by calculating the similarity between the semantic representation vector of the target query data and the semantic representation vector of the data in the database, thereby obtaining a corresponding retrieval ranking result;
[0032] Among them, the semantic representation vector of the data in the database is obtained by mapping using the above-mentioned cross-modal retrieval model.
[0033] Further preferably, in the cross-modal retrieval model constructed by the above-mentioned cross-modal retrieval model construction method, the first input end of the feature extraction module to the first output end of the public representation module forms an image channel for mapping the image modality data into the public representation space; the second input end of the feature extraction module to the second output end of the public representation module forms a text channel for mapping the text modality data into the public representation space;
[0034] The target query data or the data in the database are mapped into the common representation space using the corresponding channels according to their modalities.
[0035] Further preferably, the similarity between the target query data and the data in the database with different modalities is calculated to obtain cross-modal data similarity; the similarity between the target query data and the data in the database with different modalities is calculated to obtain homomodal data similarity; and the similarity between the target retrieval data and the data in the database is obtained by taking a weighted average of the cross-modal data similarity and the homomodal data similarity.
[0036] In a third aspect, the present invention also provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement any one of the cross-modal retrieval model construction methods and / or the cross-modal retrieval method as described above.
[0037] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects:
[0038] 1. The present invention provides a method for constructing a cross-modal retrieval model based on a multi-layer attention mechanism. By considering the mutual influence between different modalities, the attention mechanism is cascaded into a multi-layer neural network. The global feature correspondence between text and image and the fine-grained contextual local information in the text and image are learned based on different attention mechanisms. The present invention makes full use of the semantic information in the original data, fuses multimodal features, and greatly improves the accuracy of cross-modal retrieval.
[0039] 2. The present invention provides a method for constructing a cross-modal retrieval model based on a multi-layer attention mechanism, wherein the multimodal fusion module includes a self-attention unit and a collaborative attention unit. The self-attention unit is used to learn the local contextual information within the modality, and the collaborative attention unit is used to learn the global interaction information of different modal data. The self-attention unit and the collaborative attention unit are then stacked into a multi-layer neural network structure, and the results of text feature encoding are used to guide the learning process of image features.
[0040] 3. The method for constructing a cross-modal retrieval model based on a multi-layer attention mechanism provided by the present invention calculates the label space loss, the loss within each modality and between different modalities in the common representation space, and the invariance loss between the image and text modalities, and adds different weights to obtain the loss function of the retrieval model; the parameters of the retrieval model are optimized by minimizing the loss function to obtain the optimized retrieval model. Due to the use of an end-to-end deep learning-based model framework, the global information of multimodal data is fully utilized to learn the fine-grained features between different modalities, which not only retains the discriminability of different semantic data samples, but also eliminates the differences between cross-modal data.
[0041] 4. Since the learning ability of shallow models is limited and they cannot capture the semantic associations of data of different modalities at a deeper level, the present invention proposes a method for cross-modal semantic fusion based on a multi-layer attention mechanism. This method cascades the attention mechanism into a multi-layer neural network and uses different attention units to learn the global feature correspondence between text and images and the fine-grained contextual local information within the text and image, thereby improving the cross-modal retrieval performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 A schematic diagram of a method for constructing a cross-modal retrieval model based on a multi-layer attention mechanism provided in Example 1 of the present invention;
[0043] Figure 2 A schematic diagram of the cross-modal retrieval model structure provided in Example 1 of the present invention;
[0044] Figure 3 A schematic diagram of the structure of a self-attention unit SA provided in Embodiment 1 of the present invention;
[0045] Figure 4 A schematic diagram of the structure of the collaborative attention unit GA provided in Example 1 of the present invention;
[0046] Figure 5 A schematic diagram of the structure of a multimodal fusion module based on a stacking structure provided in Example 1 of the present invention;
[0047] Figure 6 A schematic diagram of the structure of a multimodal fusion module based on an encoder-decoder structure provided in Embodiment 1 of the present invention;
[0048] Figure 7 Schematic diagram of the MCA layer structure provided in Example 1 of the present invention; wherein (a) is a schematic diagram of the first MCA layer structure, (b) is a schematic diagram of the second MCA layer structure, and (c) is a schematic diagram of the third MCA layer structure. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0050] Embodiment 1,
[0051] A method for constructing a cross-modal retrieval model based on a multi-layer attention mechanism, such as Figure 1 As shown, the following steps are included:
[0052] S1. Build a cross-modal retrieval model;
[0053] Specifically, Figure 2 As shown, the cross-modal retrieval model includes a cascaded feature extraction module, a multimodal fusion module and a common representation module;
[0054] For the feature extraction module:
[0055] In the training phase, the feature extraction module is used to extract features from the image modality and text modality data of each image-text data pair in the pre-collected image-text data set, respectively, to obtain text features and image features of each image-text data pair; wherein the image-text data set includes multiple image-text data pairs and their corresponding semantic label vectors; the image-text data pair includes image modality data and its corresponding text modality data. The image-text data set of this embodiment includes n image-text data pairs, denoted as in, is the data of the i-th image modality, is the data of the i-th text modality. Each image-text pair corresponds to a semantic label vector lable i =[lable 1i ,label 2i ,…,label ci ], c represents the number of directories. If the i-th instance belongs to the j-th directory, the corresponding component in the label vector is 1, otherwise it is 0. It should be noted that the image modality data and text modality data in the image and text dataset are all preprocessed data; the preprocessing of the image modality data includes resizing, cropping, normalization, etc.; the preprocessing of the text modality data includes denoising, word segmentation, stop word filtering, etc.
[0056] Specifically, the feature extraction module includes a first input end and a second input end. The data of the image modality is input into the cross-modal retrieval model via the first input end, and the data of the text modality is input into the cross-modal retrieval model via the second input end. The feature extraction module includes two parallel sub-networks for performing feature extraction on the data of the image modality and the data of the text modality respectively. Among them, the input end of the first sub-network is the first input end of the feature extraction module, which is used to extract the data of the image modality; the input end of the second sub-network is the second input end of the feature extraction module, which is used to extract the data of the text modality.
[0057] Feature extraction of image modal data: The first subnetwork includes a serially connected image extraction subnetwork and a first fully connected layer; wherein, a convolutional neural network is usually used as an image extraction subnetwork to obtain a feature representation of image modal data. A convolution operation is performed between the convolution kernel in the convolutional neural network and the input image to convert the read image information into a vector in the feature map. In addition, due to the end-to-end training method, the model needs to control the feature dimensions of each level through the pooling layer, and finally represent the image as a feature vector of a specific dimension. The convolutional neural network stacks multiple convolutional layers, and image features can be extracted in a more abstract way. Since convolutional neural networks have very unique advantages in the field of image recognition, specific convolutional neural networks can be used to extract features from images in the cross-modal retrieval process. This embodiment uses the VGG16 model as a tool for image feature extraction, and the image is preprocessed and input into the model, and then the 4096-dimensional vector output by the penultimate layer of the model is used as the image feature extraction result.
[0058] Feature extraction of text modal data: The second subnetwork includes a text extraction subnetwork and a second fully connected layer connected in series; the text extraction subnetwork usually adopts a feature extraction method based on a language model to convert text information from an unstructured original text into a multi-dimensional vector. In this embodiment, the text extraction subnetwork is BERT. BERT uses the Transformer structure to construct a multi-layer bidirectional encoder network, which can directly convert the original text into a high-level semantic vector form with semantic features, and has achieved good results in natural language processing tasks. In the use of BERT, you first need to load the Chinese and English pre-trained models, and then input the pre-processed text into the pre-trained model to obtain a vector of a specific dimension, and finally output the generated multi-dimensional feature vector to the cross-modal retrieval model for attention learning.
[0059] For the multimodal fusion module:
[0060] In the training phase, the multimodal fusion module is used to learn the fine-grained local context information of the text features and image features of each image-text data pair based on the multi-layer attention mechanism, as well as the global feature correspondence between the text features and image features, so as to further extract the text features and image features and output them to the common representation module;
[0061] The present invention introduces a multi-layer cascaded attention mechanism in the cross-modal retrieval process, each layer is called an MCA unit, and each layer is composed of one or more GAs and SAs. SA represents a self-attention unit, which is used to extract the potential semantic relationship within each modality, and GA represents a collaborative attention unit, which is used to extract the semantic relationship between different modalities. An MCA layer can be formed by connecting SA and GA in series, and then multiple MCAs can be connected in series to form a multi-layer attention mechanism. This complex multi-layer structure can better realize complex reasoning operations compared to shallow models. Considering the influence of image modality on the representation form of text modality, the present invention introduces an attention mechanism and a multi-layer attention mechanism to further fuse the input text features and image features. Among them, the attention mechanism includes self-attention and collaborative attention mechanisms. Self-attention and collaborative attention mechanisms can be used to mine the content similarity of image modality and text modality, and improve the performance of cross-modal retrieval by fusing multi-modal information. The multi-layer attention mechanism can realize fine-grained interaction between multi-modal features. Specifically, the multimodal fusion module includes multiple cascaded MCA layers and a dimension reduction unit located after the last MCA layer; the MCA layer is used to learn the global feature correspondence between text features and image features based on the collaborative attention mechanism, and to learn the fine-grained contextual local information within text features and image features based on the self-attention mechanism. In addition, after the feature vector passes through multiple MCA layers, the dimension is usually relatively high. In order to reduce the dimension of the extracted features, it is necessary to reduce the dimension through a dimension reduction unit; in this implementation, the dimension reduction unit is a multi-layer perceptron MLP.
[0062] Specifically, the MCA layer includes a first self-attention unit SA1, a first fully connected layer FF1, a second self-attention unit SA2, a collaborative attention unit GA and a second fully connected layer FF2; the output end of the first self-attention unit SA1 is connected to the input end of the first fully connected layer FF1; the output end of the second self-attention unit SA2 is connected to the input end of the collaborative attention unit GA; the output end of the collaborative attention unit GA is connected to the input end of the second fully connected layer FF2; wherein, the first self-attention unit SA1 is used to extract the latent semantic relationship within the text modality based on the self-attention mechanism, so as to learn the fine-grained contextual local information within the text features, so as to further extract the text features; the second self-attention unit SA2 is used to extract the latent semantic relationship within the image modality based on the self-attention mechanism, so as to learn the fine-grained contextual local information within the image features, so as to further extract the image features; the collaborative attention unit GA is used to extract the semantic relationship between the image modality and the text modality based on the collaborative attention mechanism, realize the learning process of the text features guiding the image features, thereby learning the global feature correspondence between the text features and the image features, so as to fuse the text features into the image features. The text features are input into the multimodal fusion module, first into the first self-attention unit SA1 in each MCA layer, and then into the first fully connected layer FF1; the image features are input into the multimodal fusion module, first through the second self-attention unit SA2 in each MCA layer, then into the collaborative attention unit GA, and finally into the second fully connected layer FF2. Multiple MCA layers can be cascaded to form a multi-layer attention mechanism. This complex multi-layer structure can better implement complex reasoning operations compared to shallow models. In this embodiment, the number of MCA layers is L, and the image features X and text features Y obtained by the feature extraction module are input into the multimodal fusion module for attention learning. For the MCA layer, the input of each layer is the output of the previous layer, that is, [X (l) ,Y (l) ]=MCA (l) ([X (l-1) ,Y (l-1) ]), where l=2,3,…,L.
[0063] Specifically, Figure 3 The self-attention unit SA is shown as Figure 4 The collaborative attention unit GA is shown; the self-attention unit is used to learn the relationship within the modality, while the collaborative attention unit is used to learn the attention mechanism of the relationship between different modalities. Its calculation process is similar to that of the self-attention unit. The main difference is that the input is data of two different modalities X and Y. Specifically, in this embodiment, the self-attention unit SA and the collaborative attention unit GA are both composed of a multi-head attention layer, a feedforward layer, and a normalization layer (Add&LayerNorm).
[0064] The self-attention mechanism uses Scaled Dot-ProductAttention to calculate the attention mechanism of the internal information of the modality, where Q, K, and V represent the question, keyword, and value respectively. The specific method is to first dot-product K and Q, and then divide by where d k The dimensions representing K and Q are generally set to the same size, and then the weight of V is obtained through softmax, and finally the weighted sum is performed to obtain the attention result, which is specifically expressed as: If a query Q∈R 1×d And n keyword key and value value pairs, where d is the dimension of question Q, then K∈R n×d , V∈R n×d ,in is the scaling factor. Using point multiplication can achieve faster and more efficient operations. The self-attention unit SA takes the input feature vector (image feature X or text feature Y) as K, V, Q respectively, and then inputs it into the multi-head attention layer. Through multi-head attention, the relationship between the feature vectors is learned point by point, and all the outputs are weighted summed as the final result. In addition to the multi-head attention layer that performs linear transformation, the self-attention unit SA also introduces another basic component, the feedforward network layer, to increase the nonlinearity of the model. The feedforward network layer takes the output features of the multi-head attention layer as its input and further transforms them using two fully connected layers (including ReLU and Dropout layers). The feedforward layer further transforms the learned attention and finally normalizes it. Among them, the multi-head attention layer uses h parallel heads, each head corresponds to a different scaled attention, and finally obtains different Attention, which can more effectively mine features in multiple dimensions. Specifically, the output result of the multi-head attention layer is expressed as:
[0065] MultiHead(Q,K,V)=[head1,head2,head3···head h ]W o
[0066] head j =Attention(QW j Q ,KW j K ,VW j V ), j = 1, 2, ..., h
[0067] in, is the projection matrix of the j-th head, which is used to generate the attention result of the j-th head; Used to splice the results; d h Represents the output dimension of each attention head, usually d h = d / h; set Q = [q1,q2....,q m ]∈R m×d , then the output feature F∈R of the jth head is obtained m×d .
[0068] Similarly, the collaborative attention unit GA inputs the image feature X as Q and the text feature Y as K and V into the multi-head attention layer, learns the relationship between the two point by point, and finally realizes the text feature Y to guide the learning process of the image feature X.
[0069] It should be noted that compared with the shallow attention model, the model proposed in the present invention requires multi-layer stacking of MCA to generate a more complex network for interactive learning, thereby generating more discriminative text and visual features. There are two ways to design the multimodal fusion module. One way is to use a stacking structure, that is, the output of each MCA layer is used as the input of the next MCA layer; the other way is to use an encoder-decoder structure, and the output of the last layer of the encoder composed of multiple MCA layers is used as the input of each layer of the decoder, so as to guide the learning of image features based on text features.
[0070] Specifically, Figure 5 The figure shows a schematic diagram of the structure of a multimodal fusion module based on a stacking structure (taking L=3 as an example); for non-last-level MCA layers, the output of the first fully connected layer is connected to the input of the collaborative attention unit and the input of the first self-attention unit of the next-level MCA layer; the output of the second fully connected layer is connected to the input of the second self-attention unit of the next-level MCA layer; for the last-level MCA layer, the output of the first fully connected layer is connected to the input of the collaborative attention unit and the input of the dimension reduction unit; the output of the second fully connected layer is connected to the input of the dimension reduction unit. The multimodal fusion module based on the stacking structure uses the text features corresponding to the layer and the image features for fusion in each MCA layer, and then inputs the learning results into the next MCA layer. By stacking multiple MCA layers, the model has a deeper reasoning ability.
[0071] like Figure 6The structure diagram of the multimodal fusion module based on the encoder-decoder structure is shown (taking L=3 as an example); wherein, for the non-last MCA layer, the output of its first fully connected layer is connected to the input of the first self-attention unit of the next MCA layer; the output of the second fully connected layer is connected to the input of the second self-attention unit of the next MCA layer; for the last MCA layer, the output of its first fully connected layer is respectively connected to the input of the collaborative attention units of the previous levels and the input of the dimension reduction unit; the output of the second fully connected layer is connected to the input of the dimension reduction unit. For the multimodal fusion module based on the encoder-decoder structure, the text feature Y is first taken as input, and then the final representation Y' of the text feature is obtained through multiple first self-attention units SA1, and Y' is input into the collaborative attention units GA in each MCA layer to guide the learning process of the image modality X, and at the same time, the image modality X selectively extracts its own key information through the second self-attention unit SA2.
[0072] The biggest difference between the multimodal fusion modules under the two structures is whether the final text feature representation is used to guide image learning. The multimodal fusion module based on the encoder-decoder structure uses the final text form for collaborative attention learning to achieve a deeper level of semantic interaction understanding.
[0073] It should be noted that the global feature representation of an image or text may result in the loss of some key information, and this information may involve a local area of the image or a word in the text. In order to solve the above problem, the present invention adopts an attention mechanism. However, a single-layer attention mechanism can only learn rough interactions between multi-modalities, while a multi-layer attention mechanism can achieve fine-grained interactions between multi-modal features. Therefore, the present invention uses a multi-layer cascaded attention model. As for the MCA layer structure proposed in the present invention, the MCA layer, that is, the component modular joint attention layer, can use different self-attention units SA and collaborative attention units GA to form an MCA layer structure. Three forms are listed below, among which the first MCA layer structure is as follows: Figure 7 As shown in Figure (a), only a collaborative attention unit GA is used in the image modality without processing the text features. The collaborative attention mechanism is used to guide the learning process of image features and capture the subtle interactions between the two modal data. The second MCA layer structure is shown in Figure 7 As shown in Figure (b), in the text modality, the self-attention unit SA is used to selectively focus on the relationship within the text, and the collaborative attention unit GA is used in the image modality to fuse the information between the text modality and the image modality. This method not only considers the potential semantic features within the modality, but also considers the semantic association between the modalities. The third MCA layer structure is the structure adopted by the present invention, such as Figure 7 As shown in Figure (c), the first self-attention unit SA1 is used for feature extraction in the text modality, and a second self-attention unit SA2 and a collaborative attention unit GA are used in the other modality. Compared with the other two structures, the MCA layer structure adopted in the present invention also takes the attention mechanism of the image modality itself into consideration to obtain a richer image feature representation.
[0074] For public representation modules:
[0075] The common representation module is used to map the text features and image features input by the multimodal fusion module to the common representation space respectively, and obtain the semantic representation vector of each image-text data pair; the semantic representation vector of the image-text data pair includes the semantic representation vector of the image modality data and the semantic representation vector of the text modality data; the common representation module includes a first output end and a second output end, the semantic representation vector of the image-text data pair is output from the cross-modality retrieval model via the first output end, and the semantic representation vector of the text modality data is output from the cross-modality retrieval model via the second output end;
[0076] Specifically, in this embodiment, the common representation module is the third fully connected layer, and the extracted image data features and text data features are mapped to the common representation space through the shared fully connected layer.
[0077] S2. Based on the semantic label vector and semantic representation vector of each image-text data pair, calculate the invariance loss between the image modality and the text modality, the label space loss, and the discrimination loss between different modalities and within each modality in the common representation space, and add different weights to obtain the loss function of the cross-modal retrieval model;
[0078] Specifically, according to the relevant theories of deep learning, Loss is defined as the overall objective function of the model, which is the linear weighted loss of three loss functions, namely, the label space loss L1 (i.e., the loss between the label space and the public representation space), the discrimination loss L2 between different modalities and within each modality in the public representation space, and the invariance loss L3 between the image modality and the text modality (i.e., the distance loss between all image-text representation pairs). Since the three losses L1, L2, and L3 have different corresponding influences, they are given different weights. Specifically, the loss function of the cross-modal retrieval model is:
[0079] Loss=λL1+μL2+ηL3
[0080] Among them, λ, μ, and η are the weight coefficients of L1, L2, and L3 respectively.
[0081] Specifically, a linear classifier is added after the third fully connected layer to predict the categories of image modality data and text modality data, and compared with the true categories to calculate the label space loss. The label space loss is used to measure the loss between the label space and the common representation space, that is, the difference between the predicted categories of image modality data and text modality data and the corresponding true categories (i.e., semantic labels), specifically:
[0082]
[0083] Among them, ||·|| F represents the Frobenius norm; α and β are the weights corresponding to the semantic representation vectors of the image modality data and the text modality data respectively; due to the difference in the way of extracting high-level semantic vectors between images and texts, the prediction loss of features mapped to the common representation space is inconsistent, so different weights are given to the image and text prediction labels to balance the difference in prediction loss; P is the projection matrix of the linear classifier; U = [u1,u2,…,u n ] is the prediction representation matrix of the image modality data of the image-text dataset in the common representation space, u i is the semantic representation vector of the data of the i-th image modality in the image-text dataset; V = [v1, v2, …, v n ] is the prediction representation matrix of the text modality data of the image-text dataset in the common representation space, v i is the semantic representation vector of the data of the i-th text modality in the image and text dataset; Lable = [lable1, lable2, …, lable n ] is the matrix corresponding to the semantic label vector; i = 1, 2,…, n.
[0084] The discrimination loss between different modalities and within each modality in the common representation space is:
[0085]
[0086] Among them, Γ ij =cos(u i ,v j ), Φ ij =cos(u i ,u j ), Θ ij = cos(v i ,v j ), cos is the cosine function used to measure similarity, sgn is the sign function, which is 1 if two elements belong to the same class, otherwise it is 0; u i is the semantic representation vector of the data of the i-th image modality in the image-text dataset; vj is the semantic representation vector of the data of the jth text modality in the image and text dataset; i = 1, 2, ..., n, j = 1, 2, ..., n.
[0087] The likelihood function used to measure the similarity between modalities is expressed as follows:
[0088]
[0089] The L2 function is used to measure the similarity of the common representation space and is a criterion for learning discriminant features. It consists of three parts. The first part measures the similarity between the image modality data and the text modality data. The second and third parts calculate the similarity within the image modality data and the text modality data respectively. Since the first part needs to maximize the likelihood function, that is, minimize the negative sign of the logarithm of the likelihood function, it can be deduced that the cosine similarity cos(u i ,v j ) is larger, Γ ij The larger the value, the greater the probability p(1|u i ,v j ) is larger.
[0090] The invariance loss L3 between the image modality and the text modality is the semantic representation vector (u i ,v i ), specifically:
[0091] S3. Train the cross-modal retrieval model by minimizing the loss function of the cross-modal retrieval model to obtain a trained cross-modal retrieval model.
[0092] The present invention supervises the model to learn discriminative features by minimizing the discriminative loss in both the label space and the common representation space. At the same time, the modality-invariant features in the common representation space are learned by minimizing the invariance loss between different modalities and using a weight sharing strategy. According to this learning strategy, both paired label information and classification information are utilized as fully as possible to ensure that the learned representation is discriminative in semantic structure and invariant in all modalities.
[0093] Embodiment 2,
[0094] A cross-modal retrieval method based on a multi-layer attention mechanism, comprising:
[0095] After mapping the target query data to a common representation space based on the cross-modal retrieval model constructed by the cross-modal retrieval model construction method provided in Example 1, a semantic representation vector of the target query data is obtained, and the similarity between the target query data and the data in the database is calculated by calculating the similarity between the semantic representation vector of the target query data and the semantic representation vector of the data in the database, thereby obtaining a corresponding retrieval ranking result;
[0096] Among them, the semantic representation vector of the data in the database is obtained by mapping using the above-mentioned cross-modal retrieval model.
[0097] Specifically, in the cross-modal retrieval model, an image channel is formed from the first input end of the feature extraction module to the first output end of the common representation module, which is used to map the data of the image modality to the common representation space; a text channel is formed from the second input end of the feature extraction module to the second output end of the common representation module, which is used to map the data of the text modality to the common representation space; the target query data or the data in the database is mapped to the common representation space using the corresponding channel according to its modality.
[0098] Preferably, in actual use, the similarity of homomodal data can be added to improve the accuracy of retrieval, specifically: calculate the similarity between the target query data and the data in the database with a different modality to obtain the cross-modal data similarity; calculate the similarity between the target query data and the data in the database with a different modality to obtain the homomodal data similarity; by taking a weighted average of the cross-modal data similarity and the homomodal data similarity, obtain the similarity between the target retrieval data and the data in the database, which is expressed as follows:
[0099] S=εSimilarity(x,U')+γSimilarity(x,V')
[0100] Among them, ε and γ are weights; Similarity(·) is a function to measure similarity; x is the target query data, which can be image modality data or text modality data; U'=[u1',u2',…,u n '] is the representation matrix of the image modality data of the database in the public representation space, u i ' is the semantic representation vector of the data of the i-th image modality in the database; V'=[v1',v2',…,v n '] is the representation matrix of the image modality data of the database in the public representation space, v i ' is the semantic representation vector of the data of the i-th image modality in the database; i = 1, 2, ..., n. The database can be the above-mentioned image and text dataset. S is the final returned result, which is then sorted, and the data with the highest sorting is taken as the final result.
[0101] The relevant technical solution is the same as that in Example 1 and will not be described in detail here.
[0102] Embodiment 3,
[0103] A machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the method for constructing a cross-modal retrieval model described in Example 1 and / or the cross-modal retrieval method described in Example 2.
[0104] The relevant technical solutions are the same as those in Example 1 and Example 2 and will not be described in detail here.
[0105] It should be noted that any reference to storage media, storage, databases or other media used in the present invention may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM), which is used as an external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0106] In summary, the present invention proposes a method for cross-modal semantic fusion based on a multi-layer attention mechanism. In the cross-modal retrieval process, a multi-layer attention mechanism is introduced to extract fine-grained features of text and image data, and learn the potential semantic relationship within a single modality data and between different modalities. By using self-attention units in the model to learn the local context information within the modality, using collaborative attention units to learn the global interactive information of different modal data, and then stacking the self-attention units and collaborative attention units into a multi-layer neural network structure, the results of text feature encoding are used to guide the learning process of image features. Finally, a common space is constructed, in which samples from the same semantic category should be close in space, even if these data may come from different modalities, and samples from different semantic categories should be far apart. Here, the method of shared neural network is used to map data of different modalities to a common space for representation, and the classification results are output with the help of a classifier. In the model training process, it is first necessary to minimize the distance between each image-text pair, and then minimize the discriminant loss in the label space and the common representation space to learn the discriminant representation features of multimodal data. Finally, in order to reduce cross-modal differences, it is necessary to minimize the loss within and between modalities. After the model is trained, the target retrieval data is mapped to the common representation space using the optimized retrieval model, and the similarity between the target retrieval data and the data in the image and text dataset is calculated to obtain the corresponding retrieval ranking results.
[0107] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for constructing a cross-modal retrieval model based on a multi-layer attention mechanism, characterized in that: The following steps are involved: S1. Building a cross-modal retrieval model; the cross-modal retrieval model includes a cascaded feature extraction module, a multimodal fusion module, and a common representation module; During the training phase, the feature extraction module is used to extract features from the image modality and text modality data of each image-text data pair in the pre-collected image-text dataset, respectively, to obtain text features and image features of each image-text data pair; wherein the image-text dataset includes a plurality of image-text data pairs and their corresponding semantic label vectors; and the image-text data pairs include image modality data and their corresponding text modality data; The multimodal fusion module is used to learn the fine-grained contextual local information within the text features and image features of each image-text data pair based on a multi-layer attention mechanism, as well as the global feature correspondence between the text features and the image features, so as to further extract the text features and image features and output them to the common representation module; The common representation module is used to map the text features and image features input by the multimodal fusion module to a common representation space to obtain a semantic representation vector of each image-text data pair; the semantic representation vector of the image-text data pair includes a semantic representation vector of the image modality data and a semantic representation vector of the text modality data; The feature extraction module includes a first input terminal and a second input terminal, and the image modality data is input into the cross-modal retrieval model via the first input terminal, and the text modality data is input into the cross-modal retrieval model via the second input terminal; the common representation module includes a first output terminal and a second output terminal, and the semantic representation vector of the image-text data pair is output from the cross-modal retrieval model via the first output terminal, and the semantic representation vector of the text modality data is output from the cross-modal retrieval model via the second output terminal; S2. Based on the semantic label vector and semantic representation vector of each image-text data pair, calculate the invariance loss between the image modality and the text modality, the label space loss, and the discrimination loss between different modalities and within each modality in the common representation space, and add different weights to obtain the loss function of the cross-modal retrieval model; S3. Training the cross-modal retrieval model by minimizing the loss function of the cross-modal retrieval model to obtain the trained cross-modal retrieval model; The multimodal fusion module includes a plurality of cascaded MCA layers and a dimension reduction unit located after the last MCA layer; The MCA layer is used to learn the global feature correspondence between text features and image features based on the collaborative attention mechanism, and to learn the fine-grained contextual local information within text features and image features based on the self-attention mechanism; The dimension reduction unit is used to reduce the dimension of the text features and image features input by the last level MCA layer respectively; The MCA layer includes a first self-attention unit, a first fully connected layer, a second self-attention unit, a collaborative attention unit, and a second fully connected layer; the output end of the first self-attention unit is connected to the input end of the first fully connected layer; the output end of the second self-attention unit is connected to the input end of the collaborative attention unit; the output end of the collaborative attention unit is connected to the input end of the second fully connected layer; The first self-attention unit is used to extract latent semantic relationships within the text modality based on the self-attention mechanism to learn fine-grained contextual local information within the text features, thereby further extracting text features; The second self-attention unit is used to extract the latent semantic relationship within the image modality based on the self-attention mechanism to learn the fine-grained contextual local information within the image features, thereby further extracting the image features; The collaborative attention unit is used to extract the semantic relationship between the image modality and the text modality based on the collaborative attention mechanism, realize the learning process of the text features guiding the image features, and thus learn the global feature correspondence between the text features and the image features to fuse the text features into the image features.
2. The method for constructing a cross-modal retrieval model according to claim 1, wherein: For non-last-level MCA layers, the output of the first fully connected layer is connected to the input of the collaborative attention unit and the input of the first self-attention unit of the next-level MCA layer; the output of the second fully connected layer is connected to the input of the second self-attention unit of the next-level MCA layer; For the last-level MCA layer, the output end of its first fully connected layer is connected to the input end of the collaborative attention unit and the input end of the dimensionality reduction unit respectively; the output end of the second fully connected layer is connected to the input end of the dimensionality reduction unit.
3. The method for constructing a cross-modal retrieval model according to claim 1, wherein: For non-last-level MCA layers, the output of its first fully connected layer is connected to the input of the first self-attention unit of the next-level MCA layer; the output of its second fully connected layer is connected to the input of the second self-attention unit of the next-level MCA layer; For the last-level MCA layer, the output end of its first fully connected layer is respectively connected to the input end of the collaborative attention unit of each level before it and the input end of the dimensionality reduction unit; the output end of the second fully connected layer is connected to the input end of the dimensionality reduction unit.
4. A cross-modal retrieval method based on a multi-layer attention mechanism, characterized in that: include: After mapping the target query data into a common representation space based on the cross-modal retrieval model constructed using the cross-modal retrieval model construction method according to any one of claims 1 to 3, a semantic representation vector of the target query data is obtained, and similarity between the target query data and the data in the database is calculated by calculating the similarity between the semantic representation vector of the target query data and the semantic representation vector of the data in the database, thereby obtaining a corresponding retrieval ranking result; The semantic representation vector of the data in the database is obtained by mapping using the cross-modal retrieval model.
5. The cross-modal retrieval method according to claim 4, characterized in that: In the cross-modal retrieval model, the first input end of the feature extraction module and the first output end of the common representation module form an image channel for mapping image modality data into the common representation space; the second input end of the feature extraction module and the second output end of the common representation module form a text channel for mapping text modality data into the common representation space; The target query data or the data in the database are mapped into the common representation space using the corresponding channels according to their modalities.
6. The cross-modal retrieval method according to claim 5, characterized in that: Calculate the similarity between the target query data and the data in the database with different modalities to obtain cross-modal data similarity; The similarity between the target query data and the data in the database with different modalities is calculated to obtain the homomodal data similarity; the similarity between the target retrieval data and the data in the database is obtained by taking a weighted average of the cross-modal data similarity and the homomodal data similarity.
7. A machine-readable storage medium, characterized in that The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by the processor, the machine-executable instructions prompt the processor to implement the method for constructing a cross-modal retrieval model described in any one of claims 1-3 and / or the cross-modal retrieval method described in any one of claims 4-6.
