Text extraction method, device and electronic equipment

By identifying, converting and verifying prompt words, combined with language model technology, it solves the problem of low efficiency in extracting text in specified formats and specified fields from images in the existing technology, and achieves efficient and accurate text extraction.

CN118522017BActive Publication Date: 2024-10-15ZHUO SHI ZHI XING (QINGTIAN) YUAN UNIVERSE TECH CO LTD

Patent Information

Application Number
CN202410973264.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-19
Publication Date
2024-10-15
Estimated Expiration
2044-07-19

AI Technical Summary

Technical Problem

When existing OCR technology extracts text from images, it is difficult to efficiently identify text in specified formats and specified fields, requiring a lot of manual analysis, resulting in low efficiency.

Method used

By identifying, converting, verifying and mapping prompt words, the language model is used to convert and verify the format of the text in the image, establish a mapping relationship between the specified field and the text, and extract the text of the specified field.

Benefits of technology

It achieves efficient and accurate extraction of required text from images, reduces manual analysis, and improves text extraction efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118522017B_ABST
    Figure CN118522017B_ABST
Patent Text Reader

Abstract

The present invention provides a text extraction method, device and electronic device, belonging to the field of artificial intelligence technology. The method comprises: identifying the text in the image to be extracted to obtain the first text in the first format; determining the text segment and the corresponding segment type based on the first grammatical rule corresponding to the first format; converting the first text into the second text in the second format based on the conversion prompt word and the segment type of each text segment; performing a rationality check on the second text using the check prompt word to obtain a third text that passes the rationality check; based on the mapping prompt word, guiding the mapping model to establish a mapping relationship between the third text and the specified field, and extracting the specified text corresponding to the specified field from the third text based on the mapping relationship. The present invention can fully utilize the ability of the language model to extract text by setting different prompt words, thereby realizing efficient text extraction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a text extraction method, device and electronic equipment. Background Art

[0002] Text extraction refers to the process of extracting the required text information from an image containing text. Usually, images containing text are not editable. Currently, optical character recognition (OCR) technology can be used to extract text from images.

[0003] However, OCR technology only supports recognizing text from images. When text in a specified format and field is required, a lot of manpower is needed to analyze and process the recognized text, making it difficult to efficiently extract the required text from the image. Summary of the invention

[0004] In view of the above problems, an object of the present invention is to provide a text extraction method, device and electronic device, which can efficiently extract the required text from an image.

[0005] In order to solve the above technical problems, the present invention provides the following technical solutions:

[0006] On the one hand, a text extraction method is provided, comprising:

[0007] Recognize the text in the image to be extracted to obtain a first text in a first format;

[0008] Based on a first grammatical rule corresponding to the first format, determining a text segment and a segment type corresponding to the text segment from the first text;

[0009] Based on the conversion prompt word and the segment type of each text segment, converting the first text into a second text in a second format, wherein a second grammar rule corresponding to the second format is different from the first grammar rule;

[0010] Performing a rationality check on the second text using the check prompt word to obtain a third text that passes the rationality check;

[0011] Based on the mapping prompt word, the mapping model is guided to establish a mapping relationship between the third text and the designated field, and based on the mapping relationship, the designated text corresponding to the designated field is extracted from the third text.

[0012] Optionally, the converting the first text into a second text in a second format based on the conversion prompt word and the segment type of each text segment includes:

[0013] Generate a conversion prompt word using the first text and a conversion template, wherein the conversion prompt word includes an output format and a plurality of conversion steps;

[0014] For each of the text segments, the multiple conversion steps are performed according to the segment type of the text segment and the second grammar rule to obtain a conversion segment corresponding to the text segment;

[0015] The conversion segments are organized based on the output format to obtain a second text in a second format.

[0016] Optionally, for each of the text segments, performing the multiple conversion steps according to the segment type of the text segment and the second grammar rule to obtain a conversion segment corresponding to the text segment includes:

[0017] For each of the text segments, the text segment is parsed according to the segment type and the first grammar rule to obtain a text element, an element type of the text element, and an element style of the text element;

[0018] According to the element type of the text element and the second grammar rule, converting the text element into an intermediate element;

[0019] Using the element style corresponding to the text element and the specified style, the style of the intermediate element is adjusted to obtain a target element;

[0020] All the target elements are organized based on the second grammar rule to obtain a conversion fragment.

[0021] Optionally, the using the verification prompt word to perform a rationality check on the second text to obtain a third text that passes the rationality check includes:

[0022] For each text segment, a verification prompt word is generated using a segment group and a verification template, wherein the segment group includes a text segment and a conversion segment corresponding to the text segment, and the verification prompt word includes sub-checks corresponding to multiple element types and a preset threshold;

[0023] By using the verification model, performing a plurality of sub-verifications on the segment group to obtain sub-verification results corresponding to the sub-verifications;

[0024] generating a verification score for the segment group according to the sub-verification result;

[0025] If the verification score is not less than the preset threshold, taking the converted segments in the segment group as the segments to be combined;

[0026] If the verification score is less than the preset threshold, modifying the converted segments in the segment group to obtain the segment to be combined;

[0027] All the to-be-combined segments are combined to obtain a third text that passes the rationality check.

[0028] Optionally, performing a plurality of sub-checks on the segment group through the verification model to obtain sub-check results corresponding to the sub-checks includes:

[0029] For the text segments in the segment group, obtaining the element type of each text element in the text segments to obtain a target type;

[0030] Determining a target sub-check from the plurality of sub-checks according to the target type;

[0031] The target sub-verification is performed on the segment group through the verification model to obtain a verification result corresponding to the target sub-verification.

[0032] Optionally, guiding the mapping model to establish a mapping relationship between the third text and a designated field based on a mapping prompt word, and extracting a designated text corresponding to the designated field from the third text based on the mapping relationship includes:

[0033] Generate a mapping prompt word based on a designated field, the third text and a mapping template, wherein the mapping prompt word includes a plurality of mapping steps;

[0034] Executing the plurality of mapping steps through a mapping model to establish a mapping relationship between the third text and a specified field;

[0035] According to the mapping relationship and the designated field, the designated text corresponding to the designated field is extracted from the third text.

[0036] Optionally, performing the multiple mapping steps through a mapping model to establish a mapping relationship between the third text and a specified field includes:

[0037] Extracting the to-be-mapped fields from the third text by using the mapping model;

[0038] For each designated field, calculating the semantic similarity between the designated field and each field to be mapped;

[0039] A mapping relationship between each designated field and the field to be mapped is established by using the semantic similarity and the similarity threshold.

[0040] Optionally, extracting the designated text corresponding to the designated field from the third text according to the mapping relationship and the designated field includes:

[0041] Based on the mapping relationship, mapping processing is performed on the third text to obtain a fourth text;

[0042] Verifying the accuracy of the fourth text;

[0043] If the fourth text passes the accuracy verification, a designated text corresponding to the designated field is obtained from the fourth text.

[0044] On the other hand, a text extraction device is also provided, comprising:

