Answer determination method, device, electronic device and storage medium
By acquiring and analyzing multi-modal features in the target image, and determining and replacing low-probability text, the problem of reduced accuracy of visual question and answer answers caused by OCR recognition errors is solved and the accuracy of the answers is improved.
Patent Information
- Application Number
- CN202410888608.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-04
AI Technical Summary
In the existing visual question and answer technology, the optical character recognition (OCR) method has errors in text recognition, which leads to a decrease in the accuracy of the answers predicted by the visual question and answer.
By obtaining the multi-modal features of the original text in the target image, including semantic features and positional features, the candidate text is determined, and the accurate recognition probability of the target text is predicted based on the multi-modal features and semantic features of the context text, and the low-probability text is replaced. to improve the accuracy of answers.
It improves the accuracy of answers predicted by visual question and answer, enhances the accurate recognition of target text, and reduces the impact of OCR recognition errors.
Smart Images

Figure CN118410877B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of visual question answering technology, and in particular to an answer determination method, device, electronic device and storage medium. Background Art
[0002] The VQA (Visual Question Answering) task can predict the answer to a question based on an image and a question related to the image. During the VQA task, the text information in the image is usually recognized based on the OCR (Optical Character Recognition) method, and the answer to the question is determined directly based on the text information recognized by OCR. However, due to certain errors in OCR recognition, the text in the image may be incorrectly recognized. Therefore, if the text recognized by OCR is directly used as the answer to the question, the accuracy of the answer predicted by the visual question answering will be reduced. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a method, device, electronic device and storage medium for determining an answer, so as to improve the accuracy of the answer predicted by the visual question answering. The specific technical solution is as follows:
[0004] The present application provides a method for determining an answer, the method comprising:
[0005] Obtaining each original text in the target image through OCR recognition, and obtaining multimodal features of each original text, wherein the multimodal features include semantic features of the original text and position features for indicating the position of the original text in the target image;
[0006] Determining, from the plurality of original texts, texts that are answers to the target question as candidate texts according to the multimodal features of the original texts;
[0007] For each target text in the candidate texts, determine in each original text a text whose position is associated with the position of the target text as the context text corresponding to the target text, the target text being any of the candidate texts;
[0008] For each target text, based on the multimodal features of each context text corresponding to the target text and the semantic features of the target text, predict the probability that the target text is an accurately recognized text as the target probability of the target text;
[0009] For each of the target texts, according to the multimodal features of each context text corresponding to the target text, predict the text at the position of the target text in the target image as the predicted text corresponding to the target text;
[0010] Among the candidate texts, the target text whose target probability meets the preset low probability condition is determined, and the determined target text is replaced with the corresponding predicted text to obtain the replaced candidate text as the answer to the target question.
[0011] In a possible embodiment, for each of the target texts, predicting the text at the position of the target text in the target image according to the multimodal features of each context text corresponding to the target text as the predicted text corresponding to the target text includes:
[0012] Determine an initial current context feature according to the multimodal feature of the context text corresponding to the non-alternative text, and determine the initial current hidden state according to the semantic feature of the non-alternative text, the multimodal feature of the context text corresponding to the non-alternative text, and the hidden state of the non-alternative text;
[0013] Determine a new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state, wherein the current target text is initially the target text located at the first position of the candidate text;
[0014] Determining, according to the multimodal features of each context text corresponding to the current target text, a context feature of the current target text as a new current context feature;
[0015] Predicting the text at the position of the current target text in the target image according to the new current context feature and the new current hidden state as the predicted text corresponding to the current target text;
[0016] The target text located one position after the current target text is used as the new current target text, and the step of determining the new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state is returned to be executed.
[0017] In a possible embodiment, for each target text, according to the multimodal features of each context text corresponding to the target text and the semantic features of the target text, predicting the probability that the target text is an accurately recognized text as the target probability of the target text includes:
[0018] Determine an initial current context feature according to the multimodal feature of the context text corresponding to the non-alternative text, and determine the initial current hidden state according to the semantic feature of the non-alternative text, the multimodal feature of the context text corresponding to the non-alternative text, and the hidden state of the non-alternative text;
[0019] Determine a new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state, wherein the current target text is initially the target text located at the first position of the candidate text;
[0020] Determining, according to the multimodal features of each context text corresponding to the current target text, a context feature of the current target text as a new current context feature;
[0021] According to the new current context feature, the new current hidden state, and the semantic feature of the current target text, predict the probability that the current target text is the accurately recognized text as the target probability of the current target text;
[0022] The target text located one position after the current target text is used as the new current target text, and the step of determining the new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state is returned to be executed.
[0023] In a possible embodiment, determining the context feature of the current target text as a new current context feature according to the multimodal features of each context text corresponding to the current target text includes:
[0024] The multimodal features of each context text corresponding to the current target text are weighted to obtain the context feature of the current target text as a new current context feature, wherein the weight corresponding to the multimodal feature of the context text belonging to the alternative text is greater than the weight corresponding to the multimodal feature of the context text not belonging to the alternative text.
[0025] In a possible embodiment, the multimodal features of the original text further include: visual features of the original text;
[0026] The obtaining of the multimodal features of each of the original texts includes:
[0027] Acquire the semantic features of each of the original texts and the position features of each of the original texts;
[0028] Dividing the target image into a plurality of blocks, and determining visual features of each of the blocks;
[0029] The semantic features of each of the original texts, the positional features of each of the original texts, the visual features of each of the image blocks, and the target question are input into a multimodal pre-training model to obtain multimodal features of each of the original texts; the multimodal pre-training model is obtained by pre-training the original training model based on sample images.
[0030] In a possible embodiment, the multimodal pre-trained model is obtained by pre-training the original training model based on the sample image by any one or more of the following methods: method 1, method 2, and method 3;
[0031] Method 1 includes:
[0032] For each of the sample images, obtaining each sample text existing in the sample image, a semantic feature of each of the sample texts, and a position feature of each of the sample texts;
[0033] For each of the sample images, masking the masked text in the sample image to obtain a masked sample image; the masked text is any sample text in the sample image;
[0034] For each of the sample images, the masked sample image, the sample text belonging to the non-masked text, the semantic features of the sample text belonging to the non-masked text, and the position features of the sample text belonging to the non-masked text are input into the original training model, and the text at the position of the masked text in the sample image output by the original training model is obtained as the predicted masked text corresponding to the masked text in the sample image;
[0035] Based on the difference between the covered text in each of the sample images and the predicted covered text corresponding to the covered text in each of the sample images, the parameters of the original training model are adjusted, and the original training model with the adjusted parameters is used as the new original training model, and the step of returning to execute the step of inputting the covered sample image, the sample text belonging to the non-covered text, the semantic features of the sample text belonging to the non-covered text, and the position features of the sample text belonging to the non-covered text into the original training model for each of the sample images, and obtaining the text at the position of the covered text in the sample image output by the original training model as the predicted covered text corresponding to the covered text in the sample image, until the first preset termination condition is reached;
[0036] Method 2 includes:
[0037] For each of the sample images, obtaining each sample text existing in the sample image, a visual feature of each of the sample texts, and a position feature of each of the sample texts;
[0038] For each of the sample images, masking the masked text in the sample image to obtain a masked sample image; the masked text is any sample text in the sample image;
[0039] For each of the sample images, the masked sample image, the sample text belonging to the non-masked text, the visual features of the sample text belonging to the non-masked text, and the position features of the sample text belonging to the non-masked text are input into the original training model, and the text at the position of the masked text in the sample image output by the original training model is obtained as the predicted masked text corresponding to the masked text in the sample image;
[0040] Based on the difference between the covered text in each of the sample images and the predicted covered text corresponding to the covered text in each of the sample images, the parameters of the original training model are adjusted, and the original training model with the adjusted parameters is used as the new original training model, and the step of returning to execute the step of inputting the covered sample image, the sample text belonging to the non-covered text, the visual features of the sample text belonging to the non-covered text, and the position features of the sample text belonging to the non-covered text into the original training model for each of the sample images, and obtaining the text at the position of the covered text in the sample image output by the original training model as the predicted covered text corresponding to the covered text in the sample image, until a second preset termination condition is reached;
[0041] Method three includes:
[0042] For each of the sample images, obtaining each sample text existing in the sample image, a semantic feature of each of the sample texts, a visual feature of each of the sample texts, and a position feature of each of the sample texts;
[0043] For each of the sample images, a first cover text in the sample image is covered to obtain a first cover image, and a second cover text in the sample image is covered to obtain a second cover image; the first cover text is any sample text in the sample image, and the second cover text is any sample text in the sample image;
[0044] For each of the sample images, determining whether a first covered text in the first covered image and a second covered text in the second covered image are the same sample text, and using the determination result as the true value of the sample image;
[0045] For each of the sample images, the first cover image, the second cover image, the non-first cover text in the first cover image, the semantic features of each of the non-first cover texts, the position features of each of the non-first cover texts, the non-second cover text in the second cover image, the visual features of each of the non-second cover texts, and the position features of each of the non-second cover texts are input into the original training model to obtain a prediction result output by the original training model as the prediction result of the sample image; the prediction result is used to characterize whether the first cover text in the first cover image and the second cover text in the second cover image are the same sample text;
[0046] Based on the difference between the prediction results of each of the sample images and the true values of each of the sample images, the parameters of the original training model are adjusted, and the original training model with adjusted parameters is used as the new original training model, and the step of returning to execute the step of inputting the first cover image, the second cover image, the non-first cover text in the first cover image, the semantic features of each of the non-first cover texts, the position features of each of the non-first cover texts, the non-second cover text in the second cover image, the visual features of each of the non-second cover texts, and the position features of each of the non-second cover texts into the original training model for each of the sample images to obtain the prediction results output by the original training model as the prediction results of the sample images, until a third preset termination condition is reached.
[0047] In a possible embodiment, the position feature includes: a one-dimensional position feature and a two-dimensional position feature; the position feature of each original text is obtained by the following method, including:
[0048] The area where each original text in the target image is located is obtained by OCR recognition as the text area;
[0049] For each of the text regions, determining a position of the text region in the target image as a two-dimensional position feature of each of the original texts included in the text region;
[0050] For each of the text regions, starting from the first original text in the text region, the position of each of the original texts in the text region is used as a one-dimensional position feature of each of the original texts in the text region.
[0051] The present application also provides an answer determination device, the device comprising:
[0052] A recognition module, used for obtaining each original text existing in the target image through OCR recognition, and obtaining multimodal features of each original text, wherein the multimodal features include semantic features of the original text and position features for indicating the position of the original text in the target image;
[0053] An alternative text determination module, configured to determine, from the plurality of original texts, texts that are answers to the target question as alternative texts according to the multimodal features of the original texts;
[0054] A context text determination module, for determining, for each target text in the candidate texts, a text in each original text whose position is associated with the position of the target text as a context text corresponding to the target text, wherein the target text is any of the candidate texts;
[0055] A target probability obtaining module is used to predict the probability of the target text being an accurately recognized text according to the multimodal features of the context texts corresponding to the target text and the semantic features of the target text, as the target probability of the target text;
[0056] A predicted text obtaining module is used to predict, for each target text, the text at the position of the target text in the target image according to the multimodal features of each context text corresponding to the target text, as the predicted text corresponding to the target text;
[0057] The replacement module is used to determine the target text whose target probability meets the preset low probability condition among the alternative texts, and replace the determined target text with the corresponding predicted text to obtain the replaced alternative text as the answer to the target question.
[0058] The present application also provides an electronic device, including:
[0059] Memory, used to store computer programs;
[0060] The processor is used to implement any of the above-mentioned answer determination methods when executing the program stored in the memory.
[0061] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any of the above-mentioned answer determination methods is implemented.
[0062] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-described answer determination methods.
[0063] Beneficial effects of the embodiments of the present application:
[0064] The embodiments of the present application provide an answer determination method, device, electronic device and storage medium, which obtain each original text existing in the target image through OCR recognition, and obtain multimodal features of each original text, wherein the multimodal features include semantic features of the original text and position features used to indicate the position of the original text in the target image; according to the multimodal features of each original text, determine the text that is the answer to the target question from multiple original texts as the candidate text; for each target text in the candidate text, determine the text whose position is associated with the position of the target text in each original text as the context text corresponding to the target text, and the target text This is any candidate text; for each target text, according to the multimodal features of each context text corresponding to the target text and the semantic features of the target text, the probability of the target text being the text accurately recognized is predicted as the target probability of the target text; for each target text, according to the multimodal features of each context text corresponding to the target text, the text at the position of the target text in the target image is predicted as the predicted text corresponding to the target text; among the candidate texts, the target text whose target probability meets the preset low probability condition is determined, and the determined target text is replaced with the corresponding predicted text to obtain the replaced candidate text as the answer to the target question. Since the position of the context text corresponding to the target text is associated with the position of the target text, it can be considered that the context text corresponding to the target text is semantically associated with the target text, and it can be judged whether the semantics of the content composed of the target text and the context text corresponding to the target text is correct according to the multimodal features of each context text corresponding to the target text and the semantic features of the target text, and it can also be judged that the probability of the target text being the text accurately recognized is obtained, and the target probability of the target text is obtained. Furthermore, since the position of the context text corresponding to the target text is associated with the position of the target text, it can be considered that the context text corresponding to the target text is semantically associated with the text at the target text position, and the semantics that may be expressed by the content composed of the text at the target text position and the context text corresponding to the target text can be predicted based on the multimodal features of the context text corresponding to the target text, and the text at the target text position can be predicted more accurately, and the predicted text corresponding to the target text can be obtained. It can be considered that the predicted text may be the real text at the target text position in the target image. It can be understood that if the target probability of the target text is higher, the probability that the target text is accurately recognized is greater, that is, the accuracy of OCR recognition is higher. Therefore, when the target probability meets the preset low probability condition, it can be considered that the accuracy of OCR recognition is low, that is, the text at the target text position should not be the target text, and the target text can be replaced with a predicted text with higher accuracy.Based on this, the alternative text is corrected by replacing the target text in the alternative text whose target probability meets the preset low probability condition with the corresponding predicted text to obtain the replaced alternative text. Compared with the alternative text, the replaced alternative text, that is, the answer to the target question, has a higher accuracy, thereby improving the accuracy of the answer to the target question predicted by the visual question answering.
[0065] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0067] Figure 1a A schematic diagram of a visual question-answering scenario provided in an embodiment of the present application;
[0068] Figure 1b A schematic diagram of a pure document target image provided in an embodiment of the present application;
[0069] Figure 2 A schematic diagram of a flow chart of a method for determining an answer provided in an embodiment of the present application;
[0070] Figure 3 A schematic diagram of a process for predicting and obtaining a predicted text corresponding to a target text provided in an embodiment of the present application;
[0071] Figure 4 A schematic diagram of a flow chart for predicting the target probability of a target text provided in an embodiment of the present application;
[0072] Figure 5 A schematic diagram of a process for obtaining multimodal features of each original text provided in an embodiment of the present application;
[0073] Figure 6a A schematic diagram of the position features of the original text provided in the embodiment of the present application;
[0074] Figure 6b A schematic diagram of a flow chart for obtaining position features of each original text provided in an embodiment of the present application;
[0075] Figure 7 Another schematic diagram of a process for obtaining multimodal features of each original text provided in an embodiment of the present application;
[0076] Figure 8aA flow chart of a model training process provided in an embodiment of the present application;
[0077] Figure 8b A schematic diagram of a processed sample image provided in an embodiment of the present application;
[0078] Figure 9a A schematic diagram of a flow chart of a model training method 1 provided in an embodiment of the present application;
[0079] Figure 9b A schematic diagram of a flow chart of the second model training method provided in an embodiment of the present application;
[0080] Fig.9c A schematic diagram of a flow chart of the model training method 3 provided in the embodiment of the present application;
[0081] Fig.10 Another schematic diagram of a flow chart of a method for determining an answer provided in an embodiment of the present application;
[0082] Fig.11 A schematic diagram of a structure of an answer determination device provided in an embodiment of the present application;
[0083] Fig.12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0084] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.
[0085] In order to more clearly explain the answer determination method, device, electronic device and storage medium provided by the present application, some terms appearing in this document are explained below:
[0086] VQA: The VQA task can predict the answer to a question based on an image and a question related to the image. For ease of description, the image is referred to as the target image and the question related to the image is referred to as the target question.
[0087] OCR: OCR refers to the process by which an electronic device determines the shape of characters in a target image by detecting dark and light patterns, and translates the shape of characters in the target image into computer text using character recognition methods. Electronic devices can refer to scanners, digital cameras, etc.
[0088] NLP (Natural Language Processing): NLP refers to various theories and methods that enable effective communication between humans and computers using natural language.
[0089] In order to more clearly illustrate the answer determination method, device, electronic device and storage medium provided by the present application, the possible application scenarios of the answer determination method, device, electronic device and storage medium provided by the present application will be exemplified below. It can be understood that the following examples are only possible application scenarios of the answer determination method, device, electronic device and storage medium provided by the present application. In other possible embodiments, the answer determination method, device, electronic device and storage medium provided by the present application can be applied to other possible application scenarios, and the following examples do not impose any limitations on this.
[0090] Currently in the field of visual question answering, the answer to the target question can usually be predicted through the following three solutions:
[0091] (1) The text recognition module uses OCR technology to obtain the target text included in the image and the location information of each target text in the image. The image feature extraction module extracts the image features of the corresponding position according to the target text. The word encoding module encodes the target text and the target question text to obtain a text feature sequence. The answer determination module determines the answer to the question based on the image features output by the image feature extraction module and the text feature sequence output by the word encoding module. This patent uses the multimodal information of the document's vision, text, and location to determine the answer to the question.
[0092] (2) The text reading expert module in the hybrid expert model uses OCR technology to obtain the text information in the target image, and obtains the answer to the target question based on the text information and the target question input into the hybrid expert model. Different expert models are used to process the questions according to the question category, thereby improving the accuracy of the answer.
[0093] (3) In natural scenes, the relative spatial relationship features between the object and the text object in the target image are obtained through modeling, and the relative semantic features of the predicted words and text objects are obtained when no modeling is performed to obtain the prior knowledge relationship. The answer to the target question is generated based on the relative spatial relationship features and the prior knowledge relationship.
[0094] The above solutions (1) and (2) both rely on OCR technology to obtain text information in the target image, and determine the answer to the target question based on the text information obtained by OCR technology. When OCR recognition errors occur, solutions (1) and (2) will determine the answer based on the erroneous OCR recognition results. This phenomenon is called OCR error accumulation in this article. For example, Figure 1a As shown in the figure, if the optical character recognition technology, i.e., OCR technology, mistakenly recognizes "Taiyuan XX University" in the target image as "Dayuan XX University", the answer to the target question "Where did you study for a master's degree" will be the wrong "Dayuan XX University". Therefore, the result obtained by OCR recognition will directly affect the accuracy of the answer predicted by the visual question answering. Therefore, the above solutions (1) and (2) cannot solve the problem that OCR recognition may mistakenly recognize the text in the image, thereby reducing the accuracy of the answer predicted by the visual question answering.
[0095] The above solution (3) needs to extract the relevant features of the object in the target image through the offline target detection network, and relies on the relative spatial features between the object and the text object in the target image. Figure 1b There is no object in the pure document target image shown, so solution (3) cannot determine the answer to the target question based on the relative spatial features between the object and the text object. Therefore, solution (3) does not support Figure 1b The document-only scenario shown.
[0096] Based on this, in order to improve the accuracy of the answers predicted by visual question answering and improve the applicability of visual question answering, this application provides an answer determination method, see Figure 2 , methods include:
[0097] S201, identifying each original text in the target image by an optical character recognition method, and obtaining multimodal features of each original text.
[0098] The multimodal features include semantic features of the original text and positional features used to indicate the position of the original text in the target image.
[0099] S202, according to the multimodal features of each original text, determine the text that is the answer to the target question from the multiple original texts as the candidate text.
[0100] S203, for each target text in the candidate texts, determine in each original text a text whose position is associated with the position of the target text as a context text corresponding to the target text.
[0101] The target text is any alternative text.
[0102] S204, for each target text, based on the multimodal features of each context text corresponding to the target text and the semantic features of the target text, predict the probability that the target text is an accurately recognized text as the target probability of the target text.
[0103] S205 , for each target text, predict the text at the position of the target text in the target image according to the multimodal features of each context text corresponding to the target text as the predicted text corresponding to the target text.
[0104] S206, among the candidate texts, determine the target text whose target probability meets the preset low probability condition, and replace the determined target text with the corresponding predicted text to obtain the replaced candidate text as the answer to the target question.
[0105] In the application of the embodiment of the present application, on the one hand, each original text existing in the target image is obtained through OCR recognition, and the multimodal features of each original text are obtained, wherein the multimodal features include the semantic features of the original text and the position features used to indicate the position of the original text in the target image; according to the multimodal features of each original text, the text belonging to the answer to the target question is determined from multiple original texts as the candidate text; for each target text in the candidate text, the text whose position is associated with the position of the target text is determined in each original text as the context text corresponding to the target text, and the target text is any candidate text; for each target text, according to the multimodal features of each context text corresponding to the target text and the semantic features of the target text, the probability that the target text is the text accurately recognized is predicted as the target probability of the target text; for each target text, according to the multimodal features of each context text corresponding to the target text, the text at the position of the target text in the target image is predicted as the predicted text corresponding to the target text; among the candidate texts, the target text whose target probability meets the preset low probability condition is determined, and the determined target text is replaced with the corresponding predicted text to obtain the replaced candidate text as the answer to the target question. Since the position of the context text corresponding to the target text is associated with the position of the target text, it can be considered that the context text corresponding to the target text is semantically associated with the target text, and it can be determined whether the semantics of the content composed of the target text and the context text corresponding to the target text are correct according to the multimodal features of the context texts corresponding to the target text and the semantic features of the target text, and it can be determined that the probability of the target text being an accurately recognized text can be obtained, and the target probability of the target text can be obtained. In addition, since the position of the context text corresponding to the target text is associated with the position of the target text, it can be considered that the context text corresponding to the target text is semantically associated with the text at the position of the target text, and it can be predicted that the text at the position of the target text and the content composed of the context text corresponding to the target text can be expressed according to the multimodal features of the context text corresponding to the target text, and the text at the position of the target text can be more accurately predicted, and the predicted text corresponding to the target text can be obtained. It can be considered that the predicted text may be the real text at the position of the target text in the target image. It can be understood that if the target probability of the target text is higher, the probability that the target text is an accurately recognized text is greater, that is, the accuracy of OCR recognition is higher. Therefore, when the target probability meets the preset low probability condition, it can be considered that the accuracy of OCR recognition is low, that is, the text at the target text position should not be the target text, and the target text can be replaced with a predicted text with higher accuracy.Based on this, the alternative text is corrected by replacing the target text in the alternative text whose target probability meets the preset low probability condition with the corresponding predicted text to obtain the replaced alternative text. Compared with the alternative text, the replaced alternative text, that is, the answer to the target question, has a higher accuracy, thereby improving the accuracy of the answer to the target question predicted by the visual question answering.
[0106] On the other hand, the target image in the embodiment of the present application can be a document image in a document scene, or it can be an image containing text obtained by photographing a natural scene. Therefore, the answer determination method provided in the embodiment of the present application has a wider scope of application and can support document scenes, natural scenes, etc., thereby improving the applicability of visual question answering.
[0107] The above S201-S206 will be described exemplarily below:
[0108] In S201, the optical character recognition method is OCR. The target image may refer to a document image in a document scene. For example, the target image may be Figure 1b As shown, the target image may also be a document image such as a paper or newspaper. The target image may also refer to an image containing text obtained by photographing a natural scene with an image acquisition device such as a camera or a mobile phone. For example, the target image may be an animal in a zoo and an animal introduction obtained by photographing the animal with a mobile phone.
[0109] The original texts existing in the target image can be obtained through OCR recognition, and the positions of the original texts in the target image can be obtained, that is, the positional features of the original texts can be obtained. In addition, the semantic features of the original texts can be obtained by extracting features from the original texts. The multimodal features of the original texts can be obtained by fusing the semantic features of the original texts with the positional features of the original texts. Exemplarily, the method of fusing the semantic features and the positional features to obtain the multimodal features can be: splicing the semantic features and the positional features to obtain the multimodal features; or: inputting the semantic features and the positional features into the fusion model to obtain the multimodal features output by the fusion model.
[0110] The features in this article can be represented in the form of vectors or other non-vector forms. The following will explain how to obtain the multimodal features of each original text, which will not be repeated here.
[0111] In S202, the multimodal features of each original text and the problem text features corresponding to the text that makes up the target problem can be input into a classifier, and the classifier classifies each original text. If the output of the classifier corresponding to a certain original text is 0, it is considered that the original text does not belong to the answer to the target problem; if the output of the classifier corresponding to a certain original text is 1, it is considered that the original text belongs to the answer to the target problem. Determine the original text for which the corresponding classifier output is 1 as the alternative text. The classifier can refer to a softmax classifier that can be used for multi-classification tasks, or it can refer to other classifiers that can be used for multi-classification tasks. Exemplarily, in Figure 1a the shown scenario, the alternative text is "Dayaun XX University".
[0112] In S203, the target text can be any alternative text. Exemplarily, in Figure 1a the shown scenario, the target text can be "Da" at the first position of the alternative text, or "Yuan", or "X", or "X", or "Da" at the fifth position of the alternative text, or "University".
[0113] The position having an association relationship with the position of the target text can refer to a position within a preset range from the position of the target text. The preset range can refer to the number of texts separated from the target text being less than a preset number threshold, and the preset number threshold can be set to 8, 10, 12, etc. Then in this example, the context text corresponding to the target text refers to the text for which the number of texts separated from the target text is less than the preset number threshold.
[0114] The preset range can also refer to being on the same line or adjacent lines as the target text. Then in this example, the context text corresponding to the target text refers to the text on the same line as or adjacent to the target text.
[0115] In S204, the probability that the target text is the accurately recognized text can be predicted based on the correlation between the multimodal features of each context text corresponding to a certain target text and the semantic features of the target text, as the target probability of the target text.
[0116] Since the position of the context text corresponding to the target text has an association relationship with the position of the target text, it can be considered that the context text corresponding to the target text is semantically associated with the target text. Thus, it is possible to determine whether the semantics of the content composed of the target text and the context text corresponding to the target text is correct based on the correlation between the multimodal features of each context text corresponding to the target text and the semantic features of the target text, and it is also possible to determine the probability that the target text is the accurately recognized text, obtaining the target probability of the target text.
[0117] The greater the correlation between the multimodal features of the context texts corresponding to the target text and the semantic features of the target text, the greater the probability that the target text is accurately recognized. That is, the higher the accuracy of OCR recognition, the higher the target probability of the target text. How to predict the target probability of the target text will be described below, so it will not be repeated here.
[0118] In S205, the commonly used texts can be stored in a text database, which can be regarded as a fixed dictionary, so the text database is referred to as a fixed dictionary hereinafter. For each commonly used text in the fixed dictionary, the correlation between the semantic features of the commonly used text and the multimodal features of each context text corresponding to a target text is calculated, and the commonly used text whose correlation meets the preset conditions is used as the predicted text corresponding to the target text.
[0119] The preset condition may refer to the correlation being greater than a preset correlation threshold, or may refer to being in the front of a preset number of places in the order of correlation from large to small.
[0120] Since the position of the context text corresponding to the target text is associated with the position of the target text, it can be considered that the context text corresponding to the target text is semantically associated with the text at the target text position. Based on the correlation between the semantic features of each commonly used text in the fixed dictionary and the multimodal features of the context text corresponding to the target text, the greater the correlation between the semantic features of a certain commonly used text and the multimodal features of the context text corresponding to the target text, it can be considered that the commonly used text is more likely to be the real text at the target text position in the target image, which means that the accuracy of using the commonly used text as the predicted text corresponding to the target text is higher.
[0121] For example, in Figure 1aIn the scene shown, if the target text is "Da" which is in the first position of the alternative texts, then based on the correlation between the context text "2016.09 - present (Master)" corresponding to "Da" and the text at the position of "Da", it can be predicted that the text at the position of "Da" in the target image should be the text in a certain university name. Moreover, based on the correlation between the context text "Former XX University" corresponding to "Da" and the text at the position of "Da", it can be predicted that the text at the position of "Da" and "Former XX University" should form a certain university name. Then, the probability that each common text and "Former XX University" form a certain university name can be predicted, that is, the correlation between the semantic features of each common text and the multimodal features of the context text corresponding to the target text is obtained. Based on the preset conditions, it can be determined that the probability that the common text "Tai" and "Former XX University" form a certain university name is relatively large, so "Tai" can be used as the predicted text corresponding to the target text "Da". It can also predict the probability that the target text "Da" and "Former XX University" form a certain university name, that is, obtain the target probability of the target text "Da".
[0122] The example provided in this application is only for facilitating the understanding of the process of predicting the target probability of the target text and the predicted text corresponding to the target text, and does not mean that the machine predicts the target probability of the target text and the predicted text corresponding to the target text by executing the steps shown in the above example. The steps executed by the machine can refer to the steps shown in S201 - S206. How to predict the predicted text corresponding to the target text will be described below and will not be elaborated here.
[0123] In S206, the preset low - probability condition can refer to that the target probability is less than the first preset probability threshold. The first preset probability threshold can be set according to the actual situation or past experience. Exemplarily, the first preset probability threshold can be 0.8, 0.9, 0.95, etc. Then, the target text whose target probability satisfies the preset low - probability condition refers to: the target text whose target probability is less than the first preset probability threshold.
[0124] Exemplarily, if the first preset probability threshold is 0.9, in Figure 1aIn the example shown, assume that the target probability of the target text "big" (in the first position of the alternative text) is 0.4, the target probability of the target text "original" is 0.95, the target probability of the target text "X" is 0.96, the target probability of the target text "X" is 0.94, the target probability of the target text "big" (in the fifth position of the alternative text) is 0.95, and the target probability of the target text "university" is 0.96. Then, the target text whose target probability satisfies the preset low-probability condition is "big" in the first position of the alternative text. If it is assumed that the predicted text corresponding to this target text is "too", then replace the target text "big" with the predicted text "too" corresponding to this target text to obtain the replaced alternative text "Taiyuan XX University", and use this replaced alternative text as the answer to the target question.
[0125] In the following, based on Figure 3 the flowchart shown, an exemplary description will be given of how to predict the predicted text corresponding to the target text in the aforementioned S205. Refer to Figure 3 , the aforementioned S205 includes:
[0126] S2051, determine the initial current context feature according to the multi-modal features of the context text corresponding to the non-alternative text, and determine the initial current hidden state according to the semantic feature of the non-alternative text, the multi-modal features of the context text corresponding to the non-alternative text, and the hidden state of the non-alternative text.
[0127] S2052, determine a new current hidden state according to the semantic feature of the current target text, the current context feature, and the current hidden state.
[0128] Among them, the current target text is initially the target text in the first position of the alternative text.
[0129] S2053, determine the context feature of the current target text according to the multi-modal features of the context texts corresponding to the current target text, and use it as the new current context feature.
[0130] S2054, predict the text at the position of the current target text in the target image according to the new current context feature and the new current hidden state, and use it as the predicted text corresponding to the current target text.
[0131] S2055, use the target text in the position one after the current target text as the new current target text, and return to execute the step of determining a new current hidden state according to the semantic feature of the current target text, the current context feature, and the current hidden state.
[0132] Selecting this embodiment, the new current hidden state can be determined based on the semantic features, current context features, and current hidden state of the current target text, and the context features of the current target text can be determined based on the multimodal features of each context text corresponding to the current target text as the new current context features. According to the new context features and the new current hidden state, the predicted text corresponding to the current target text is predicted, and the target text located at the position one after the current target text is used as the new current target text, and the step of determining the new current hidden state based on the semantic features, current context features, and current hidden state of the current target text is returned for execution. The predicted texts corresponding to each target text are obtained in a loop manner, and the hidden state and context features of the current loop can be calculated based on the hidden state and context features of the previous loop, considering the relevance between adjacent target texts, and improving the accuracy of the predicted text corresponding to the predicted target text.
[0133] The following will give an exemplary description of the foregoing S2051 - S2055:
[0134] In S2051, the initial current context features can be determined according to the multimodal features of the context texts corresponding to all non - alternative texts in each original text, or the initial current context features can be determined according to the multimodal features of the context texts corresponding to some non - alternative texts in each original text. Some non - alternative texts can refer to all non - alternative texts located before the position of the alternative text, or can refer to non - alternative texts located a preset number of lines before the position of the alternative text, etc.
[0135] Exemplarily, in Figure 1a the example shown, some non - alternative texts can refer to the non - alternative texts in the part of "Educational experience... Master", or can refer to the non - alternative texts in the part of "College: ... Master".
[0136] The selection of non - alternative texts when determining the initial current hidden state is the same as the selection of non - alternative texts for determining the initial current context features, which will not be elaborated here.
[0137] In S2052, the current target text is initially the target text located at the first position of the alternative text. Exemplarily, in Figure 1a the example shown, the alternative text is "Dayuan XX University", and the current target text is initially the "Da" located at the first position of the alternative text.
[0138] The semantic features, current context features, and current hidden state of the current target text can be input into the recurrent neural network to obtain a new current hidden state output by the neural network model. The recurrent neural network can be a language generation model or other recurrent neural network other than the language generation model. Specifically, the new current hidden state can be calculated using the following formula (1):
[0139]
[0140] in, is the new current hidden state; is a recurrent neural network; is the current context feature; Represents a splicing operation; is the semantic feature of the current target text; is the current hidden state.
[0141] In S2053, the context feature of the current target text can be obtained as a new current context feature by taking the average of the multimodal features of the context texts corresponding to the current target text. The context feature of the current target text can also be obtained as a new current context feature by taking the weighted sum of the multimodal features of the context texts corresponding to the current target text. The following will provide an exemplary description of how to determine the new current context feature, which will not be repeated here.
[0142] In S2054, commonly used texts can be stored in a fixed dictionary, and for each commonly used text in the fixed dictionary, the probability of each commonly used text is calculated according to the new current context features and the new current hidden state, and the commonly used text whose probability meets the preset probability condition is used as the predicted text corresponding to the current target text.
[0143] The preset probability condition may refer to the probability being greater than a second preset probability threshold, or may refer to being in the front preset number of digits in the descending order of probability.
[0144] Specifically, the probability of each commonly used text can be calculated by the following formula (2):
[0145]
[0146] in, is the probability of the common text p corresponding to the current target text; It is the K classification regression algorithm; is a super parameter; is the new current context feature; is the new current hidden state; Represents a splicing operation; It is a super parameter.
[0147] In S2055, the new current target text is the target text located at the position one after the current target text. Exemplarily, in Figure 1a the example shown, if the current target text is "original", then the new current target text is "X".
[0148] Based on the new current target text, return to execute the step of determining the new current hidden state according to the semantic features, current context features, and current hidden state of the current target text until all target text positions are traversed. That is, if the new current target text is the target text located at the last position of the alternative text, then based on this new current target text, execute S2052 - S2054, and after executing S2054, no longer execute S2055.
[0149] Exemplarily, in Figure 1a the example shown, the alternative text is "Dayaun XX University". If the current target text is "Da" located at the fifth position of the alternative text, then the new current target text is "University". Based on this new current target text "University", execute S2052 - S2054, and after executing S2054, no longer execute S2055.
[0150] The following will take Figure 1a the scenario shown as an example to give an exemplary description of the loop process of the above S2052 - S2055. Initially, that is, in the first loop, the current target text is "Da" located at the first position of the alternative text. According to the semantic features of "Da", the initial current context features, and the initial current hidden state, determine the new current hidden state, and denote this new current hidden state as hidden state 1; according to the multimodal features and position of the context text corresponding to "Da", determine the new current context features, and denote this new current context features as context features 1; according to hidden state 1 and context features 1, predict the prediction text corresponding to "Da".
[0151] In the second loop, the current target text is "original". According to the semantic features of "original", context features 1, and hidden state 1, determine the new current hidden state, and denote this new current hidden state as hidden state 2; according to the multimodal features and position of the context text corresponding to "original", determine the new current context features, and denote this new current context features as context features 2; according to hidden state 2 and context features 2, predict the prediction text corresponding to "original". The subsequent loop process is类推 until the prediction text corresponding to "University" is predicted in the fifth loop.
[0152] An exemplary description of how to predict the prediction text corresponding to the target text has been given above. In the following text, it will be based on Figure 4The flowchart shown in FIG. 1 is an exemplary description of how to predict the target probability of the target text in the aforementioned S204. Figure 4 , the aforementioned S204 includes:
[0153] S2041, determining the initial current context features based on the multimodal features of the context text corresponding to the non-alternative text, and determining the initial current hidden state based on the semantic features of the non-alternative text, the multimodal features of the context text corresponding to the non-alternative text, and the hidden state of the non-alternative text.
[0154] S2042, determining a new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state.
[0155] The current target text is initially the target text located at the first position of the alternative text.
[0156] S2043: Determine the context feature of the current target text according to the multimodal features of each context text corresponding to the current target text as a new current context feature.
[0157] S2044, based on the new current context features, the new current hidden state, and the semantic features of the current target text, predict the probability that the current target text is the accurately recognized text as the target probability of the current target text.
[0158] S2045, taking the target text located one position after the current target text as the new current target text, and returning to execute the step of determining a new current hidden state based on the semantic features of the current target text, the current context features, and the current hidden state.
[0159] By selecting this embodiment, a new current hidden state can be determined based on the semantic features, current context features, and current hidden state of the current target text, and the context features of the current target text can be determined based on the multimodal features and position of the context text corresponding to the current target text as the new current context features. According to the new current context features, the new current hidden state, and the semantic features of the current target text, the probability of the current target text being an accurately recognized text is predicted as the target probability of the current target text, and the target text located one position after the current target text is used as the new current target text, and the step of determining the new current hidden state according to the semantic features, current context features, and current hidden state of the current target text is returned. The predicted text corresponding to each target text is obtained in a cyclic manner, and the hidden state and context features of the current cycle can be calculated based on the hidden state and context features of the previous cycle, taking into account the correlation between adjacent target texts, and improving the accuracy of the target probability of the predicted target text.
[0160] The following will give an exemplary description of the foregoing S2041 - S2045:
[0161] S2041 - S2043 are the same as the foregoing S2051 - S2053, and the relevant descriptions of the foregoing S2051 - S2053 can be referred to, and will not be elaborated here.
[0162] In S2044, the target probability of the current target text can be calculated through the following formula (3):
[0163]
[0164] Wherein, is the target probability of the current target text; c is the current target text; is the binary classification regression algorithm; , , and are all hyperparameters; is the new current hidden state; is the new current context feature; is the semantic feature of the current target text.
[0165] In S2045, the new current target text is the target text whose position is one position after the current target text. Exemplarily, in the example shown in Figure 1a , if the current target text is "original", then the new current target text is "X".
[0166] Based on the new current target text, return to execute the step of determining the new current hidden state according to the semantic feature, current context feature, and current hidden state of the current target text until all target text positions are traversed, that is, if the new current target text is the target text whose position is at the last position of the alternative text, then based on this new current target text, execute S2042 - S2044, and after executing S2044, S2045 is no longer executed.
[0167] Exemplarily, in the example shown in Figure 1a , the alternative text is "Dayaun XX University". If the current target text is "Da" whose position is the fifth position of the alternative text, then the new current target text is "University". Based on this new current target text "University", execute S2042 - S2044, and after executing S2044, S2045 is no longer executed.
[0168] The following will take Figure 1aTaking the scenario shown as an example, an exemplary description is given for the loop process of S2042 - S2045 above. Initially, that is, in the first loop, the current target text is "big" which is at the first position of the alternative texts. According to the semantic features of "big", the initial current context features, and the initial current hidden state, a new current hidden state is determined, and this new current hidden state is denoted as hidden state 1; according to the multimodal features and position of the context text corresponding to "big", a new current context feature is determined, and this new current context feature is denoted as context feature 1; according to the semantic features of "big", hidden state 1, and context feature 1, the target probability of "big" is predicted.
[0169] In the second loop, the current target text is "original". According to the semantic features of "original", context feature 1, and hidden state 1, a new current hidden state is determined, and this new current hidden state is denoted as hidden state 2; according to the multimodal features and position of the context text corresponding to "original", a new current context feature is determined, and this new current context feature is denoted as context feature 2; according to the semantic features of "original", hidden state 2, and context feature 2, the target probability of "original" is predicted. The subsequent loop process follows the same pattern until the target probability of "learning" is predicted in the fifth loop.
[0170] An exemplary description of how to predict the target probability of the target text has been given above. Below, an exemplary description will be given for how to determine the new current context features in S2053 and S2043 above.
[0171] In a possible embodiment, the multimodal features of each context text corresponding to the current target text are weighted to obtain the context feature of the current target text as the new current context feature, where the weight corresponding to the multimodal feature of the context text belonging to the alternative text is greater than the weight corresponding to the multimodal feature of the context text not belonging to the alternative text.
[0172] The new context feature can be calculated through the following formulas (4) - (6):
[0173]
[0174]
[0175]
[0176] Among them, is the new current context feature; is the weight corresponding to the multimodal feature of context text i corresponding to the current target text; is the multimodal feature of context text i corresponding to the current target text; The weight corresponding to the multimodal features of the context text corresponding to the current target text; It is the K classification regression algorithm; It can be calculated by formula (6). If the context text corresponding to the current target text is i, then ; , , , , as well as All are hyperparameters; C is a category feature, which is used to characterize whether the context text corresponding to the current target text belongs to the candidate text; is the new current hidden state.
[0177] According to the description of the above formulas (1)-(6), the cycle of calculating the target probability of the current target text and the predicted text corresponding to the current target text can be recorded as time t, and the context texts corresponding to different current target texts may be the same, so, The multimodal features that can represent the context feature i corresponding to the current target text are The weight corresponding to the moment.
[0178] Based on the relevant description of the aforementioned S202, when determining the alternative text, the original text of the answer to the target question, that is, the alternative text, can be marked as "answer", and the original text that does not belong to the answer to the target question can be marked as "other". If the tags of the context text corresponding to the current target text are different, then the category feature C of the context text corresponding to the current target text is different. The weight corresponding to the multimodal feature of the context text belonging to the alternative text is greater than the weight corresponding to the multimodal feature of the context text that does not belong to the alternative text, that is, the weight corresponding to the multimodal feature of the context text marked as "answer" is greater than the weight corresponding to the multimodal feature of the context text marked as "other".
[0179] By selecting this embodiment, the context features of the current target text can be obtained by weighting the multimodal features of each context text corresponding to the current target text, and the new current context features can be obtained as a new current context feature. In addition, since the answer to the target question is generally a phrase or a sentence, the correlation between the alternative texts should be higher than the correlation between the alternative texts and the non-alternative texts. Therefore, when setting the weight, the weight corresponding to the multimodal features of the context text belonging to the alternative text is greater than the weight corresponding to the multimodal features of the context text not belonging to the alternative text, thereby increasing the influence of the multimodal features of the context text with a higher correlation with the current target text on the new current context features, and reducing the influence of the multimodal features of the context text with a lower correlation with the current target text on the new current context features, thereby more reasonably allocating the weights corresponding to the multimodal features of each context text, improving the accuracy of the obtained new context features, improving the accuracy of the predicted text corresponding to the predicted target text and the target probability of the target text, and thus improving the accuracy of the answer predicted by the visual question answering.
[0180] An exemplary description has been given above on how to determine new current context features. An exemplary description will be given below on how to obtain the multimodal features of each original text in the aforementioned S201.
[0181] In a possible embodiment, the multimodal features of the original text also include: visual features of the original text; see Figure 5 In the aforementioned S201, the multimodal features of each original text are obtained, including:
[0182] S501, obtaining semantic features of each original text and position features of each original text.
[0183] The original texts in the target image can be obtained through OCR recognition, and the original texts in the target image can be divided into multiple tokens (units), and each original text corresponds to a token. By arranging the tokens according to their positions in the target image, the text sequence corresponding to the target image can be obtained. The text sequence can be input into the text encoder to obtain the semantic features of each token, that is, the semantic features of each original text. The text sequence can also be input into the semantic feature extraction module to obtain the semantic features of each token, that is, the semantic features of each original text. The following will provide an exemplary explanation of how to obtain the position features of each original text, which will not be repeated here.
[0184] S502, dividing the target image into a plurality of blocks, and determining the visual features of each block.
[0185] The target image can be divided into multiple P×P patches (tiles), each of which corresponds to an original text. By arranging each patch according to the position of each original text in the target image, the image sequence corresponding to the target image can be obtained. The image sequence can be input into the image encoder to obtain the visual features of each patch. The image sequence can also be input into the image feature extraction module to obtain the visual features of each patch. Since each patch corresponds to an original text, the visual features of each patch are also the visual features of each original text. The following is a description corresponding to the semantic features, and the visual features of each tile are called the visual features of each original text.
[0186] S503, inputting the semantic features of each original text, the position features of each original text, the visual features of each block and the target question into the multimodal pre-training model to obtain the multimodal features of each original text.
[0187] The multimodal pre-trained model is obtained by pre-training the original training model based on sample images.
[0188] As described in S501 and S502 above, the semantic features of each original text are obtained according to the text sequence corresponding to the target image, and the visual features of each original text are obtained according to the image sequence corresponding to the target image. Therefore, the semantic features of each original text are arranged according to the position of each original text in the target image, that is, the semantic features of each original text can form a semantic feature sequence. The visual features of each original text are also arranged according to the position of each original text in the target image, that is, the visual features of each original text can form a visual feature sequence.
[0189] When the semantic features of each original text, the positional features of each original text, the visual features of each original text, and the target question are input into the multimodal pre-training model, in order to distinguish the semantic features of each original text and the visual features of each original text, the semantic features of each original text and the visual features of each original text may also carry feature category flags.
[0190] Since the semantic feature sequence is obtained by arranging the semantic features of each original text according to the position of each original text in the target image, and the visual feature sequence is obtained by arranging the visual features of each original text according to the position of each original text in the target image, the semantic feature sequence and the visual feature sequence themselves already carry the position features of each original text. Therefore, the multimodal pre-training model can fuse the semantic features, visual features, and position features of a certain original text based on the semantic feature sequence and the visual feature sequence to obtain the multimodal features of the original text. The multimodal pre-training model can also fuse the features of the text contained in the target question with the semantic features and visual features of each original text to obtain the multimodal features of each original text, so as to more accurately judge whether the original text belongs to the answer to the target question based on the multimodal features of a certain original text. The training process of the multimodal pre-training model will be exemplified below, which will not be repeated here.
[0191] By selecting this embodiment, the target image can be divided into multiple blocks by obtaining the semantic features of each original text and the positional features of each original text, determining the visual features of each block, and inputting the semantic features of each original text, the positional features of each original text, the visual features of each block, and the target question into the multimodal pre-training model to obtain the multimodal features of each original text, and the three different types of features, namely, semantic features, positional features, and visual features corresponding to each original text, are fused to obtain the multimodal features of each original text. The types of features included in the multimodal features are enriched, thereby improving the accuracy of the multimodal features of each original text, and further improving the accuracy of the answers predicted by the visual question answering.
[0192] The following is an exemplary description of how to obtain the position features of each original text in the aforementioned S201 and S501.
[0193] In a possible embodiment, starting with the first original text in the target image, all original texts in the target image are encoded, and the codes corresponding to each original text are used as position features of each original text. However, since the multimodal pre-training models related to NLP generally only support 512-length inputs, and start with 0 in computer language, when the code corresponding to a certain original text is 511, that is, when the original text is the 512th original text in the target image, the code of the original text located after the original text should be 0, which means that it is necessary to start with the original text after the original text and encode other unencoded original texts in the target image.
[0194] For example, see Figure 6a, the position features of each original text obtained in this embodiment are denoted as position_id (position encoding), that is, Figure 6a the position encoding 1 in Figure 6a . Starting from the first original text "egg" in the target image, each original text in the target image is encoded. Then, the position_id (position encoding) corresponding to the original text "egg" is 0, the position_id corresponding to the original text "white" is 1, the position_id corresponding to the original text "quality" is 2, the position_id corresponding to the original text "structure" is 3, the position_id corresponding to the original text "of" is 5, the position_id corresponding to the original text "most" is 6, the position_id corresponding to the original text "new" is 7, the position_id corresponding to the original text "progress" is 8, and the position_id corresponding to the original text "development" is 9.
[0195] Moreover, in this embodiment, if the semantic features of each original text need to be input into the multi-modal pre-training model, only the semantic features of 512 original texts encoded from 0 to 511 can be input into the multi-modal pre-training model each time. That is, if the number of original texts in the target image is greater than 512, the semantic features of the original texts in the target image need to be input into the multi-modal pre-training model in batches. Then, since the multi-modal pre-training model only obtains the connection between the original text contexts based on the semantic features of the original texts input in the same batch, the method of inputting the semantic features of the original texts in the target image into the multi-modal pre-training model in batches may cause a certain original text and its context to be in different batches, making the multi-modal pre-training model unable to completely obtain the connection between the original text and its context, and thus resulting in a relatively low accuracy of the multi-modal features of the original text obtained by the multi-modal pre-training model.
[0196] Based on this, in order to avoid the situation that the input text is incomplete, resulting in a relatively low accuracy of the multi-modal features of the original text obtained by the multi-modal pre-training model, in a possible embodiment, the position features include: one-dimensional position features and two-dimensional position features; see Figure 6b , the position features of each original text are obtained by the following method, including:
[0197] S601, identifying the regions where each original text exists in the target image through an optical character recognition method as text regions.
[0198] The optical character recognition method is OCR. OCR can determine the area in the target image where the original text exists, and generally divides the original text on the same line into the same text area. Exemplarily, the text area can be as shown in Figure 6a each text box in the target image in the figure, and one original text in the text area is a unit.
[0199] S602. For each text area, determine the position of the text area in the target image as the two-dimensional position feature of each original text included in the text area.
[0200] The position of the text area in the target image can refer to which row and which column the text area is located in the target image. Exemplarily, in the example shown in Figure 6a Figure, if the text area 2 is located in the first column of the second row in the target image, then the second row and the first column can be used as the two-dimensional position feature of the original texts "最", "新", "进", "展" included in the text area 2.
[0201] S603. For each text area, starting from the first original text in the text area, use the position of each original text in the text area as the one-dimensional position feature of each original text in the text area.
[0202] Exemplarily, in the example shown in Figure 6a Figure, record the one-dimensional position feature of each original text as position_id_bbox (position encoding), that is, the position encoding 2 in Figure 6a Figure. Then, for the text area 1, the position_id_bbox corresponding to the original text "蛋" is 0, the position_id_bbox corresponding to the original text "白" is 1, the position_id_bbox corresponding to the original text "质" is 2, the position_id_bbox corresponding to the original text "结" is 3, the position_id_bbox corresponding to the original text "构" is 4, and the position_id_bbox corresponding to the original text "的" is 5; for the text area 2, the position_id_bbox corresponding to the original text "最" is 0, the position_id_bbox corresponding to the original text "新" is 1, the position_id_bbox corresponding to the original text "进" is 2, and the position_id_bbox corresponding to the original text "展" is 3.
[0203] This embodiment is selected. Since the number of original texts in a text area generally does not exceed 512, the original texts in the target image can be divided by the text areas obtained by OCR recognition, and by taking the position of each text area in the target image as the two-dimensional position feature of each original text included in each text area, for each text area, starting from the first original text in the text area, the position of each original text in the text area is taken as the one-dimensional position feature of each original text in the text area to determine the position feature of each original text, so that the position code of each original text does not exceed 512, thereby avoiding the need to input the semantic features of the original text in the target image into the multimodal pre-training model in batches, so that the multimodal pre-training model can completely obtain the text content in the target image, and improve the accuracy of the multimodal features of the original text obtained by the multimodal pre-training model.
[0204] The following will take the representation of features as vectors as an example, based on the above method of obtaining the position features of each original text, combined with Figure 7 The process shown is an exemplary description of the method of obtaining multimodal features of each original text. Figure 7 The one-dimensional position encoding in is the aforementioned one-dimensional position feature, the two-dimensional position encoding is the aforementioned two-dimensional position feature, and the vector category mark corresponds to the aforementioned feature category mark.
[0205] See also Figure 7 , the original texts in the target image are identified by an optical character recognition method, and the semantic vectors of the original texts are obtained according to the method shown in S501 above, the visual vectors of the original texts are obtained based on the method shown in S502 above, and the position features of the original texts are obtained according to the methods shown in S601-S603 above, that is, the one-dimensional position coding and two-dimensional position coding of the original texts are obtained. The semantic vector, visual vector, one-dimensional position coding, two-dimensional position coding and the vector category mark used to characterize a vector as a semantic vector or a visual vector of each original text are input into the multimodal pre-training model to obtain the multimodal feature representation vector of each original text output by the multimodal pre-training model. The multimodal feature representation vector of the original text is the multimodal feature of the original text. The multimodal pre-training model can be a model with a Transformer structure.
[0206] The above has been an exemplary description of how to obtain the multimodal features of each original text. Figure 8a The model training flowchart shown is an exemplary description of how to pre-train the original training model based on the sample images in the aforementioned S503 to obtain the multimodal pre-training model.
[0207] See also Figure 8aThe model training process includes two modules: data processing and model training. The data processing module includes two processes: data loading and data conversion. The model training module includes two processes: model forward and self-supervised training. The following will first illustrate the two processes included in the data processing module:
[0208] Data loading process:
[0209] If a large number of sample images are used when training a multimodal pre-training model, the trained multimodal pre-training model can be exposed to a wide range of scenes and thus have better generalization capabilities. Therefore, in order to enhance the generalization of the multimodal pre-training model, it is necessary to construct a dataset that stores a large number of sample images. Specifically, the constructed dataset can mainly include: a Chinese dataset consisting of tens of millions of Chinese sample images, and an English dataset consisting of tens of millions of English sample images.
[0210] The English data set can use the more recognized English document scanning data set in the field of document understanding, which contains tens of millions of English documents. Each document is in tif format (Tagged Image File Format, a flexible lossless image file storage format) and can be split into multiple images, which can eventually be split into tens of millions of images in total.
[0211] Chinese data sets can include: Chinese newspapers, journals, magazines, etc. The Chinese newspaper data set comes from electronic newspaper websites, covering dozens of newspapers, tens of thousands of newspapers, hundreds of thousands of sample images, and rich and varied layouts.
[0212] Data sets can be stored in the form of shared memory, and multi-process acceleration can be achieved through parallel operations, so that data can be loaded and processed quickly. In stand-alone mode, all processes access the same shared memory, so all data in the data set is stored in a fixed shared memory. In order to distribute the amount of data to each process as evenly as possible, you can first determine the json (JavaScript Object Notation, a lightweight data exchange format) list processed by each process, and then allocate the amount of data required to load to each process.
[0213] In the case of multiple machines, since shared memory is accessible to the same electronic devices, each electronic device needs to create shared memory. In order to support the storage of larger amounts of data, all data in the data set can be evenly stored in the shared memory of different electronic devices, so that the amount of data that can be processed is theoretically expanded by M times (M is the number of electronic devices). When allocating the amount of data to be loaded to each process, you can also first determine the json list processed by each process, and then allocate the amount of data to be loaded to each process, and it is necessary to determine the data to be loaded by each process and divide it into different electronic devices.
[0214] After each process has loaded the data, the data information loaded by each process is summarized to obtain a complete data set.
[0215] Data conversion process:
[0216] After the data is loaded and the data set is obtained, the sample images in the data set are labeled and processed to obtain the processed sample images and the corresponding annotation true values of each processed sample image. The processed sample images can be Figure 8b shown.
[0217] The following is an illustrative description of the two processes included in the model training module:
[0218] Model forward process:
[0219] The processed sample images are input into the original training model to obtain the output results corresponding to each processed sample image output by the original training model.
[0220] Self-supervised training process:
[0221] According to the differences between the true values of the annotations corresponding to each processed sample image and the output results corresponding to each processed sample image, the parameters of the original training model are adjusted, and the original training model with adjusted parameters is used as the new original training model. The model forward process and the self-supervised training process are repeated until the preset termination conditions are reached to obtain a multimodal pre-training model.
[0222] Specifically, the multimodal pre-trained model is obtained by pre-training the original training model based on the sample image through any one or more of the following methods 1, 2 and 3.
[0223] See also Figure 9a , Method 1 includes:
[0224] S911 , for each sample image, obtaining each sample text existing in the sample image, a semantic feature of each sample text, and a position feature of each sample text.
[0225] Specifically, the method of obtaining the semantic features of each sample text in the sample image is the same as the method of obtaining the semantic features of each original text in the target image in the aforementioned S501, and the method of obtaining the position features of each sample text in the sample image is the same as the method of obtaining the position features of each original text in the target image in the aforementioned S601-S603, which will not be repeated here.
[0226] S912: for each sample image, mask the mask text in the sample image to obtain a masked sample image.
[0227] The masked text is any sample text in the sample image.
[0228] The method of covering the cover text in the sample image may refer to: setting the color of the position where the cover text is located in the sample image to a color different from the background color of the sample image; it may also refer to setting the color of the position where the cover text is located in the sample image to the same color as the background color of the sample image, and so on.
[0229] S911-S912 belong to the aforementioned data conversion process.
[0230] S913, for each sample image, the masked sample image, the sample text belonging to the non-masked text, the semantic features of the sample text belonging to the non-masked text, and the position features of the sample text belonging to the non-masked text are input into the original training model, and the text at the position of the masked text in the sample image output by the original training model is obtained as the predicted masked text corresponding to the masked text in the sample image.
[0231] S913 belongs to the forward process of the aforementioned model.
[0232] S914, based on the difference between the covered text in each sample image and the predicted covered text corresponding to the covered text in each sample image, the parameters of the original training model are adjusted, and the original training model with adjusted parameters is used as the new original training model, and the step of returning to execute for each sample image, inputting the covered sample image, the sample text belonging to the non-covered text, the semantic features of the sample text belonging to the non-covered text, and the position features of the sample text belonging to the non-covered text into the original training model, and obtaining the text at the position of the covered text in the sample image output by the original training model as the predicted covered text corresponding to the covered text in the sample image, until the first preset termination condition is reached.
[0233] S914 belongs to the aforementioned self-supervised training process. The first preset termination condition may refer to the difference between the masked text in each sample image and the predicted masked text corresponding to the masked text in each sample image being less than a first preset difference threshold, or may refer to the number of parameter adjustments to the original training model reaching a first preset number threshold, or may be other first preset termination conditions, and this application does not impose any restrictions on this.
[0234] See also Figure 9b , the second method includes:
[0235] S921, for each sample image, obtaining each sample text existing in the sample image, the visual features of each sample text, and the position features of each sample text.
[0236] Specifically, the method of obtaining the visual features of each sample text in the sample image is the same as the method of obtaining the visual features of each original text in the target image in the aforementioned S502, and the method of obtaining the position features of each sample text in the sample image is the same as the method of obtaining the position features of each original text in the target image in the aforementioned S601-S603, which will not be repeated here.
[0237] S922: for each sample image, mask the mask text in the sample image to obtain a masked sample image.
[0238] The masked text is any sample text in the sample image.
[0239] S922 is the same as the aforementioned S912, and the relevant description of the aforementioned S912 can be referred to, and will not be repeated here. S921-S922 belong to the aforementioned data conversion process.
[0240] S923, for each sample image, the masked sample image, the sample text belonging to the non-masked text, the visual features of the sample text belonging to the non-masked text, and the position features of the sample text belonging to the non-masked text are input into the original training model, and the text at the position of the masked text in the sample image output by the original training model is obtained as the predicted masked text corresponding to the masked text in the sample image.
[0241] S923 belongs to the forward process of the aforementioned model.
[0242] S924, based on the difference between the covered text in each sample image and the predicted covered text corresponding to the covered text in each sample image, the parameters of the original training model are adjusted, and the original training model with adjusted parameters is used as the new original training model, and the step of returning to execute for each sample image, inputting the covered sample image, the sample text belonging to the non-covered text, the visual features of the sample text belonging to the non-covered text, and the position features of the sample text belonging to the non-covered text into the original training model, and obtaining the text at the position of the covered text in the sample image output by the original training model as the predicted covered text corresponding to the covered text in the sample image, until the second preset termination condition is reached.
[0243] S924 belongs to the aforementioned self-supervised training process. The second preset termination condition may refer to the difference between the masked text in each sample image and the predicted masked text corresponding to the masked text in each sample image being less than a second preset difference threshold, or may refer to the number of parameter adjustments to the original training model reaching a second preset number threshold, or may be other second preset termination conditions, and this application does not impose any restrictions on this.
[0244] See also Fig.9c , Method 3 includes:
[0245] S931 , for each sample image, obtaining each sample text existing in the sample image, the semantic feature of each sample text, the visual feature of each sample text, and the position feature of each sample text.
[0246] Specifically, the method for obtaining the semantic features of each sample text in the sample image is the same as the method for obtaining the semantic features of each original text in the target image in the aforementioned S501, the method for obtaining the visual features of each sample text in the sample image is the same as the method for obtaining the visual features of each original text in the target image in the aforementioned S502, and the method for obtaining the position features of each sample text in the sample image is the same as the method for obtaining the position features of each original text in the target image in the aforementioned S601-S603, which will not be repeated here.
[0247] S932: For each sample image, mask the first masking text in the sample image to obtain a first masking image, and mask the second masking text in the sample image to obtain a second masking image.
[0248] The first masked text is any sample text in the sample image, and the second masked text is any sample text in the sample image.
[0249] The first masked image is obtained by masking only the first masked text in the sample image, and the second masked image is obtained by masking only the second masked text in the sample image. The method of masking the first masked text or the second masked text in the sample image is the same as the method of masking the masked text in the sample image in S912, and will not be repeated here.
[0250] S933: for each sample image, determine whether the first masked text in the first masked image and the second masked text in the second masked image are the same sample text, and use the determination result as the true value of the sample image.
[0251] S931-S933 belong to the aforementioned data conversion process. If the first masked text in the first masked image and the second masked text in the second masked image are the same sample text, the judgment result is aligned; if the first masked text in the first masked image and the second masked text in the second masked image are the same sample text, the judgment result is unaligned.
[0252] S934, for each sample image, the first cover image, the second cover image, the non-first cover text in the first cover image, the semantic features of each non-first cover text, the position features of each non-first cover text, the non-second cover text in the second cover image, the visual features of each non-second cover text, and the position features of each non-second cover text are input into the original training model to obtain the prediction result output by the original training model as the prediction result of the sample image.
[0253] The prediction result is used to indicate whether the first masked text in the first masked image and the second masked text in the second masked image are the same sample text.
[0254] S934 belongs to the forward process of the aforementioned model.
[0255] S935, based on the difference between the prediction results of each sample image and the true value of each sample image, the parameters of the original training model are adjusted, and the original training model with adjusted parameters is used as the new original training model, and the execution is returned to the step of inputting the first cover image, the second cover image, the non-first cover text in the first cover image, the semantic features of each non-first cover text, the position features of each non-first cover text, the non-second cover text in the second cover image, the visual features of each non-second cover text, and the position features of each non-second cover text into the original training model for each sample image, and obtaining the prediction result output by the original training model as the prediction result of the sample image, until the third preset termination condition is reached.
[0256] S935 belongs to the aforementioned self-supervised training process. The third preset termination condition may refer to the difference between the prediction result of each sample image and the true value of each sample image being less than the third preset difference threshold, or may refer to the number of parameter adjustments to the original training model reaching the third preset number threshold, or may refer to other third preset termination conditions, and this application does not impose any restrictions on this.
[0257] In a possible embodiment, the original training model may be trained based on the above-mentioned method 1, method 2, and method 3 to obtain a multimodal pre-trained model. In other possible embodiments, the original training model may be trained based on the above-mentioned method 1 and method 2 to obtain a multimodal pre-trained model, and the original training model may be trained based on the above-mentioned method 1 to obtain a multimodal pre-trained model, and so on.
[0258] When the original training model is trained based on the above-mentioned method 1 and method 2 to obtain a multimodal pre-training model, referring to the above-mentioned relevant description of S501-S502, the semantic features are obtained based on each token, and the visual features are obtained based on each patch. Therefore, the above-mentioned method 1 needs to be trained based on the token corresponding to each sample text, and the above-mentioned method 2 needs to be trained based on the patch corresponding to each sample text. In order to map the patch corresponding to a sample text to the token corresponding to the sample text, an image encoding network module can be added to the original training model.
[0259] Before model training based on the above-mentioned method 1 and method 2, the mapping relationship between the token and the patch corresponding to each sample text is used as the true value mapping relationship, and the token and the patch corresponding to each sample text are respectively input into the image coding network module to obtain the predicted mapping relationship output by the image coding network module. Based on the difference between the true value mapping relationship and the predicted mapping relationship, the parameters of the image coding network module are adjusted, and the image coding network module with adjusted parameters is used as the new image coding network module, and the step of inputting the token and the patch corresponding to each sample text into the image coding network module to obtain the predicted mapping relationship output by the image coding network module is returned to execute, until the fourth preset termination condition is reached. After the fourth preset termination condition is reached, the parameters of the image coding network module are fixed, and the model training is performed again based on the above-mentioned method 1 and method 2.
[0260] The fourth preset termination condition may refer to the difference between the true value mapping relationship and the predicted mapping relationship of each sample text being less than the fourth preset difference threshold, or it may refer to the number of parameter adjustments to the image coding network module reaching the fourth preset number threshold, or it may be other fourth preset termination conditions, and the present application does not impose any restrictions on this.
[0261] In the above scheme (3), the prior knowledge relationship is derived from the text object itself in the target image. If the semantic features between texts are not pre-trained based on sample data, the accuracy of the prior knowledge relationship obtained may be low, and the accuracy of the answers predicted by visual question answering may be low. By selecting this embodiment, the original training model can be trained based on a large number of sample images, thereby enhancing the generalization of the obtained multimodal pre-training model. In addition, the semantic information of the text in the image can be trained by method one, the visual information of the text in the image can be trained by method two, and the alignment training of the semantic information of the text in the image and the visual information of the text can be performed by method three, thereby improving the accuracy of the multimodal pre-training model, thereby improving the accuracy of the multimodal features of each original text obtained based on the multimodal pre-training model, and thereby improving the accuracy of the answers predicted by visual question answering.
[0262] After obtaining the multimodal pre-training model, the parameters of the multimodal pre-training model can also be adjusted according to sample questions related to the sample images and the answers corresponding to the sample questions to obtain an adjusted multimodal pre-training model, so that multimodal features that integrate multimodal information such as visual features, position features, semantic features, and target questions can be obtained through the adjusted multimodal pre-training model.
[0263] The following will Figure 1a Taking the example shown as an example, the process of the answer determination method provided in this application is exemplarily explained.
[0264] See also Fig.10 , each original text in the target image can be identified by the recognition model included in the offline optical character recognition engine, and the positional features of each original text can be detected by the detection model included in the offline optical character recognition engine, and the semantic features and visual features of each original text can be obtained by the aforementioned S501-S502. The target image, each original text, the semantic features of each original text, the visual features of each original text, the positional features of each original text, and the target question are input into the multimodal pre-training model to obtain the multimodal features of each original text output by the multimodal pre-training model. Based on the multimodal features of each original text, each original text is classified to determine the text that is the answer to the target question as the candidate text. Since each original text corresponds to a token (unit), this step is also equivalent to determining whether each unit belongs to the answer. The determined candidate text is "Ohara XX University".
[0265] According to the method shown in the foregoing S203 - S206, if the target text whose target probability meets the preset low - probability condition in the alternative text is "big" which is located at the first position in the alternative text, then replace this target text with the predicted text "too" corresponding to this target text. Since the target text "big" is replaced with the predicted text "too" corresponding to this target text, therefore, the operation on the target text "big" can be recorded as prediction. The target probabilities of the target texts "original", "X", "X", "big" located at the fifth position in the alternative text, and "university" do not meet the preset low - probability condition. Therefore, no replacement is required, and they are still the target texts obtained by OCR recognition. Then, the operations on the target texts "original", "X", "X", "big", "university" can be recorded as copying, and the replaced alternative text "Taiyuan XX University" is obtained as the answer to the target question. Compared with the alternative text "Dayuan XX University", the accuracy of the replaced alternative text "Taiyuan XX University" is higher.
[0266] Corresponding to the foregoing answer determination method, the present application also provides an answer determination device. Refer to Fig.11 , the device includes:
[0267] An identification module 111, configured to obtain each original text existing in the target image through OCR recognition, and acquire the multi - modal features of each original text, where the multi - modal features include the semantic features of the original text and the position features used to represent the position of the original text in the target image;
[0268] An alternative text determination module 112, configured to determine, according to the multi - modal features of each original text, the text belonging to the answer to the target question from multiple original texts as the alternative text;
[0269] A context text determination module 113, configured to, for each target text in the alternative text, determine the text whose position has an associated relationship with the position of the target text in each original text as the context text corresponding to the target text, where the target text is any alternative text;
[0270] A target probability obtaining module 114, configured to, for each target text, predict the probability that the target text is the text accurately recognized according to the multi - modal features of each context text corresponding to the target text and the semantic features of the target text as the target probability of the target text;
[0271] A predicted text obtaining module 115, configured to, for each target text, predict the text at the position of the target text in the target image according to the multi - modal features of each context text corresponding to the target text as the predicted text corresponding to the target text;
[0272] The replacement module 116 is used to determine the target text whose target probability meets the preset low probability condition among the candidate texts, and replace the determined target text with the corresponding predicted text to obtain the replaced candidate text as the answer to the target question.
[0273] In a possible embodiment, for each target text, predicting the text at the position of the target text in the target image according to the multimodal features of each context text corresponding to the target text as the predicted text corresponding to the target text includes:
[0274] Determine the initial current context feature according to the multimodal feature of the context text corresponding to the non-alternative text, and determine the initial current hidden state according to the semantic feature of the non-alternative text, the multimodal feature of the context text corresponding to the non-alternative text, and the hidden state of the non-alternative text;
[0275] Determine a new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state, wherein the current target text is initially the target text located at the first position of the candidate text;
[0276] Determine the context feature of the current target text as a new current context feature according to the multimodal features of each context text corresponding to the current target text;
[0277] According to the new current context features and the new current hidden state, the text at the position of the current target text in the target image is predicted as the predicted text corresponding to the current target text;
[0278] The target text located one position after the current target text is used as the new current target text, and the step of determining the new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state is returned.
[0279] In a possible embodiment, for each target text, according to the multimodal features of each context text corresponding to the target text and the semantic features of the target text, predicting the probability that the target text is an accurately recognized text as the target probability of the target text includes:
[0280] Determine the initial current context feature according to the multimodal feature of the context text corresponding to the non-alternative text, and determine the initial current hidden state according to the semantic feature of the non-alternative text, the multimodal feature of the context text corresponding to the non-alternative text, and the hidden state of the non-alternative text;
[0281] Determine a new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state, wherein the current target text is initially the target text located at the first position of the candidate text;
[0282] Determine the context feature of the current target text as a new current context feature according to the multimodal features of each context text corresponding to the current target text;
[0283] According to the new current context features, the new current hidden state, and the semantic features of the current target text, the probability that the current target text is the accurately recognized text is predicted as the target probability of the current target text;
[0284] The target text located one position after the current target text is used as the new current target text, and the step of determining the new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state is returned.
[0285] In a possible embodiment, determining the context feature of the current target text as a new current context feature according to the multimodal features of each context text corresponding to the current target text includes:
[0286] The multimodal features of each context text corresponding to the current target text are weighted to obtain the context feature of the current target text as a new current context feature, wherein the weight corresponding to the multimodal feature of the context text belonging to the alternative text is greater than the weight corresponding to the multimodal feature of the context text not belonging to the alternative text.
[0287] In a possible embodiment, the multimodal features of the original text further include: visual features of the original text;
[0288] The obtaining of multimodal features of each original text includes:
[0289] Acquire semantic features of each original text and position features of each original text;
[0290] Divide the target image into multiple blocks and determine the visual features of each block;
[0291] The semantic features of each original text, the positional features of each original text, the visual features of each image block and the target question are input into the multimodal pre-training model to obtain the multimodal features of each original text; the multimodal pre-training model is obtained by pre-training the original training model based on sample images.
[0292] In a possible embodiment, the multimodal pre-trained model is obtained by pre-training the original training model based on the sample image by any one or more of the following methods 1, 2 and 3;
[0293] Method 1 includes:
[0294] For each sample image, obtaining each sample text existing in the sample image, a semantic feature of each sample text, and a position feature of each sample text;
[0295] For each sample image, masking text in the sample image is masked to obtain a masked sample image; the masking text is any sample text in the sample image;
[0296] For each sample image, the masked sample image, the sample text belonging to the non-masked text, the semantic features of the sample text belonging to the non-masked text, and the position features of the sample text belonging to the non-masked text are input into the original training model, and the text at the position of the masked text in the sample image output by the original training model is obtained as the predicted masked text corresponding to the masked text in the sample image;
[0297] Based on the difference between the covered text in each sample image and the predicted covered text corresponding to the covered text in each sample image, the parameters of the original training model are adjusted, and the original training model with the adjusted parameters is used as the new original training model, and the step of returning to execute for each sample image, inputting the covered sample image, the sample text belonging to the non-covered text, the semantic features of the sample text belonging to the non-covered text, and the position features of the sample text belonging to the non-covered text into the original training model, and obtaining the text at the position of the covered text in the sample image output by the original training model as the predicted covered text corresponding to the covered text in the sample image, until the first preset termination condition is reached;
[0298] Method 2 includes:
[0299] For each sample image, obtain each sample text existing in the sample image, the visual features of each sample text, and the position features of each sample text;
[0300] For each sample image, masking text in the sample image is masked to obtain a masked sample image; the masking text is any sample text in the sample image;
[0301] For each sample image, the masked sample image, the sample text belonging to the non-masked text, the visual features of the sample text belonging to the non-masked text, and the position features of the sample text belonging to the non-masked text are input into the original training model, and the text at the position of the masked text in the sample image output by the original training model is obtained as the predicted masked text corresponding to the masked text in the sample image;
[0302] Based on the difference between the covered text in each sample image and the predicted covered text corresponding to the covered text in each sample image, the parameters of the original training model are adjusted, and the original training model with the adjusted parameters is used as the new original training model, and the step of returning to execute for each sample image, inputting the covered sample image, the sample text belonging to the non-covered text, the visual features of the sample text belonging to the non-covered text, and the position features of the sample text belonging to the non-covered text into the original training model, and obtaining the text at the position of the covered text in the sample image output by the original training model as the predicted covered text corresponding to the covered text in the sample image, until the second preset termination condition is reached;
[0303] Method three includes:
[0304] For each sample image, obtaining each sample text existing in the sample image, a semantic feature of each sample text, a visual feature of each sample text, and a position feature of each sample text;
[0305] For each sample image, the first cover text in the sample image is covered to obtain a first cover image, and the second cover text in the sample image is covered to obtain a second cover image; the first cover text is any sample text in the sample image, and the second cover text is any sample text in the sample image;
[0306] For each sample image, determine whether the first masked text in the first masked image and the second masked text in the second masked image are the same sample text, and use the determination result as the true value of the sample image;
[0307] For each sample image, the first cover image, the second cover image, the non-first cover text in the first cover image, the semantic features of each non-first cover text, the position features of each non-first cover text, the non-second cover text in the second cover image, the visual features of each non-second cover text, and the position features of each non-second cover text are input into the original training model to obtain the prediction result output by the original training model as the prediction result of the sample image; the prediction result is used to characterize whether the first cover text in the first cover image and the second cover text in the second cover image are the same sample text;
[0308] Based on the difference between the prediction results of each sample image and the true value of each sample image, the parameters of the original training model are adjusted, and the original training model with adjusted parameters is used as the new original training model, and the execution is returned to the step of inputting the first cover image, the second cover image, the non-first cover text in the first cover image, the semantic features of each non-first cover text, the position features of each non-first cover text, the non-second cover text in the second cover image, the visual features of each non-second cover text, and the position features of each non-second cover text into the original training model for each sample image, and obtaining the prediction result output by the original training model as the prediction result of the sample image, until the third preset termination condition is reached.
[0309] In a possible embodiment, the position feature includes: a one-dimensional position feature and a two-dimensional position feature; the position feature of each original text is obtained by the following method, including:
[0310] The area where each original text in the target image is located is obtained by OCR recognition as the text area;
[0311] For each text region, determining the position of the text region in the target image as a two-dimensional position feature of each original text included in the text region;
[0312] For each text region, starting from the first original text in the text region, the position of each original text in the text region is used as the one-dimensional position feature of each original text in the text region.
[0313] The present application also provides an electronic device, such as Fig.12 As shown, including:
[0314] A memory 121, used for storing computer programs;
[0315] The processor 122 is used to execute the program stored in the memory 121 to implement the following steps:
[0316] Obtaining each original text in the target image through OCR recognition, and obtaining multimodal features of each original text, wherein the multimodal features include semantic features of the original text and positional features for indicating the position of the original text in the target image;
[0317] According to the multimodal features of each original text, determine the text that is the answer to the target question from the multiple original texts as the candidate text;
[0318] For each target text in the candidate texts, determine in each original text a text whose position is associated with the position of the target text as the context text corresponding to the target text, where the target text is any candidate text;
[0319] For each target text, based on the multimodal features of each context text corresponding to the target text and the semantic features of the target text, the probability that the target text is an accurately recognized text is predicted as the target probability of the target text;
[0320] For each target text, based on the multimodal features of each context text corresponding to the target text, the text at the position of the target text in the target image is predicted as the predicted text corresponding to the target text;
[0321] Among the candidate texts, a target text whose target probability meets a preset low probability condition is determined, and the determined target text is replaced with the corresponding predicted text to obtain the replaced candidate text as the answer to the target question.
[0322] Furthermore, the electronic device may further include a communication bus and / or a communication interface, and the processor 122, the communication interface, and the memory 121 communicate with each other via the communication bus.
[0323] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0324] The communication interface is used for communication between the above electronic device and other devices.
[0325] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0326] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0327] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned answer determination methods are implemented.
[0328] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any one of the answer determination methods in the above embodiments.
[0329] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a solid-state hard disk (SSD), etc.
[0330] It should be noted that, in this article, relational terms such as first and second, etc. are only used 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. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0331] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the embodiments of the device, electronic device, computer-readable storage medium, and computer program product containing instructions, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0332] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.
Claims
1. A method for determining an answer, characterized in that: The method comprises: Obtaining each original text in the target image through OCR recognition, and obtaining multimodal features of each original text, wherein the multimodal features include semantic features of the original text and position features for indicating the position of the original text in the target image; Determining, from the plurality of original texts, a text that is an answer to the target question as an alternative text according to the multimodal features of each of the original texts; For each target text in the candidate texts, determine in each original text a text whose position is associated with the position of the target text as the context text corresponding to the target text, the target text being any of the candidate texts; For each target text, based on the multimodal features of each context text corresponding to the target text and the semantic features of the target text, predict the probability that the target text is an accurately recognized text as the target probability of the target text; For each of the target texts, according to the multimodal features of each context text corresponding to the target text, predict the text at the position of the target text in the target image as the predicted text corresponding to the target text; Among the candidate texts, determine the target text whose target probability meets the preset low probability condition, and replace the determined target text with the corresponding predicted text to obtain the replaced candidate text as the answer to the target question; The method of predicting, for each target text, the probability that the target text is an accurately recognized text according to the multimodal features of each context text corresponding to the target text and the semantic features of the target text as the target probability of the target text includes: Determine an initial current context feature according to the multimodal feature of the context text corresponding to the non-alternative text, and determine the initial current hidden state according to the semantic feature of the non-alternative text, the multimodal feature of the context text corresponding to the non-alternative text, and the hidden state of the non-alternative text; Determine a new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state, wherein the current target text is initially the target text located at the first position of the candidate text; Determining, according to the multimodal features of each context text corresponding to the current target text, a context feature of the current target text as a new current context feature; According to the new current context feature, the new current hidden state, and the semantic feature of the current target text, predict the probability that the current target text is the accurately recognized text as the target probability of the current target text; The target text located one position after the current target text is used as the new current target text, and the step of determining the new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state is returned to be executed.
2. The method according to claim 1, characterized in that: The method of predicting, for each target text, a text at a position of the target text in the target image according to multimodal features of each context text corresponding to the target text as a predicted text corresponding to the target text includes: Determine an initial current context feature according to the multimodal feature of the context text corresponding to the non-alternative text, and determine the initial current hidden state according to the semantic feature of the non-alternative text, the multimodal feature of the context text corresponding to the non-alternative text, and the hidden state of the non-alternative text; Determine a new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state, wherein the current target text is initially the target text located at the first position of the candidate text; Determining, according to the multimodal features of each context text corresponding to the current target text, a context feature of the current target text as a new current context feature; Predicting the text at the position of the current target text in the target image according to the new current context feature and the new current hidden state as the predicted text corresponding to the current target text; The target text located one position after the current target text is used as the new current target text, and the step of determining the new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state is returned to be executed.
3. The method according to claim 1 or 2, characterized in that: The determining, according to the multimodal features of each context text corresponding to the current target text, the context feature of the current target text as a new current context feature includes: The multimodal features of each context text corresponding to the current target text are weighted to obtain the context feature of the current target text as a new current context feature, wherein the weight corresponding to the multimodal feature of the context text belonging to the alternative text is greater than the weight corresponding to the multimodal feature of the context text not belonging to the alternative text.
4. The method according to claim 1, characterized in that: The multimodal features of the original text also include: visual features of the original text; The obtaining of the multimodal features of each of the original texts includes: Acquire the semantic features of each of the original texts and the position features of each of the original texts; Dividing the target image into a plurality of blocks, and determining visual features of each of the blocks; The semantic features of each of the original texts, the positional features of each of the original texts, the visual features of each of the image blocks, and the target question are input into a multimodal pre-training model to obtain multimodal features of each of the original texts; the multimodal pre-training model is obtained by pre-training the original training model based on sample images.
5. The method according to claim 4, characterized in that The multimodal pre-trained model is obtained by pre-training the original training model based on the sample image through any one or more of the following methods: method 1, method 2 and method 3; Method 1 includes: For each of the sample images, obtaining each sample text existing in the sample image, a semantic feature of each of the sample texts, and a position feature of each of the sample texts; For each of the sample images, masking the masked text in the sample image to obtain a masked sample image; the masked text is any sample text in the sample image; For each of the sample images, the masked sample image, the sample text belonging to the non-masked text, the semantic features of the sample text belonging to the non-masked text, and the position features of the sample text belonging to the non-masked text are input into the original training model, and the text at the position of the masked text in the sample image output by the original training model is obtained as the predicted masked text corresponding to the masked text in the sample image; Based on the difference between the covered text in each of the sample images and the predicted covered text corresponding to the covered text in each of the sample images, the parameters of the original training model are adjusted, and the original training model with the adjusted parameters is used as the new original training model, and the step of returning to execute the step of inputting the covered sample image, the sample text belonging to the non-covered text, the semantic features of the sample text belonging to the non-covered text, and the position features of the sample text belonging to the non-covered text into the original training model for each of the sample images, and obtaining the text at the position of the covered text in the sample image output by the original training model as the predicted covered text corresponding to the covered text in the sample image, until the first preset termination condition is reached; Method 2 includes: For each of the sample images, obtaining each sample text existing in the sample image, a visual feature of each of the sample texts, and a position feature of each of the sample texts; For each of the sample images, masking the masked text in the sample image to obtain a masked sample image; the masked text is any sample text in the sample image; For each of the sample images, the masked sample image, the sample text belonging to the non-masked text, the visual features of the sample text belonging to the non-masked text, and the position features of the sample text belonging to the non-masked text are input into the original training model, and the text at the position of the masked text in the sample image output by the original training model is obtained as the predicted masked text corresponding to the masked text in the sample image; Based on the difference between the covered text in each of the sample images and the predicted covered text corresponding to the covered text in each of the sample images, the parameters of the original training model are adjusted, and the original training model with the adjusted parameters is used as the new original training model, and the step of returning to execute the step of inputting the covered sample image, the sample text belonging to the non-covered text, the visual features of the sample text belonging to the non-covered text, and the position features of the sample text belonging to the non-covered text into the original training model for each of the sample images, and obtaining the text at the position of the covered text in the sample image output by the original training model as the predicted covered text corresponding to the covered text in the sample image, until a second preset termination condition is reached; Method three includes: For each of the sample images, obtaining each sample text existing in the sample image, a semantic feature of each of the sample texts, a visual feature of each of the sample texts, and a position feature of each of the sample texts; For each of the sample images, a first cover text in the sample image is covered to obtain a first cover image, and a second cover text in the sample image is covered to obtain a second cover image; the first cover text is any sample text in the sample image, and the second cover text is any sample text in the sample image; For each of the sample images, determining whether a first covered text in the first covered image and a second covered text in the second covered image are the same sample text, and using the determination result as the true value of the sample image; For each of the sample images, the first cover image, the second cover image, the non-first cover text in the first cover image, the semantic features of each of the non-first cover texts, the position features of each of the non-first cover texts, the non-second cover text in the second cover image, the visual features of each of the non-second cover texts, and the position features of each of the non-second cover texts are input into the original training model to obtain a prediction result output by the original training model as the prediction result of the sample image; the prediction result is used to characterize whether the first cover text in the first cover image and the second cover text in the second cover image are the same sample text; Based on the difference between the prediction results of each of the sample images and the true values of each of the sample images, the parameters of the original training model are adjusted, and the original training model with adjusted parameters is used as the new original training model, and the step of returning to execute the step of inputting the first cover image, the second cover image, the non-first cover text in the first cover image, the semantic features of each of the non-first cover texts, the position features of each of the non-first cover texts, the non-second cover text in the second cover image, the visual features of each of the non-second cover texts, and the position features of each of the non-second cover texts into the original training model for each of the sample images to obtain the prediction results output by the original training model as the prediction results of the sample images, until a third preset termination condition is reached.
6. The method according to claim 1, characterized in that The position features include: one-dimensional position features and two-dimensional position features; the position features of each of the original texts are obtained by the following methods, including: The area where each original text in the target image is located is obtained by OCR recognition as the text area; For each of the text regions, determining a position of the text region in the target image as a two-dimensional position feature of each of the original texts included in the text region; For each of the text regions, starting from the first original text in the text region, the position of each of the original texts in the text region is used as a one-dimensional position feature of each of the original texts in the text region.
7. An answer determination device, characterized in that: The device comprises: A recognition module, used for obtaining each original text existing in the target image through OCR recognition, and obtaining multimodal features of each original text, wherein the multimodal features include semantic features of the original text and position features for indicating the position of the original text in the target image; An alternative text determination module, used to determine, from a plurality of the original texts, a text that is an answer to the target question as an alternative text according to the multimodal features of each of the original texts; A context text determination module, for determining, for each target text in the candidate texts, a text in each original text whose position is associated with the position of the target text as a context text corresponding to the target text, wherein the target text is any of the candidate texts; A target probability obtaining module is used to predict the probability of the target text being an accurately recognized text according to the multimodal features of the context texts corresponding to the target text and the semantic features of the target text, as the target probability of the target text; A predicted text obtaining module is used to predict, for each target text, the text at the position of the target text in the target image according to the multimodal features of each context text corresponding to the target text, as the predicted text corresponding to the target text; A replacement module, used to determine, among the candidate texts, a target text whose target probability satisfies a preset low probability condition, and replace the determined target text with a corresponding predicted text to obtain the replaced candidate text as an answer to the target question; The target probability obtaining module predicts the probability of the target text being an accurately recognized text according to the multimodal features of each context text corresponding to the target text and the semantic features of the target text, as the target probability of the target text, including: Determine an initial current context feature according to the multimodal feature of the context text corresponding to the non-alternative text, and determine the initial current hidden state according to the semantic feature of the non-alternative text, the multimodal feature of the context text corresponding to the non-alternative text, and the hidden state of the non-alternative text; Determine a new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state, wherein the current target text is initially the target text located at the first position of the candidate text; Determining, according to the multimodal features of each context text corresponding to the current target text, a context feature of the current target text as a new current context feature; According to the new current context feature, the new current hidden state, and the semantic feature of the current target text, predict the probability that the current target text is the accurately recognized text as the target probability of the current target text; The target text located one position after the current target text is used as the new current target text, and the step of determining the new current hidden state according to the semantic features of the current target text, the current context features, and the current hidden state is returned to be executed.
8. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-6 when executing a program stored in a memory.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Optical character recognition OCR system and automatic OCR correction system and method
CN112016553A
Text visual question and answer method and device
CN113849623A
OCR text error correction method and device
CN115641591A
Unsupervised training method of character recognition model and related equipment
CN115965978A
Scene text visual question and answer method based on graph pooling reasoning network
CN117475422A
