Knowledge distillation method and device, visual question answering method, medium and electronic device
By using knowledge distillation to convey semantic information of answer text in visual question answering models, this approach solves the problem of ignoring the semantics of answer text in existing technologies, improves the model's understanding ability, and is applicable to the training of a wide range of visual question answering models.
Patent Information
- Application Number
- CN202210168931.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-23
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2042-02-23
AI Technical Summary
In existing technologies, visual question answering tasks ignore the textual semantic information of the answer itself, causing the model to be unable to fully understand the semantic information of both the visual and textual aspects.
The teacher and student models are trained using a knowledge distillation method. The first training data includes question text, answer text, and images, while the second training data includes question text and images. Knowledge distillation is performed on the student model using a loss function to convey the textual semantic information of the answer text.
It enables the effective transmission of semantic information of answer text in visual question answering models, improves the model's understanding ability, and does not increase the computational overhead during the testing phase. It is applicable to the training of various visual question answering models.
Smart Images

Figure CN116702890B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence, and in particular to a knowledge distillation method and apparatus, a visual question answering method, a medium, and an electronic device. Background Technology
[0002] With the increasing prevalence of smart devices such as intelligent cameras and robots, providing a user-friendly interactive method to acquire and process the visual information desired by users has become a pressing technical problem for researchers in related fields. Among the many solutions to this problem, visual question answering is one of the most popular topics. In visual question answering tasks, an agent can retrieve the corresponding answer from the visual information of an image based on the user's question. Because the task involves both computer vision and natural language processing, the model needs to fully understand the semantic information in both visual and textual data. For ease of evaluation, visual question answering has traditionally been treated as a classification problem, where answers within the candidate answer set are merely used as classification numbers, ignoring the semantic information of the answer's text itself. Summary of the Invention
[0003] In view of the shortcomings of the prior art described above, the purpose of this invention is to provide a knowledge distillation method and apparatus, a visual question answering method, a medium and an electronic device to solve the above-mentioned problems existing in the prior art.
[0004] To achieve the above and other related objectives, a first aspect of the present invention provides a knowledge distillation method, the knowledge distillation method comprising: training a teacher model using first training data and based on a first loss function, the first training data including question text, answer text, and an image; training a student model using second training data and based on a second loss function, the second training data including question text and an image, wherein both the teacher model and the student model are visual question answering models and have the same network architecture; and performing knowledge distillation on the student model using the teacher model and based on a third loss function, so as to at least transmit the textual semantic information of the answer text to the student model.
[0005] In one embodiment of the first aspect, the first loss function is related to the predicted answer distribution and the true answer distribution of the teacher model, and / or the second loss function is related to the predicted answer distribution and the true answer distribution of the student model.
[0006] In one embodiment of the first aspect, the third loss function is related to the predicted answer distribution of the teacher model and the predicted answer distribution of the student model.
[0007] In one embodiment of the first aspect, the knowledge distillation method further includes: jointly training the teacher model and the student model based on a fourth loss function.
[0008] In one embodiment of the first aspect, the fourth loss function is related to the first loss function, the second loss function, and the third loss function.
[0009] In one embodiment of the first aspect, the input data of the teacher model includes a first word feature sequence and a first visual word, wherein the first word feature sequence is obtained by word segmentation of the question text and answer text in the first training data, and the first visual word is obtained by region extraction and / or image feature extraction of the image in the first training data; and / or the input data of the student model includes a second word feature sequence and a second visual word, wherein the second word feature sequence is obtained by word segmentation of the question text in the second training data, and the second visual word is obtained by region extraction and / or image feature extraction of the image in the second training data.
[0010] A second aspect of the present invention provides a visual question answering method, the visual question answering method comprising: acquiring a question to be answered and a target image; processing the question to be answered and the target image using a student model to obtain an answer to the question to be answered, wherein the student model is obtained using the knowledge distillation method described in any one of the first aspects of the present invention.
[0011] A third aspect of the present invention provides a knowledge distillation apparatus for a visual question-answering model, the knowledge distillation apparatus comprising: a first training module configured to train a teacher model using first training data and based on a first loss function, the first training data including question text, answer text, and an image; a second training module configured to train a student model using second training data and based on a second loss function, the second training data including question text and an image, wherein both the teacher model and the student model belong to visual question-answering models and have the same network architecture; and a knowledge distillation module configured to perform knowledge distillation on the student model using the teacher model and based on a third loss function, so as to at least transmit the textual semantic information of the answer text to the student model.
[0012] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the knowledge distillation method described in any one of the first aspects of the present invention and / or the visual question-answering method described in the second aspect of the present invention.
[0013] A fifth aspect of the present invention provides an electronic device comprising: a memory storing a computer program; and a processor communicatively connected to the memory, wherein, when the computer program is invoked, the processor executes the knowledge distillation method of any one of the first aspects of the present invention and / or the visual question-answering method of the second aspect of the present invention.
[0014] As described above, the knowledge distillation method and apparatus described in one or more embodiments of the present invention have the following beneficial effects:
[0015] The described knowledge distillation method trains the teacher model using first training data containing answer text, and then transfers the semantic information of the answer text obtained by the teacher model during training to the student model through knowledge distillation. This knowledge distillation method has advantages such as high versatility and no additional computational overhead during the testing phase, and can be widely applied to the training of various visual question-answering models.
[0016] Furthermore, the visual question-answering model based on the knowledge distillation method can be deployed to intelligent robots, enabling the robots to respond accordingly based on the currently collected images and received questions. Therefore, it can be applied to human-computer interaction in scenarios such as welcoming robots, sweeping robots, and industrial robots. Attached Figure Description
[0017] Figure 1 The flowchart shown is a specific embodiment of the knowledge distillation method described in this invention.
[0018] Figure 2A The flowchart shown is a specific embodiment of the knowledge distillation method described in this invention.
[0019] Figure 2B The diagram shown is a schematic representation of a specific embodiment of the knowledge distillation method described in this invention.
[0020] Figure 3 The flowchart shown is a specific embodiment of the visual question-answering method described in this invention.
[0021] Figure 4 The diagram shown is a structural schematic of the knowledge distillation apparatus described in this invention in a specific embodiment.
[0022] Figure 5 The diagram shown is a structural schematic of the electronic device described in a specific embodiment of the present invention.
[0023] Component designation explanation
[0024] 4. Knowledge Distillation Apparatus
[0025] 41 First Training Module
[0026] 42 Second Training Module
[0027] 43 Knowledge Distillation Module
[0028] 5 Electronic devices
[0029] 51 Memory
[0030] 52 processor
[0031] 53 Monitors
[0032] Steps S11 to S13
[0033] Steps S21 to S27
[0034] Steps S31 to S32 Detailed Implementation
[0035] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.
[0036] It should be noted that the illustrations provided in the following embodiments are merely schematic representations of the basic concept of the present invention. The illustrations only show components relevant to the present invention and are not drawn according to the actual number, shape, and size of the components in implementation. In actual implementation, the form, quantity, and proportion of each component can be arbitrarily changed, and the component layout may also be more complex. Furthermore, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0037] For ease of evaluation, visual question answering in related technologies has traditionally been treated as a classification problem, where answers within the candidate answer set are merely used as classification numbers while ignoring the textual semantic information of the answers themselves. To address this issue, this invention provides a knowledge distillation method for visual question answering models. The knowledge distillation method will now be described through specific embodiments and accompanying drawings.
[0038] Please see Figure 1 In one embodiment of the present invention, the knowledge distillation method includes the following steps S11 to S13.
[0039] Step S11: Train the teacher model using the first training data and based on the first loss function. The first training data includes question text, images, and corresponding answer text. The first loss function represents the difference between the teacher model's predicted answer and the actual answer.
[0040] Step S12: Train the student model using the second training data and based on the second loss function. The second training data includes question text and images, and the second loss function represents the difference between the student model's predicted answer and the actual answer. Furthermore, both the teacher model and the student model are visual question-answering models, and they have the same network architecture.
[0041] Step S13 involves using the teacher model and performing knowledge distillation on the student model based on the third loss function to at least transfer the textual semantic information of the answer text to the student model. The third loss function represents the difference between the predicted answer from the teacher model and the predicted answer from the student model. Approximating the predicted answers from the teacher model and the student model based on the third loss function effectively transfers knowledge from the teacher model to the student model.
[0042] As described above, this embodiment includes a training process for a teacher model and a student model. The teacher and student models have the same network architecture; the difference lies in the training data used. Specifically, the teacher model's training data includes the answer text, while the student model's training data does not. Therefore, the teacher model possesses more knowledge and is more advanced than the student model. Based on this, step S13 in this embodiment uses knowledge distillation to transfer the knowledge possessed by the teacher model, including the speech information of the answer text, to the student model. After knowledge distillation, the student model can be used for practical applications or testing. Therefore, the knowledge distillation method described in this embodiment fully utilizes the semantic information of the answer text in the training data, rather than simply treating it as a classification number. Furthermore, the knowledge distillation method described in this embodiment has advantages such as strong versatility and no additional computational overhead during the testing phase, and can be widely applied to the training of various visual question-answering models.
[0043] In one embodiment of the present invention, the first loss function is related to the predicted answer distribution and the true answer distribution of the teacher model; that is, the function value of the first loss function is determined by the predicted answer distribution and the true answer distribution of the teacher model. Specifically, the prediction result of the teacher model is a probability distribution, also called the predicted answer distribution. The predicted answer distribution corresponds to the probability that each answer in the candidate answer set is predicted to be true, where the answer with the largest probability score is the predicted answer of the teacher model. For example, the predicted answer distribution can be "answer 1, probability p1, answer 2, probability p2, ..., answer N, probability pN", and the predicted answer can be answer n, where 1 ≤ n ≤ N and pn = max(p1, p2, ..., pN). The true answer distribution can be obtained through manual annotation or other methods and is used to represent the true answer to the question.
[0044] Preferably, the first loss function is the cross-entropy loss function of the predicted answer distribution and the actual answer distribution of the teacher model, but the present invention is not limited thereto.
[0045] In one embodiment of the present invention, the second loss function is related to the predicted answer distribution and the true answer distribution of the student model; that is, the value of the second loss function is determined by the predicted answer distribution and the true answer distribution of the student model. Specifically, the prediction result of the student model is a probability distribution, also called the predicted answer distribution, which corresponds to the probability that each answer in the candidate answer set is predicted to be true. The answer with the highest probability score is the predicted answer of the student model. The true answer distribution can be obtained through manual annotation or other methods and is used to represent the true answer to the question.
[0046] Preferably, the second loss function is the cross-entropy loss function of the predicted answer distribution and the actual answer distribution of the student model, but the present invention is not limited thereto.
[0047] In one embodiment of the present invention, the third loss function is related to the predicted answer distribution of the teacher model and the predicted answer distribution of the student model; that is, the function value of the third loss function is determined by the predicted answer distribution of the teacher model and the predicted answer distribution of the student model.
[0048] Preferably, the third loss function is the relative entropy loss function of the predicted answer distribution of the teacher model and the predicted answer distribution of the student model.
[0049] In one embodiment of the present invention, the knowledge distillation method may further include: jointly training the teacher model and the student model based on a fourth loss function. In this embodiment, by jointly training the teacher model and the student model, the teacher model can simultaneously focus on how to improve its own prediction accuracy and how to better distill knowledge to the student model.
[0050] Optionally, the fourth loss function is related to the first, second, and third loss functions; that is, the fourth loss function is determined by the first, second, and third loss functions.
[0051] Preferably, the fourth loss function is the sum of the first loss function, the second loss function, and the third loss function, but the present invention is not limited thereto.
[0052] As described above, this embodiment also includes a step of jointly training the teacher model and the student model, which enables the knowledge of the teacher model to be transferred to the student model more effectively.
[0053] In one embodiment of the present invention, the input data of the teacher model includes a first word feature sequence and a first visual word. The first word feature sequence is obtained by word segmentation of the question text and answer text in the first training data, and the first visual word is obtained by region extraction and / or image feature extraction of the images in the first training data. Based on this, during the training process of the teacher model, the first word feature sequence and the first visual word can be obtained from the first training data and simultaneously input into the teacher model for training.
[0054] In one embodiment of the present invention, the input data of the student model includes a second word feature sequence and a second visual word. The second word feature sequence is obtained from the question text in the second training data through word segmentation, and the second visual word is obtained from the image in the second training data through region extraction and / or image feature extraction. Based on this, during the training process of the student model, the second word feature sequence and the second visual word can be obtained from the second training data, and simultaneously input into the student model for training.
[0055] In one embodiment of the present invention, both the student model and the teacher model are deep learning visual question answering models based on Transformer networks.
[0056] Figure 2A The flowchart shown is a preferred embodiment of the knowledge distillation method of the present invention. Figure 2B The diagram shown is a schematic representation of the knowledge distillation method in this preferred embodiment. It should be noted that this preferred embodiment is merely one preferred mode of the present invention, and its content is not essential for implementing the invention. That is, some embodiments may not include all the content of this preferred embodiment. Specifically, as... Figure 2A As shown, the knowledge distillation method in this preferred embodiment includes the following steps S21 to S27.
[0057] Step S21: Construct teacher and student models based on the Transformer network. The language branch segments the text information into word feature sequences Q. θ Upon input, the visual branch extracts region or object features from the image and uses them as visual words (V). θ Input the model's predicted answers, which are distributed as s. θ The answer of the prediction model is the one with the highest probability score. For any model F θ Its output s θ For s θ =F θ (V θ Q θ The prediction model's answer is a. pred =argmax a∈A s θ [a], where A represents the set of candidate answers, s θ [a] represents the predicted probability that the answer is a.
[0058] Step S22: Train the teacher model using the first training data, which includes images, question text, and answer text. Specifically, for the teacher model F... te The text modality's word feature sequence input includes both the question Q and the answer a, while the visual modality's input includes features V extracted from the image and the answer distribution s predicted by the teacher model. te It can be expressed by the following formula: s te =F te (V,[Q,a]). For example, for Figure 2B The image shown has a question Q, for example, "What animal is in the picture?" The true answer a is "giraffe," and the predicted answer distribution s is... te For example, “Giraffe (99.98%), Sika deer (0.01%), Red deer (0.01%)”.
[0059] Step S23: Train the student model using the second training data, which includes images and questions. Specifically, for the student model F... st The text modality's word feature sequence input only contains the question Q, while the visual modality's input contains features V extracted from the image. The student model predicts the answer distribution as s. st =F st (V,Q).
[0060] Step S24: Calculate the binary cross-entropy of the predicted answer distribution and the actual answer distribution of the teacher model as the first loss function L. ce (s te ,s gt ), where sgt The true distribution of answers can be obtained through methods such as manual annotation.
[0061] Step S35: Calculate the binary cross-entropy of the predicted answer distribution and the actual answer distribution of the student model as the second loss function L. ce (s st ,s gt ).
[0062] Step S26: Calculate the relative entropy of the predicted answer distributions of the teacher model and the student model as the third loss function L. kl (F te ,F st And knowledge distillation is achieved based on the third loss function, where L kl (F te ,F st ) = KL(F te (V,[Q,a])||F st (V,Q)), where KL is the relative entropy function. Knowledge can be effectively transferred from the teacher model to the student model by approximating the prediction distributions of the teacher and student models.
[0063] Step S27: Summing the first loss function, the second loss function, and the third loss function yields the fourth loss function. The gradient backpropagation algorithm is then used to optimize the loss function, thereby enabling joint training of the teacher model and the student model.
[0064] As described above, this embodiment proposes a knowledge distillation method for deep learning visual question answering models. This method can fully utilize the semantic information of the answer text in the training data, rather than simply treating it as a classification number. Furthermore, this embodiment also proposes a joint training strategy, enabling the knowledge of the teacher model to be more effectively transferred to the student model during the joint optimization process.
[0065] This invention also provides a visual question-answering method. For details, please refer to... Figure 3 The above is a flowchart of a visual question-answering method according to an embodiment of the present invention. Figure 3 As shown, the visual question-answering method in this embodiment includes the following steps S31 to S33.
[0066] Step S31: Obtain the questions to be answered and the target image.
[0067] Step S32: The student model is used to process the question to be answered and the target image to obtain the answer to the question. The student model employs... Figure 1 Alternatively, it can be obtained through the knowledge distillation method shown in Figure 2.
[0068] This invention also provides a knowledge distillation apparatus for visual question-answering models. For details, please refer to [link / reference]. Figure 4 In one embodiment of the present invention, the knowledge distillation device 4 includes a first training module 41, a second training module 42, and a knowledge distillation module 43.
[0069] The first training module 41 is configured to train the teacher model using first training data and based on a first loss function, wherein the first training data includes question text, answer text, and images.
[0070] The second training module 42 is configured to train the student model using the second training data and based on the second loss function. The second training data includes question text and images. Both the teacher model and the student model are visual question answering models and have the same network architecture.
[0071] The knowledge distillation module 43 is connected to the first training module 41 and the second training module 42, and is configured to use the teacher model and perform knowledge distillation on the student model based on the third loss function, so as to at least pass the textual semantic information of the answer text to the student model.
[0072] It should be noted that the modules in the knowledge distillation apparatus 4 described in this embodiment are related to... Figure 1 Steps S11 to S13 in the knowledge distillation method shown correspond one-to-one. To save space in the manual, they will not be described in detail here.
[0073] Optionally, the knowledge distillation device 1 may further include a joint training module. This joint training module is connected to the knowledge distillation module 43 and is used to jointly train the teacher model and the student model based on a fourth loss function.
[0074] The present invention also provides a computer-readable storage medium having a computer program stored thereon, the computer program being implemented when executed by a processor. Figure 1 Or the knowledge distillation method shown in Figure 2 and / or Figure 3 The visual question-and-answer method shown.
[0075] The present invention also provides an electronic device. Specifically, please refer to [link to relevant documentation]. Figure 5 In one embodiment of the present invention, the electronic device 5 includes a memory 51 and a processor 52. The memory 51 is configured to store a computer program. The processor 52 is connected to the memory 51 and is configured to execute the computer program when invoked. Figure 1 Or the knowledge distillation method shown in Figure 2 and / or Figure 3 The visual question-and-answer method shown.
[0076] Optionally, the electronic device 5 may also include a display 53, which is communicatively connected to the memory 51 and the processor 52, for displaying the relevant GUI interactive interface of the knowledge distillation method and / or visual question answering method.
[0077] The scope of protection of the knowledge distillation method described in this invention is not limited to the order of steps listed in this embodiment. Any solution implemented by adding, subtracting, or replacing steps in the prior art based on the principles of this invention is included within the scope of protection of this invention.
[0078] The present invention also provides a knowledge distillation apparatus, which can implement the knowledge distillation method described in the present invention. However, the apparatus for implementing the knowledge distillation method described in the present invention includes, but is not limited to, the structure of the knowledge distillation apparatus listed in this embodiment. All structural modifications and substitutions of the prior art made in accordance with the principles of the present invention are included within the protection scope of the present invention.
[0079] In summary, the knowledge distillation method described in one or more embodiments of the present invention trains a teacher model using first training data containing answer text, and transfers the semantic information of the answer text obtained by the teacher model through knowledge distillation to the student model. This knowledge distillation method has advantages such as strong versatility and no additional computational overhead during the testing phase, and can be widely applied to the training of various visual question-answering models. Furthermore, the visual question-answering model obtained through this knowledge distillation method can be deployed to intelligent robots, enabling the robot to respond accordingly based on the currently collected images and received questions, thus making it suitable for human-computer interaction in scenarios such as welcoming robots, cleaning robots, and industrial robots. Therefore, the present invention effectively overcomes the various shortcomings of the prior art and has high industrial application value.
[0080] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.
Claims
1. A knowledge distillation method for visual question answering models, characterized in that, The knowledge distillation method includes: The teacher model is trained using the first training data and based on the first loss function, wherein the first training data includes question text, answer text, and images; The student model is trained using second training data and based on a second loss function. The second training data includes question text and images. Both the teacher model and the student model belong to visual question answering models and have the same network architecture. The teacher model is used and the student model is subjected to knowledge distillation based on a third loss function, so as to at least pass the textual semantic information of the answer text to the student model; The teacher model and the student model are jointly trained based on the fourth loss function, and the first loss function, the second loss function and the third loss function are jointly optimized through the gradient backpropagation algorithm. Both the teacher model and the student model are visual question answering models based on Transformer networks, and the third loss function is the relative entropy loss function between the predicted answer distribution of the teacher model and the predicted answer distribution of the student model. The first loss function is related to the predicted answer distribution and the true answer distribution of the teacher model, the second loss function is related to the predicted answer distribution and the true answer distribution of the student model, and the fourth loss function is the sum of the first loss function, the second loss function, and the third loss function.
2. The knowledge distillation method according to claim 1, characterized in that: The input data of the teacher model includes a first word feature sequence and a first visual word, wherein the first word feature sequence is obtained by word segmentation of the question text and answer text in the first training data, and the first visual word is obtained by region extraction and / or image feature extraction of the images in the first training data; and / or The input data of the student model includes a second word feature sequence and a second visual word, wherein the second word feature sequence is obtained by word segmentation of the question text in the second training data, and the second visual word is obtained by region extraction and / or image feature extraction of the image in the second training data.
3. A visual question-answering method, characterized in that, The visual question-answering method includes: Retrieve the questions to be answered and the target image; The student model is used to process the question to be answered and the target image to obtain the answer to the question to be answered, wherein the student model is obtained by the knowledge distillation method according to any one of claims 1 to 2.
4. A knowledge distillation device for a visual question-answering model, characterized in that, The knowledge distillation apparatus includes: The first training module is configured to train the teacher model using first training data and based on a first loss function, wherein the first training data includes question text, answer text, and images; The second training module is configured to train the student model using the second training data and based on the second loss function. The second training data includes question text and images. Both the teacher model and the student model belong to the visual question answering model and have the same network architecture. The knowledge distillation module is configured to use the teacher model and perform knowledge distillation on the student model based on a third loss function, so as to at least pass the textual semantic information of the answer text to the student model; The joint training module is configured to jointly train the teacher model and the student model based on the fourth loss function, and to jointly optimize the first loss function, the second loss function and the third loss function through the gradient backpropagation algorithm. Wherein, both the teacher model and the student model are visual question answering models based on Transformer networks, and the third loss function is the relative entropy loss function between the predicted answer distribution of the teacher model and the predicted answer distribution of the student model; Wherein, the first loss function is related to the predicted answer distribution and the true answer distribution of the teacher model, the second loss function is related to the predicted answer distribution and the true answer distribution of the student model, and the fourth loss function is the sum of the first loss function, the second loss function, and the third loss function.
5. A computer-readable storage medium having a computer program stored thereon, characterized in that: When executed by a processor, the computer program implements the knowledge distillation method of any one of claims 1 to 2 and / or the visual question answering method of claim 3.
6. An electronic device, characterized in that, The electronic device includes: A memory that stores a computer program; The processor, which is communicatively connected to the memory, executes the knowledge distillation method of any one of claims 1 to 2 and / or the visual question answering method of claim 3 when the computer program is invoked.