[0045] A recognition module, used for recognizing text in the image to be extracted to obtain a first text in a first format;

[0046] a determination module, configured to determine a text segment and a segment type corresponding to the text segment from the first text based on a first grammar rule corresponding to the first format;

[0047] a conversion module, configured to convert the first text into a second text in a second format based on a conversion prompt word and a segment type of each text segment, wherein a second grammar rule corresponding to the second format is different from the first grammar rule;

[0048] A verification module, used for performing a rationality check on the second text using a verification prompt word to obtain a third text that passes the rationality check;

[0049] The extraction module is used to guide the mapping model to establish a mapping relationship between the third text and the designated field based on the mapping prompt word, and extract the designated text corresponding to the designated field from the third text based on the mapping relationship.

[0050] On the other hand, an electronic device is also provided, comprising a processor and a memory, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps in any one of the text extraction methods provided by the present invention.

[0051] On the other hand, a computer-readable storage medium is also provided, wherein the computer-readable storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor to execute the steps in any one of the text extraction methods provided by the present invention.

[0052] On the other hand, a computer program product is also provided, comprising a computer program / instruction, wherein when the computer program / instruction is executed by a processor, the steps in any text extraction method provided by the present invention are implemented.

[0053] The beneficial effects brought about by the technical solution provided by the present invention include at least:

[0054] In an embodiment of the present invention, the text in the image to be extracted is identified to obtain a first text, and then a text segment is segmented from the first text, and the segment type corresponding to the text segment is obtained; the first text can be converted into a second text using the segment type and the conversion extraction word; the second text is checked for rationality using the verification prompt word to obtain a third text, and finally a mapping relationship between the third text and the specified field is established using the mapping prompt word to extract the specified text corresponding to the specified field. By setting different prompt words, the present invention can make full use of the ability of the language model to convert the format of the identified text and then extract the specified text, so that the required text can be extracted from the image efficiently and accurately. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0056] Figure 1 is a schematic diagram of an application scenario of the text extraction method provided by an embodiment of the present invention;

[0057] Figure 2 It is a flowchart of a text extraction method provided by an embodiment of the present invention;

[0058] Figure 3 It is a schematic diagram of the architecture of the text extraction method provided by an embodiment of the present invention;

[0059] Figure 4 It is a schematic diagram of the structure of LLM-Chain provided by an embodiment of the present invention;

[0060] Figure 5 is a structural schematic diagram of a text extraction device provided by an embodiment of the present invention;

[0061] Figure 6 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0062] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0063] It is understandable that in the specific implementation of the present invention, data related to user information, etc., needs to obtain user permission or consent, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.

[0064] In this embodiment, a data processing method is provided, such as Figure 1 As shown, a schematic diagram of an application scenario of a text extraction method is shown. The application scenario may include a terminal 101 and a server 102, and data can be exchanged between the terminal 101 and the server 102 via a network. The terminal 101 may be a mobile phone, a tablet computer, a smart Bluetooth device, a computer, and the like; the server 102 may be a single server or a server cluster consisting of multiple servers.

[0065] The user can upload the image to be extracted to the server 102 through the terminal 101, and the server 102 can recognize the text in the image to be extracted to obtain the first text in the first format; based on the first grammatical rule corresponding to the first format, determine the text segment and the segment type corresponding to the text segment from the first text; and use the conversion prompt word and the segment type of each text segment to convert the first text into the second text. Specifically, the conversion prompt word can be input into the conversion model so that the conversion model converts the first text into the second text.

[0066] Then, the second text can be checked for rationality using the check prompt word to obtain the third text. That is, the check prompt word is input into the check model to implement the check of the second text, and finally the third text that passes the rationality check is obtained. Finally, the mapping prompt word is used to guide the mapping model to establish a mapping relationship between the third text and the specified field, so as to extract the specified text corresponding to the specified field from the third text.

[0067] The specified field may also be provided by the user through the terminal 101, for example Figure 1 In the example, the terminal 101 may also send the specified field to the server 102. After obtaining the specified text, the server 102 may send the specified text to the terminal 101 for display.

[0068] In this embodiment, a text extraction method is provided, such as Figure 2 As shown, the specific process of the method can be as follows:

[0069] S110 , recognizing text in the image to be extracted to obtain a first text in a first format.

[0070] The image to be extracted refers to an image from which text extraction is required, and the image may refer to an image of a non-editable text document, such as a document in PDF format, or a photo or picture containing text.

[0071] The first format may be a specific format pre-set according to actual needs. In an embodiment of the present invention, the first format may be a markdown format, wherein Markdown is a lightweight markup language whose language rules are intended to achieve the goal of "easy to read and write", making the text content easier to read and write. After identifying the text from the image to be extracted, the text may be converted to the first format to retain information such as the layout of the text in the image, and the first text refers to the text in the image having the first format.

[0072] In some embodiments, in order to obtain the first text in the first format, optical character recognition (OCR) may be performed on the image to be extracted to obtain editable text; and then the editable text is converted into the first text in the first format. OCR is a technology that uses a specific recognition algorithm to convert printed or handwritten characters into a text format that can be edited and processed by a computer. In order to improve the accuracy of OCR recognition, the image to be extracted may be first subjected to denoising and other processing, and then the denoised image may be subjected to text recognition using OCR recognition technology.

[0073] Optionally, when performing text recognition, layout analysis can be performed to identify different areas and layouts in the image to be extracted. The areas can refer to titles, paragraphs, tables, etc., and the text in the corresponding areas is identified based on the characteristics of the different areas. In order to improve the accuracy of text recognition, the recognized text can also be error-corrected. Finally, the recognized text is organized according to the first format, and the first text in the first format can be obtained.

[0074] S120: Determine, from the first text, a text segment and a segment type corresponding to the text segment based on a first grammatical rule corresponding to the first format.

[0075] The first grammatical rule refers to the grammatical rule that the first text in the first format needs to satisfy, that is, the first text is organized according to the first grammatical rule. To facilitate subsequent processing, a text segment and a segment type corresponding to the text segment can be determined from the first text based on the first grammatical rule.

[0076] In some implementations, when determining a text segment and a segment type, a segmentation mark and a classification mark may be obtained; the first text may be divided into a plurality of text segments based on the segmentation mark; and each text segment may be classified based on the classification mark to obtain a segment type corresponding to the text segment.

[0077] In this embodiment, the segmentation mark can be "\n\n", that is, each character in the first text is recognized in turn. When the segmentation mark "\n\n" is recognized, all the content before the segmentation mark "\n\n" is regarded as a text segment; the text segment is deleted from the first text, and the above steps are repeated until the first text is completely segmented into multiple text segments.

[0078] The classification mark is a symbol in the first grammar rule, and in this embodiment, the classification mark is "|". For each text segment, the classification mark can be detected in the text segment to determine whether the text segment contains the classification mark; if the text segment contains the classification mark, the segment type of the text segment is determined to be a table type; if the text segment does not contain the classification mark, the segment type of the text segment is determined to be a common type.

