Text generation device, text generation method, and program
The Transformer-based model with across-attention and a topic layer addresses domain shift in text generation, enabling accurate reflection of target knowledge with less data, enhancing image description text quality.
Patent Information
- Application Number
- JP2023020611
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-02-14
- Publication Date
- 2024-08-26
- Estimated Expiration
- 2043-02-14
AI Technical Summary
Existing text generation models face challenges in accurately reflecting target domain knowledge due to domain shift, leading to mismatched generated text when applying pre-trained models to new domains.
A Transformer-based model with an across-attention mechanism and a topic layer is introduced to extract target-specific information, allowing for domain adaptation by mapping images and text into the same latent space and reflecting target knowledge in text generation.
The model generates highly accurate image description text that reflects target knowledge with reduced training data requirements, overcoming domain shift issues and improving text generation accuracy.
Smart Images

Figure 2024115121000001
Abstract
Description
[Technical field]
[0001] The present disclosure relates to a text generation device, a text generation method, and a program. [Background technology]
[0002] In the world of natural language processing, one of the applied fields of AI, automatic text generation has been realized, and in the field of image processing, image recognition has achieved a practical level of accuracy. As a fusion of these fields, "image description text generation," which understands images and describes their contents in text, is attracting attention. Conventional technology is expected to generate text for general images as well as generate domain-specific text. [Prior art documents] [Non-patent literature]
[0003] [Non-Patent Document 1] Marcella Cornia, Matteo Stefanini, Lorenzo Baraldi, and Rita Cucchiara, “Meshed-Memory Transformer for Image Captioning”, In CVPR, 2020, 10575-10584 [Non-Patent Document 2] Jun Chen, Han Guo, Kai Yi, Boyang Li, and Mohamed Elhoseiny, “VisualGPT: Data-Efficient Adaptation of Pretrained Language Models for Image Captioning”, In CVPR, 2022, 18030-18040. Summary of the Invention [Problem to be solved by the invention]
[0004] When using a text generation model in a specific business or service, the training cost can be reduced by using a pre-trained model for text generation, but there is a problem that the influence of the trained model (source) is strong, making it difficult to reflect the target knowledge in the generated text. Applying the domain of the trained model (source domain) to the domain to which it is applied (target domain) is called domain shifting.
[0005] The present disclosure has been made in consideration of the above, and aims to generate text that reflects the knowledge of a target from an image. [Means for solving the problem]
[0006] A text generation device of one embodiment of the present disclosure is a text generation device that receives an image as an input and generates text describing the image, and includes an input unit that inputs an image and extracts image features, and a generation unit that inputs the image features into a trained model and generates text by concatenating words that are recursively output from the model, and the model is a Transformer-based model that introduces an across-attention mechanism that uses a common attention mask across the encoder and decoder as an attention mechanism, and adds a topic layer that extracts information specific to the target and reflects it in text generation.
[0007] A text generation method according to one embodiment of the present disclosure is a text generation method that, when an image is input, generates text describing the image, in which a computer inputs an image, extracts image features, inputs the image features into a trained model, and generates text by concatenating words recursively output from the model, and the model is a Transformer-based model that introduces a cross-attention mechanism that uses a common attention mask across the encoder and decoder as an attention mechanism, and adds a topic layer that extracts information specific to the target and reflects it in text generation. Effect of the Invention
[0008] According to the present disclosure, text that reflects the target's knowledge can be generated from an image. [Brief description of the drawings]
[0009] [Figure 1] FIG. 1 is a diagram illustrating an example of a configuration of a text generation system. [Diagram 2] FIG. 2 is a diagram illustrating an example of the configuration of a decoder of the model. [Diagram 3] FIG. 3 is a diagram showing an example of an across attention mask. [Figure 4] FIG. 4 is a flowchart showing an example of the flow of a learning process of the text generation system. [Diagram 5] FIG. 5 is a flowchart showing an example of the flow of a text generation process in the text generation system. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0010] [System Configuration] Hereinafter, an embodiment of the present invention will be described with reference to the drawings.
[0011] The text generation system of this embodiment utilizes a model based on Transformer, and is a system that, when an image is input, generates text that describes the image.
[0012] Transformer is a deep learning model that is mainly used in the field of natural language processing. Transformer can generate text by probabilistically predicting the next word to appear from an input word and repeating this process recursively. The Transformer encoder finds an embedded representation of the image features. The Transformer decoder generates text by referring to the embedded representation of the image features.
[0013] In this embodiment, in order to generate text that reflects the knowledge of the target, a domain shift is realized by introducing across attention, a mapping layer, and a topic layer into Transformer. Across attention is an attention mechanism that improves the existing attention of Transformer. The mapping layer maps images and text into the same latent space. The topic layer extracts information specific to the target and reflects it in text generation. By domain-shifting the pre-trained model by focusing on topics, it is possible to generate image description text with high accuracy using less data than existing models. Details of the proposed model will be described later.
[0014] Fig. 1 is a diagram showing an example of the configuration of a text generation system according to this embodiment. The text generation system 1 shown in Fig. 1 includes a learning unit 10, a generation unit 20, a data storage unit 30, a calculation result storage unit 40, and an input / output unit 50. Each unit included in the text generation system 1 may be configured by a computer including an arithmetic processing unit, a storage unit, etc., and the processing of each unit may be executed by a program. This program is stored in a storage unit included in the text generation system 1, and can be recorded on a recording medium such as a magnetic disk, an optical disk, or a semiconductor memory, or can be provided via a network.
[0015] The learning unit 10 inputs pairs of images and text describing the images as learning data, inputs the images to an encoder, and inputs the text to a decoder to learn the association between the images and the text. The learning unit 10 extracts features from the images, extracts words from the text, and inputs the image features and words into a model. The learning unit 10 maps the image features into the same latent space as the words, and learns the model so that the topics obtained from the image features and the topics obtained from the text become closer to each other and information specific to the target is reflected in the text generation.
[0016] The generation unit 20 inputs the image into the trained model and generates text that describes the image.
[0017] The data storage unit 30 stores learning data such as images and text.
[0018] The calculation result storage unit 40 holds calculation results such as a deep learning model that generates text, parameters of the deep learning model obtained by learning, image features, and word variance vectors (distributed embedding representations).
[0019] The input / output unit 50 inputs an image from the user terminal 5 and transmits it to the generation unit 20 , and receives the generated text from the generation unit 20 and returns it to the user terminal 5 .
[0020] [Proposed model] The model proposed in this embodiment will be described with reference to FIG. 2. The encoder has blocks in the mth layer, and the decoder has blocks in the lth layer. FIG. 2 illustrates the mth layer of the encoder, the lth layer of the decoder, and a topic layer. The encoder has the same structure as a normal Transformer encoder except for across attention. The decoder has a structure in which the multi-head attention of a normal Transformer decoder is changed to across attention. The mth layer encoder receives the output H m-1 The lth layer decoder receives the output of the previous layer, H l-1 is entered.
[0021] First, we will explain across attention. Figure 3 shows an example of an attention mask used in across attention. Across attention uses a common mask for the encoder and decoder. In Figure 3, the attention masks used during learning and inference are shown with the reference image feature tokens and word tokens arranged vertically, and the reference image feature tokens and word tokens arranged horizontally. The shaded boxes indicate tokens that can be referenced. In the attention mask during learning in the upper part of Figure 3, the image feature tokens can refer to all image feature tokens and all word tokens, and the word tokens can refer to all image tokens and word tokens that have appeared up to that point. In the attention mask during inference in the lower part of Figure 3, the image feature tokens can only refer to all image feature tokens, and the word tokens can refer to all image tokens and word tokens that have appeared up to that point. Since the attention mask is used across the encoder and decoder, it is called across attention.
[0022] Input H to the encoder and decoder a 0 is expressed by the following equation.
[0023]
number
[0024] The output of the lth layer of the encoder and decoder, H a l is expressed by the following equation.
[0025]
number
[0026] The across attention is calculated using the attention mask M as follows:
[0027]
number
[0028] where d h is the number of dimensions, O is the image size, and t is the length of the text input. H l corresponds to the Q of the Transformer's attention, and is the output of the previous layer (Masked Self Attention) in the l-layer block of the decoder. H m corresponds to Transformer's attention,K,V,, and contains the internal state of the m-layer block of the encoder and,K,V,from the decoder. This allows us to learn which parts of an image to pay attention to based on the words in the text.
[0029] Next, the topic layer will be described.
[0030] Introducing a variable z representing the topic, the text generation model can be decomposed as follows:
[0031]
number
[0032] Here, D is the number of texts in the training data, and K is the number of topics. Weights are assigned to each of the K topics to effectively separate past data while learning and reflecting the target data.
[0033] On top of the encoder and decoder, there is a topic layer, Χ, I ,X T Introduce the following.
[0034]
number
[0035] The proposed model introduced MRM, TIM, TDM, and TTM as learning tasks.
[0036] MRM represents the error between the visual features of an image and the features predicted by the encoder. It is defined as follows:
[0037]
number
[0038] where v k,m represents the mth image feature, and v k,m (^ above) is the mth image feature predicted by masking the mth image feature.
[0039] TIM uses topics to represent the similarity between images and text in the training data. TIM learns to make the topics of images and texts closer.
[0040]
number
[0041] TDM is defined as follows: TDM trains the encoder and decoder so that the difference in the topic layer probability distribution is as small as possible.
[0042]
number
[0043] TTM represents the topic error between the encoder and the decoder. TTM learns to match the topics obtained from the image and the topics obtained from the text, and maps the image and the text to the same latent space. TTM is defined as follows:
[0044]
number
[0045] The model is trained using the following objective function L KEIC This is done by maximizing
[0046]
number
[0047] L TLN This allows the system to learn how topics are reflected in text generation.
[0048] [Operation] Next, the learning process will be described with reference to the flowchart in FIG.
[0049] In step S11, the learning unit 10 reads out learning data of pairs of images and text from the data storage unit 30, and divides the text into words using a tokenizer.
[0050] In step S12, the learning unit 10 extracts features from the image, and inputs the embedded representations of the image features and the embedded representations of the words into the model.
[0051] In step S13, the learning unit 10 updates the parameters of the model so as to minimize the objective function shown above.
[0052] Next, the text generation process will be described with reference to the flowchart of FIG.
[0053] In step S21, the generation unit 20 inputs an image and inputs an embedded representation of image features into a model.
[0054] In step S22, the generation unit 20 inputs the seed words and inputs the embedding representations of the words into the model.
[0055] In step S23, the generation unit 20 obtains the word following the seed word from the model.
[0056] In step S24, the generation unit 20 determines whether the generation of the text is completed. For example, the generation unit 20 may generate a <end>The process is determined to be finished when " " is output or when the text length reaches a predetermined maximum number of characters.
[0057] If text generation is to continue, the process returns to step S22, where the obtained words are concatenated after the seed word and fed into the model.
[0058] When the generation of the text is completed, in step S25, the generation unit 20 outputs a text explaining the image by connecting words. The generated text is returned from the input / output unit 50 to the user terminal 5.
[0059] As described above, the text generation system 1 of this embodiment includes an input / output unit 50 that inputs an image and extracts image features, and a generation unit 20 that inputs the image features into a trained model and generates text by concatenating words recursively output from the model. The proposed model is a Transformer-based model that introduces an across-attention mechanism that uses a common attention mask across the encoder and decoder as an attention mechanism, and adds a topic layer that extracts information specific to the target and reflects it in text generation. This makes it possible to generate text that reflects the target's knowledge from an image.
[0060] The text generation system 1 includes a learning unit 10 that inputs pairs of an image and text describing the image as training data, and trains a model so that the topic obtained from the image features of the image input to the encoder becomes closer to the topic obtained from the text input to the decoder, and information specific to the target is reflected in the text generation. The attention mask during training is an attention mask that allows access to all image features and all words for image features, and allows access to all image features and words that appeared before the word for words. This allows the pre-trained model to be domain-shifted by focusing on topics, and image description text with high accuracy can be generated with less training data than existing models. It is possible to reduce calculation costs compared to existing models. [Explanation of symbols]
[0061] 1. Text Generation Systems 10. Learning Department 20 Generation part 30 Data Storage Section 40 Calculation result storage section 50 Input / output section 5. User terminal< / end>
Claims
1. A text generator that generates text describing an image when an image is input, comprising: an input unit that inputs an image and extracts image features; A generation unit that inputs the image feature amount into a trained model and generates text by concatenating words that are recursively output from the model, The model is a Transformer-based model that introduces a cross-attention mechanism that uses a common attention mask across the encoder and decoder as an attention mechanism, and adds a topic layer that extracts information specific to the target and reflects it in text generation. Text generator.
2. 2. A text generator according to claim 1, comprising: a learning unit that inputs a pair of an image and a text explaining the image as learning data, and learns the model so that a topic obtained from an image feature of the image input to an encoder becomes close to a topic obtained from the text input to a decoder, and the topic is reflected in text generation; The attention mask during training is an attention mask that allows access to all image features and all words in the text for image features, and allows access to all image features and words that appear before the word for words. Text generator.
3. A text generation method for generating text describing an image when an image is input, comprising the steps of: The computer Input an image and extract image features. The image features are input into a trained model, and words output from the model are recursively concatenated to generate text; The model is a Transformer-based model that introduces a cross-attention mechanism that uses a common attention mask across the encoder and decoder as an attention mechanism, and adds a topic layer that extracts information specific to the target and reflects it in text generation. Text generation methods.
4. 4. A method for generating text according to claim 3, comprising the steps of: Pairs of images and text describing the images are input as training data, The model is trained so that a topic obtained from the image features of the image input to the encoder and a topic obtained from the text input to the decoder become close to each other, and the topic is reflected in text generation; The attention mask during training is an attention mask that allows access to all image features and all words in the text for image features, and allows access to all image features and words that appear before the word for words. Text generation methods.
5. A program for causing a computer to operate as each unit of the text generator according to claim 1 or 2.
Citation Information
Patent Citations
Character identification method and device for image, equipment and medium
CN113762261A
Image processing method and device, equipment, storage medium and computer program product
CN114299517A
Information generation method and device
CN114549935A
Image recognition learning system, image recognition learning method, image recognition learning program, image recognition machine learning unit, and image recognition system
WO2022185432A1
