Method and device for extracting hyponymy in table
By obtaining table text and prompt templates, combining large language models and multimodal models to process visual semantics, and identifying and verifying the hierarchical relationships in the table, the accuracy problem of large language models when processing hierarchical relationship queries is solved, and the accuracy of the generated model's answers is improved.
Patent Information
- Application Number
- CN202510796499.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-13
- Publication Date
- 2025-10-03
AI Technical Summary
Large language models cannot provide accurate answers when processing queries involving hierarchical relationships in tables, affecting user experience and content generation quality.
By obtaining table text and prompt templates, a large language model is used to identify and extract the hierarchical relationships between cells in the table. The multimodal model is combined to process the visual semantic information, verify the accuracy of the output results, and construct a knowledge graph to identify the hierarchical relationships.
This improves the large language model's ability to identify and extract hierarchical relationships in tables, enhances the accuracy of answers to questions of specified types, and improves the quality of query results generated by the model.
Smart Images

Figure CN120745599A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method and device for extracting hierarchical relationships in a table. Background Art
[0002] With the increasing application of generative models such as large language models, Retrieval Augmented Generation (RAG) technology has become an important technical means to improve the performance of generative models. In some scenarios where tables are used for data queries, RAG technology can be used to query data using tables. The data query process generally includes: converting the table into text format to obtain the table's text data. Then, after obtaining the query text entered by the user, the text format data of the table is combined with the query text and the large language model is used to determine the corresponding answer text.
[0003] In some scenarios, the query text entered by the user may involve questions that need to be answered based on the content of data cells in rows with hierarchical relationships in a table. Based on the above query process, large language models are still unable to provide accurate answers to such query texts. Therefore, in order to provide users with higher-quality content generation services, it is crucial to provide a method for extracting hierarchical relationships in tables. Summary of the Invention
[0004] One or more embodiments of this specification provide a method and apparatus for extracting hierarchical relationships in a table, so as to achieve the extraction of hierarchical relationships in a table.
[0005] According to a first aspect, a method for extracting a hierarchical relationship in a table is provided, comprising:
[0006] Obtaining a first table text corresponding to a first table, wherein the first table includes: a first cell and a plurality of second cells, and a value of the first cell is determined based on the values of the plurality of second cells;
[0007] Determining a first prompt text based on the first table text and a first prompt template, wherein the first prompt template is used to guide the first large language model to determine a hierarchical relationship between the first cell and a plurality of second cells based on the first table text;
[0008] Based on the first prompt text, the hierarchical relationship between the first cell and the plurality of second cells is extracted using the first large language model.
[0009] According to a second aspect, a device for extracting a hierarchical relationship in a table is provided, comprising:
[0010] A first acquisition module is configured to acquire a first table text corresponding to a first table, wherein the first table includes: a first cell and a plurality of second cells, and a value of the first cell is determined based on the values of the plurality of second cells;
[0011] a first determining module configured to determine a first prompt text based on the first table text and a first prompt template, wherein the first prompt template is used to guide the first large language model to determine a hierarchical relationship between the first cell and a plurality of second cells based on the first table text;
[0012] The first extraction module is configured to extract the hierarchical relationship between the first cell and the plurality of second cells based on the first prompt text and using the first large language model.
[0013] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the method described in the first aspect.
[0014] According to a fourth aspect, a computing device is provided, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in the first aspect is implemented.
[0015] According to the method and device for extracting hierarchical relationships in a table provided in an embodiment of the present specification, a first table text corresponding to a first table for which a hierarchical relationship in a table needs to be constructed is obtained, the first table including a first cell and multiple second cells, the value of the first cell being determined based on the values of the multiple second cells; a first prompt text is determined based on the first table text and a first prompt template for guiding a first large language model to determine the hierarchical relationship between the first cell and the multiple second cells based on the first table text; then, based on the first prompt text, the hierarchical relationship between the first cell and the multiple second cells is determined through the first large language model, so as to realize the recognition and extraction of the hierarchical relationship between the first cell and the multiple second cells in the first table based on the semantic understanding ability of the first large language model itself. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. Those skilled in the art can also derive other drawings based on these drawings without inventive effort.
[0017] Figure 1 A schematic diagram of an implementation framework of an embodiment disclosed in this specification;
[0018] Figure 2 A schematic diagram of a partial structure of the first table provided in the embodiment;
[0019] Figure 3 A flow chart of a method for extracting hierarchical relationships in a table provided in an embodiment;
[0020] Figure 4 A schematic diagram of another flow chart of a method for constructing and extracting hierarchical relationships in a table provided in an embodiment;
[0021] Figure 5 A partial schematic diagram of the first knowledge graph provided in the embodiment;
[0022] Figure 6 A schematic diagram of a query process of a table-based knowledge graph provided in an embodiment;
[0023] Figure 7 A schematic block diagram of a device for extracting hierarchical relationships in a table provided in an embodiment. DETAILED DESCRIPTION
[0024] The technical solutions of the embodiments of this specification will be described in detail below with reference to the accompanying drawings.
[0025] In this specification, the Large Language Model (LLM) may also be referred to as the large model. The large language model is a natural language processing model based on deep learning technology. Its parameter scale usually reaches billions to hundreds of billions or even higher, and it has powerful language understanding and generation capabilities. The large language model can adopt the Transformer architecture or its variants (such as GPT, BERT, etc.). This architecture uses the attention mechanism to achieve global modeling of sequence data, which can efficiently handle long-distance dependencies, thereby performing well in natural language tasks. The large language model learns the statistical characteristics and semantic relevance of the language by pre-training on a large-scale corpus, giving it good generalization capabilities. The core capabilities of the large language model include but are not limited to: understanding contextual semantics, generating coherent and grammatically correct text, performing logical reasoning, and handling multi-task scenarios. Its usage methods generally include two modes: direct inference and fine-tuning. In direct inference mode, the user guides the large language model to generate specific outputs by designing prompts. The prompts can be textual task descriptions or instructions, stimulating the semantic understanding and generation capabilities of the large language model. In fine-tuning mode, the large language model is further trained on a small-scale dataset in a specific domain to optimize its performance on a specific task. The powerful generalization and flexibility of large language models make them a valuable tool in the field of artificial intelligence technology, providing efficient and accurate solutions for automated text generation and comprehension.
[0026] In some embodiments, the large language model may also have the ability to understand and generate data from other modalities (such as vision, audio, etc.). In this case, the large language model may also be called a multimodal large language model (MLLMs). MLLMs provide a richer and more natural interactive experience by integrating multiple types of inputs and outputs such as text, images, and sounds. The core advantage of MLLMs is that they can process and understand information from different modalities and fuse this information to complete complex tasks. For example, MLLMs can analyze a picture and generate descriptive text, or generate corresponding images based on the text description. This cross-modal understanding and generation capability gives MLLMs broad application prospects in multiple fields.
[0027] It should be noted that the key technologies of large language models can be found in the detailed description in the paper "A Survey of Large Language Models" (paper number: arXiv:2303.18223v16, published on March 11, 2025, public link: https: / / doi.org / 10.48550 / arXiv.2303.18223), which will not be repeated in this manual.
[0028] The embodiments of this specification disclose a method and device for extracting hierarchical relationships in a table. Figure 1 A schematic diagram of an implementation scenario according to an embodiment disclosed in this specification is shown. In this implementation scenario, a large language model is used to extract the hierarchical relationship between data cells between rows or between columns in a table. For example: there are multiple data cells in a table, and the value of a first cell in the multiple data cells is determined based on the values of the other multiple second cells. At this time, it can be considered that there is a hierarchical relationship between the first cell and the multiple second cells, wherein the first cell is the superordinate cell of the multiple second cells, and the multiple second cells are the subordinate cells of the first cell.
[0029] like Figure 2 The figure shows a partial schematic diagram of a first table, wherein the first table has n rows and m columns. The first row of the first table contains the table column headers, which are used to identify the contents of the corresponding columns. This can be called a table header or column header. In the embodiments of this specification, the contents within the table header are referred to as table header data. The first column of the first table contains the table row headers, which are used to identify the contents of the corresponding rows. This can be called a row header or index column. In the embodiments of this specification, the contents within the index column are referred to as index column data.
[0030] Among them, such as Figure 2 As shown, the first table includes multiple data cells 1-3 in the same column c, and the value of data cell 3 is determined based on the values of data cell 1 and data cell 2. Data cell 1 is in row a, data cell 2 is in row a+1, and data cell 3 is in row a+2.
[0031] The first table may also include indicator rows corresponding to multiple rows in a hierarchical relationship, for example Figure 2As shown in the a-1 row, the indication row may include content in a specified format. For example, the content in the indication row generally occupies one row and may be in a left-aligned format. The content in the indication row may be indicative content describing the existence of a hierarchical relationship between the a-th row, the a+1-th row, and the a+2-th row. Exemplarily, the index column data corresponding to the multiple rows in a hierarchical relationship may differ in format relative to the content in the indication row. For example, when the content in the indication row is left-aligned, the format of the index column data corresponding to the multiple rows in a hierarchical relationship may be non-left-aligned, for example, there is a space at the front of the index column data. For another example: when the content in the indication row is center-aligned, the format of the index column data corresponding to the multiple rows in a hierarchical relationship may be left-aligned.
[0032] Figure 2 As shown, row a-1 includes attributes indicating that the values in the data cells in row a and row a+1 (i.e., data cell 1) are all current assets, wherein the attribute of the value in the data cell in row a indicates that it is an asset of subtype A in current assets; the attribute of the value in the data cell in row a+1 (i.e., data cell 2) indicates that it is an asset of subtype B in current assets; and the attribute of the value in the data cell in row a+2 (i.e., data cell 3) indicates that it is the total current assets.
[0033] like Figure 2 As shown, the multiple data cells 1-3 in a hierarchical relationship may be data cells in different rows of the same column. In some other examples, the multiple data cells in a hierarchical relationship may also be data cells in different columns of the same row in a table.
[0034] It is understandable that Figure 2 This diagram only illustrates an exemplary partial structure of a table and does not limit the specific format of the table. In some scenarios, a table may include more rows of column headers and more columns of column indexes. For example, the first three rows of a table are table headers, or column headers, used to identify the contents of the corresponding columns; and the first two columns of a table are index columns, used to identify the contents of the corresponding rows.
[0035] Identifying and extracting cells with hierarchical relationships in a table can, to a certain extent, help the large language model provide more accurate answers to certain types of questions or queries. For example, questions of this type involve queries targeting content in a table with a total-to-score relationship. Therefore, identifying and extracting the hierarchical relationships between data cells in a table can more clearly characterize the relationships between data cells in the table, helping the large language model provide more accurate answers to certain types of questions or queries.
[0036] The process of identifying and extracting hierarchical relationships in a table may include: obtaining a first table text corresponding to a first table whose hierarchical relationships are to be extracted, the first table including: a first cell and multiple second cells, the value of the first cell being determined based on the values of the multiple second cells; determining a first prompt text based on the first table text and a first prompt template, wherein the first prompt template is used to guide a first large language model to extract the hierarchical relationships between the first cell and the multiple second cells based on the first table text; extracting the hierarchical relationships between the first cell and the multiple second cells through the first large language model based on the first prompt text.
[0037] In the above process, the first large language model, based on its semantic understanding capabilities, identifies and extracts the hierarchical relationships between a first cell and multiple second cells in the first table. Subsequently, the hierarchical relationships between the first cell and multiple second cells can be further identified, providing a basis for the large language model to provide more accurate answers to specific types of questions or queries.
[0038] The following describes in detail the method for extracting hierarchical relationships in a table provided in this specification in conjunction with specific embodiments.
[0039] Figure 3 The flowchart of a method for extracting the hierarchical relationship in a table in one embodiment of the present specification is shown. The method is executed by an electronic device, which can be implemented by any device, equipment, platform, equipment cluster, etc. with computing and processing capabilities. In the process of extracting the hierarchical relationship in the table, such as Figure 3 As shown, the method includes the following steps S310-S330:
[0040] In step S310 , a first table text corresponding to a first table is obtained, wherein the first table includes: a first cell and a plurality of second cells, and a value of the first cell is determined based on the values of the plurality of second cells.
[0041] In some examples, the first table may be any type of table. For example, the first table may be a matrix table, such as a financial table.
[0042] In some possible examples, the first table text may include at least: the text table data of the first table. The text table data is, for example, markdown format data of the first table, including all the data in the first table, and the positional relationship between the data, which is the same as its positional relationship in the first table. The data in the first table includes: each header data, each index column data and the value in each data cell in the first table, and the positional relationship between the data may include: the position of each header data, each index column data and the value in each data cell in the first table, and the positional relationship between them.
[0043] It can be understood that in some scenarios, a table can be stored in a file, which may include explanatory description content of the table, such as but not limited to: the table name of the table, content used to explain the unit, currency, order of magnitude, etc. of the numerical values in the table, and content explaining the meaning of certain nouns in the table. Such content is generally located near the location of the table in the file, for example, within W lines before and after the location of the table, that is, the contextual information corresponding to the subsequently mentioned table in the file where it is located.
[0044] In addition, the file name and file directory information of the file containing the form can also be used to explain and describe the content of the form. For example, the file name can indicate that the form belongs to XX Company, and further, it can indicate that the form is a form for a certain period of time (for example, quarter y of year XX) of XX Company. The file directory information can also indicate that the form is a form for a subsidiary of XX Company, and can also indicate which project, department, or product the form is related to, etc.
[0045] In view of the above situation, in some possible examples, the first table text includes the text table data of the first table, and may also include: the file name of the file where the first table is located, the file directory information, and at least one of the context information corresponding to the first table in the file where it is located. The above information can all contain the content of the explanation of the first table, which can achieve a better and clearer explanation description of the content of the first table. It further helps the large language model to more accurately identify and extract the hierarchical relationship in the table, and further helps the subsequently constructed knowledge graph to better express the specific meaning of the content of the first table, thereby improving the accuracy of the subsequent query results based on the knowledge graph of the table.
[0046] In some possible examples, the value of a first cell is determined based on the values of multiple second cells. For example, the value of the first cell is equal to the sum of the values of the multiple second cells. Accordingly, there is a hierarchical relationship between the first cell and the multiple second cells, wherein the first cell is the superordinate cell of the multiple second cells, and each second cell is the subordinate cell of the first cell. In some examples, the first cell and the multiple second cells in the first table can be multiple data cells in the same row but different columns in the first table, or multiple data cells in the same column but different rows in the first table.
[0047] In step S320 , a first prompt text is determined based on the first table text and the first prompt template, wherein the first prompt template is used to guide the first large language model to extract the hierarchical relationship between the first cell and the plurality of second cells based on the first table text.
[0048] The designated storage space of the electronic device can be pre-stored with a set first prompt template, which can also be called a prompt word. The first prompt template is used to guide the first large language model to gradually analyze and understand the content of the data cells in each row and / or column in the first table based on the first table text, including the content of the first cell and the content of each second cell. Based on the content it understands, it extracts the hierarchical relationship between the first cell and the multiple second cells, that is, determines whether there is a hierarchical relationship between the first cell and the multiple second cells, and determines the data cells that are superordinate cells and the data cells that are subordinate cells in the first cell and the multiple second cells. Among them, the first large language model can identify the hierarchical relationship between the first cell and the multiple second cells by analyzing and understanding the text semantics between the first cell and the multiple second cells in the first table text.
[0049] Accordingly, after the electronic device obtains the first table text, it can combine the first table text and the first prompt template to obtain the first prompt text. Exemplarily, the first prompt template can include a fill-in position for filling in the first table text, and the first table text is filled in the corresponding fill-in position to achieve the combination of the first table text and the first prompt template.
[0050] Next, in step S330, based on the first prompt text, the first large language model is used to extract the hierarchical relationship between the first cell and the plurality of second cells. In this step, the electronic device may input the first prompt text into the first large language model, so that the first large language model analyzes and understands the first table text based on the instructions in the first prompt template, identifies and extracts the hierarchical relationship between the first cell and the plurality of second cells in the first table, obtains a first output result of the first large language model, and determines the hierarchical relationship between the first cell and the plurality of second cells based on the first output result.
[0051] The first language model and the subsequent second and third language models can be any language model in the related art that can provide content generation. The first language model and the subsequent second and third language models can be the same language model or different language models.
[0052] In some possible examples, there are certain particularities in the positional relationship between data cells that have a hierarchical relationship in a table, which can be expressed through visual semantics in an image. For example, in a table, if multiple data cells that have a hierarchical relationship are data cells in different rows of the same column, the previous row or the next row of the row where the multiple data cells are located includes descriptions of the contents of the multiple data cells, and the content display format of the previous row or the next row of the row where the multiple cells that have a hierarchical relationship are located is different from the content display format of the row where the multiple cells that have a hierarchical relationship are located. Figure 2 The a-1th row shown contains indicative content describing the existence of a hierarchical relationship among the ath row, the a+1th row, and the a+2th row.
[0053] In view of the above situation, in some possible examples, in order to better ensure the accuracy of the extracted hyponym relationship, step S330 may include steps 11-13:
[0054] In step 11, based on the first prompt text, a first output result representing the hierarchical relationship between the first cell and the plurality of second cells is determined using a first large language model. In this step, the electronic device inputs the first prompt text into the first large language model, causing the first large language model to analyze and understand the first table text based on instructions in the first prompt template, thereby identifying and extracting the hierarchical relationship between the first cell and the plurality of second cells in the first table. A first output result of the first large language model is obtained, which includes information indicating the hierarchical relationship between the first cell and the plurality of second cells.
[0055] Then, in step 12, based on the first prompt text and the first image, a second output result characterizing the hierarchical relationship between the first cell and the plurality of second cells is determined through a multimodal model, wherein the first image includes at least a first table. In this step, the electronic device can input the first prompt text and the first image into the multimodal model respectively, so that the multimodal model processes the first prompt text and the first image, extracts text features indicating the hierarchical relationship between the first cell and the plurality of second cells from the first prompt text, and extracts visual features indicating the hierarchical relationship between the first cell and the plurality of second cells from the first image; fuses the text features and the visual features to obtain a fused feature, and then obtains a second output result indicating the hierarchical relationship between the first cell and the plurality of second cells based on the fused feature. In some examples, the multimodal model can be any content generation model in the related art that can jointly process multiple modal data such as text and images.
[0056] In some possible examples, the first image may also include contextual information of the first table, and the contextual information may include but is not limited to: the contextual information corresponding to the first table in the file in which it is located and the file name of the file in which the first table is located. Through this type of first image, the multimodal model can identify more features that are helpful for understanding the content of the first table from the first image, and then obtain more features that help it identify and extract the second hierarchical relationship between the first cell and the multiple second cells from the first table. Based on this type of feature, a second output result that more accurately characterizes the hierarchical relationship between the first cell and the multiple second cells can be obtained.
[0057] Next, in step 13, the first output result and the second output result are combined to obtain the hierarchical relationship between the first cell and the plurality of second cells.
[0058] In some possible examples, the first output result and the second output result include information indicating the relationship between the first cell and multiple second cells, such as information indicating which cell is the parent cell and which cells are subordinate cells of the parent cell. For example, the first output result and the second output result may both include information indicating that the first cell has no parent cell and that the parent cell of each second cell is the first cell.
[0059] In some examples, it can be determined whether the hierarchical relationship between the first cell and the plurality of second cells represented in the first output result is the same as the hierarchical relationship between the first cell and the plurality of second cells represented in the second output result; if the hierarchical relationship is the same, either the first output result or the second output result can be verified, and if the verification passes, the hierarchical relationship between the first cell and the plurality of second cells is determined based on the first output result and the second output result. In some cases, if the hierarchical relationship is different, the accuracy of the hierarchical relationship between the first cell and the plurality of second cells indicated by both can be verified separately, and if both fail to pass the verification, the hierarchical relationship between the first cell and the plurality of second cells can be extracted again based on the first prompt text and / or the first image.
[0060] In some examples, the accuracy of the hierarchical relationship between the first cell and the multiple second cells represented in the first output result, as well as the accuracy of the hierarchical relationship between the first cell of the table and the multiple second cells in the second output result can be directly verified respectively; based on the information of the hierarchical relationship between the first cell and the multiple second cells indicated by the output result that passed the verification, the hierarchical relationship between the first cell and the multiple second cells is determined. If both verification results indicate that the verification failed, the hierarchical relationship between the first cell and the multiple second cells can be extracted again based on the first prompt text and / or the first image. The specific verification process will be introduced later.
[0061] It can be understood that in the first table, data cells in the same row generally correspond to the same index column data; data cells in the same column generally correspond to the same header data.
[0062] In view of this, when a first cell and multiple second cells are multiple data cells in the same column but different rows, the value of the first cell is determined based on the values of the multiple second cells. Accordingly, the value of any data cell x in the row where the first cell is located is determined based on the values of each data cell in the row where the second cells are located that is in the same column as the data cell x. In other words, when the first cell is the parent cell of multiple second cells, there is also a hierarchical relationship between the row where the first cell is located and the rows where the second cells are located, i.e., the row where the first cell is located is the parent row of the rows where the second cells are located, and the row where the second cells are located is the child row of the row where the first cell is located.
[0063] Similarly, when a first cell and multiple second cells are multiple data cells in the same row but different columns, the value of the first cell is determined based on the values of the multiple second cells. Correspondingly, the value of any data cell y in the column where the first cell is located is determined based on the values of each data cell in the column where the second cell is located that is in the same row as the data cell y. In other words, when the first cell is the parent cell of multiple second cells, the column where the first cell is located also has a hierarchical relationship with the columns where the second cells are located, i.e., the column where the first cell is located is the parent column of the column where the second cells are located, and the column where the second cells are located is the parent column of the column where the first cell is located.
[0064] In some possible examples, when the first cell and multiple second cells are data cells in the same column in each first row, the aforementioned first prompt template can be used to guide the first large language model to gradually analyze and understand the content of the data cells in each row and / or column of the first table based on the first table text, including the content of the data cells in each first row where the first cell and each second cell are located, and extract the hierarchical relationship between each first row based on the content it understands. Subsequently, in the aforementioned step S330, the electronic device determines the hierarchical relationship between each first row of the table based on the first prompt text and the first large language model to determine the hierarchical relationship between the first cell and each second cell.
[0065] In some other possible examples, when the first cell and multiple second cells are data cells in the same column in each first row; the aforementioned step S330 may include: based on the first prompt text, determining the third output result of the hierarchical relationship between each first row of the table through the first large language model; based on the first prompt text and the aforementioned first image, determining the fourth output result of the hierarchical relationship between each first row of the table through the multimodal model; combining the third output result and the fourth output result to determine the hierarchical relationship between each first row, thereby determining the hierarchical relationship between the first cell and the multiple second cells.
[0066] When the first cell and multiple second cells are data cells in the same row in each first column, the process of determining the hierarchical relationship can be referred to the aforementioned process of determining the hierarchical relationship when the first cell and multiple second cells are data cells in the same column in each first row, and will not be repeated here.
[0067] In some possible examples, the accuracy of the hierarchical relationship between the extracted first cell and the plurality of second cells needs to be verified to ensure that the extracted hierarchical relationship is accurate, thereby safeguarding the accuracy of the query results in the subsequent query process based on the hierarchical relationship. The hierarchical relationship between the first cell and the plurality of second cells can indicate which cell is the superordinate cell and which cells are the subordinate cells of the superordinate cell; in the process of verifying the extracted hierarchical relationship, the method may further include the following steps 21-23:
[0068] In step 21 , based on the aforementioned hierarchical relationship, a first sum of the values of the plurality of subordinate cells is calculated.
[0069] In step 22, it is determined whether the first sum is the same as the value of the cell indicated as the superordinate cell by the superordinate relationship. In this step, the first sum is compared with the value of the first cell.
[0070] Then, in step 23, if it is determined to be the same, it is determined that the hierarchical relationship is correct.
[0071] In the above example, when it is determined that the hierarchical relationship between the determined first cell and the multiple second cells is accurate, it can be determined that the first cell indicated in the hierarchical relationship is the upper cell of the multiple second cells, and the multiple second cells are the lower cells of the first cell. Subsequently, the hierarchical relationship between the first cell and the multiple second cells in the first table can be further marked, for example, the upper cell of the multiple second cells is marked as the first cell and / or the lower cells of the first cell include the multiple second cells. Exemplarily, a column is expanded in the first table, and in the expanded column, for each row where the second cell is located, information is recorded that the upper row corresponding to the row where the second cell is located is the row where the first cell is located; for the row where the first cell is located, if there is no upper row for it, information is recorded that there is no upper row for it, for example, it is empty.
[0072] In some further possible examples, the method may further include the following step 24:
[0073] In step 24, if it is determined that the first sum value is different from the numerical value of the cell indicated as the superordinate cell by the hierarchical relationship, the hierarchical relationship between the first cell and the multiple second cells in the first table is determined through a multimodal model based on the first table text and the second image, wherein the second image at least includes the first table.
[0074] In the above example, if the electronic device determines that the first sum value is different from the numerical value of the superordinate cell indicated by the superordinate relationship, then it can be determined that the superordinate relationship between the first cell and the plurality of second cells extracted by the electronic device is inaccurate, and accordingly, the superordinate relationship between the first cell and the plurality of second cells in the first table can be re-determined. Specifically, the superordinate relationship between the first cell and the plurality of second cells in the first table can be re-determined through a multimodal model in combination with the first table text and a second image including at least the first table.
[0075] Subsequently, the hierarchical relationship between the re-determined first cell and the multiple second cells may be further verified. If the verification is accurate, the first cell and the multiple second cells may be marked based on the hierarchical relationship between the re-determined first cell and the multiple second cells.
[0076] In this embodiment, the semantic understanding capabilities of the first large language model are leveraged to identify and extract the hierarchical relationships between a first cell and multiple second cells in a first table. Subsequently, the hierarchical relationships between the first cell and multiple second cells can be further identified, providing a foundation for the large language model to provide more accurate responses to specific types of questions or queries.
[0077] It is understandable that the first table may also include other rows or columns with hierarchical relationships. Through the method of extracting hierarchical relationships in a table provided in the embodiments of this specification, the hierarchical relationships between all rows or columns with hierarchical relationships in the first table can be extracted.
[0078] Figure 4 The flowchart of a method for extracting the hierarchical relationship in a table in one embodiment of the present specification is shown. The method is executed by an electronic device, which can be implemented by any device, equipment, platform, equipment cluster, etc. with computing and processing capabilities. In the process of extracting the hierarchical relationship in the table, such as Figure 4 As shown, the method includes the following steps S410-S440:
[0079] In step S410 , a first table text corresponding to a first table is obtained, wherein the first table includes: a first cell and a plurality of second cells, and a value of the first cell is determined based on the values of the plurality of second cells.
[0080] In step S420, a first prompt text is determined based on the first table text and the first prompt template, wherein the first prompt template is used to guide the first large language model to extract the hierarchical relationship between the first cell and the plurality of second cells based on the first table text.
[0081] In step S430 , based on the first prompt text, the first large language model is used to extract the hierarchical relationship between the first cell and the plurality of second cells.
[0082] Among them, the implementation principle of steps S410-S430 is similar to the implementation principle of the aforementioned steps S310-S330. The implementation process thereof can refer to the implementation process of the aforementioned steps S310-S330 and will not be repeated here.
[0083] Then, in step S440, based on the first table text, a first knowledge graph of the first table is determined through the second largest language model, and the first knowledge graph includes a first cell node corresponding to the first cell, a second cell node corresponding to each of the multiple second cells, and a first edge indicating a hierarchical relationship between the first cell node and the multiple second cell nodes.
[0084] In some possible examples, a set second prompt template can be pre-stored, and the second prompt template is used to instruct the second largest language model to analyze and process the text of the first table, and gradually construct cell nodes corresponding to each data cell in the first table; wherein, each data cell in the first table includes a first cell and each second cell, and the corresponding aforementioned cell nodes include a first cell node corresponding to the first cell, and a second cell node corresponding to each of the multiple second cells.
[0085] Subsequently, the electronic device can combine the second prompt template and the first table text to obtain the second prompt text, and then input the second prompt text into the second largest language model so that the second largest language model constructs a cell node corresponding to each data cell in the first table based on the instructions of the second prompt template; and then constructs a first edge between the first cell node and multiple second cell nodes, which is used to indicate the hierarchical relationship between the first cell node and multiple second cell nodes.
[0086] For example, the hierarchical relationship between the first cell and the plurality of second cells indicates that the first cell is the superordinate cell of the plurality of second cells, and the plurality of second cells are the subordinate cells of the first cell. In this case, in one implementation, a first edge pointing from each second cell node to the first cell node can be constructed between the first cell node and the plurality of second cell nodes to indicate that the first cell is the superordinate cell of the plurality of second cells, such as Figure 5 As shown, the edge (as shown in FIG1 ) between the second cell node 21 corresponding to the data cell 1 (belonging to the row a) and the first cell node 11 corresponding to the data cell 3 (belonging to the row a+2) is shown in FIG1 . Figure 5The edge between the second cell node 31 corresponding to the data cell 2 (belonging to row a+1) and the first cell node 11 corresponding to the data cell 3 (as shown in the dashed line); Figure 5 shown as dashed lines).
[0087] In another implementation, a first edge may be constructed between the first cell node and the plurality of second cell nodes, with the first cell node pointing to each second cell node, to indicate that the first cell is a superordinate cell of the plurality of second cells.
[0088] In some possible examples, the first knowledge graph may also include: grid attribute information corresponding to each cell node, each grid attribute information is determined based at least on the value of the corresponding data cell and the index column data of its row and the header data of its column. The text format data in the first table text may include the index column data corresponding to all rows in the first table, the header data corresponding to all columns, and the values in each data cell. The values in the data cells may include, but are not limited to, numerical values, symbols, and text. Symbols include, for example, an upward arrow that can indicate that the data is on an upward trend, a downward arrow that can indicate that the data is on a downward trend, a symbol that can indicate that there is no numerical value in the data cell, etc.
[0089] Correspondingly, the aforementioned second prompt template is used to instruct the second largest language model to analyze and process the first table text, and gradually construct cell nodes corresponding to each data cell in the first table, which can specifically include: instructing the second largest language model to analyze and process the first table text, and gradually construct grid attribute information corresponding to each data cell in the first table, and the grid attribute information corresponds to the cell nodes corresponding to each data cell.
[0090] In some possible examples, the first knowledge graph may also include: row nodes corresponding to each row and / or column nodes corresponding to each column in the first table, and a second edge representing the inclusion relationship between each row node and / or column node and the first table, and a third edge representing the inclusion relationship between each cell node and each row node and / or column node, the first cell and multiple second cells are data cells in the same column in each first row or data cells in the same row in each first column.
[0091] In some other possible examples, the first knowledge graph may further include: row attribute information corresponding to each row node and / or column attribute information corresponding to each column node. Exemplarily, each row attribute information is determined based on at least the header data of all columns in the first table included in the first table text, the index column data of the corresponding row, and the value of the data cell; each column attribute information is determined based on at least the header data and the value of the data cell of the corresponding column in the first table included in the first table text, and the index column data of all rows.
[0092] In some possible examples, a third prompt template may be pre-stored, which is used to instruct the large language model to at least gradually determine row attribute information corresponding to each row and / or column attribute information corresponding to each column in the first table based on the first table text.
[0093] Correspondingly, the electronic device can also combine the third prompt template and the first table text to obtain a third text prompt; then input the third text prompt into the second largest language model, so that the second largest language model determines the row attribute information corresponding to each row in the first table based on the instructions of the third prompt template, at least based on the header data of all columns of the first table in the first table text, the index column data of the row and the value of the data cell, and further obtains the row attribute information corresponding to each row; and / or determines the column attribute information corresponding to each column in each first table based on at least the header data and data cell value corresponding to the column in the first table text and the index column data of all rows, and further obtains the column attribute information corresponding to each column; constructs the association relationship between each row node in the first knowledge graph and the row attribute information of its corresponding row, and / or constructs the association relationship between each column node in the first knowledge graph and the column attribute information of its corresponding column.
[0094] Next, based on the inclusion relationship between each data cell in the first table and each row and / or column in the first table, a third edge is constructed between each cell node and each row node and / or column node; and based on the inclusion relationship between each row and / or column and the first table, a second edge is constructed to obtain a first knowledge graph corresponding to the first table.
[0095] It is understood that the row attribute information of any row i is used to describe the specific meaning of all data cells in row i, and may include descriptive information for all data cells in row i. The column attribute information of any column j is used to describe the specific meaning of all data cells in column j, and may include descriptive information for all data cells in column j.
[0096] Considering that in some query scenarios, there may be multiple tables that the large language model relies on to provide query services to users, accordingly, in order to better improve the accuracy of the query results and feedback a more accurate answer text for the query text entered by the user, the first knowledge graph can also include a table node representing the first table, so as to facilitate the table nodes in the knowledge graphs of each table and quickly match the knowledge graph that matches the query text entered by the user from the knowledge graphs of multiple tables.
[0097] Accordingly, in some possible examples, the first knowledge graph may also include a table node corresponding to the first table, and the table node may correspond to a table keyword set, which is determined based on the first table text.
[0098] In the above example, the electronic device may pre-store a fourth prompt template that has been set up, and the fourth prompt template is used to instruct the second largest language model to extract a table keyword set from the first table text, and the table keyword set includes a number of words that can indicate the characteristics of the content of the first table. Accordingly, the electronic device can combine the first table text and the fourth prompt template to obtain a fourth text prompt, and input the fourth text prompt into the second largest language model, so that the second largest language model extracts the table keyword set corresponding to the first table text from the first table text based on the instructions in the fourth prompt template, and then constructs an association relationship between the table keyword set corresponding to the first table text and the table node in the first knowledge graph. The aforementioned second edge is an edge between a table node and each row node and / or each column node.
[0099] In some other possible examples, it is also possible to determine table attribute information corresponding to the first table based on the first table text using the second language model, and then establish an association relationship between the table attribute information and the table nodes in the first knowledge graph. The table attribute information is used to describe the content of the first table.
[0100] In the above example, the first knowledge graph may include three layers of entities, namely, table nodes in the first layer, row nodes and / or column nodes in the second layer, and cell nodes in the third layer. In some implementations, if the first cell and the multiple second cells are data cells in the same column in each first row, the aforementioned first edge indicating the hierarchical relationship between the first cell node and the multiple second cell nodes may be: an edge between row nodes corresponding to the first row in which the first cell and the multiple second cells are respectively located; if the first cell and the multiple second cells are data cells in the same row in each first column, the aforementioned first edge indicating the hierarchical relationship between the first cell node and the multiple second cell nodes may be: an edge between column nodes corresponding to the first column in which the first cell and the multiple second cells are respectively located.
[0101] In some possible examples, when the first table text only includes the text table data of the first table, in order to ensure the accuracy of the constructed first knowledge graph, the electronic device can determine the first knowledge graph of the first table through the second large language model based on the file name, file directory information, and at least one of the context information corresponding to the first table in the file where the first table is located and the first table text.
[0102] Specifically, the file name of the file where the aforementioned first table is located, the file directory information, and at least one of the context information corresponding to the first table in the file where it is located, as well as the aforementioned text table data, can be combined to jointly determine the row attribute information and / or column attribute information corresponding to each row, as well as the grid attribute information and the table keyword set, so that the content in the corresponding row can be better represented by the row attribute information and / or the content in the corresponding column can be better represented by the column attribute information; the content in the corresponding data cell can be represented by the grid attribute information, and the content of the first table can be better represented by the table keyword set.
[0103] Figure 5 An example is shown based on Figure 2 A partial schematic diagram of the first knowledge graph constructed by the first table shown.
[0104] Among them, row a corresponds to row node a, row a+1 corresponds to row node a+1, row a-1 corresponds to row node a-1, row a+2 corresponds to row node a+2, column c corresponds to column node c, edges between column node c, row node a, row node a+1, row node a-1, row node a+2 and cell nodes respectively, and edges between column node c, row node a, row node a+1, row node a-1, row node a+2 and table node M respectively, indicating that row a and row a+1 are the lower rows of row a+2 respectively.
[0105] Through the above process, any table can be knowledge graphed, that is, a knowledge graph of the table can be constructed, and the table itself, the rows and / or columns in the table, and the data cells can be knowledge graphed. The hierarchical relationship between data cells (or rows / columns) can also be knowledge graphed, and then combined with a large language model to provide users with better table-based query services.
[0106] Corresponding to the above method embodiment, Figure 6 A schematic diagram of a query process of a table-based knowledge graph provided in an embodiment; Figure 6 As shown, after step S440, steps S450-S460 may be further included:
[0107] In step S450 , a query text for a question of a specified type is obtained.
[0108] Exemplarily, the specified type of question may be a query question related to a table and involving a total-score relationship.
[0109] Exemplarily, a third language model can be used to determine whether the query text obtained is for a question of a specified type. Specifically, a specified prompt template constructed based on a small number of sample prompt strategies can be obtained, wherein the specified prompt template includes text samples corresponding to questions of a specified type. After obtaining the query text, the query text is combined with the specified prompt template to obtain a query text prompt. The query text prompt is input into the third language model so that the third language model can determine whether the query text is for a question of a specified type based on the text samples corresponding to the question of a specified type in the specified prompt template. If the query text is determined to be a query text for a question of a specified type, the subsequent process can be continued.
[0110] In some possible examples, the query text may be text input by the user through the input window of the third language model that needs to be answered by the third language model. The query text is used to represent the question that the user needs to query, and the question needs to be answered using the content in the table.
[0111] For example, the query text may include a query for the total revenue of XX Company from the XX R&D Project in YY. XX R&D Project involves multiple sub-projects, and the hierarchical relationship between XX R&D Project and its sub-projects can be shown in a table. For example, the revenue corresponding to each sub-project in the table occupies a row, and the total revenue of XX R&D Project occupies a row below the revenue corresponding to all sub-projects. For another example, the query text may include a query for analyzing the investment proportions of Company E in each sub-project under Project Y (e.g., y1, y2, and y3).
[0112] In step S460, the answer text corresponding to the query text is determined based on the hyponym relationship indicated by the first edge in the first knowledge graph and the query text. In this step, the electronic device can determine the answer text corresponding to the query text using the third language model based on the hyponym relationship indicated by the first edge in the first knowledge graph and the query text.
[0113] Exemplarily, the electronic device can determine the cells that match the query text from the first knowledge graph through the third language model based on the query text and the hierarchical relationship indicated by the first edge in the first knowledge graph, and then determine the answer text corresponding to the query text based on the data cells that match the query text.
[0114] Exemplarily, the first knowledge graph includes row nodes corresponding to each row and / or column node of the first table, cell nodes corresponding to each data cell of the first table, and a second edge representing the inclusion relationship between each row node and / or column node and the first table, a third edge representing the inclusion relationship between each cell node and each row node and / or column node, and a first edge indicating the hierarchical relationship between the first cell node and each second cell node.
[0115] Taking the case where the first cell and the plurality of second cells are data cells in the same column in each first row of the first table as an example, the process of determining the answer text corresponding to the query text is explained. In the case where the first cell and the plurality of second cells are data cells in the same row in each first column of the first table, the process of determining the answer text corresponding to the query text is similar to the process of determining the answer text corresponding to the query text in the case where the first cell and the plurality of second cells are data cells in the same column in each first row of the first table. The implementation process can be referred to the process of determining the answer text corresponding to the query text in the case where the first cell and the plurality of second cells are data cells in the same column in each first row of the first table, and will not be described in detail here.
[0116] In some possible examples, the first cell and the plurality of second cells are data cells in the same column in each first row, and the first edge is an edge between row nodes corresponding to the first row in which the first cell and the plurality of second cells are located. When the electronic device determines that the query text is a text involving a specified type of question, the electronic device can determine a retrieval plan corresponding to the query text based on the query text through the third language model. The retrieval plan can include multiple retrieval steps. The retrieval steps can include, for example: determining a knowledge graph of a table matching the query text; determining an upper row node matching the query text based on the table knowledge graph matching the text and the query text; determining a lower row node corresponding to the upper row node based on the upper row node and the first edge representing the upper and lower relationship in the knowledge graph of the table matching the query text; and then determining the answer text corresponding to the query text based on the query text, the upper row node matching the query text and its lower row node, through the third language model. Subsequently, the answer text corresponding to the query text can be determined based on each retrieval step in the aforementioned retrieval plan.
[0117] When the third language model is associated with the first knowledge graph, the knowledge graph of the table matching the query text is the first knowledge graph. When the third language model is associated with the knowledge graphs of multiple tables, including the first table, the knowledge graph of the table matching the query text may be the knowledge graph of one or more tables matching the query text, determined from the knowledge graphs of the multiple tables based on the query text using the third language model or other specified method.
[0118] In some possible examples, the first cell and the plurality of second cells are data cells in the same column in each first row, and the first edge is an edge between row nodes corresponding to the first row in which the first cell and the plurality of second cells are located. When the third language model is associated with a knowledge graph of multiple tables, step S460 may include steps 31-35:
[0119] In step 31 , a query keyword set is determined based on the query text.
[0120] In a possible example, the electronic device can segment the query text to obtain segmentation results, and then filter out keywords from the segmentation results to form a query keyword set, so as to find a matching knowledge graph from the table knowledge graphs of multiple tables through the query keyword set.
[0121] In another possible example, the electronic device may determine a query keyword set based on the query text using a third language model. Specifically, the query text is combined with a fifth prompt template that instructs the third language model to extract keywords from the input query text to obtain a fifth prompt text. The fifth prompt text is then input into the third language model so that the third language model processes the query text based on the instructions of the fifth prompt template to obtain a query keyword set corresponding to the query text. The query keyword set includes several keywords determined based on the query text.
[0122] Next, in step 32, based on the query keyword set and the table keyword sets corresponding to the table nodes in the table knowledge graphs of each of the multiple tables, each matching knowledge graph that matches the query text is determined from each table knowledge graph, wherein the multiple tables include the first table.
[0123] Each table knowledge graph includes: row nodes corresponding to each row in the corresponding table and row attribute information corresponding to the row nodes, and / or column nodes corresponding to each column in the corresponding table and column attribute information corresponding to the column nodes, as well as cell nodes corresponding to each data cell in the corresponding table and grid attribute information corresponding to the cell nodes, edges that identify the inclusion relationship between the corresponding table and its rows and / or columns, and edges that identify the inclusion relationship between each row and / or column and each data cell. Each table knowledge graph may also include table nodes corresponding to the corresponding table entities. Each table knowledge graph may also include edges that identify the hierarchical relationship between multiple rows in the corresponding table and / or edges that identify the hierarchical relationship between multiple columns.
[0124] In some possible examples, the electronic device can determine the matching degree between the table knowledge graph of each table respectively based on the query keyword set and the table keyword set corresponding to the table node in the table knowledge graph to obtain the matching degree corresponding to each table; and determine the table knowledge graphs of several tables with the highest matching degree as several matching knowledge graphs that match the query text, wherein the several matching knowledge graphs include the first knowledge graph.
[0125] In another possible example, the electronic device can input the query keyword set and the table keyword sets corresponding to the table nodes in the table knowledge graphs of multiple tables into a third language model, so that the third language model determines, based on the query keyword set and the multiple table keyword sets, several matching knowledge graphs that match the query text from the multiple table knowledge graphs, wherein the several matching knowledge graphs include the first knowledge graph.
[0126] In some possible implementations, the electronic device may further determine table attribute information corresponding to each table based on the table text corresponding to each table, where the table attribute information is used to describe the content in the table; and then establish a correspondence between the table attribute information and the table nodes in the table knowledge graph. Subsequently, in the process of determining a matching knowledge graph that matches the query text from the table knowledge graphs of multiple tables, a matching knowledge graph that matches the query text may also be determined using a third language model based on the table attribute information corresponding to the table nodes and the query text.
[0127] Then, in step 33, based on the row attribute information of each row node in each matching knowledge graph, the target upper row node matching the query text is determined through the third language model, wherein the target upper row node belongs to the first knowledge graph, and each row attribute information is constructed based on the table text of the corresponding table.
[0128] In some possible examples, the electronic device may also pre-store a sixth prompt template, which is used to instruct the third language model to analyze the query text and the row attribute information corresponding to each row node, and determine a row node that matches the query text and serves as a superordinate row from the multiple row nodes, as the target superordinate row node. In some possible instances, the row attribute information of each row may also indicate a superordinate relationship between the corresponding row and other rows in the table.
[0129] Correspondingly, the row attribute information, query text and sixth prompt template of each row node in each matching knowledge graph are combined to obtain a sixth text prompt; the sixth text prompt is input into the third language model, so that the third language model analyzes the row attribute information and query text corresponding to each row node based on the instructions of the sixth prompt template, and obtains the target upper row node that matches the query text.
[0130] Next, in step 34, based on the edges indicating the hierarchical relationship between rows in the first knowledge graph and the target superordinate row node, a plurality of target subordinate row nodes corresponding to the target superordinate row node are determined.
[0131] In some possible examples, after the electronic device determines the target upper row node that matches the query text through the third language model, when the target upper row node belongs to the first knowledge graph, the target upper row node can be the row where the aforementioned first cell is located, or it can be the upper row of other rows with a hierarchical relationship in the first knowledge graph.
[0132] The electronic device can continue to determine multiple target subordinate row nodes corresponding to the target superordinate row node from the first knowledge graph based on the edges indicating the superordinate and subordinate relationships between rows in the first knowledge graph and the target superordinate row node.
[0133] Then, in step 35, based on the query text and the grid attribute information corresponding to the cell nodes contained in the target upper row node and each target lower row node, the answer text is determined through the third language model.
[0134] In some possible examples, the electronic device may also pre-store a seventh prompt template, which is used to instruct the third language model to analyze and understand the query text and the grid attribute information corresponding to the cell nodes contained in the target upper row node and its respective target lower row nodes, and determine the answer text corresponding to the query text based on the grid attribute information corresponding to the cell nodes contained in the query text and the target upper row node and its respective target lower row nodes.
[0135] Accordingly, the electronic device can combine the query text, the grid attribute information corresponding to the cell nodes contained in the target upper row node and its respective target lower row nodes, and the seventh prompt template to obtain a seventh text prompt. The seventh text prompt is then input into the third language model, so that the third language model generates a response text corresponding to the query text based on the instructions of the seventh prompt template in the seventh text prompt, the grid attribute information corresponding to the cell nodes contained in the target upper row node and its respective target lower row nodes, and the aforementioned query text. The response text can then be fed back to the user.
[0136] Considering that when generating the answer text corresponding to the query text, the generation of the answer text generally involves the content of some or a certain data cell in the table, in some possible examples, step 35 may include the following steps 351-352:
[0137] In step 351 , based on at least the grid attribute information corresponding to the multiple cell nodes included in the target upper row node, a first upper cell node matching the query text is determined through the third language model.
[0138] In some possible examples, the electronic device may determine the first upper cell node that matches the query text through a third language model based on the grid attribute information corresponding to multiple cell nodes included in the target upper row node and the query text.
[0139] Exemplarily, the electronic device may also pre-store an eighth prompt template, which is used to instruct the third language model to analyze and understand the query text and the grid attribute information corresponding to the multiple cell nodes contained in the target upper row node, so as to determine the first upper cell node that best matches the query text from the multiple cell nodes contained in the target upper row node.
[0140] Correspondingly, the electronic device can combine the query text and the grid attribute information corresponding to the multiple cell nodes contained in the target upper row node and the eighth prompt template to obtain an eighth text prompt; input the eighth text prompt into the third largest language model, so that the third largest language model analyzes the matching relationship between each grid attribute information and the aforementioned query text based on the instructions of the eighth prompt template in the eighth text prompt, and determines the first upper cell node that best matches the query text from the multiple cell nodes contained in the target upper row node.
[0141] In some other possible examples, the electronic device can also determine the cell nodes that match the query text through the third language model based on the grid attribute information corresponding to the multiple cell nodes contained in the target upper row node, the grid attribute information corresponding to the multiple cell nodes contained in at least one target lower row node corresponding to the target upper row node, and the query text. Exemplarily, the third language model can respectively determine a cell node that matches the query text from the cell nodes included in the target upper row node and the cell nodes included in each target lower row node. In theory, the aforementioned cell nodes that match the query text belong to the same column.
[0142] After the electronic device obtains the first superordinate cell node that best matches the query text through the third language model, it can determine that the data cells in each target subordinate row that are in the same column as the data cell corresponding to the first superordinate cell node can all be considered as data cells that match the query text.
[0143] Correspondingly, in step 352, based on the grid attribute information corresponding to the first upper cell node and the grid attribute information corresponding to each first lower cell node in each target lower row node, the answer text corresponding to the query text is determined through the third language model, and the data cells corresponding to each first lower cell node are in the same column as the data cells corresponding to the first upper cell node.
[0144] In some implementations, the electronic device may also pre-store a ninth prompt template, which is used to instruct the third language model to analyze and understand the query text, the grid attribute information corresponding to the first upper cell node, and the grid attribute information corresponding to each first lower cell node in each target lower row node, and determine the answer text corresponding to the query text based on the analysis and understanding results.
[0145] Correspondingly, the electronic device can combine the query text and the grid attribute information corresponding to the first upper cell node, the grid attribute information corresponding to each first lower cell node in each target lower row node, and the ninth prompt template to obtain a ninth text prompt; input the ninth text prompt into the third largest language model, so that the third largest language model analyzes the query texts of the grid attribute information corresponding to the first upper cell node and each first lower cell node based on the instructions of the ninth prompt template in the ninth text prompt, and generates an answer text that matches the query text.
[0146] In the above process, a new table-based query process is provided, which pre-constructs a knowledge graph for the table, that is, the rows and / or columns and data cells in the table are entity-ized, and the hierarchical relationships between rows or columns in the table are entity-ized, so as to obtain a knowledge graph including row nodes corresponding to the rows in the table and / or column nodes corresponding to each column, cell nodes corresponding to the data cells, and edges representing the inclusion relationship between rows, columns and data cells, and edges representing the hierarchical relationship between rows or columns, so as to explicitly represent the structure, inclusion relationship and hierarchical relationship between each entity in the table (table node, row node, column node and cell node) through the table knowledge graph. Then, for the query text of a specified type of question, based on the hierarchical relationship between rows or columns in the table explicitly represented in the table knowledge graph, a better and more accurate answer text can be generated to provide users with better quality services.
[0147] The foregoing description describes specific embodiments of the present disclosure, and other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in a different order than that described in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily need to be performed in the specific order shown or in a sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0148] Corresponding to the above method embodiment, the present specification embodiment provides a device 700 for extracting the hierarchical relationship in a table, and its schematic block diagram is shown as follows: Figure 7 As shown, it includes: a first acquisition module 710, configured to obtain a first table text corresponding to a first table, wherein the first table includes: a first cell and multiple second cells, and the value of the first cell is determined based on the values of the multiple second cells; a first determination module 720, configured to determine a first prompt text based on the first table text and a first prompt template, wherein the first prompt template is used to guide a first large language model to determine the hierarchical relationship between the first cell and the multiple second cells based on the first table text; a first extraction module 730, configured to extract the hierarchical relationship between the first cell and the multiple second cells based on the first prompt text through the first large language model.
[0149] In some possible examples, the apparatus further includes:
[0150] The second determination module (not shown in the figure) is configured to determine the first knowledge graph of the first table based on the first table text through a second large language model, the first knowledge graph including a first cell node corresponding to the first cell, a second cell node corresponding to each of the multiple second cells, and a first edge indicating the hierarchical relationship between the first cell node and the multiple second cell nodes.
[0151] In some possible examples, the first knowledge graph also includes: row nodes corresponding to each row and / or column nodes corresponding to each column in the first table, and table nodes corresponding to the first table, cell nodes corresponding to each data cell in the first table, a second edge representing the inclusion relationship between each row node and / or column node and the table node, and a third edge representing the inclusion relationship between each cell node and each row node and / or column node, the first cell and the multiple second cells are data cells in the same column in each first row of the first table or data cells in the same row in each first column.
[0152] In some possible examples, the first knowledge graph also includes: row attribute information corresponding to each row node and / or column attribute information corresponding to each column node, as well as a table keyword set corresponding to the table node and grid attribute information corresponding to each cell node, wherein the table keyword set is determined based on the first table text, each row attribute information is determined at least based on the header data of all columns in the first table included in the first table text, the index column data of the corresponding row and the value of the data cell, and each column attribute information is determined at least based on the header data and data cell value of the corresponding column in the first table included in the first table text and the index column data of all rows; each grid attribute information is determined at least based on the value of the corresponding data cell and the index column data of its row and the header data of its column.
[0153] In some possible examples, the first table text includes: at least one of the file name and file directory information of the file where the first table is located and context information corresponding to the first table in the file, and text table data corresponding to the first table.
[0154] In some possible examples, the first extraction module 730 is specifically configured to determine, based on the first prompt text and using the first large language model, a first output result representing a hierarchical relationship between the first cell and the plurality of second cells;
[0155] Based on the first prompt text and the first image, a second output result representing the hierarchical relationship between the first cell and the multiple second cells is determined through a multimodal model, wherein the first image at least includes the first table; the first output result and the second output result are combined to obtain the hierarchical relationship between the first cell and the multiple second cells.
[0156] In some possible examples, the device also includes: a calculation module (not shown in the figure), configured to calculate a first sum of the numerical values of multiple cells indicated as subordinate cells by the hierarchical relationship based on the hierarchical relationship; a judgment module (not shown in the figure), configured to judge whether the first sum is the same as the numerical value of the cell indicated as the superordinate cell by the hierarchical relationship; and a third determination module (not shown in the figure), configured to determine that the hierarchical relationship is accurate if it is judged to be the same.
[0157] In some possible examples, it also includes: a fourth determination module (not shown in the figure), which is configured to determine the hierarchical relationship between the first cell and the multiple second cells in the first table based on the first table text and the second image through a multimodal model if it is determined that the first sum value is different from the value of the upper cell, wherein the second image at least includes the first table.
[0158] In some possible examples, the apparatus further includes: a second acquisition module (not shown in the figure), configured to acquire a query text for a specified type of question after determining the first knowledge graph of the first table;
[0159] The fifth determination module (not shown in the figure) is configured to determine the answer text corresponding to the query text based on the hierarchical relationship indicated by the first edge in the first knowledge graph and the query text.
[0160] In some possible examples, the first cell and the plurality of second cells are data cells in the same column in each first row, and the first edge is an edge between row nodes corresponding to the first rows in which the first cell and the plurality of second cells are located;
[0161] The fifth determining module (not shown in the figure) includes: a first determining unit (not shown in the figure) configured to determine a query keyword set based on the query text using a third language model;
[0162] a second determining unit (not shown in the figure), configured to determine, from each table knowledge graph, matching knowledge graphs that match the query text based on the query keyword set and table keyword sets corresponding to table nodes in each table knowledge graph of a plurality of tables, wherein the plurality of tables include the first table;
[0163] A third determining unit (not shown in the figure) is configured to determine, based on row attribute information of each row node in each matching knowledge graph, a target upper-level row node matching the query text using the third language model, wherein the target upper-level row node belongs to the first knowledge graph, and each row attribute information is constructed based on the table text of the corresponding table;
[0164] a fourth determining unit (not shown in the figure), configured to determine a plurality of target subordinate row nodes corresponding to the target superordinate row node based on the edges indicating the superordinate and subordinate relationships between rows in the first knowledge graph and the target superordinate row node;
[0165] The fifth determination unit (not shown in the figure) is configured to determine the answer text based on the query text and the grid attribute information corresponding to the cell nodes contained in the target upper row node and its respective target lower row nodes, through the third language model.
[0166] In some possible examples, the fifth determining unit is specifically configured to determine, based on at least the grid attribute information corresponding to the plurality of cell nodes included in the target upper-level row node, a first upper-level cell node matching the query text through the third language model;
[0167] Based on the grid attribute information corresponding to the first upper-level cell node and the grid attribute information corresponding to each first lower-level cell node in each target lower-level row node, the answer text corresponding to the query text is determined through the third language model, and the data cells corresponding to each first lower-level cell node are in the same column as the data cells corresponding to the first upper-level cell node.
[0168] The above-mentioned device embodiments correspond to the method embodiments. For detailed descriptions, please refer to the description of the method embodiments, which will not be repeated here. The device embodiments are obtained based on the corresponding method embodiments and have the same technical effects as the corresponding method embodiments. For detailed descriptions, please refer to the corresponding method embodiments.
[0169] The embodiments of this specification further provide a computer-readable storage medium having a computer program stored thereon. When the computer program is executed in a computer, the computer is caused to execute the method for extracting the hierarchical relationship in a table provided in this specification.
[0170] An embodiment of this specification further provides a computing device including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method for extracting hierarchical relationships in a table provided in this specification is implemented.
[0171] The various embodiments in this specification are described in a progressive manner. Similar portions between the various embodiments can be referenced to each other, and each embodiment focuses on the differences between the other embodiments. In particular, the storage medium and computing device embodiments are described briefly because they are generally similar to the method embodiments. For relevant portions, refer to the description of the method embodiments.
[0172] Those skilled in the art will appreciate that, in one or more of the above examples, the functions described in the embodiments of the present invention may be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions may be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.
[0173] The specific implementation methods described above further illustrate the purpose, technical solutions, and beneficial effects of the embodiments of the present invention. It should be understood that the above description is only a specific implementation method of the embodiments of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent replacements, improvements, etc. made on the basis of the technical solutions of the present invention shall be included in the scope of protection of the present invention.
Claims
1. A method for extracting hierarchical relationships in a table, comprising: Obtaining a first table text corresponding to a first table, wherein the first table includes: a first cell and a plurality of second cells, and a value of the first cell is determined based on the values of the plurality of second cells; Determining a first prompt text based on the first table text and a first prompt template, wherein the first prompt template is used to guide the first large language model to extract a hierarchical relationship between the first cell and a plurality of second cells based on the first table text; Based on the first prompt text, the hierarchical relationship between the first cell and the plurality of second cells is extracted using the first large language model.
2. The method of claim 1, further comprising: Based on the first table text, a first knowledge graph of the first table is determined through a second language model, wherein the first knowledge graph includes a first cell node corresponding to the first cell, a second cell node corresponding to each of the multiple second cells, and a first edge indicating a hierarchical relationship between the first cell node and the multiple second cell nodes.
3. The method according to claim 2, wherein: The first knowledge graph also includes: row nodes corresponding to each row and / or column nodes corresponding to each column in the first table, and table nodes corresponding to the first table, cell nodes corresponding to each data cell in the first table, a second edge representing the inclusion relationship between each row node and / or column node and the table node, and a third edge representing the inclusion relationship between each cell node and each row node and / or column node. The first cell and the multiple second cells are data cells in the same column in each first row of the first table or data cells in the same row in each first column.
4. The method according to claim 3, wherein: The first knowledge graph also includes: row attribute information corresponding to each row node and / or column attribute information corresponding to each column node, as well as a table keyword set corresponding to the table node and grid attribute information corresponding to each cell node, wherein the table keyword set is determined based on the first table text, each row attribute information is determined at least based on the header data of all columns in the first table included in the first table text, the index column data of the corresponding row and the value of the data cell, and each column attribute information is determined at least based on the header data of the corresponding column in the first table included in the first table text and the value of the data cell and the index column data of all rows; each grid attribute information is determined at least based on the value of the corresponding data cell and the index column data of its row and the header data of its column.
5. The method according to claim 2, wherein: The first table text includes: at least one of the file name and file directory information of the file where the first table is located and context information corresponding to the first table in the file, and text table data corresponding to the first table.
6. The method according to any one of claims 1 to 5, wherein: The extracting the hierarchical relationship between the first cell and the plurality of second cells includes: Based on the first prompt text, determining, by using the first large language model, a first output result representing a hierarchical relationship between the first cell and the plurality of second cells; Determining, based on the first prompt text and the first image, through a multimodal model, a second output result representing a hierarchical relationship between the first cell and the plurality of second cells, wherein the first image includes at least the first table; The first output result and the second output result are combined to obtain the hierarchical relationship between the first cell and the plurality of second cells.
7. The method according to any one of claims 1 to 5, further comprising: Based on the hierarchical relationship, calculating a first sum of the values of a plurality of cells indicated by the hierarchical relationship as subordinate cells; Determining whether the first sum value is the same as a value of a cell indicated as a superordinate cell by the superordinate relationship; If they are judged to be the same, it is determined that the hierarchical relationship is accurate.
8. The method of claim 7, further comprising: If it is determined that the first sum value is different from the numerical value of the cell indicated as the superordinate cell by the superordinate relationship, the superordinate relationship between the first cell and the multiple second cells in the first table is determined through a multimodal model based on the first table text and the second image, wherein the second image includes at least the first table.
9. The method according to claim 2, further comprising, after determining the first knowledge graph of the first table: Get the query text for a specified type of question; Based on the hyponym and hyponym relationship indicated by the first edge in the first knowledge graph and the query text, determine the answer text corresponding to the query text.
10. The method of claim 9, wherein: The first cell and the plurality of second cells are data cells in the same column in each first row, and the first edge is an edge between row nodes corresponding to the first row in which the first cell and the plurality of second cells are located; Determining the answer text corresponding to the query text includes: Determining a query keyword set based on the query text; Based on the query keyword set and table keyword sets corresponding to table nodes in table knowledge graphs of each of a plurality of tables, determining, from each of the table knowledge graphs, matching knowledge graphs that match the query text, wherein the plurality of tables include the first table; Based on the row attribute information of each row node in each matching knowledge graph, determining a target upper-level row node that matches the query text through the third language model, wherein the target upper-level row node belongs to the first knowledge graph, and the row attribute information of each row is constructed based on the table text of the corresponding table; Determine a plurality of target subordinate row nodes corresponding to the target superordinate row node based on the edges indicating the superordinate and subordinate relationships between rows in the first knowledge graph and the target superordinate row node; The answer text is determined based on the query text and the grid attribute information corresponding to the cell nodes respectively included in the target upper row node and each target lower row node thereof, through the third language model.
11. The method according to claim 10, wherein: The determining of the answer text includes: Determining a first upper-level cell node that matches the query text by using the third language model based on at least grid attribute information corresponding to a plurality of cell nodes included in the target upper-level row node; Based on the grid attribute information corresponding to the first upper-level cell node and the grid attribute information corresponding to each first lower-level cell node in each target lower-level row node, the answer text corresponding to the query text is determined through the third language model, and the data cells corresponding to each first lower-level cell node are in the same column as the data cells corresponding to the first upper-level cell node.
12. A device for extracting hierarchical relationships in a table, comprising: A first acquisition module is configured to acquire a first table text corresponding to a first table, wherein the first table includes: a first cell and a plurality of second cells, and a value of the first cell is determined based on the values of the plurality of second cells; a first determining module configured to determine a first prompt text based on the first table text and a first prompt template, wherein the first prompt template is used to guide the first large language model to determine a hierarchical relationship between the first cell and a plurality of second cells based on the first table text; The first extraction module is configured to extract the hierarchical relationship between the first cell and the plurality of second cells based on the first prompt text and using the first large language model.
13. A computing device comprising a memory and a processor, wherein: The memory stores executable code, and when the processor executes the executable code, the method according to any one of claims 1 to 11 is implemented.