[0079] S130: Convert the first text into a second text in a second format based on the conversion prompt word and the segment type of each text segment.

[0080] The conversion prompt word refers to a prompt word used to guide the large language model to perform text conversion on the text fragment. The second format is the final format of the text extracted from the image. In the embodiment of the present invention, the second format is the JSON format, and the second text is the text that conforms to the second grammar rule corresponding to the second format. It is understandable that the first grammar rule and the second grammar rule are completely different grammar rules. The first text needs to be parsed and analyzed in combination with the first grammar rule, and then the analyzed content needs to be converted according to the second grammar rule to obtain the second text.

[0081] In some embodiments, when obtaining the second text in the second format, a conversion prompt word may be generated using the first text and a conversion template, wherein the conversion prompt word includes an output format and multiple conversion steps; for each of the text fragments, the multiple conversion steps are executed according to the fragment type of the text fragment and the second grammar rule to obtain a conversion fragment corresponding to the text fragment; and the conversion fragments are organized based on the output format to obtain the second text in the second format.

[0082] The conversion template refers to a preset prompt word template for conversion, which may include a conversion slot, multiple conversion steps, and an output format. The conversion slot is a slot that needs to be filled in the conversion template, and the conversion slot may include a text slot. That is, the conversion prompt word can be generated by simply filling the first text in the form of a text segment into the text slot.

[0083] For example, delimiter="```" in the conversion template is a text slot, in which you can fill in the text fragment.

[0084] In the embodiment of the present invention, the specific conversion template is as follows:

[0085] delimiter = "```"

[0086] system_prompt = f"""

[0087] According to the following steps, convert the markdown text enclosed by {delimiter} above into structured data in json format (second format). Extract all the key information in the text and organize the information according to the requirements of json format. The detailed description of each step will be separated by {delimiter}.

[0088] Step 1: {delimiter} parses the markdown text and classifies all text elements, such as titles (#), subtitles (##), unordered lists (- or ), links ([text](link)), and text paragraphs. It is roughly divided into a structure like {<other parsed information>, "<high-level title name>": [{}, other content under this title], <other parsed information>}.

[0089] Step 2: {delimiter} maps the parsed elements to the json structure. Each title should be converted to a key of the json object, and the following content should be the corresponding value. Simple example: {<parsed other information>, "<high-level title name>": [{}, other content under this title], <parsed other information>}. Unordered and ordered lists in json text should be as follows (taking this step paragraph as an example): {<parsed other information>, "ordered list 1": [<content of step 1>, <content of step 2>, <content of step 3>, <content of step 4>], <parsed other information>} should be converted into an array. Links should be stored as an object containing two parts: "text" and "link".

[0090] Step 3: {delimiter} To process special format text elements, first confirm whether they have unmodifiable features. For example, phone numbers, bank card accounts, customer names, and links are unmodifiable features. When converting, ensure that they are migrated intact. For special format text, such as bold, italic, or code blocks, remove the special format, but be aware that these elements are likely to have unmodifiable features. Determine how to reasonably represent these elements in the JSON structure.

[0091] Step 4: {delimiter} Organize all converted information and ensure that the final output is in a valid JSON format. Make sure that each key-value pair is correctly matched, and arrays and objects are correctly constructed. For complex nested structures, ensure that their hierarchy and association in JSON are correct.

[0092] The final output should follow the following format:

[0093] Step 1: {delimiter} <result of step 1>

[0094] Step 2: {delimiter} <result of step 2>

[0095] Step 3: {delimiter} <result of step 3>

[0096] Step 4: {delimiter} <result of step 4>

[0097] JSON format output: {delimiter} <converted JSON text>

[0098] After each step is completed, use {delimiter} to separate the step result and json structured data.

[0099] Based on the above content, it can be known that the conversion prompt word may include multiple conversion steps and output formats, etc. The conversion steps refer to the specific steps that the conversion model needs to perform when obtaining the second text in the second format; the output format conversion model outputs the format that needs to be followed. Based on the conversion steps, the text fragment can be converted into the corresponding conversion fragment, and then the conversion fragment is organized according to the output format to obtain the second text.

[0100] As an implementation method, the conversion prompt word can be input into the conversion model, and the conversion model can process the text fragment according to the conversion steps in the conversion prompt word to convert each text fragment into a conversion fragment. The output format refers to the format of the content output by the conversion model, and the conversion fragments are organized according to the output format to obtain a second text in a second format. Among them, the output format can be for each conversion step, the result corresponding to the conversion step is output, and finally the conversion fragment is output. Using this output format, the conversion fragment can be quickly determined from the output content, so that the conversion fragment can be directly extracted to obtain the second text. In other words, the second text includes multiple conversion fragments, and the number of the conversion fragments is consistent with the number of text fragments.

[0101] Optionally, when converting a text fragment into a conversion fragment, for each of the text fragments, the text fragment is parsed according to the fragment type and the first grammar rule to obtain a text element, an element type of the text element, and an element style of the text element; according to the element type of the text element and the second grammar rule, the text element is converted into an intermediate element; using the element style corresponding to the text element and the specified style, the style of the intermediate element is adjusted to obtain a target element; and all the target elements are organized based on the second grammar rule to obtain a conversion fragment.

[0102] For each text fragment, the corresponding fragment type, i.e., ordinary type or table type, has been determined above. The text fragment can be parsed based on the fragment type and the first grammar rule to obtain the text elements in the text fragment, the element type corresponding to each text element, and the element style corresponding to the text element.

[0103] The first grammar rule defines the element identifiers corresponding to text elements of different element types. For example, "#" represents a title, one # represents a first-level title, and two # represents a second-level title. The list can be separated by "-" or " ". Element styles also define different style identifiers, for example, , indicating that A is italic; Indicates that A is bold.

[0104] Thus, for each text fragment, the element identifier can be identified in the text fragment to parse out the text elements therein, such as titles, lists, tables, links, etc. Among them, if the text fragment is of a common type, a table cannot be parsed out from it, and if the text fragment is of a table type, a table can be parsed out from it. Based on the fragment type corresponding to the text fragment, it can be verified whether the parsed text element is accurate to improve the accuracy of the text element parsing. Specifically, after parsing the text element, if it does not contain a table and the fragment type is of a common type, it can be determined that the parsing is accurate; if the table is not parsed out, but the fragment type is of a table type, it can be determined that the parsing is inaccurate and needs to be re-parsed.

[0105] After parsing the text element, the text element can be converted into an intermediate element using the element type corresponding to the text element and the second grammar rule. For example, when the element type is a title, the title can be used as the key and the text content corresponding to the title can be used as the value to obtain the intermediate element.

[0106] When the element type is a list, the list can also be divided into an ordered list and an unordered list. The difference between the two is that an ordered list uses numbers or letters in order to represent each item in the list, while an unordered list uses bullets such as dots, squares, or arrows to represent each item in the list. For a list, you can name the list, such as Ordered List 1, Unordered List 2, etc., use the name as the key, and the specific content of the list as the value to form an object, thereby obtaining the intermediate element.

[0107] When the element type is a table, the table name can be used as the key and the list group as the value in the order of appearance. The elements of the list are dictionaries. The dictionary in the list contains the attributes of each column of the table, and the corresponding value is the value of the corresponding row, so the i-th row corresponds to the i-th dictionary of this list.

[0108] When the element type is a link, it is stored as an object containing two fields: text and link, to obtain an intermediate element. The parsed text element may have its corresponding element style, such as bold, italic, etc. The element style of the corresponding text element can be modified to a specified style, and the specified style can refer to no style. That is, the element style of the text element is directly removed, such as removing the italic and bold styles to obtain a text element with a specified style. When adjusting the style of the intermediate element, only the style adjustment is performed, and the text content is not modified to ensure the accuracy of the conversion, and then the target element is obtained. Finally, each target element is organized according to the second grammatical rule, and the hierarchy and nesting are ensured to be correct, so as to obtain the conversion fragment.

[0109] It should be noted that the above conversion steps can be performed by a conversion model, and the conversion model can be a large language model. Specifically, the conversion prompt word can be input into the conversion model, and the conversion model can process the text fragments according to the conversion steps in the conversion prompt word to convert each text fragment into a conversion fragment. The output format refers to the format of the content output by the conversion model. Finally, the conversion fragments can be organized according to the output format to obtain a second text in a second format. Among them, the output format can be for each conversion step, the result corresponding to the conversion step is output, and finally the conversion fragment is output. Using this output format, which part of the content that can be output is the conversion fragment, so that the conversion fragment can be directly extracted to obtain the second text.

[0110] S140: Perform a rationality check on the second text using a check prompt word to obtain a third text that passes the rationality check.

[0111] The verification prompt word refers to a prompt word used to guide the large language model to perform a rationality check on the second text. The rationality check refers to checking whether the second text is reasonable and accurate compared with the first text. Using the verification prompt word, the rationality check can be performed on the second text to obtain a third text that passes the rationality check.

[0112] As an implementation mode, this step may include generating a verification prompt word for each text segment using a segment group and a verification template, wherein the segment group includes a text segment and a conversion segment corresponding to the text segment, and the verification prompt word includes sub-checks corresponding to multiple element types and a preset threshold; performing multiple sub-checks on the segment group through a verification model to obtain sub-check results corresponding to the sub-checks; generating a verification score for the segment group according to the sub-check results; if the verification score is not less than the preset threshold, using the conversion segment in the segment group as a segment to be combined; if the verification score is less than the preset threshold, modifying the conversion segment in the segment group to obtain a segment to be combined; and combining all the segments to be combined to obtain a third text that passes the rationality check.

[0113] According to the foregoing content, the second text includes multiple conversion segments, wherein a conversion segment corresponds to a text segment, and the conversion segments and text segments having a corresponding relationship are recorded as a segment group. Using the segment group and the verification template, a verification prompt word can be generated. The verification template refers to a preset prompt word template for verification, and the verification template may include a verification slot, which is a slot that needs to be filled in the verification template, for example, a text slot, a conversion slot, and a threshold slot, wherein the text slot is used to fill the text segment in the segment group, the conversion slot is used to fill the conversion segment in the same segment group, and the preset threshold in the threshold slot can be pre-filled as part of the template. Exemplarily, delimiter = "```" is a text slot and a conversion slot; threshold = 90 is a threshold slot, and 90 is a preset threshold, which can be adjusted according to actual needs.

[0114] In the embodiment of the present invention, the specific verification template is as follows:

[0115] delimiter = "```"

[0116] threshold = 90 # In an actual system, the threshold can be modified according to the scenario.

[0117] system_prompt2 = f""" According to the following steps, use {delimiter} to separate, evaluate and verify the markdown text (text fragment) and json text (converted fragment) enclosed by {delimiter}, where the json text is the result of information extraction from the markdown text. It is necessary to ensure that all information is correctly converted from markdown (first format) to json (second format) without any errors or omissions.

