Text information generation method and device, model training method and device and electronic equipment
By extracting multi-scale image features and using attention mechanisms and large language models, the problem of low accuracy in extracting document image information in the existing technology is solved, and accurate extraction and accurate generation of text images are achieved, which is suitable for text in complex scenes. information processing.
Patent Information
- Application Number
- CN202410868476.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-09-03
AI Technical Summary
The information extraction accuracy of document images in the existing technology is low, resulting in inaccurate text information recognition and extraction, especially in the case of redundant information and complex scenes, where it is difficult to effectively extract text content.
By extracting multi-scale image features, the attention mechanism is used to filter out the features that best match the text, and combined with the large language model, the text generation instructions are executed to accurately extract text information and improve the accuracy of text generation.
It achieves precise feature extraction of text images and short and detailed text information extraction, improves the accuracy of text generation, and can better handle document image information extraction in complex backgrounds.
Smart Images

Figure CN118587729A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, in particular to computer vision, deep learning, large models and other technical fields, and can be applied to OCR (Optical Character Recognition) and human-computer interaction scenarios. Specifically, it relates to a method for generating text information, a model training method, a device, an electronic device, a storage medium and a program product. Background Art
[0002] Information extraction from document images refers to the identification and extraction of target content and fragments in document images, including named entity extraction and document image question answering (Document VQA (Vision Questions & Answers)). Named entity extraction mainly identifies and extracts entities in documents such as names, dates, addresses, telephone numbers, and some specific data, such as valid data types such as goods, amounts, and check codes on bills. Document image question answering is mainly based on a high degree of semantic and content understanding to find answers to relevant questions from the document context.
[0003] The related technology has low accuracy in extracting information from document images. Therefore, there is an urgent need for a method that can generate text information with higher accuracy. Summary of the invention
[0004] The present disclosure provides a method for generating text information, a model training method, an apparatus, an electronic device, a storage medium, and a program product.
[0005] According to one aspect of the present disclosure, a method for generating text information is provided, comprising: extracting multi-scale image features of an image to be processed, wherein the content of the image to be processed includes text; the multi-scale image features include features for characterizing structural information and content information of the text; based on an attention mechanism, processing the multi-scale image features to obtain target image features that match the text; and based on a text generation instruction, processing the target image features to generate target text information corresponding to the text generation instruction.
[0006] According to another aspect of the present disclosure, a text information generation model training method is provided, the model includes a feature extraction module, an attention module and a generation module, the method includes: using the feature extraction module to extract multi-scale sample image features of a sample image, wherein the content of the sample image includes a sample text; the multi-scale sample image features include features for characterizing structural information and content information of the sample text; using the attention module, based on the attention mechanism, processing the multi-scale sample image features to obtain target sample image features that match the sample text; using the generation module, based on the sample text generation instruction, processing the target sample image features to generate target sample text information corresponding to the sample text generation instruction; based on the loss function, obtaining a loss value according to the target sample text information and the sample text label; and based on the loss value, obtaining a trained model by adjusting the model parameters of the model.
[0007] According to another aspect of the present disclosure, a device for generating text information is provided, comprising: an extraction module for extracting multi-scale image features of an image to be processed, wherein the content of the image to be processed includes text; the multi-scale image features include features for characterizing structural information and content information of the text; a first processing module for processing the multi-scale image features based on an attention mechanism to obtain target image features that match the text; and a second processing module for processing the target image features based on a text generation instruction to generate target text information corresponding to the text generation instruction.
[0008] According to another aspect of the present disclosure, a text information generation model training device is provided, including: a feature extraction module, used to extract multi-scale sample image features of a sample image, wherein the content of the sample image includes a sample text; the multi-scale sample image features include features for characterizing structural information and content information of the sample text; an attention module, used to process the multi-scale sample image features based on an attention mechanism to obtain target sample image features that match the sample text; a generation module, used to process the target sample image features based on a sample text generation instruction to generate target sample text information corresponding to the sample text generation instruction; a loss function module, used to obtain a loss value based on the target sample text information and a sample text label based on a loss function; and an adjustment module, used to obtain a trained model by adjusting model parameters of the model based on the loss value.
[0009] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described above.
[0010] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the method described above.
[0011] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the method described above is implemented.
[0012] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0014] Figure 1 An exemplary system architecture to which the method and device for generating text information according to an embodiment of the present disclosure can be applied is schematically shown;
[0015] Figure 2 A flowchart schematically shows a method for generating text information according to an embodiment of the present disclosure;
[0016] Figure 3 A schematic diagram of a method for generating text information according to an embodiment of the present disclosure is shown;
[0017] Figure 4 A schematic diagram schematically shows a method for determining multi-scale image features according to an embodiment of the present disclosure;
[0018] Figure 5 A schematic diagram of a target image feature extraction method according to an embodiment of the present disclosure is schematically shown.
[0019] Figure 6 A schematic diagram of a method for generating text information according to another embodiment of the present disclosure is shown;
[0020] Figure 7 An example diagram schematically shows a method for generating text information according to an embodiment of the present disclosure;
[0021] Figure 8 An example diagram schematically shows a method for generating text information according to another embodiment of the present disclosure;
[0022] Fig. 9 An example diagram schematically shows a method for generating text information according to another embodiment of the present disclosure;
[0023] Fig.10A flowchart of a text information generation model training method according to an embodiment of the present disclosure is schematically shown;
[0024] Fig.11 The schematic diagram of the text information generation model training method according to the embodiment of the present disclosure is shown;
[0025] Fig.12 A block diagram schematically shows a device for generating text information according to an embodiment of the present disclosure;
[0026] Fig.13 A block diagram schematically shows a text information generation model training device according to an embodiment of the present disclosure; and
[0027] Fig.14 A block diagram of an electronic device suitable for implementing a method for generating text information according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0028] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0029] In the related art, information extraction of document images generally adopts OCR (Optical Character Recognition) technology, which extracts corresponding text information from the recognition result of the text image based on the OCR engine through some rules or model methods.
[0030] However, this method requires all text in the text image to be recognized indiscriminately, which results in a large amount of redundant information. In addition, OCR text recognition and information extraction are two independent serial units, and text recognition errors will directly interfere with the accuracy of subsequent information extraction.
[0031] Therefore, the embodiment of the present disclosure provides a method for generating text information, which extracts multi-scale image features from text images to obtain text content and structural features of different granularities; then, based on the attention mechanism, screens the image features that best match the text in the multi-scale image features to obtain the target image features, and then uses a large language model to extract the corresponding text from the image by executing different text generation instructions. The method provided by the present disclosure can accurately extract multi-scale image features of text images, and extract shorter and more detailed image features from lengthy multi-scale image features, and convert the extracted image features into inputs of a large language model, splice them with text generation instructions, and use the large language model to extract the corresponding text, thereby helping to improve the accuracy of text generation.
[0032] Figure 1 An exemplary system architecture to which the method and apparatus for generating text information according to an embodiment of the present disclosure can be applied is schematically shown.
[0033] It should be noted that Figure 1 The examples shown are only examples of system architectures to which the embodiments of the present disclosure can be applied, in order to help those skilled in the art understand the technical content of the present disclosure, but do not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios. For example, in another embodiment, the exemplary system architecture to which the method and apparatus for generating text information can be applied may include a terminal device, but the terminal device may implement the method and apparatus for generating text information provided by the embodiments of the present disclosure without interacting with the server.
[0034] like Figure 1 As shown, the system architecture 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired and / or wireless communication links, etc.
[0035] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as knowledge reading applications, web browser applications, search applications, instant messaging tools, email clients and / or social platform software, etc. (only as examples).
[0036] The terminal devices 101 , 102 , and 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0037] The server 105 may be a server that provides various services, such as a background management server (only an example) that provides support for the content browsed by the user using the terminal devices 101, 102, and 103. The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to the user request) to the terminal device.
[0038] It should be noted that the text information generation method provided in the embodiment of the present disclosure can generally be executed by the terminal device 101, 102, or 103. Accordingly, the content processing apparatus provided in the embodiment of the present disclosure can also be set in the terminal device 101, 102, or 103.
[0039] Alternatively, the method for generating text information provided in the embodiment of the present disclosure may also be generally executed by the server 105. Accordingly, the content processing device provided in the embodiment of the present disclosure may generally be arranged in the server 105. The method for generating text information provided in the embodiment of the present disclosure may also be executed by a server or server cluster that is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and / or the server 105. Accordingly, the content processing device provided in the embodiment of the present disclosure may also be arranged in a server or server cluster that is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and / or the server 105.
[0040] For example, the terminal devices 101, 102, and 103 may obtain an image to be processed, and then send the obtained image to be processed to the server 105, which analyzes the image to be processed and extracts multi-scale image features of the image to be processed; processes the multi-scale image features based on the attention mechanism to obtain target image features that match the text; and processes the target image features based on the text generation instruction to generate target text information corresponding to the text generation instruction. Alternatively, a server or server cluster that can communicate with the terminal devices 101, 102, 103 and / or the server 105 analyzes the image to be processed and finally generates target text information corresponding to the text generation instruction.
[0041] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0042] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision, disclosure and application of user personal information involved comply with the provisions of relevant laws and regulations, take necessary confidentiality measures, and do not violate public order and good morals.
[0043] In the technical solution of the present disclosure, the user's authorization or consent is obtained before obtaining or collecting the user's personal information.
[0044] Figure 2 The flowchart of the method for generating text information according to the embodiment of the present disclosure is schematically shown.
[0045] like Figure 2 As shown, the method 200 includes operations S210 to S230.
[0046] In operation S210 , multi-scale image features of an image to be processed are extracted.
[0047] In operation S220, based on the attention mechanism, the multi-scale image features are processed to obtain target image features that match the text.
[0048] In operation S230, based on the text generation instruction, the target image features are processed to generate target text information corresponding to the text generation instruction.
[0049] According to an embodiment of the present disclosure, the content of the image to be processed includes text; the multi-scale image features include features for characterizing structural information and content information of the text.
[0050] According to the embodiments of the present disclosure, different scale features in the multi-scale image features correspond to different receptive fields. For example, the feature representing text structure information may be the structural information in the image to be processed, which may specifically include structural text content with larger font sizes such as tables, titles, and icons. The feature representing text content information may be the specific content information in the image to be processed, which may specifically include text content with smaller font sizes such as specific text content in a table.
[0051] According to an embodiment of the present disclosure, multi-scale image features of an image to be processed may be extracted using a visual encoder.
[0052] For example, Swin Transformer can be used to extract features of the image to be processed to obtain multi-scale image features. Specifically, it can include: configuring the resolution of the image to be processed to 1600×1600 pixels, extracting the multi-scale features of Swin Transformer, and making the output feature length reach more than 4096. Due to the shift window design of Swin Transformer, it can ensure the efficiency of processing high-resolution images, help to accurately extract image features of small characters and dense text, and thus help to improve the accuracy of feature extraction.
[0053] According to an embodiment of the present disclosure, processing multi-scale image features based on an attention mechanism may include: based on the attention mechanism, screening out features in the multi-scale image features that match the text to obtain target image features.
[0054] For example, if the image to be processed includes image A and article B, the obtained multi-scale features include feature information of image A, feature information of article B, and feature information of blank positions in the image to be processed. At this time, based on the attention mechanism, processing the multi-scale image features may include: filtering feature information of article B from feature information of image A, feature information of article B, and feature information of blank positions in the image to be processed to obtain target image features.
[0055] According to an embodiment of the present disclosure, processing multi-scale image features based on an attention mechanism to obtain target image features that match text may include: using a resampler in a Q-Former structure to process multi-scale image features to obtain target image features.
[0056] According to an embodiment of the present disclosure, by processing multi-scale image features based on an attention mechanism, lengthy visual features, namely multi-scale image features, can be mapped into features suitable for a large language model input dimension, thereby facilitating subsequent text extraction.
[0057] According to an embodiment of the present disclosure, the text generation instruction may include an instruction based on a natural language description, for example, the text generation instruction may include: identifying and locating text in an image. In some other embodiments, the text generation instruction may also include a text attribute name, a question text, and the like.
[0058] According to an embodiment of the present disclosure, processing target image features based on text generation instructions may include: inputting target image features and text generation instructions into a large language model for processing, and outputting target text information corresponding to the text generation instructions.
[0059] For example, if the text generation instruction includes identifying and locating text in an image, the target image features and the text generation instruction are input into the large language model for processing, and outputting the target text information corresponding to the text generation instruction may include: inputting the target image features and the text generation instruction "identify and locate text in the image" into the large language model for processing, and outputting all text information in the image to be processed. For example, if all the text contained in the image to be processed includes "abcdef", then the output is also "abcdef".
[0060] According to the embodiments of the present disclosure, multi-scale image features are extracted from images to obtain text content and structural features of different granularities; and based on the attention mechanism, the image features that best match the text are screened; and then the large language model is used to extract the corresponding text from the image by executing different text generation instructions. This can improve the accuracy of text generation, and at the same time, can realize end-to-end information extraction of document images, and better handle text information extraction in arbitrary layouts and complex scenarios.
[0061] Reference below Figure 3~Figure 9 , combined with specific embodiments Figure 2 The method shown is further explained.
[0062] Figure 3 The principle diagram of the method for generating text information according to an embodiment of the present disclosure is schematically shown.
[0063] like Figure 3 As shown, in embodiment 300, the image to be processed is input into Swin Transformer 310 for feature extraction to obtain multi-scale image features; then, the multi-scale image features are input into Q-Former 320, wherein Q-Former 320 includes a feedforward layer 321, a cross-attention mechanism 322 and a self-attention mechanism 323, and the multi-scale image features are resampled through the feedforward layer 321, the cross-attention mechanism 322 and the self-attention mechanism 323 to obtain target image features; then, the target image features and the text generation instruction are input into LLM (large language model) 330 together, and the target text corresponding to the text generation instruction is output.
[0064] According to an embodiment of the present disclosure, extracting multi-scale image features of an image to be processed may include the following operations: dividing the image to be processed into multiple pixel blocks, wherein there are overlapping areas between the multiple pixel blocks; processing the multiple pixel blocks to obtain global features of the image to be processed; and downsampling the global features of the image to be processed to obtain multi-scale image features.
[0065] According to an embodiment of the present disclosure, pixel blocks may be small squares in an image to be processed, and these small squares have clear positions and assigned color values, and the color and position of the small squares determine the appearance of the image.
[0066] According to an embodiment of the present disclosure, dividing the image to be processed into a plurality of pixel blocks may include: dividing the image to be processed into a plurality of pixel blocks with overlapping areas. For example, after the image to be processed is divided, it includes pixel block 1, pixel block 2, pixel block 3 and pixel block 4, wherein pixel block 1 and pixel block 2 may include the same area 1, pixel block 2 and pixel block 3 may include the same area 2, and pixel block 3 and pixel block 4 may include the same area 3.
[0067] According to an embodiment of the present disclosure, processing multiple pixel blocks to obtain global features of the image to be processed may include: processing each pixel block based on a self-attention mechanism to obtain local features corresponding to each pixel block; and splicing the local features corresponding to each pixel block according to the relative position relationship between the pixel blocks to obtain global features.
[0068] For example, after the image to be processed is divided into pixel block 1, pixel block 2, pixel block 3 and pixel block 4, each pixel block is processed based on the self-attention mechanism to obtain the local feature corresponding to each pixel block, which may include: based on the self-attention mechanism, pixel block 1 is processed to obtain local feature 1 corresponding to pixel block 1; based on the self-attention mechanism, pixel block 2 is processed to obtain local feature 2 corresponding to pixel block 2; based on the self-attention mechanism, pixel block 3 is processed to obtain local feature 3 corresponding to pixel block 3; based on the self-attention mechanism, pixel block 4 is processed to obtain local feature 4 corresponding to pixel block 4.
[0069] By limiting the attention calculation to a pixel block, the amount of calculation can be saved and the calculation efficiency can be improved.
[0070] According to the embodiments of the present disclosure, since each pixel block has image coordinate information, after obtaining the local features corresponding to each pixel block, the relative positional relationship between the pixel blocks can be determined according to the image coordinate information of the pixel blocks and then spliced to obtain the global features.
[0071] For example, as described above, the image to be processed includes pixel block 1, pixel block 2, pixel block 3 and pixel block 4, wherein pixel block 1 and pixel block 2 contain the same region 1, pixel block 2 and pixel block 3 contain the same region 2, and pixel block 3 and pixel block 4 contain the same region 3. Therefore, the local feature 1 corresponding to pixel block 1 contains the regional feature a of region 1, and the local feature 2 corresponding to pixel block 2 also contains the regional feature a of region 1. At this time, the relative position of local feature 1 and local feature 2 can be determined according to regional feature a, thereby determining the relative position of pixel block 1 and pixel block 2. According to the relative position relationship, pixel block 1 and pixel block 2 can be spliced to obtain the image features of the positions of pixel block 1 and pixel block 2; according to this method, after splicing pixel block 1, pixel block 2, pixel block 3 and pixel block 4, the global feature can be obtained.
[0072] According to an embodiment of the present disclosure, the global features of the image to be processed are downsampled to obtain multi-scale image features, including: downsampling the global features according to a first predetermined feature dimension to obtain a first scale feature for characterizing content information; and downsampling the first scale feature according to a second predetermined feature dimension to obtain a second scale feature for characterizing structural information.
[0073] According to an embodiment of the present disclosure, the first predetermined feature dimension and the second predetermined feature dimension may be pre-configured feature dimensions. In some embodiments, the first predetermined feature dimension may be 32 dimensions, and the second predetermined feature dimension may be 8 dimensions.
[0074] According to the embodiments of the present disclosure, the global features are downsampled layer by layer to obtain image features of different scales, namely, first scale features and second scale features. This allows the large model to focus on both text structure and text content information during the inference process, thereby improving the accuracy of text information extraction.
[0075] Figure 4 A schematic diagram of a method for determining multi-scale image features according to an embodiment of the present disclosure is schematically shown.
[0076] like Figure 4As shown, in this embodiment 400, the image 410 to be processed is divided to obtain a plurality of pixel blocks 420, and there are overlapping areas between the plurality of pixel blocks 420; then, based on the attention mechanism, each pixel block 420 in the plurality of pixel blocks 420 is processed separately to obtain a local feature 430 corresponding to each pixel block 420; then, based on the overlapping areas between the plurality of pixel blocks 420, the relative position relationship between the plurality of pixel blocks 420 is determined; then, based on the relative position relationship between the plurality of pixel blocks 420, the local features 430 corresponding to each pixel block 420 are spliced to obtain a global feature 440; then, the global feature 440 is downsampled layer by layer to obtain a multi-scale image feature 450.
[0077] According to an embodiment of the present disclosure, based on the attention mechanism, multi-scale image features are processed to obtain target image features that match the text, including: based on the attention mechanism, a query feature matrix and multi-scale image features are processed to obtain target image features; wherein the query feature matrix is randomly initialized according to a predetermined dimension.
[0078] According to an embodiment of the present disclosure, the query feature matrix may be a learnable matrix obtained by random initialization, for example, the query feature matrix may be an all-zero matrix or an all-one matrix, etc. The query feature matrix achieves the purpose of extracting the features that best match the text by interacting with itself and multi-scale image features at the same time.
[0079] According to an embodiment of the present disclosure, based on the attention mechanism, the query feature matrix and the multi-scale image features are processed to obtain the target image features, including: based on the cross-attention mechanism, the query feature matrix and the multi-scale image features are processed to obtain the first intermediate features; and based on the self-attention mechanism, the first intermediate features are processed to obtain the target image features.
[0080] According to the embodiments of the present disclosure, by processing the query feature matrix and the multi-scale image features based on the attention mechanism, the target image features can be obtained, and the lengthy multi-scale image features can be mapped to features suitable for the input dimension of the large language model. For example, the length of the multi-scale image features extracted from the image to be processed reaches more than 4096, and the query feature matrix and the multi-scale image features are interactively calculated based on the cross-attention mechanism; then the query feature matrix after the interaction is interactively calculated through self-attention. After performing multiple repeated operations, the length of the multi-scale image features can be compressed to 512, which is convenient for the input of the later large language model.
[0081] Figure 5 A schematic diagram of a target image feature extraction method according to an embodiment of the present disclosure is schematically shown.
[0082] like Figure 5 As shown, in embodiment 500, firstly, an interactive calculation is performed between the multi-scale image feature 450 and the query feature matrix 520 based on the cross-attention mechanism to obtain a first intermediate feature 530, wherein the first intermediate feature 530 is the learned query feature matrix; then, the first intermediate feature 530 is interactively calculated through self-attention, and the first intermediate feature 530 is feature encoded before the next interactive calculation with the multi-scale image feature is performed, and after repeating this N times, the target image feature 540 is output.
[0083] According to the embodiments of the present disclosure, by processing multi-scale images based on a multi-layer cross-attention mechanism, image features that better match the text content can be obtained, and the final dimensions of the target image features are limited by using a query feature matrix to adapt to the input dimensions of a large language model, so that the large language model can perform accurate text extraction and question-answering based on multimodal input features.
[0084] According to an embodiment of the present disclosure, target image features are processed based on text generation instructions to generate target text information corresponding to the text generation instructions, including: converting the text generation instructions into text features based on a predetermined dictionary; inserting identifiers at both ends of the target image features and concatenating them with the text features to obtain input features; and inputting the input features into a large language model to generate target text information corresponding to the text generation instructions.
[0085] According to an embodiment of the present disclosure, the predetermined dictionary includes a preset number of words and identifiers corresponding to the words. In one embodiment, the predetermined dictionary may include 160,000 words and identifiers corresponding to the words.
[0086] For example, the predetermined dictionary may include vocabulary a, vocabulary b, and vocabulary c, as well as an identifier 1 corresponding to vocabulary a, an identifier 2 corresponding to vocabulary b, and an identifier 3 corresponding to vocabulary 3.
[0087] According to an embodiment of the present disclosure, converting the text generation instruction into text features based on a predetermined dictionary may include: converting words in the text generation instruction into an identification sequence based on the predetermined dictionary to obtain the text features.
[0088] For example, the text generation instruction may be “vocabulary a+vocabulary b”, and based on the predetermined dictionary, the text feature obtained by converting the text generation instruction may be “identity 1+identity 2”.
[0089] According to an embodiment of the present disclosure, the identifier may be an identifier in any form, for example, the identifier may be a letter, a number or a special character.
[0090] According to an embodiment of the present disclosure, inserting identifiers at both ends of a target image feature can use the identifiers to distinguish the start and end of the target image feature. and represent the beginning and end of the target image features respectively.
[0091] According to an embodiment of the present disclosure, concatenating the text feature with the input feature may include concatenating the text feature at the end of the target image feature. Specifically, the text feature may be concatenated after an identifier indicating the end of the target image feature to obtain the input feature.
[0092] Figure 6 The schematic diagram shows a principle diagram of a method for generating text information according to another embodiment of the present disclosure.
[0093] like Figure 6 As shown, in embodiment 600, by dividing the image to be processed 601, a plurality of pixel blocks 602 are obtained; then, each pixel block 602 is processed based on the attention mechanism to obtain a local feature 603 corresponding to each pixel block 602; then, each local feature 603 is spliced to obtain a global feature 604 corresponding to the image to be processed 601; then, the global feature 604 is downsampled according to the first predetermined feature dimension to obtain a first scale feature 605; then, the first scale feature 605 is downsampled again according to the second predetermined feature dimension to obtain a second scale feature 606; the first scale feature 605 and the second scale feature 606 are multi-scale image features corresponding to the image to be processed 601. After obtaining the multi-scale image features, the query feature matrix 607 and the multi-scale image features are processed based on the cross attention mechanism to obtain a first intermediate feature 608; then, the first intermediate feature 608 is processed based on the self-attention mechanism to obtain a target image feature 609. Afterwards, based on a predetermined dictionary, the text generation instruction 610 is converted into a text feature 611; then, the target image feature 609 and the text feature 611 are concatenated to obtain an input feature 612 of an LLM model 613, and the input feature 612 is input into the LLM model 613, and finally the target text information 614 is output.
[0094] Figure 7 An example diagram schematically shows a method for generating text information according to an embodiment of the present disclosure.
[0095] like Figure 7As shown, in embodiment 700, the text information contained in the image to be processed 710 is name: A, age: B, date: C; the text generation instruction 720 is to identify and locate the text in the graphic; the text generation instruction 720 and the target image features of the image to be processed 710 are input into the model 730, and the output target text is all the text information in the image to be processed 710, namely name: A, age: B, date: C 740.
[0096] According to an embodiment of the present disclosure, the text features converted from the text generation instructions are concatenated with the target image features and used as input to the large language model, so that the large language model can implement the information extraction task of the document image based on the requirements of the text generation instructions.
[0097] According to an embodiment of the present disclosure, a text generation instruction includes a text attribute name; inputting input features into a large language model to generate target text information corresponding to the text generation instruction, including: inputting input features into a large language model to generate target text information corresponding to the text attribute name.
[0098] According to an embodiment of the present disclosure, the text attribute name may include any entity name. For example, the text attribute name may include name, age, gender, date, etc.
[0099] According to an embodiment of the present disclosure, if the text attribute name included in the text generation instruction is age, the input feature is input into the large language model, and the target text information corresponding to the text attribute name generated can be a specific age, such as 2 years old.
[0100] Figure 8 An example diagram schematically shows a method for generating text information according to another embodiment of the present disclosure.
[0101] like Figure 8 As shown, in embodiment 800, the text information contained in the image to be processed 810 is name: A, age: B, date: C; the text generation instruction 820 is to output the value of {name} in the image; the text generation instruction 820 and the target image features of the image to be processed 810 are input into the model 830, and the output target text is the text corresponding to the name in the image to be processed 810, namely A840.
[0102] According to the embodiments of the present disclosure, since the target image features are features that match the text, by fine-tuning the text generation instructions, the large language model can better handle entity naming extraction tasks in complex backgrounds.
[0103] In the fundamentally disclosed embodiment, the text generation instruction includes a question text; input features are input into a large language model to generate target text information corresponding to the text generation instruction, including: input features are input into a large language model to generate target text information for answering the question text.
[0104] According to an embodiment of the present disclosure, the question text may be based on a natural language question description, such as "What is the title of the article?", "How many authors does this book have?", "Which paragraph is the product description in?", etc., without a fixed format.
[0105] For example, the question text included in the text generation instruction is "How many authors are there in this book?" Then the input features are input into the large language model, and the target text information corresponding to the text attribute name generated can be the number of authors.
[0106] Fig. 9 An example diagram schematically shows a method for generating text information according to yet another embodiment of the present disclosure.
[0107] like Fig. 9 As shown, in embodiment 900, the text information contained in the image to be processed 910 is "ABC", "×××", where "ABC" is the title of the article and "×××" is the specific content of the article; the text generation instruction 920 is what the title of the article is; the text generation instruction 920 and the target image features of the image to be processed 910 are input into the model 930, and the output target text is the title of the article "ABC" 940.
[0108] According to the embodiments of the present disclosure, since the target image features are features that match the text, by fine-tuning the text generation instructions, the large language model can better handle document image question-answering tasks in complex contexts.
[0109] Fig.10 The flowchart of the text information generation model training method according to an embodiment of the present disclosure is schematically shown.
[0110] like Fig.10 As shown, in this embodiment, the model includes a feature extraction module, an attention module and a generation module, and the method 1000 includes operations S1010 to S1050.
[0111] In operation S1010, a feature extraction module is used to extract multi-scale sample image features of the sample image.
[0112] In operation S1020, the attention module is used to process the multi-scale sample image features based on the attention mechanism to obtain the target sample image features that match the sample text.
[0113] In operation S1030, the generating module is used to process the target sample image features based on the sample text generating instruction to generate target sample text information corresponding to the sample text generating instruction.
[0114] In operation S1040 , a loss value is obtained based on the loss function according to the target sample text information and the sample text label.
[0115] In operation S1050, a trained model is obtained by adjusting model parameters of the model based on the loss value.
[0116] According to an embodiment of the present disclosure, the content of the sample image includes sample text; the multi-scale sample image features include features for characterizing structural information and content information of the sample text.
[0117] According to an embodiment of the present disclosure, sample images may be document images collected from a variety of data sources to improve the richness of model training data.
[0118] For example, the sample image may be a PDF (Portable Document Format) document, which is obtained by collecting document PDFs, converting them into image documents using parsing tools, and obtaining the position and content of the text in the image document.
[0119] For example, the sample image can be web page data. The web page is obtained from a website, and then converted into a web page image document based on a web page rendering tool, and the position and content of the text in the web page image document are obtained to obtain the sample image.
[0120] For example, the sample image can be public data. By acquiring large-scale public data, existing OCR tools are used to swipe such natural images, and effective text information is filtered out to obtain the sample image.
[0121] For example, the sample image can be synthetic data, and text is rendered on various image templates through existing text corpus to obtain the sample image.
[0122] According to an embodiment of the present disclosure, the feature extraction module may be the Swin Transformer model described above, the attention module may be the resampler of the Q-Former structure described above, and the generation module may be the large language model described above.
[0123] According to the embodiments of the present disclosure, the definition scope of the multi-scale sample image features and the target sample image features is the same as that of the multi-scale image features and the target image features described above, and are not elaborated here.
[0124] According to an embodiment of the present disclosure, the sample text tag may be the content of the sample text and the position of the sample text.
[0125] According to an embodiment of the present disclosure, obtaining a trained model by adjusting the model parameters of the model based on the loss value may include: based on the loss function, simultaneously adjusting the model parameters of the feature extraction module, the attention module and the generation module to obtain the trained model.
[0126] According to an embodiment of the present disclosure, the model training process includes pre-training and instruction fine-tuning. In the pre-training process, the text in the sample image is sorted according to the image coordinates to generate a label sequence, and then the model is trained in combination with the sample text generation instruction: "Please identify and locate the text in the image" to obtain a pre-trained model. Then, the sample text generation instruction is adjusted to fine-tune the instruction of the pre-trained model to obtain a trained model.
[0127] According to the embodiments of the present disclosure, the text structure information and text content information in the image can be extracted comprehensively based on multi-scale image features. Based on the attention mechanism, the model can be more focused on the features that match the text. Using the content and position of the sample text as labels can enable the large language model to generate text information corresponding to the sample image according to the requirements of the text generation instruction, thereby improving the reasoning accuracy of the model.
[0128] Fig.11 The schematic diagram shows a principle diagram of a text information generation model training method according to an embodiment of the present disclosure.
[0129] like Fig.11 As shown, in this embodiment 1100, a sample image 1110 and a sample text generation instruction 1120 are input into an initial model 1130, and target sample text information 1140 is output after being processed by the model 1130; then a loss value 1160 is determined based on the target sample text information 1140 and the sample text label 1150, and the parameters of the model 1130 are adjusted based on the loss value 1160, and the above operations are repeated until the model 1130 meets the preset iteration conditions, thereby obtaining a trained model.
[0130] According to an embodiment of the present disclosure, a trained model is obtained by adjusting the model parameters of the model based on a loss value, including: based on a first loss value, fixing the parameters of the generation module, and obtaining an intermediate model by adjusting the parameters of the feature extraction module and the parameters of the attention module; based on a second loss value, obtaining a trained model by adjusting the parameters of all modules of the intermediate model; wherein: the first loss value represents the loss value of the target sample text information output by the initial model and the first sample text label; the second loss value represents the loss value of the target sample text information output by the intermediate model and the first sample text label; the first sample text label includes the content of the sample text and the position of the sample text.
[0131] According to an embodiment of the present disclosure, in the pre-training stage, the parameters of the generation module are fixed, the parameters of the feature extraction module and the parameters of the attention module are adjusted based on the first loss value, an intermediate model is obtained, and then based on the second loss value, the parameters of all modules of the intermediate model are adjusted to obtain a trained model. Since the generation module uses a large language model and can be used without training, the method of first training the feature extraction module and the attention module and then adjusting the parameters of all modules can improve the training efficiency.
[0132] According to an embodiment of the present disclosure, a trained model is obtained by adjusting the model parameters of the model based on the loss value, including: based on a third loss value, fixing the parameters of the feature extraction module of the pre-trained model, and obtaining the trained model by adjusting the parameters of the attention module and the parameters of the generation module; the third loss value represents the loss value of the target sample text information output by the pre-trained model and the second sample text label; the pre-trained model is obtained by training the initial model based on the first sample text label; the second sample text label includes text content corresponding to the sample attribute or text content used to answer the sample question.
[0133] According to an embodiment of the present disclosure, in the instruction fine-tuning stage, since the feature extraction part has been able to meet the pre-training requirements, this stage only adjusts the parameters of the attention module and the generation module to apply to the scenario of the adjusted instructions, thereby improving the training efficiency of the model and shortening the model training cycle.
[0134] According to an embodiment of the present disclosure, during the instruction fine-tuning stage, the multi-scale sample image features extracted by the feature extraction module of the sample image are not affected after the instruction transformation. Therefore, during the instruction fine-tuning stage, only the parameters of the attention module and the parameters of the generation module need to be adjusted.
[0135] According to the embodiments of the present disclosure, the sample attributes, the text content corresponding to the sample attributes, the sample questions and the text content used to answer the sample questions are defined the same as the text attribute names, the content corresponding to the text attribute names, the question text and the content used to answer the question text described above, and are not repeated here.
[0136] According to an embodiment of the present disclosure, based on a sample text generation instruction, target sample image features are processed to generate target sample text information corresponding to the sample text generation instruction, including: based on a predetermined dictionary, converting the sample text generation instruction into sample text features; inserting identifiers at both ends of the target sample image features and concatenating them with the sample text features to obtain sample input features; and inputting the sample input features into a large language model to generate target text information corresponding to the text generation instruction.
[0137] According to the embodiments of the present disclosure, by taking the sample text features and sample target image features of the sample text generation instructions as the input of the large language model, the large language model can learn the features of different modalities related to the text content, thereby further improving the applicability of the large language model to text image recognition, extraction, and question-answering tasks in multiple scenarios.
[0138] According to an embodiment of the present disclosure, extracting multi-scale sample image features of a sample image includes: dividing the sample image into a plurality of sample pixel blocks, wherein there are overlapping areas between the plurality of sample pixel blocks; processing the plurality of sample pixel blocks to obtain global features of the sample image; and downsampling the global features of the sample image to obtain multi-scale sample image features.
[0139] According to an embodiment of the present disclosure, multiple sample pixel blocks are processed to obtain global features of the sample image, including: based on a self-attention mechanism, processing each sample pixel block to obtain local features corresponding to each sample pixel block; and splicing the local features corresponding to each sample pixel block according to the relative position relationship between the sample pixel blocks to obtain global features.
[0140] According to the embodiments of the present disclosure, by extracting multi-scale sample image features, the model can learn feature information at multiple levels such as text structure and text content during the training process, thereby further improving the accuracy of the large language model.
[0141] According to an embodiment of the present disclosure, the global features of the sample image are downsampled to obtain multi-scale sample image features, including: downsampling the global features according to a first predetermined feature dimension to obtain a first sample scale feature for characterizing content information; and downsampling the first sample scale feature according to a second predetermined feature dimension to obtain a second sample scale feature for characterizing structural information.
[0142] According to an embodiment of the present disclosure, based on the attention mechanism, multi-scale sample image features are processed to obtain target sample image features that match the sample text; including: based on the attention mechanism, the query feature matrix and multi-scale sample image features are processed to obtain target sample image features; wherein the query feature matrix is randomly initialized according to a predetermined dimension.
[0143] According to an embodiment of the present disclosure, based on the attention mechanism, the query feature matrix and the multi-scale sample image features are processed to obtain the target sample image features, including: based on the cross-attention mechanism, the query feature matrix and the multi-scale sample image features are processed to obtain the first intermediate sample features; and based on the self-attention mechanism, the first intermediate sample features are processed to obtain the target sample image features.
[0144] According to the embodiments of the present disclosure, a multi-layer attention mechanism can be used to enable the model to pay more attention to features that match the text during the training process, thereby further improving the accuracy and processing efficiency of the large language model.
[0145] According to an embodiment of the present disclosure, the method for extracting multi-scale sample image features, the method for extracting target sample image features, and the method for processing target sample image features and generating target sample text information based on sample text generation instructions in the model training part are the same as the method for extracting multi-scale image features, the method for extracting target image features, and the method for processing target image features and generating target text information based on text generation instructions described above, and are not repeated here.
[0146] Fig.12 The block diagram of a device for generating text information according to an embodiment of the present disclosure is schematically shown.
[0147] like Fig.12 As shown, the device 1200 may include: an extraction module 1210 , a first processing module 1220 , and a second processing module 1230 .
[0148] The extraction module 1210 is used to extract multi-scale image features of the image to be processed, wherein the content of the image to be processed includes text; the multi-scale image features include features for representing structural information and content information of the text.
[0149] The first processing module 1220 is used to process the multi-scale image features based on the attention mechanism to obtain target image features that match the text.
[0150] The second processing module 1230 is used to process the target image features based on the text generation instruction to generate target text information corresponding to the text generation instruction.
[0151] According to an embodiment of the present disclosure, the extraction module includes: a first division submodule, a first processing submodule and a first downsampling submodule. The first division submodule is used to divide the image to be processed into a plurality of pixel blocks, wherein there are overlapping areas between the plurality of pixel blocks. The first processing submodule is used to process the plurality of pixel blocks to obtain the global features of the image to be processed. The first downsampling submodule is used to downsample the global features of the image to be processed to obtain multi-scale image features.
[0152] According to an embodiment of the present disclosure, the first processing submodule includes: a first processing unit and a first splicing unit. The first processing unit is used to process each pixel block based on the self-attention mechanism to obtain a local feature corresponding to each pixel block. The first splicing unit is used to splice the local features corresponding to each pixel block according to the relative position relationship between the pixel blocks to obtain a global feature.
[0153] According to an embodiment of the present disclosure, the first downsampling submodule includes: a first downsampling unit and a second downsampling unit. The first downsampling unit is used to downsample the global feature according to a first predetermined feature dimension to obtain a first scale feature for characterizing content information. The second downsampling unit is used to downsample the first scale feature according to a second predetermined feature dimension to obtain a second scale feature for characterizing structural information.
[0154] According to an embodiment of the present disclosure, the first processing module includes: a second processing submodule. The second processing submodule is used to process the query feature matrix and the multi-scale image features based on the attention mechanism to obtain the target image features.
[0155] According to an embodiment of the present disclosure, the query feature matrix is randomly initialized according to a predetermined dimension.
[0156] According to an embodiment of the present disclosure, the second processing submodule includes: a second processing unit and a third processing unit. The second processing unit is used to process the query feature matrix and the multi-scale image features based on the cross attention mechanism to obtain the first intermediate features. The third processing unit is used to process the first intermediate features based on the self-attention mechanism to obtain the target image features.
[0157] According to an embodiment of the present disclosure, the second processing module includes: a first conversion submodule, a first splicing submodule and a first generation submodule. The first conversion submodule is used to convert the text generation instruction into a text feature based on a predetermined dictionary. The first splicing submodule is used to insert identifiers at both ends of the target image feature and splice them with the text feature to obtain the input feature. The first generation submodule is used to input the input feature into the large language model to generate the target text information corresponding to the text generation instruction.
[0158] According to an embodiment of the present disclosure, the text generation instruction includes a text attribute name; the first generation submodule includes: a first generation unit. The first generation unit is used to input the input feature into the large language model to generate target text information corresponding to the text attribute name.
[0159] According to an embodiment of the present disclosure, the text generation instruction includes a question text; the first generation submodule includes: a second generation unit. The second generation unit is used to input input features into a large language model to generate target text information for answering the question text.
[0160] Fig.13 A block diagram of a text information generation model training device according to an embodiment of the present disclosure is schematically shown.
[0161] like Fig.13As shown, the training device 1300 may include: a feature extraction module 1310, an attention module 1320, a generation module 1330, a loss function module 1340 and an adjustment module 1350.
[0162] The feature extraction module 1310 is used to extract multi-scale sample image features of the sample image, wherein the content of the sample image includes sample text; the multi-scale sample image features include features for characterizing structural information and content information of the sample text.
[0163] The attention module 1320 is used to process the multi-scale sample image features based on the attention mechanism to obtain the target sample image features that match the sample text.
[0164] The generating module 1330 is used to process the target sample image features based on the sample text generating instruction, and generate target sample text information corresponding to the sample text generating instruction.
[0165] The loss function module 1340 is used to obtain a loss value based on the loss function according to the target sample text information and the sample text label.
[0166] The adjustment module 1350 is used to obtain a trained model by adjusting the model parameters of the model based on the loss value.
[0167] According to an embodiment of the present disclosure, the adjustment module includes: a first adjustment submodule and a second adjustment submodule. The first adjustment submodule is used to fix the parameters of the generation module based on the first loss value, and obtain the intermediate model by adjusting the parameters of the feature extraction module and the parameters of the attention module. The second adjustment submodule is used to obtain the trained model by adjusting the parameters of all modules of the intermediate model based on the second loss value.
[0168] According to an embodiment of the present disclosure, the first loss value represents the loss value of the target sample text information output by the initial model and the first sample text label; the second loss value represents the loss value of the target sample text information output by the intermediate model and the first sample text label; the first sample text label includes the content of the sample text and the position of the sample text.
[0169] According to an embodiment of the present disclosure, the adjustment module includes: a third adjustment submodule. The third adjustment submodule is used to fix the parameters of the feature extraction module of the pre-trained model based on the third loss value, and obtain the trained model by adjusting the parameters of the attention module and the parameters of the generation module.
[0170] According to an embodiment of the present disclosure, the third loss value represents the loss value between the target sample text information output by the pre-trained model and the second sample text label; the pre-trained model is obtained by training the initial model based on the first sample text label; the second sample text label includes text content corresponding to the sample attributes or text content used to answer the sample question.
[0171] According to an embodiment of the present disclosure, the generation module includes: a second conversion submodule, a second splicing submodule and a second generation submodule. The second conversion submodule is used to convert the sample text generation instruction into a sample text feature based on a predetermined dictionary. The second splicing submodule is used to insert identifiers at both ends of the target sample image feature and splice them with the sample text feature to obtain the sample input feature. The second generation submodule is used to input the sample input feature into the large language model to generate the target text information corresponding to the text generation instruction.
[0172] According to an embodiment of the present disclosure, the feature extraction module includes: a second division submodule, a third processing submodule and a second downsampling submodule. The second division submodule is used to divide the sample image into a plurality of sample pixel blocks, wherein there are overlapping areas between the plurality of sample pixel blocks. The third processing submodule is used to process the plurality of sample pixel blocks to obtain global features of the sample image. The second downsampling submodule is used to downsample the global features of the sample image to obtain multi-scale sample image features.
[0173] According to an embodiment of the present disclosure, the third processing submodule includes: a fourth processing unit and a second splicing unit. The fourth processing unit is used to process each sample pixel block based on the self-attention mechanism to obtain a local feature corresponding to each sample pixel block. The second splicing unit is used to splice the local features corresponding to each sample pixel block according to the relative position relationship between the sample pixel blocks to obtain a global feature.
[0174] According to an embodiment of the present disclosure, the second downsampling submodule includes: a third downsampling unit and a fourth downsampling unit. The third downsampling unit is used to downsample the global feature according to the first predetermined feature dimension to obtain a first sample scale feature for characterizing content information. The fourth downsampling unit is used to downsample the first sample scale feature according to the second predetermined feature dimension to obtain a second sample scale feature for characterizing structural information.
[0175] According to an embodiment of the present disclosure, the attention module includes: a fourth processing submodule. The fourth processing submodule is used to process the query feature matrix and the multi-scale sample image features based on the attention mechanism to obtain the target sample image features.
[0176] According to an embodiment of the present disclosure, the query feature matrix is randomly initialized according to a predetermined dimension.
[0177] According to an embodiment of the present disclosure, the fourth processing submodule includes: a fifth processing unit and a sixth processing unit. The fifth processing unit is used to process the query feature matrix and the multi-scale sample image features based on the cross-attention mechanism to obtain the first intermediate sample features. The sixth processing unit is used to process the first intermediate sample features based on the self-attention mechanism to obtain the target sample image features.
[0178] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0179] According to an embodiment of the present disclosure, an electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method as described above.
[0180] According to an embodiment of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause a computer to execute the method as described above.
[0181] According to an embodiment of the present disclosure, a computer program product includes a computer program, and when the computer program is executed by a processor, the computer program implements the method as described above.
[0182] Fig.14 A block diagram of an electronic device suitable for implementing a method for generating text information according to an embodiment of the present disclosure is schematically shown. Electronic device 1400 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0183] like Fig.14As shown, the device 1400 includes a computing unit 1401, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1402 or a computer program loaded from a storage unit 1408 into a random access memory (RAM) 1403. In the RAM 1403, various programs and data required for the operation of the device 1400 can also be stored. The computing unit 1401, the ROM 1402, and the RAM 1403 are connected to each other via a bus 1404. An input / output (I / O) interface 1405 is also connected to the bus 1404.
[0184] A number of components in the device 1400 are connected to the I / O interface 1405, including: an input unit 1406, such as a keyboard, a mouse, etc.; an output unit 1407, such as various types of displays, speakers, etc.; a storage unit 1408, such as a disk, an optical disk, etc.; and a communication unit 1409, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 1409 allows the device 1400 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0185] The computing unit 1401 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 1401 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 1401 performs the various methods and processes described above, such as a method for generating text information or a model training method. For example, in some embodiments, the method for generating text information or the model training method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 1408. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 1400 via the ROM 1402 and / or the communication unit 1409. When the computer program is loaded into the RAM 1403 and executed by the computing unit 1401, one or more steps of the method for generating text information or the model training method described above may be performed. Alternatively, in other embodiments, the computing unit 1401 may be configured to execute the text information generation method or the model training method in any other appropriate manner (eg, by means of firmware).
[0186] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0187] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0188] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0189] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0190] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0191] A computer system may include a client and a server. The client and the server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises through computer programs running on respective computers and having a client-server relationship to each other. The server may be a cloud server, a server in a distributed system, or a server combined with a blockchain.
[0192] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0193] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for generating text information, comprising: Extracting multi-scale image features of an image to be processed, wherein the content of the image to be processed includes text; the multi-scale image features include features for characterizing structural information and content information of the text; Based on the attention mechanism, the multi-scale image features are processed to obtain target image features that match the text; and Based on the text generation instruction, the target image features are processed to generate target text information corresponding to the text generation instruction.
2. The method according to claim 1, wherein: The step of extracting multi-scale image features of the image to be processed comprises: Dividing the image to be processed into a plurality of pixel blocks, wherein there are overlapping areas between the plurality of pixel blocks; Processing the multiple pixel blocks to obtain global features of the image to be processed; and Downsampling the global features of the image to be processed to obtain the multi-scale image features.
3. The method according to claim 2, wherein: The processing of the plurality of pixel blocks to obtain the global features of the image to be processed includes: Based on the self-attention mechanism, each pixel block is processed to obtain the local features corresponding to each pixel block; and The local features corresponding to each pixel block are spliced according to the relative position relationship between the pixel blocks to obtain the global features.
4. The method according to claim 2, wherein: The downsampling of the global features of the image to be processed to obtain the multi-scale image features includes: Downsampling the global feature according to a first predetermined feature dimension to obtain a first scale feature for characterizing the content information; and The first scale feature is downsampled according to a second predetermined feature dimension to obtain a second scale feature for characterizing the structural information.
5. The method according to any one of claims 1 to 4, wherein: The multi-scale image features are processed based on the attention mechanism to obtain target image features that match the text, including: Based on the attention mechanism, the query feature matrix and the multi-scale image features are processed to obtain the target image features; The query feature matrix is randomly initialized according to a predetermined dimension.
6. The method according to claim 5, wherein: The step of processing the query feature matrix and the multi-scale image features based on the attention mechanism to obtain the target image features includes: Based on a cross attention mechanism, the query feature matrix and the multi-scale image features are processed to obtain a first intermediate feature; and Based on the self-attention mechanism, the first intermediate feature is processed to obtain the target image feature.
7. The method according to any one of claims 1 to 6, wherein: The step of processing the target image feature based on the text generation instruction to generate target text information corresponding to the text generation instruction includes: Based on a predetermined dictionary, converting the text generation instruction into text features; Inserting identifiers at both ends of the target image feature and concatenating them with the text feature to obtain an input feature; and The input features are input into a large language model to generate target text information corresponding to the text generation instruction.
8. The method according to claim 7, wherein: The text generation instruction includes a text attribute name; the step of inputting the input feature into a large language model to generate target text information corresponding to the text generation instruction includes: The input features are input into a large language model to generate target text information corresponding to the text attribute name.
9. The method according to claim 7, wherein: The text generation instruction includes a question text; and the step of inputting the input features into a large language model to generate target text information corresponding to the text generation instruction includes: The input features are input into a large language model to generate target text information for answering the question text.
10. A text information generation model training method, the model includes a feature extraction module, an attention module and a generation module, the method includes: Utilizing the feature extraction module, extracting multi-scale sample image features of a sample image, wherein the content of the sample image includes sample text; the multi-scale sample image features include features for characterizing structural information and content information of the sample text; Using the attention module, based on the attention mechanism, the multi-scale sample image features are processed to obtain target sample image features that match the sample text; Using the generation module, based on the sample text generation instruction, the target sample image features are processed to generate target sample text information corresponding to the sample text generation instruction; Based on the loss function, a loss value is obtained according to the target sample text information and the sample text label; and Based on the loss value, a trained model is obtained by adjusting the model parameters of the model.
11. The method according to claim 10, wherein: The step of obtaining a trained model by adjusting a model parameter of the model based on the loss value comprises: Based on the first loss value, fixing the parameters of the generation module, and obtaining an intermediate model by adjusting the parameters of the feature extraction module and the parameters of the attention module; Based on the second loss value, adjusting parameters of all modules of the intermediate model to obtain a trained model; in: The first loss value represents the loss value between the target sample text information output by the initial model and the first sample text label; The second loss value represents a loss value between the target sample text information output by the intermediate model and the first sample text label; The first sample text tag includes the content of the sample text and the position of the sample text.
12. The method according to claim 11, wherein: The step of obtaining a trained model by adjusting a model parameter of the model based on the loss value comprises: Based on the third loss value, fixing the parameters of the feature extraction module of the pre-trained model, and obtaining a trained model by adjusting the parameters of the attention module and the parameters of the generation module; The third loss value represents the loss value between the target sample text information output by the pre-training model and the second sample text label; The pre-trained model is obtained by training the initial model based on the first sample text label; The second sample text label includes text content corresponding to the sample attribute or text content used to answer the sample question.
13. The method according to claim 10, wherein: The step of processing the target sample image features based on the sample text generation instruction to generate target sample text information corresponding to the sample text generation instruction includes: Based on a predetermined dictionary, converting the sample text generation instruction into sample text features; Inserting identifiers at both ends of the target sample image feature and concatenating them with the sample text feature to obtain a sample input feature; and The sample input features are input into a large language model to generate target text information corresponding to the text generation instruction.
14. The method according to any one of claims 10 to 13, wherein: The step of extracting multi-scale sample image features of the sample image comprises: Dividing the sample image into a plurality of sample pixel blocks, wherein there are overlapping areas between the plurality of sample pixel blocks; Processing the plurality of sample pixel blocks to obtain global features of the sample image; and The global features of the sample image are downsampled to obtain the multi-scale sample image features.
15. The method according to claim 14, wherein: The processing of the plurality of sample pixel blocks to obtain the global features of the sample image includes: Based on the self-attention mechanism, each sample pixel block is processed to obtain a local feature corresponding to each sample pixel block; and The local features corresponding to each sample pixel block are spliced according to the relative position relationship between the sample pixel blocks to obtain the global features.
16. The method according to claim 14, wherein: The downsampling of the global features of the sample image to obtain the multi-scale sample image features includes: Downsampling the global feature according to a first predetermined feature dimension to obtain a first sample scale feature for characterizing the content information; and The first sample scale feature is downsampled according to a second predetermined feature dimension to obtain a second sample scale feature for characterizing the structural information.
17. The method according to any one of claims 10 to 16, wherein: The method of processing the multi-scale sample image features based on the attention mechanism to obtain target sample image features matching the sample text comprises: Based on the attention mechanism, the query feature matrix and the multi-scale sample image features are processed to obtain the target sample image features; The query feature matrix is randomly initialized according to a predetermined dimension.
18. The method according to claim 17, wherein: The step of processing the query feature matrix and the multi-scale sample image features based on the attention mechanism to obtain the target sample image features includes: Based on a cross attention mechanism, the query feature matrix and the multi-scale sample image features are processed to obtain a first intermediate sample feature; and Based on the self-attention mechanism, the first intermediate sample features are processed to obtain the target sample image features.
19. A device for generating text information, comprising: An extraction module, used for extracting multi-scale image features of an image to be processed, wherein the content of the image to be processed includes text; the multi-scale image features include features for characterizing structural information and content information of the text; A first processing module is used to process the multi-scale image features based on an attention mechanism to obtain target image features that match the text; and The second processing module is used to process the target image features based on the text generation instruction to generate target text information corresponding to the text generation instruction.
20. The device according to claim 19, wherein The extraction module comprises: A first division submodule is used to divide the image to be processed into a plurality of pixel blocks, wherein there are overlapping areas between the plurality of pixel blocks; A first processing submodule, configured to process the plurality of pixel blocks to obtain global features of the image to be processed; and The first downsampling submodule is used to downsample the global features of the image to be processed to obtain the multi-scale image features.
21. The device according to claim 20, wherein: The first processing submodule includes: A first processing unit is used to process each pixel block based on a self-attention mechanism to obtain a local feature corresponding to each pixel block; and The first splicing unit is used to splice the local features corresponding to each pixel block according to the relative position relationship between the pixel blocks to obtain the global features.
22. The device according to claim 20, wherein: The first downsampling submodule comprises: A first downsampling unit, configured to downsample the global feature according to a first predetermined feature dimension to obtain a first scale feature for characterizing the content information; and The second downsampling unit is used to downsample the first scale feature according to a second predetermined feature dimension to obtain a second scale feature for characterizing the structural information.
23. The device according to any one of claims 19 to 22, wherein: The first processing module comprises: A second processing submodule is used to process the query feature matrix and the multi-scale image features based on the attention mechanism to obtain the target image features; The query feature matrix is randomly initialized according to a predetermined dimension.
24. The device according to claim 23, wherein: The second processing submodule includes: A second processing unit is configured to process the query feature matrix and the multi-scale image features based on a cross attention mechanism to obtain a first intermediate feature; and The third processing unit is used to process the first intermediate feature based on a self-attention mechanism to obtain the target image feature.
25. The device according to any one of claims 19 to 24, wherein: The second processing module comprises: A first conversion submodule, configured to convert the text generation instruction into text features based on a predetermined dictionary; A first splicing submodule is used to insert identifiers at both ends of the target image feature and splice them with the text feature to obtain an input feature; and The first generation submodule is used to input the input features into a large language model to generate target text information corresponding to the text generation instruction.
26. The device according to claim 25, wherein The text generation instruction includes a text attribute name; the first generation submodule includes: The first generating unit is used to input the input feature into a large language model to generate target text information corresponding to the text attribute name.
27. The device according to claim 25, wherein: The text generation instruction includes question text; The first generation submodule includes: The second generating unit is used to input the input features into the large language model to generate target text information for answering the question text.
28. A text information generation model training device, comprising: A feature extraction module, used to extract multi-scale sample image features of a sample image, wherein the content of the sample image includes sample text; the multi-scale sample image features include features for characterizing structural information and content information of the sample text; An attention module, used for processing the multi-scale sample image features based on an attention mechanism to obtain target sample image features that match the sample text; A generating module, used for processing the target sample image features based on the sample text generating instruction, and generating target sample text information corresponding to the sample text generating instruction; A loss function module, used to obtain a loss value based on the target sample text information and the sample text label based on the loss function; and An adjustment module is used to obtain a trained model by adjusting model parameters of the model based on the loss value.
29. The device according to claim 18, wherein The adjustment module comprises: A first adjustment submodule, used for fixing the parameters of the generation module based on the first loss value, and obtaining an intermediate model by adjusting the parameters of the feature extraction module and the parameters of the attention module; A second adjustment submodule, configured to obtain a trained model by adjusting parameters of all modules of the intermediate model based on a second loss value; in: The first loss value represents the loss value between the target sample text information output by the initial model and the first sample text label; The second loss value represents a loss value between the target sample text information output by the intermediate model and the first sample text label; The first sample text tag includes the content of the sample text and the position of the sample text.
30. The device according to claim 29, wherein: The adjustment module comprises: A third adjustment submodule, used for fixing the parameters of the feature extraction module of the pre-trained model based on the third loss value, and obtaining the trained model by adjusting the parameters of the attention module and the parameters of the generation module; The third loss value represents the loss value between the target sample text information output by the pre-training model and the second sample text label; The pre-trained model is obtained by training the initial model based on the first sample text label; The second sample text label includes text content corresponding to the sample attribute or text content used to answer the sample question.
31. The apparatus of claim 28, wherein: The generating module comprises: A second conversion submodule, configured to convert the sample text generation instruction into sample text features based on a predetermined dictionary; A second splicing submodule is used to insert identifiers at both ends of the target sample image feature and splice them with the sample text feature to obtain a sample input feature; and The second generation submodule is used to input the sample input features into a large language model to generate target text information corresponding to the text generation instruction.
32. The device according to any one of claims 28 to 31, wherein: The feature extraction module comprises: A second division submodule, configured to divide the sample image into a plurality of sample pixel blocks, wherein the plurality of sample pixel blocks have overlapping areas with each other; a third processing submodule, configured to process the plurality of sample pixel blocks to obtain global features of the sample image; and The second downsampling submodule is used to downsample the global features of the sample image to obtain the multi-scale sample image features.
33. The device according to claim 32, wherein: The third processing submodule comprises: a fourth processing unit, configured to process each sample pixel block based on a self-attention mechanism to obtain a local feature corresponding to each sample pixel block; and The second splicing unit is used to splice the local features corresponding to each sample pixel block according to the relative position relationship between the sample pixel blocks to obtain the global features.
34. The device according to claim 32, wherein: The second downsampling submodule comprises: A third downsampling unit, configured to downsample the global feature according to a first predetermined feature dimension to obtain a first sample scale feature for characterizing the content information; and The fourth downsampling unit is used to downsample the first sample scale feature according to a second predetermined feature dimension to obtain a second sample scale feature for characterizing the structural information.
35. The device according to any one of claims 28 to 34, wherein: The attention module comprises: A fourth processing submodule, used for processing the query feature matrix and the multi-scale sample image features based on the attention mechanism to obtain the target sample image features; The query feature matrix is randomly initialized according to a predetermined dimension.
36. The device according to claim 35, wherein The fourth processing submodule comprises: a fifth processing unit, configured to process the query feature matrix and the multi-scale sample image features based on a cross attention mechanism to obtain a first intermediate sample feature; and The sixth processing unit is used to process the first intermediate sample features based on the self-attention mechanism to obtain the target sample image features.
37. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 18.
38. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-18.
39. A computer program product comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 18.
Citation Information
Patent Citations
Method and device for constructing representative arrival positioning and segmentation model
CN114048284A
Image text information generation method and deep learning model training method
CN115359323A
Multi-scale data fusion method and device, medium and electronic equipment
CN117113268A
Training method for handwritten text image generation mode, electronic device and storage medium
US20230206522A1
Method and Apparatus for Recognizing Document Image, Storage Medium and Electronic Device
US20230260306A1
Cited By
Processing method and device for mining patent information in combination with large language model
CN119782382A
A processing method and device for mining patent information in combination with a large language model
CN119782382B
Text image recognition model training method and text image recognition method
CN120451993A
Layout analysis method and device
CN120932258A
Page analysis method and apparatus
CN120932258B