[0118] Step 1: {delimiter} Compare the markdown original text with the json output to ensure that the title and subtitle are correctly converted to the keys of the json object. Pay attention to the hierarchical relationship between titles. The lower-level titles should be included in the dictionary of the higher-level titles, and the relevant content is used as the corresponding value. Recursive parsing to form a nested dictionary format. Pay special attention to whether any title levels are incorrectly converted or omitted. Simple example: {<parsed other information>, "<high-level title name>": [{}, other content under this title], <parsed other information>}.

[0119] Step 2: {delimiter} converts the table in markdown into json in the order of appearance, where the key is the table name, the value is a list, and the elements of the list are dictionaries. The dictionary in the list contains the attributes of each column of the table, and the corresponding value is the value of the corresponding row, so the i-th row corresponds to the i-th dictionary of this list. Simple example: {<parsed other information>, "Staff Information Table": [{"Name": "Zhang San", "Age": 22}, {"Name": "Li Si", "Age": 28}], <parsed other information>}, the length of the list should be equal to the number of rows in the table - 1 (remove the header row).

[0120] Step 3: {delimiter}Number the unordered list and ordered list in the markdown in the order of appearance, "unordered list <number>" or "ordered list <number>" as the key, and convert each item into a list as the value. Make sure that each item in the list is converted accurately, without missing or incorrectly identifying list items. Taking the step of this prompt word as a simple example, it should be converted to {<parsed other information>, "Ordered list 1": [<Content of step 1>, <Content of step 2>, <Content of step 3>, <Content of step 4>, <Content of step 5>, <Content of step 6>], <parsed other information>}.

[0121] Step 4: {delimiter} Verify that the link in the markdown is correctly converted into a JSON key-value pair containing "<hyperlink text>" and "<link URL>" attributes. The link text and URL must be converted intact without any changes.

[0122] Step 5: {delimiter} Confirm that unrelated key values ​​are not linked together, for example, check whether the year of birth is mistakenly marked as age, or whether there is a conflict between different keywords. If there is a conflict, it will not pass the evaluation directly.

[0123] Step 6: {delimiter} Make sure that all important information in the markdown text is converted and included in the JSON result without missing any key data. Pay special attention to special formatting fonts such as bold and italic.

[0124] After completing each of the above steps, please provide an assessment report to ensure that the assessment covers the following:

[0125] - Any conversion errors or inaccuracies detected

[0126] - Suggested corrective actions

[0127] - Suggested solutions for any ambiguous or complex conversion situations

[0128] - Accuracy score (out of 100)

[0129] - Completeness score (out of 100)

[0130] - Whether the evaluation is passed (Boolean value, determined by whether they are all greater than {threshold})

[0131] - Modified json text (if it does not pass the evaluation)

[0132] Accuracy scoring must be strict. Conflicts or tampering with key content (such as phone numbers, bank card accounts, customer names, etc. that should not be modified) should be directly regarded as 0 points. Other situations are judged based on the characteristics of the field. For non-critical information, simple synonym replacement and sentence summary are acceptable.

[0133] Complete the assessment report using the following format:

[0134] Step 1 Result: {delimiter} <Step 1 Identified Issues and Suggestions>

[0135] Step 2 Result: {delimiter} <Step 2 Identified Issues and Suggestions> ...

[0137] Step 6 result: {delimiter} <Problems and suggestions identified in Step 6>

[0138] Evaluation report: {delimiter} <Evaluation report in JSON format> """

[0139] It should be noted that the verification prompt words can include sub-verifications of multiple element types. The verification model is a language model used for rationality verification. By inputting the verification prompt words into the verification model, the verification model can be guided to verify the converted text and text fragments according to the verification steps in the verification prompt words.

[0140] For each text fragment, it is necessary to determine whether the text fragment is accurately and comprehensively converted into a conversion fragment. This process can be determined using the verification model. When performing multiple sub-verifications on a fragment group based on the verification model, the following steps can be included: for the text fragments in the fragment group, obtain the element type of each text element in the text fragment to obtain the target type; according to the target type, determine the target sub-verification from the multiple sub-verifications; through the verification model, perform the target sub-verification on the fragment group to obtain the verification result corresponding to the target sub-verification.

[0141] When converting a text fragment into a conversion fragment as described above, the text fragment will be parsed to obtain the text elements and the types of text elements in each text fragment, and the parsing result will be output together with the output of the conversion model. Therefore, the element type of each text element in the text fragment can be directly obtained from the output result of the conversion model to obtain the target type.

[0142] For text elements of different element types, the corresponding sub-verifications are different. That is, based on the target type of the text element, the currently required sub-verification can be determined from multiple sub-verifications, denoted as the target sub-verification. For example, sub-verifications of multiple element types include sub-verifications of titles, lists, tables, etc. If a text fragment includes text elements of list type and title type, the target type includes title and list, and the target sub-verifications include sub-verifications of titles and lists.

[0143] Then, through the verification model, perform the target sub-verification on the fragment group to determine whether the text fragments in the fragment group are accurately and comprehensively converted.

[0144] For example, for the sub-verification of the title, the verification model can compare the text fragments and conversion fragments in the fragment group to ensure that titles, subtitles, etc. are accurately converted and their hierarchical relationships are accurate. If not, the verification model needs to record the inaccurate places and give the modified results.

[0145] For the sub-check of the table, the above conversion model uses the table name as the key, the list as the value, and the elements in the list as the dictionary, where the dictionary in the list contains the attributes of each column of the table, and the corresponding value is the value of the corresponding row. For example, in the conversion fragment, {"name": "Zhang San", "age": 22}, {"name": "Li Si", "age": 28}, where the name and age are the attributes of each column, and the corresponding value is the value of the corresponding row. And the length of the list in the conversion fragment satisfies the number of rows in the table minus 1. Therefore, during the check, it can be checked whether the length of the list in the dictionary is the number of rows in the table minus 1, and verify whether the relationship between the attribute and the value is accurate. If there is a problem in the above check, the check model needs to record where the problem occurs and give the modified result.

[0146] For the sub-check of the link, the link in the conversion segment is a key-value pair with the link text as the key and the link URL as the value. The verification model can verify whether the link text and link URL in the conversion segment are consistent with those in the text segment. If there is an inconsistency in the above verification, the verification model needs to record the inconsistency and give the modified result.

[0147] After executing each target check, the check result corresponding to each target check can be obtained, and the corresponding check score can be generated using the check result. For example, the first number of errors with inaccurate conversion can be determined based on the check result, and the first number is mapped to an accuracy score. Similarly, the second number of errors with incomplete conversion can be determined from the check result, and the second number is mapped to an integrity score. Then, the accuracy score and the integrity score are weighted and summed using preset weights to obtain a check score.

[0148] If the verification score is not less than the preset threshold, the converted segments in the segment group are considered to be accurate and complete, and the converted segments in the segment group can be used as the segments to be combined. If the verification score is less than the preset threshold, the verification model will modify the converted segments, and the modified converted segments will be used as the segments to be combined. Finally, all the segments to be combined are combined to obtain the third text that passes the rationality test.

[0149] S150: Based on the mapping prompt word, guide the mapping model to establish a mapping relationship between the third text and the designated field, and extract the designated text corresponding to the designated field from the third text based on the mapping relationship.

[0150] The mapping prompt word refers to a prompt word used to establish a mapping relationship between the third text and the specified field, and the mapping model is a language model that analyzes the third text and the specified field to establish the mapping relationship.

[0151] Among them, the designated field is a pre-set field, which may refer to the field for which the user wants to obtain the corresponding content. By establishing a mapping relationship between the third text and the designated field, the designated text corresponding to the designated field can be extracted from the third text, so that the user can quickly extract the desired content. The designated field may also refer to a field defined in a preset database. By establishing a mapping relationship between the third text and the designated field, the third text can be stored in the form of an adaptation database, and the relevant data can be directly obtained from the data in subsequent use.

[0152] In some embodiments, when extracting the specified text corresponding to the specified field, a mapping prompt word can be generated based on the specified field, the third text and the mapping template, and the mapping prompt word includes multiple mapping steps; the multiple mapping steps are executed through the mapping model to establish a mapping relationship between the third text and the specified field; based on the mapping relationship and the specified field, the specified text corresponding to the specified field is extracted from the third text.

[0153] The mapping template is a pre-set prompt word template for establishing a mapping relationship. The mapping template may include a mapping slot, which is a slot that needs to be filled in the mapping template. The mapping slot may include a slot to be mapped and a field slot, that is, the third text obtained in the previous step can be filled into the text slot, and the specified field can be filled into the field slot to obtain the mapping prompt word.

[0154] For example, delimiter="```" in the mapping template is the slot to be mapped, in which you can fill in the third text, and [specified field set] is the field slot, in which you can fill in the specified field.

[0155] In the embodiment of the present invention, the specific conversion template is as follows:

[0156] delimiter = "```"

[0157] predefined_set = [specified field set]

[0158] system_prompt3 = f"""

[0159] Now, according to the following steps, use {delimiter} to complete the mapping from the generated json text field (the third text field) to the specified field set. The purpose is to process and map similar fields to ensure that all key information can correctly correspond to the predefined specified field set. The json text content (the third text content) is the part enclosed by {delimiter}. The specified field set includes: {predefined_set}.

[0160] Step 1: {delimiter} First, review the generated JSON text and identify all the fields that need to be mapped. Pay special attention to whether these fields are close to any of the keywords in the predefined keyword set.

[0161] Step 2: {delimiter} Secondly, define the mapping rules for each identified field. For example, if the JSON text contains "age", it should be mapped to "age" in the keyword set.

[0162] Step 3: {delimiter} Then, apply the mapping rules to map all the identified fields to the corresponding keywords. In this process, please ensure that the mapping is 100% accurate and unambiguous, and there cannot be any word substitution.

[0163] Step 4: {delimiter}Finally, verify the accuracy of the mapping results. You need to ensure that each JSON field is correctly mapped to the predefined keyword set and that no field is incorrectly mapped or omitted.

[0164] After completing each of the above steps, please provide a detailed mapping report. The report needs to include the following:

[0165] - Each identified and mapped field and its corresponding key

[0166] - Mapping rules applied

[0167] - Any challenges encountered during the mapping process and how these were addressed

[0168] - Final confirmation of mapping results to ensure consistency and accuracy

[0169] - Finally, the json text (second format text) with the mapping rules applied is given

[0170] Complete the mapping report using the following format:

[0171] Step 1 Result: {delimiter} <identified fields and predefined keywords>

[0172] Step 2 Result: {delimiter} <defined mapping rule> ...

[0174] Step 4 Result: {delimiter} <Confirmation of mapping result>

[0175] Final result: {delimiter} <mapped json text>"""

[0176] By inputting the mapping prompt word into the mapping template, the mapping model can be guided to establish a mapping relationship according to multiple mapping steps, and then based on the mapping relationship and the designated field, the designated text corresponding to the designated field is extracted from the third text.

[0177] The mapping prompt may include multiple mapping steps, and the mapping relationship between the third text and the specified field can be established by executing the multiple mapping steps through the mapping model. As an implementation method, this step may specifically include: extracting the fields to be mapped from the third text through the mapping model; for each specified field, calculating the semantic similarity between the specified field and each field to be mapped; and establishing the mapping relationship between each specified field and the field to be mapped using the semantic similarity and the similarity threshold.

[0178] After the mapping prompt word is input into the mapping model, the mapping model performs multiple mapping steps, and firstly, the third text can be identified to identify the fields to be mapped therein. It can be understood that in the third text of the second format, the text elements of different element types have different expressions, but most of them are in the form of key-value pairs, so the third text can be structurally parsed, and the key can be used as the field to be mapped according to the element type.

[0179] Then, for each designated field, the semantic similarity between the designated field and each field to be mapped is calculated, and a mapping relationship between the designated field and the field to be mapped is established using the semantic similarity and the similarity threshold. Optionally, the field to be mapped whose semantic similarity is greater than the similarity threshold is determined as a candidate field; if the number of the candidate fields is greater than a designated number, the candidate field with the largest semantic similarity is determined as a target field; if the number of the candidate fields is less than or equal to the preset number, the candidate field is determined as a target field; and a mapping relationship between the designated field and the target field is established.

[0180] The target field is the field with the highest semantic similarity to the field to be mapped, so that a mapping relationship between the target field and the specified field can be established. According to this process, a mapping relationship between each specified field and the field to be mapped can be established, and the target field corresponding to each specified field can be obtained. For example, the field to be specified is "age", and the target field is "age"; for another example, the specified field is "graduate school", and the target field is "education experience".

[0181] When extracting the specified text corresponding to the specified field from the third text, the third text can be mapped based on the mapping relationship to obtain a fourth text; the accuracy of the fourth text is verified; if the fourth text passes the accuracy verification, the specified text corresponding to the specified field is obtained from the fourth text.

[0182] In some implementations, in order to ensure the accuracy of the mapping, the mapping relationship may be used to directly replace the target field in the third text with a designated field corresponding to the target field in the mapping relationship to obtain the fourth text.

[0183] Furthermore, in order to ensure the accuracy and completeness of the mapping, the fourth text can also be verified for accuracy using the mapping relationship. For example, it is determined that each mapping relationship is used without omission, and it is determined that the third text and the fourth text after mapping are only different in fields, and the values ​​corresponding to the fields have not changed; if there are no omissions and the values ​​after mapping have not changed, the fourth text can be considered to be an accurately mapped text. Therefore, the content corresponding to the specified field can be directly used as the specified text in the fourth text.

[0184] For a clearer understanding of the above process, please refer to Figure 3 , which shows a schematic diagram of the text extraction method. Starting from the image to be extracted, the text image in the image to be extracted can be directly recognized as a first text in a first format through OCR recognition technology. Then the first text is segmented to obtain multiple text segments, and each text segment is input into the LLM-Chain to obtain the corresponding specified text. Among them, the LLM-Chain is a sequential chain in topology, which can be referred to Figure 4 , showing a schematic diagram of the structure of LLM-Chain. That is, a text segment in the first format can be input into the conversion model, and the conversion model outputs a corresponding second text in the second format. The second text is input into the verification model in the form of a conversion segment, and the verification model outputs a third text that passes the verification; and the third text is input into the mapping model to obtain the specified text.

[0185] The text extraction method provided by the embodiment of the present invention can be applied in multiple scenarios. For example, in the legal scenario, specific clauses, case facts or judgment basis can be extracted from a large number of legal documents to assist legal personnel in case research and analysis. In the medical scenario, the required information can be extracted from case reports and research literature to provide support for medical research and clinical decision-making. In the financial scenario, text can be extracted from imaged news reports and financial reports to obtain market trends. In the social media scenario, specified public opinions and user feedback in social media can be automatically extracted to provide data support for marketing and brand management.

[0186] The method provided by the embodiment of the present invention can identify a first text in a first format from an image to be extracted, and convert the first text into a second text based on a conversion prompt word and a corresponding conversion model, and can achieve accurate conversion through the ability of a large language model. Subsequently, the second text is verified using a verification prompt word and a corresponding verification model to ensure that an accurately and completely converted third text can be obtained. Finally, a mapping relationship between the third text and a specified field is established using a mapping prompt word and a mapping model, so as to extract a specified text corresponding to a specified field from the third text. In the process of extracting text, the understanding ability of the large language model is fully utilized based on the prompt word to quickly and accurately extract the required text from the image.

[0187] In order to better implement the above method, the embodiment of the present invention further provides a text extraction device, which can be integrated in an electronic device, and the electronic device can be a terminal, a server, etc. Among them, the terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop computer, a personal computer, etc.; the server can be a single server or a server cluster composed of multiple servers.

[0188] For example, in this embodiment, the method of the embodiment of the present invention is described in detail by taking the text extraction device being specifically integrated in the server as an example.

[0189] For example, Figure 5 As shown, the text extraction device 200 may include a recognition module 210 , a determination module 220 , a conversion module 230 , a verification module 240 and an extraction module 250 .

[0190] A recognition module 210, configured to recognize text in the image to be extracted, and obtain a first text in a first format;

[0191] A determination module 220, configured to determine a text segment and a segment type corresponding to the text segment from the first text based on a first grammar rule corresponding to the first format;

[0192] A conversion module 230, configured to convert the first text into a second text in a second format based on a conversion prompt word and a segment type of each text segment, wherein a second grammar rule corresponding to the second format is different from the first grammar rule;

[0193] A verification module 240, configured to perform a rationality check on the second text using a verification prompt word to obtain a third text that passes the rationality check;

[0194] The extraction module 250 is used to guide the mapping model to establish a mapping relationship between the third text and the designated field based on the mapping prompt word, and extract the designated text corresponding to the designated field from the third text based on the mapping relationship.

[0195] In some embodiments, the conversion module 230 is specifically configured to:

[0196] Generate a conversion prompt word using the first text and a conversion template, wherein the conversion prompt word includes an output format and a plurality of conversion steps;

[0197] For each of the text segments, the multiple conversion steps are performed according to the segment type of the text segment and the second grammar rule to obtain a conversion segment corresponding to the text segment;

[0198] The conversion segments are organized based on the output format to obtain a second text in a second format.

[0199] In some embodiments, the conversion module 230 is specifically configured to:

[0200] For each of the text segments, the text segment is parsed according to the segment type and the first grammar rule to obtain a text element, an element type of the text element, and an element style of the text element;

[0201] According to the element type of the text element and the second grammar rule, converting the text element into an intermediate element;

[0202] Using the element style corresponding to the text element and the specified style, the style of the intermediate element is adjusted to obtain a target element;

[0203] All the target elements are organized based on the second grammar rule to obtain a conversion fragment.

[0204] In some embodiments, the verification module 240 is specifically used to:

[0205] For each text segment, a verification prompt word is generated using a segment group and a verification template, wherein the segment group includes a text segment and a conversion segment corresponding to the text segment, and the verification prompt word includes sub-checks corresponding to multiple element types and a preset threshold;

[0206] By using the verification model, performing a plurality of sub-verifications on the segment group to obtain sub-verification results corresponding to the sub-verifications;

[0207] generating a verification score for the segment group according to the sub-verification result;

[0208] If the verification score is not less than the preset threshold, taking the converted segments in the segment group as the segments to be combined;

[0209] If the verification score is less than the preset threshold, modifying the converted segments in the segment group to obtain the segment to be combined;

[0210] All the to-be-combined segments are combined to obtain a third text that passes the rationality check.

[0211] In some embodiments, the verification module 240 is specifically used to:

[0212] For the text segments in the segment group, obtaining the element type of each text element in the text segments to obtain a target type;

[0213] Determining a target sub-check from the plurality of sub-checks according to the target type;

[0214] The target sub-verification is performed on the segment group through the verification model to obtain a verification result corresponding to the target sub-verification.

[0215] In some embodiments, the extraction module 250 is specifically used to:

[0216] Generate a mapping prompt word based on a designated field, the third text and a mapping template, wherein the mapping prompt word includes a plurality of mapping steps;

[0217] Executing the plurality of mapping steps through a mapping model to establish a mapping relationship between the third text and a specified field;

[0218] According to the mapping relationship and the designated field, the designated text corresponding to the designated field is extracted from the third text.

[0219] In some embodiments, the extraction module 250 is specifically used to:

[0220] Extracting the to-be-mapped fields from the third text by using the mapping model;

[0221] For each designated field, calculating the semantic similarity between the designated field and each field to be mapped;

[0222] A mapping relationship between each designated field and the field to be mapped is established by using the semantic similarity and the similarity threshold.

[0223] In some embodiments, the extraction module 250 is specifically used to:

[0224] Based on the mapping relationship, mapping processing is performed on the third text to obtain a fourth text;

[0225] Verifying the accuracy of the fourth text;

[0226] If the fourth text passes the accuracy verification, a designated text corresponding to the designated field is obtained from the fourth text.

[0227] In specific implementation, the above modules can be implemented as independent entities, or can be arbitrarily combined and implemented as the same or several entities. The specific implementation of the above modules can be found in the previous method embodiments, which will not be repeated here.

[0228] As can be seen from the above, the text extraction device of this embodiment can identify the first text in the first format from the image to be extracted, and convert the first text into the second text based on the conversion prompt word and the corresponding conversion model, and can achieve accurate conversion through the ability of the large language model. Then, the second text is verified using the verification prompt word and the corresponding verification model to ensure that the third text with accurate and complete conversion can be obtained. Finally, the mapping prompt word and the mapping model are used to establish a mapping relationship between the third text and the specified field, so as to extract the specified text corresponding to the specified field from the third text. In the process of extracting text, the understanding ability of the large language model is fully utilized based on the prompt word to quickly and accurately extract the required text from the image.

[0229] The embodiment of the present invention further provides an electronic device, which may be a terminal, a server, or the like. The terminal may be a mobile phone, a tablet computer, a smart Bluetooth device, a notebook computer, a personal computer, or the like; the server may be a single server or a server cluster composed of multiple servers, or the like.

[0230] In some embodiments, the text extraction device may also be integrated into multiple electronic devices. For example, the text extraction device may be integrated into multiple servers, and the text extraction method of the present invention may be implemented by multiple servers.

[0231] In this embodiment, the electronic device of this embodiment is a server as an example for detailed description, for example, Figure 6 As shown, it shows a schematic diagram of the structure of an electronic device involved in an embodiment of the present invention, specifically:

[0232] The electronic device may include components such as a processor 310 with one or more processing cores, a memory 320 with one or more computer-readable storage media, a power supply 330, an input module 340, and a communication module 350. Those skilled in the art will appreciate that Figure 6 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0233] The processor 310 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. It executes various functions of the electronic device and processes data by running or executing software programs and / or modules stored in the memory 320, and calling data stored in the memory 320. In some embodiments, the processor 310 may include one or more processing cores; in some embodiments, the processor 310 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 310.

[0234] The memory 320 can be used to store software programs and modules. The processor 310 executes various functional applications and data processing by running the software programs and modules stored in the memory 320. The memory 320 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 320 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 320 may also include a memory controller to provide the processor 310 with access to the memory 320.

[0235] The electronic device also includes a power supply 330 for supplying power to various components. In some embodiments, the power supply 330 can be logically connected to the processor 310 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 330 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.

[0236] The electronic device may further include an input module 340, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function controls.

[0237] The electronic device may further include a communication module 350. In some embodiments, the communication module 350 may include a wireless module. The electronic device may perform short-range wireless transmission through the wireless module of the communication module 350, thereby providing the user with wireless broadband Internet access. For example, the communication module 350 may be used to help the user send and receive emails, browse web pages, and access streaming media.

[0238] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 310 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 320 according to the following instructions, and the processor 310 will run the application programs stored in the memory 320, thereby implementing the steps in the methods of the embodiments of the present invention.

[0239] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0240] As can be seen from the above, the present invention can identify a first text in a first format from an image to be extracted, and convert the first text into a second text based on a conversion prompt word and a corresponding conversion model, and can achieve accurate conversion through the ability of a large language model. Subsequently, the second text is verified using a verification prompt word and a corresponding verification model to ensure that an accurately and completely converted third text can be obtained. Finally, a mapping relationship between the third text and a specified field is established using a mapping prompt word and a mapping model, so as to extract a specified text corresponding to a specified field from the third text. In the process of extracting text, the understanding ability of the large language model is fully utilized based on the prompt word to quickly and accurately extract the required text from the image.

[0241] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0242] To this end, an embodiment of the present invention provides a computer-readable storage medium, in which a plurality of instructions are stored. The instructions can be loaded by a processor to execute the steps in any text extraction method provided by the embodiment of the present invention.

[0243] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0244] According to one aspect of the present invention, a computer program product or computer program is provided, the computer program product or computer program comprising a computer program / instruction, the computer program / instruction being stored in a computer-readable storage medium. A processor of an electronic device reads the computer program / instruction from the computer-readable storage medium, and the processor executes the computer program / instruction, so that the electronic device executes the method provided in various optional implementations of the text extraction aspect provided in the above-mentioned embodiments.

[0245] Since the instructions stored in the storage medium can execute the steps in any text extraction method provided in the embodiments of the present invention, the beneficial effects that can be achieved by any text extraction method provided in the embodiments of the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0246] The above is a detailed introduction to a text extraction method, device and electronic device provided in an embodiment of the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A text extraction method, characterized in that: The method comprises: Recognize the text in the image to be extracted to obtain a first text in a first format; Based on a first grammatical rule corresponding to the first format, determining a text segment and a segment type corresponding to the text segment from the first text; Based on a conversion prompt word and a segment type of each text segment, the first text is converted into a second text in a second format, wherein a second grammar rule corresponding to the second format is different from the first grammar rule, the conversion prompt word is generated based on the first text and a conversion template, the conversion template is a preset prompt word template for conversion, and the conversion prompt word includes an output format and a plurality of conversion steps; Performing a rationality check on the second text using a check prompt word to obtain a third text that passes the rationality check, wherein the check prompt word is generated based on a segment group and a check template, wherein the segment group includes a text segment and a conversion segment corresponding to the text segment, wherein the conversion segment is obtained after executing the multiple conversion steps on the text segment, and the check template is a preset prompt word template for checking, wherein the check prompt word includes sub-checks corresponding to multiple element types and a preset threshold value; Based on the mapping prompt word, the mapping model is guided to establish a mapping relationship between the third text and the specified field, and based on the mapping relationship, the specified text corresponding to the specified field is extracted from the third text. The mapping prompt word is generated based on the specified field, the third text and a mapping template. The mapping template is a pre-set prompt word template for establishing a mapping relationship. The mapping prompt word includes multiple mapping steps.

2. The method according to claim 1, characterized in that The converting the first text into a second text in a second format based on the conversion prompt word and the segment type of each text segment includes: For each of the text segments, the multiple conversion steps are performed according to the segment type of the text segment and the second grammar rule to obtain a conversion segment corresponding to the text segment; The conversion segments are organized based on the output format to obtain a second text in a second format.

3. The method according to claim 2, characterized in that For each of the text segments, performing the multiple conversion steps according to the segment type of the text segment and the second grammar rule to obtain a conversion segment corresponding to the text segment includes: For each of the text segments, the text segment is parsed according to the segment type and the first grammar rule to obtain a text element, an element type of the text element, and an element style of the text element; According to the element type of the text element and the second grammar rule, converting the text element into an intermediate element; Using the element style corresponding to the text element and the specified style, the style of the intermediate element is adjusted to obtain a target element; All the target elements are organized based on the second grammar rule to obtain a conversion fragment.

4. The method according to claim 2, characterized in that: The method of performing a rationality check on the second text by using the check prompt word to obtain a third text that passes the rationality check includes: By using the verification model, performing a plurality of sub-verifications on the segment group to obtain sub-verification results corresponding to the sub-verifications; generating a verification score for the segment group according to the sub-verification result; If the verification score is not less than the preset threshold, taking the converted segments in the segment group as the segments to be combined; If the verification score is less than the preset threshold, modifying the converted segments in the segment group to obtain the segment to be combined; All the to-be-combined segments are combined to obtain a third text that passes the rationality check.

5. The method according to claim 4, characterized in that The verification model is used to perform a plurality of sub-verifications on the segment group to obtain sub-verification results corresponding to the sub-verifications, including: For the text segments in the segment group, obtaining the element type of each text element in the text segments to obtain a target type; Determining a target sub-check from the plurality of sub-checks according to the target type; The target sub-verification is performed on the segment group through the verification model to obtain a verification result corresponding to the target sub-verification.

6. The method according to claim 1, characterized in that The step of guiding the mapping model to establish a mapping relationship between the third text and the designated field based on the mapping prompt word, and extracting the designated text corresponding to the designated field from the third text based on the mapping relationship includes: Executing the plurality of mapping steps through a mapping model to establish a mapping relationship between the third text and a specified field; According to the mapping relationship and the designated field, the designated text corresponding to the designated field is extracted from the third text.

7. The method according to claim 6, characterized in that The performing the plurality of mapping steps through the mapping model to establish a mapping relationship between the third text and the specified field includes: Extracting the to-be-mapped fields from the third text by using the mapping model; For each designated field, calculating the semantic similarity between the designated field and each field to be mapped; A mapping relationship between each designated field and the field to be mapped is established by using the semantic similarity and the similarity threshold.

8. The method according to claim 6, characterized in that The step of extracting the designated text corresponding to the designated field from the third text according to the mapping relationship and the designated field includes: Based on the mapping relationship, mapping processing is performed on the third text to obtain a fourth text; Verifying the accuracy of the fourth text; If the fourth text passes the accuracy verification, a designated text corresponding to the designated field is obtained from the fourth text.

9. A text extraction device, used to implement the method according to any one of claims 1 to 8, characterized in that: The device comprises: A recognition module, used for recognizing text in the image to be extracted to obtain a first text in a first format; a determination module, configured to determine a text segment and a segment type corresponding to the text segment from the first text based on a first grammar rule corresponding to the first format; a conversion module, configured to convert the first text into a second text in a second format based on a conversion prompt word and a segment type of each text segment, wherein a second grammar rule corresponding to the second format is different from the first grammar rule, wherein the conversion prompt word is generated based on the first text and a conversion template, wherein the conversion template is a preset prompt word template for conversion, and wherein the conversion prompt word includes an output format and a plurality of conversion steps; a verification module, configured to perform a rationality check on the second text using a verification prompt word to obtain a third text that passes the rationality check, wherein the verification prompt word is generated based on a segment group and a verification template, wherein the segment group includes a text segment and a conversion segment corresponding to the text segment, wherein the conversion segment is obtained after executing the multiple conversion steps on the text segment, and the verification template is a preset prompt word template for verification, wherein the verification prompt word includes sub-checks corresponding to multiple element types and a preset threshold value; An extraction module is used to guide a mapping model to establish a mapping relationship between the third text and a designated field based on a mapping prompt word, and to extract a designated text corresponding to the designated field from the third text based on the mapping relationship. The mapping prompt word is generated based on the designated field, the third text and a mapping template. The mapping template is a preset prompt word template for establishing a mapping relationship. The mapping prompt word includes multiple mapping steps.

10. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps in the text extraction method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • User reporting processing method and terminal device

    CN107995376A

  • Image text recognition method and device, computer equipment and computer storage medium

    CN111275038A

  • Policy text analysis method based on policy text classification and key information identification

    CN115310425A

  • Multi-mode invoice automatic classification identification method, verification method and system

    CN116052186A

  • Rapid development platform based on metadata model

    CN117056312A

Cited By

  • Electromagnetic spectrum game situation extraction method based on large language model

    CN119990107A