Reply generation method, electronic device and computer storage medium
By mapping table values in TableQA system into labels and constructing heterogeneous graphs, the input and output length problems caused by long table values are solved, the efficiency and accuracy of reply generation are improved, and more efficient natural language reply generation is achieved.
Patent Information
- Application Number
- CN202210581191.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-26
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2042-05-26
AI Technical Summary
The existing TableQA system may have particularly long table values in the question statement or answer statement, causing the input and output length of the neural network model to become very long, affecting the training and decoding efficiency, increasing noise and reducing the generation effect.
By mapping the table values in the query results into fixed-length tags, building heterogeneous plots, combining SQL statements and query results to generate text sequences, input them into the reply generation model, generating natural language reply statements, and replacing the tags when output is the table value.
The model input length is shortened, the decoding speed is improved, the accuracy of reply statements is improved, the semantic interference of table values is avoided, and the generation effect is enhanced.
Smart Images

Figure CN114996294B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a reply generation method, an electronic device, and a computer storage medium. Background Art
[0002] The TableQA (Table Question and Answer) system can be used in the fields of finance, education, operators, medical care, etc. The existing TableQA system converts the user's question statements into SQL statements through a neural network model, then queries the database through SQL statements, and generates natural language answer statements based on the query results.
[0003] This kind of TableQA system may have particularly long table values in the question or answer statements, such as addresses, descriptions, and introductions. This will make the input and output lengths of the neural network model very long and uncontrollable, seriously affecting the efficiency of training and decoding. At the same time, it also introduces more noise into the neural network model, affecting the generation effect. Summary of the invention
[0004] In view of this, an embodiment of the present application provides a reply generation solution to at least partially solve the above-mentioned problem.
[0005] According to a first aspect of an embodiment of the present application, a reply generation method is provided, comprising: obtaining an SQL statement generated based on a question statement, and a query result of the SQL statement, the query result comprising a plurality of table values of different lengths in a data table; mapping at least part of the table values in the query result to labels of fixed length, and constructing a heterogeneous graph based on the SQL statement, the query result, and the mapping result; generating a text sequence containing the label based on the connection relationship of the nodes and the content of the nodes in the heterogeneous graph; inputting the text sequence and the heterogeneous graph into a trained reply generation model to obtain a natural language sentence with the label output by the reply generation; replacing the label in the sentence output by the reply generation model with the corresponding table value to obtain a natural language reply sentence.
[0006] According to a second aspect of an embodiment of the present application, a reply generation device is provided, comprising: a first acquisition module, used to acquire an SQL statement generated based on a question statement, and a query result of the SQL statement, wherein the query result includes a plurality of table values of different lengths in a data table; a construction module, used to map at least part of the table values in the query result into a label of a fixed length, and to construct a heterogeneous graph based on the SQL statement, the query result, and the mapping result; a generation module, used to generate a text sequence containing the label based on the connection relationship of the nodes and the content of the nodes in the heterogeneous graph; a second acquisition module, used to input the text sequence and the heterogeneous graph into a trained reply generation model, and acquire a natural language statement with the label output by the reply generation; and a third acquisition module, used to replace the label in the statement output by the reply generation model with a corresponding table value, so as to obtain a natural language reply statement.
[0007] According to a third aspect of an embodiment of the present application, there is provided an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the method described in the first aspect.
[0008] According to a fourth aspect of an embodiment of the present application, a computer storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described in the first aspect is implemented.
[0009] According to a fifth aspect of an embodiment of the present application, a computer program product is provided, comprising computer instructions, wherein the computer instructions instruct a computing device to perform operations corresponding to the above-mentioned method.
[0010] According to the method provided in the embodiment of the present application, by replacing the table value label, the longer table value is converted into a label, and then the label is mapped back to the original table value description through the mapping dictionary during output, so as to shorten the model input length and speed up the decoding speed. By generating a heterogeneous graph, and generating the heterogeneous graph and the text sequence determined based on the heterogeneous graph into the reply generation model, the reply generation model can not only extract the semantic information of the text sequence, but also extract the semantic information represented by the connection relationship between nodes in the heterogeneous graph, thus retaining the semantic information contained in the SQL statement and the data table in a structural manner, and improving the accuracy of the reply statement. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0012] Figure 1A A schematic diagram of an application scenario of a reply generation method according to Embodiment 1 of the present application;
[0013] Figure 1B A schematic diagram of the steps of a reply generation method according to Embodiment 1 of the present application;
[0014] Figure 1C This is a schematic diagram of the sub-step flow of step 104 of a reply generation method according to Embodiment 1 of the present application;
[0015] Figure 1D is a schematic diagram of an isomorphic graph according to Embodiment 1 of the present application;
[0016] Figure 1E A schematic diagram of a response generation model according to Embodiment 1 of the present application;
[0017] Figure 1F This is a schematic diagram of the sub-step flow of step 106 of a reply generation method according to Embodiment 1 of the present application;
[0018] Figure 1G is a schematic diagram of another isomorphic graph according to the first embodiment of the present application;
[0019] Figure 1H is a schematic diagram of a heterogeneous graph replaced with table value labels according to the first embodiment of the present application;
[0020] Figure 2 is a structural block diagram of a data processing device according to Embodiment 2 of the present application;
[0021] Figure 3 This is a schematic diagram of the structure of an electronic device according to the third embodiment of the present application. DETAILED DESCRIPTION
[0022] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the embodiments of the present application should fall within the scope of protection of the embodiments of the present application.
[0023] The specific implementation of the embodiment of the present application is further explained below in conjunction with the accompanying drawings of the embodiment of the present application.
[0024] Embodiment 1
[0025] For ease of understanding, before describing in detail the implementation process of the method of the present application, an exemplary use scenario of the method is described, but the method of the present application is not limited to this use scenario, and it can also be applied to other appropriate scenarios.
[0026] This usage scenario can be an intelligent question-answering system or other scenarios where intelligent conversational robots can be applied, without limitation. Figure 1A As shown, in the intelligent question-answering system, the sentence sent by the user to the intelligent question-answering system can be recorded as a question sentence, and correspondingly, the reply of the intelligent question-answering system is recorded as a reply sentence.
[0027] In one example, the user's question statement is: "What are the Internet companies in China with a market value of more than 1 trillion? What are their market values?"
[0028] Based on the question statement, the intelligent question answering system can convert the question statement into a corresponding SQL statement (such as select company name, market value where market value>10000and country=China). Then use the SQL statement to query the data table of the database to obtain the query results that meet the query conditions of the SQL statement (the query results are as follows Figure 1A Based on the query results, a natural language reply statement can be generated.
[0029] However, in this process, due to the different lengths of the table values in the query results, there may be longer table values, which results in the length of the data input to the neural network model becoming longer when generating the natural language reply statement, thereby increasing the amount of calculation. In addition, some table values have more content (such as the introduction), and their content may have an adverse effect on the accuracy of the reply statement, resulting in an impact on the accuracy of the reply statement.
[0030] This embodiment provides a reply generation method for generating a reply statement. Figure 1B As shown, the method comprises the following steps:
[0031] Step S102: Obtain an SQL statement generated based on the question statement, and a query result of the SQL statement, wherein the query result includes a plurality of table values of different lengths in a data table.
[0032] In one feasible manner, step S102 may be implemented as follows: using the NL2SQL model to obtain an SQL statement corresponding to the question statement; using the SQL statement to query a data table in the data to obtain a query result that satisfies the query condition of the SQL statement.
[0033] The NL2SQL model (Natural Language to SQL) can convert the input natural language into the corresponding SQL statement. For example, the aforementioned "What are the Internet companies in China with a market value of more than 1 trillion? What are their market values?" can be converted into the SQL statement "select company name, market value where market value>10000and country=China".
[0034] By executing SQL statements, the data tables in the database are queried to obtain data that meets the query conditions as query results. The query results corresponding to the aforementioned SQL statements can be represented by the following table:
[0035] Company Name Market value (trillion) AA Ltd. 1.7 BB Group 2.6 CC Co., Ltd. 3.86
[0036] As can be seen from the above table, the lengths of table values (such as company names) in the query results are different and generally long. This means that when generating natural language reply statements based on the query results, the length of the input query data is long and the amount of calculation increases, resulting in reduced efficiency in generating reply statements and a longer waiting time. In addition, because the reply generation model predicts each word in the reply statement when generating a reply statement, the number of words in the corresponding generated reply statement will also increase for cases where the table value is long, which increases the probability of prediction errors. For example, the content of the table value that should be presented as is may be predicted incorrectly, resulting in a decrease in the accuracy of the reply statement.
[0037] In order to solve this problem, in this embodiment, through step S104, the data in the query result is processed.
[0038] Step S104: Map at least part of the table values in the query result into labels of fixed length, and construct a heterogeneous graph based on the SQL statement, the query result, and the mapping result.
[0039] In this step, since the table value content in the query results is usually content that needs to be output to the user as is, it will not affect the semantics of the reply statement. Therefore, at least one table value in the query results can be mapped to a corresponding label to shorten the length of the input data to reduce the amount of calculation and improve the calculation speed. It can also avoid the adverse impact of the semantics of the table value on the prediction accuracy of the reply statement, thereby improving the accuracy of the reply statement.
[0040] Based on the replaced mapping results, in order to ensure the accuracy of the prediction, a heterogeneous graph can be constructed based on the SQL statement, the query result, and the mapping result. By constructing a heterogeneous graph, the structured information in the SQL statement and the data table can be retained, solving the problem of losing the semantics expressed through structured expression when directly converting the SQL statement and the query result into serialized input into the response generation model.
[0041] In one possible approach, Figure 1C As shown, the construction of a heterogeneous graph based on the SQL statement, the query result, and the mapping result can be achieved through the following sub-steps:
[0042] Sub-step S1041: Generate a first graph structure based on the SQL statement, wherein the first graph structure includes a plurality of SQL nodes, and the content of the SQL nodes corresponds to the content of the SQL statement.
[0043] like Figure 1D As shown, the first graph structure includes multiple SQL nodes, and the content of the SQL nodes corresponds to the content of the SQL statement. Taking the aforementioned SQL statement as an example, the first graph structure is established according to the logical relationship of the SQL statement. Among them, the content of the root SQL node is "SQL", and the content of the first-level SQL nodes is "select" and "where" respectively.
[0044] The contents of the next layer of nodes of the SQL node with the content of "select" are "company name" and "market value" respectively.
[0045] The content of the next layer of nodes of the SQL node with the content of "where" is "and". The content of the next layer of nodes of the SQL node with the content of "and" is "=" and ">". The content of the next layer of SQL nodes with the content of "=" is "country" and "China". The content of the next layer of SQL nodes with the content of ">" is "market value" and "10000".
[0046] Sub-step S1042: generating a second graph structure based on the query result, wherein the second graph structure includes a plurality of data table nodes, and the content of at least one of the data table nodes corresponds to a label of a table value in the query result.
[0047] The second graph structure includes a plurality of data table nodes, and the content of at least one of the data table nodes corresponds to a table value in the query result. Figure 1D As shown, the contents of the data table nodes are "Company Name", "Market Value", "AA Co., Ltd." and so on, which are not listed here.
[0048] Since at least part of the table values (such as AA Ltd.) have been replaced with fixed-length tags, the contents of some data table nodes in the generated second graph structure are replaced tags. Tags are fixed-length, and different table values can be mapped to different tags, such as [value_TAG1], [value_TAG2], and so on.
[0049] Sub-step S1043: generating a heterogeneous graph including labels corresponding to the table values according to the first graph structure and the second graph structure.
[0050] For example, according to the attribute relationship between the SQL statement and the query result, the first graph structure and the second graph structure are linked into a heterogeneous graph. Figure 1D The lines between the nodes represent the attribute relationship between the nodes.
[0051] Step S106: Generate a text sequence containing the label based on the connection relationship of the nodes and the content of the nodes in the heterogeneous graph.
[0052] For example, step S106 may be implemented as follows: starting from the root node of the heterogeneous graph, according to the connection relationship between the nodes of the heterogeneous graph, reading the content of each node in the heterogeneous graph to generate the text sequence.
[0053] Step S108: input the text sequence and the heterogeneous graph into the trained response generation model to obtain the natural language sentence with the label output by the response generation.
[0054] The reply generation model can be a trained neural network model. For example, it is a Graph-to-text model. The reply generation model includes an encoder and a decoder. In this embodiment, in order to effectively utilize the advantages of pre-trained language models (PLMs) and improve accuracy, structural bias is introduced into the reply generation model. Specifically, a pre-trained language model containing a structured adapter is used as an encoder (SA-GAT).
[0055] like Figure 1E As shown, the encoder of the reply generation model includes M encoding units, and the encoding unit includes a transformer encoder block (encoding block layer), a layer normalization (normalization layer) and a graph attention network (structured adapter). The decoder of the reply generation model includes M transformer decoder blocks (decoding block layers).
[0056] In one possible approach, Figure 1F As shown, step S108 includes the following sub-steps:
[0057] Sub-step S1081: input the text sequence and the heterogeneous graph into the encoder of the response generation model to obtain the text semantic information in the text sequence and the structural semantic information in the heterogeneous graph.
[0058] In one feasible embodiment, sub-step S1081 can be implemented as follows: use the encoding block layer of the response generation model to encode the semantic information in the text sequence to obtain text semantic information; input the text semantic information into the normalization layer of the response generation model for normalization; input the normalized data and the heterogeneous graph into the structured adapter of the response generation model to obtain the structural semantic information in the heterogeneous graph.
[0059] Since the structured adapter is unique to the response generation model of this embodiment, the process of structure extraction is described as follows:
[0060] Process A: For each node in the heterogeneous graph, calculate the similarity in N dimensions between the feature data of the adjacent nodes connected to the current node in the heterogeneous graph and the feature data of the current node.
[0061] For example, Figure 1D The node with the content of select (denoted as node 1) can have adjacent nodes with the content of company name (denoted as node 2) and market value (denoted as node 3). For node 1 and node 2, the feature data corresponding to node 1 and the feature data corresponding to node 2 are determined from the normalized data. Then, the parameters corresponding to each dimension are used to calculate the similarity between the feature data of node 1 and the feature data of node 2 under that dimension.
[0062] Let n be the dimension that needs to be calculated currently, then n belongs to [1, N]. Different parameters can be trained for different dimensions. For example, the parameter corresponding to the nth dimension can be as well as
[0063] For the vth node, its feature data can be expressed as h v Its similarity with the adjacent h-th node (only nodes that are connected to the v-th node are considered to be its adjacent nodes) can be expressed as
[0064]
[0065] Among them, h h is the characteristic data of the hth adjacent node. Both d and N are fixed values, which can be determined as needed.
[0066] Process B: for the current node, the similarities corresponding to each dimension are normalized to obtain the weights corresponding to the N dimensions.
[0067] The weight can be expressed as It represents the weight between the vth node and its adjacent hth node for the nth dimension.
[0068]
[0069] Where H is the number of all adjacent nodes of the vth node. e is a natural constant.
[0070] Process C: for each dimension of the current node, the feature data corresponding to the dimension is determined according to the weight between the current node and each adjacent node and the feature data of each adjacent node.
[0071] The feature data of dimension can be expressed as z n , which means the characteristic data of the nth attribute.
[0072]
[0073] Among them, h h is the feature data of the hth adjacent node. The feature data corresponding to this dimension may represent the weighted sum of the feature data of all H adjacent nodes of the vth node according to the weight of the attribute.
[0074] Process D: concatenating the feature data of each dimension as the structural semantic information of the current node.
[0075] Structural semantic information can be expressed as h r Among them, h r =concat(z 1 , ..., z N ).
[0076] The structural semantic information of each node can be obtained by the above method for each node. The structural semantic information of each node can be spliced to obtain the semantic information carried in the structured SQL statement and the query result, thereby avoiding semantic loss.
[0077] The text semantic information and the structural semantic information are concatenated, and the concatenated data can be used as input data of the decoder and input into the decoder.
[0078] Sub-step S1082: input the text semantic information and the structural semantic information into the decoder of the response generation model to obtain a natural language sentence with the table value label output by the decoder.
[0079] The decoder may be a transformer decoder model, and the decoder may output a natural language sentence by processing the concatenated data, and the sentence may carry a label.
[0080] Step S110: Replace the label in the sentence output by the reply generation model with the corresponding table value to obtain a natural language reply sentence.
[0081] By replacing the labels with the corresponding table values, the statements output by the response generation model can be made into natural language response statements that carry the table values in the query results.
[0082] In the above manner, based on tag replacement, in the encoder processing stage, the longer table value is replaced with a tag, and in the decoder stage, the tag is converted back to the text of the original table value through the tag dictionary (which is used to characterize the correspondence between the tag and the table value). This speeds up the decoding speed and improves the generation effect, avoiding the information carried in the text of the table value from adding interference information to the semantics of the entire reply statement, which has an adverse effect on the generation of the reply statement. By generating a heterogeneous graph of the query results and SQL statements and processing the heterogeneous graph in the reply generation model, the problem that the encoding block layer needs to input serialized data, resulting in the loss of semantics represented by the structure in the SQL statement and the data table, is solved.
[0083] The following is an example to illustrate the generation process of the reply statement:
[0084] Users input question statements using natural language, such as "What are the products with a yield greater than 5% and relatively low risk?".
[0085] Based on the problem statement, the NL2SQL model is used to automatically generate the SQL statement "select product name, product code where risk level = low and rate of return > 5%".
[0086] By querying the database based on the SQL statement, the query results can be obtained. The query results contain product names that meet the query conditions (such as product name 1, product name 2, etc.) and codes corresponding to the product names (such as F238987, FY3G1563, etc.). Each name or code in these query results, such as product names and codes, is used as a table value. Each character in the product name and code needs to be converted into a token and input into the reply generation model. When different lengths are converted from product name and code representations into input data, the length of the input data is uncertain and the length will be relatively long. This makes the reply generation model have a large amount of calculation during calculation, affecting the processing speed. In addition, the content of some table values (such as introduction, etc.) may also cause interference, resulting in an adverse effect on the semantics of the generated reply statement.
[0087] Based on the SQL statement and query results, the table values in the query results (that is, the queried data is mapped to tags, such as [value_TAG1], [value_TAG2], etc.) can then be used to build a heterogeneous graph based on the SQL statement, query results, and mapping results, such as Figure 1G shown.
[0088] These labels have a fixed length, for example, the length can be 1, so that the amount of calculation will not increase. The heterogeneous graph after replacement is as follows Figure 1H shown.
[0089] According to the replaced heterogeneous graph, its nodes are scanned in the set traversal order to generate a text sequence, and the text sequence and the heterogeneous graph are input into the trained response generation model, which is processed by the response generation model to generate a labeled sentence, which is a natural language sentence (such as "There are two low-risk financial products with a yield greater than 5%, [Value_Tag1], code [Value_Tag3] and [Value_Tag2], code [Value_Tag4]").
[0090] Then, according to the mapping relationship between labels and table values, the labels are replaced with table values to obtain a reply statement for the natural sentence (such as "There are two low-risk financial products with a yield greater than 5%, product name No. 1, code F239889 and product name No. 2, code FY3G1566"). This reply statement can be used to reply to the user.
[0091] By experimenting with this method, the experimental results show that the ResponseNLG dataset BLUE is improved by 2.7 (from 56.6 to 59.3), and the average length of the token input to the decoder is reduced from 39.4 to 24.8, a reduction of 39%, achieving an improvement.
[0092] Through label replacement, longer table values are converted into labels, and then the labels are mapped back to the original table value descriptions through the mapping dictionary during output, which can shorten the model input length and speed up the decoding speed.
[0093] The method of this embodiment can be executed by any appropriate electronic device with data processing capability, including but not limited to: a server, a mobile terminal (such as a mobile phone, a PAD, etc.) and a PC, etc.
[0094] Embodiment 2
[0095] Reference Figure 2 , showing a structural block diagram of a reply generating device according to a second embodiment of the present application.
[0096] The reply generating device comprises:
[0097] A first acquisition module 202, used to acquire an SQL statement generated based on the question statement, and a query result of the SQL statement, wherein the query result includes a plurality of table values of different lengths in a data table;
[0098] A construction module 204, configured to map at least part of the table values in the query result into labels of fixed length, and to construct a heterogeneous graph based on the SQL statement, the query result, and the mapping result;
[0099] A generating module 206, configured to generate a text sequence including the label based on the connection relationship of the nodes and the content of the nodes in the heterogeneous graph;
[0100] A second acquisition module 208, configured to input the text sequence and the heterogeneous graph into a trained response generation model, and acquire a natural language sentence with the label output by the response generation;
[0101] The third acquisition module 210 is used to replace the label in the sentence output by the reply generation model with the corresponding table value to obtain a reply sentence in natural language.
[0102] Optionally, the construction module 204 is used to generate a first graph structure based on the SQL statement, the first graph structure including multiple SQL nodes, and the content of the SQL nodes corresponds to the content of the SQL statement; generate a second graph structure based on the query result, the second graph structure including multiple data table nodes, and the content of at least one of the data table nodes corresponds to the label of the table value in the query result; and generate a heterogeneous graph containing labels corresponding to the table values based on the first graph structure and the second graph structure.
[0103] Optionally, the construction module 204 is used to link the first graph structure and the second graph structure into a heterogeneous graph according to the attribute relationship between the SQL statement and the query result when generating a heterogeneous graph according to the first graph structure and the second graph structure.
[0104] Optionally, the generating module 206 is used to start from the root node of the heterogeneous graph and read the content of each node in the heterogeneous graph according to the connection relationship between the nodes of the heterogeneous graph to generate the text sequence.
[0105] Optionally, the second acquisition module 208 is used to input the text sequence and the heterogeneous graph into the encoder of the response generation model to obtain the text semantic information in the text sequence and the structural semantic information in the heterogeneous graph; input the text semantic information and the structural semantic information into the decoder of the response generation model to obtain the natural language sentence with the table value label output by the decoder.
[0106] Optionally, the second acquisition module 208 is used to, when the text sequence and the heterogeneous graph are input into the encoder of the response generation model to obtain the text semantic information in the text sequence and the structural semantic information in the heterogeneous graph, use the encoding block layer of the response generation model to encode the semantic information in the text sequence to obtain the text semantic information; input the text semantic information into the normalization layer of the response generation model for normalization; input the normalized data and the heterogeneous graph into the structured adapter of the response generation model to obtain the structural semantic information in the heterogeneous graph.
[0107] The device of this embodiment is used to implement the corresponding methods in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here. In addition, the functional implementation of each module in the device of this embodiment can refer to the description of the corresponding parts in the aforementioned method embodiments, which will not be repeated here.
[0108] Embodiment 3
[0109] Reference Figure 3 , shows a schematic diagram of the structure of an electronic device according to the third embodiment of the present application. The specific embodiment of the present application does not limit the specific implementation of the electronic device.
[0110] like Figure 3 As shown, the electronic device may include: a processor (processor) 302 , a communication interface (Communications Interface) 304 , a memory (memory) 306 , and a communication bus 308 .
[0111] in:
[0112] The processor 302 , the communication interface 304 , and the memory 306 communicate with each other via the communication bus 308 .
[0113] The communication interface 304 is used to communicate with other electronic devices or servers.
[0114] The processor 302 is used to execute the program 310, and specifically can execute the relevant steps in the above method embodiment.
[0115] Specifically, the program 310 may include program codes, which include computer operation instructions.
[0116] The processor 302 may be a processor CPU, or an application specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in the smart device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0117] The memory 306 is used to store the program 310. The memory 306 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0118] The program 310 may be specifically used to enable the processor 302 to execute operations corresponding to the aforementioned method.
[0119] The specific implementation of each step in program 310 can refer to the corresponding description of the corresponding steps and units in the above method embodiment, which will not be repeated here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described devices and modules can refer to the corresponding process description in the above method embodiment, which will not be repeated here.
[0120] An embodiment of the present application also provides a computer program product, including computer instructions, which instruct a computing device to execute operations corresponding to any one of the above-mentioned multiple method embodiments.
[0121] It should be pointed out that, according to the needs of implementation, the various components / steps described in the embodiments of the present application can be split into more components / steps, or two or more components / steps or partial operations of components / steps can be combined into new components / steps to achieve the purpose of the embodiments of the present application.
[0122] The above-mentioned method according to the embodiment of the present application can be implemented in hardware, firmware, or implemented as software or computer code that can be stored in a recording medium (such as a CD ROM, RAM, floppy disk, hard disk or magneto-optical disk), or implemented as a computer code originally stored in a remote recording medium or a non-temporary machine-readable medium downloaded through a network and to be stored in a local recording medium, so that the method described herein can be stored in such software processing on a recording medium using a general-purpose computer, a special-purpose processor or programmable or special-purpose hardware (such as an ASIC or FPGA). It can be understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component (e.g., RAM, ROM, flash memory, etc.) that can store or receive software or computer code, and when the software or computer code is accessed and executed by a computer, a processor or hardware, the method described herein is implemented. In addition, when a general-purpose computer accesses the code for implementing the method shown here, the execution of the code converts the general-purpose computer into a special-purpose computer for executing the method shown here.
[0123] Those of ordinary skill in the art will appreciate that the units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present application.
[0124] The above implementation methods are only used to illustrate the embodiments of the present application, and are not limitations on the embodiments of the present application. Ordinary technicians in the relevant technical field can make various changes and modifications without departing from the spirit and scope of the embodiments of the present application. Therefore, all equivalent technical solutions also belong to the scope of the embodiments of the present application. The scope of patent protection of the embodiments of the present application should be limited by the claims.
Claims
1. A reply generation method, comprising: Obtaining an SQL statement generated based on the question statement and a query result of the SQL statement, wherein the query result includes a plurality of table values of different lengths in a data table; Mapping at least part of the table values in the query result into labels of a fixed length, and constructing a heterogeneous graph based on the SQL statement, the query result, and the mapping result, wherein the length of the table value is greater than the fixed length, the mapping result is used to represent the label of the fixed length after the table value is mapped, and the nodes and edges of the heterogeneous graph are respectively determined based on the SQL statement, the query result, and the content of the mapping result and the attribute relationship between the three; Based on the connection relationship of the nodes in the heterogeneous graph and the content of the nodes, a text sequence including the label is generated; Inputting the text sequence and the heterogeneous graph into a trained response generation model, and obtaining a natural language sentence with the label output by the response generation model; The labels in the sentences output by the reply generation model are replaced with corresponding table values to obtain natural language reply sentences.
2. The method according to claim 1, wherein: The constructing a heterogeneous graph based on the SQL statement, the query result, and the mapping result includes: Generate a first graph structure based on the SQL statement, the first graph structure including a plurality of SQL nodes, the content of the SQL nodes corresponding to the content of the SQL statement; generating a second graph structure based on the query result, the second graph structure comprising a plurality of data table nodes, wherein content of at least one of the data table nodes corresponds to a label of a table value in the query result; A heterogeneous graph including labels corresponding to the table values is generated according to the first graph structure and the second graph structure.
3. The method according to claim 2, wherein: Generating a heterogeneous graph according to the first graph structure and the second graph structure includes: According to the attribute relationship between the SQL statement and the query result, the first graph structure and the second graph structure are linked into a heterogeneous graph.
4. The method according to claim 2, wherein: The generating a text sequence containing the label based on the connection relationship of the nodes and the content of the nodes in the heterogeneous graph includes: Starting from the root node of the heterogeneous graph, the content of each node in the heterogeneous graph is read according to the connection relationship between the nodes of the heterogeneous graph to generate the text sequence.
5. The method according to claim 2, wherein: Inputting the text sequence and the heterogeneous graph into a trained response generation model, and obtaining a natural language sentence with the label output by the response generation model, including: Inputting the text sequence and the heterogeneous graph into the encoder of the response generation model to obtain text semantic information in the text sequence and structural semantic information in the heterogeneous graph; The text semantic information and the structural semantic information are input into the decoder of the response generation model to obtain a natural language sentence with the table value label output by the decoder.
6. The method according to claim 5, wherein: The step of inputting the text sequence and the heterogeneous graph into the encoder of the response generation model to obtain text semantic information in the text sequence and structural semantic information in the heterogeneous graph includes: Using the coding block layer of the response generation model to encode the semantic information in the text sequence to obtain text semantic information; Inputting the text semantic information into the normalization layer of the response generation model for normalization processing; The normalized data and the heterogeneous graph are input into the structured adapter of the response generation model to obtain the structural semantic information in the heterogeneous graph.
7. A reply generating device, comprising: A first acquisition module, used to acquire an SQL statement generated based on the question statement, and a query result of the SQL statement, wherein the query result includes a plurality of table values of different lengths in a data table; A construction module, used to map at least part of the table values in the query result into a label of a fixed length, and to construct a heterogeneous graph based on the SQL statement, the query result, and the mapping result, wherein the length of the table value is greater than the fixed length, the mapping result is used to represent the label of the fixed length after the table value is mapped, and the nodes and edges of the heterogeneous graph are respectively determined based on the SQL statement, the query result, and the content of the mapping result and the attribute relationship between the three; A generation module, used for generating a text sequence containing the label based on the connection relationship of the nodes and the content of the nodes in the heterogeneous graph; A second acquisition module, used for inputting the text sequence and the heterogeneous graph into a trained response generation model, and acquiring a natural language sentence with the label output by the response generation model; The third acquisition module is used to replace the label in the sentence output by the reply generation model with the corresponding table value to obtain a natural language reply sentence.
8. An electronic device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the method according to any one of claims 1 to 6.
9. A computer storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising computer instructions, wherein the computer instructions instruct a computing device to execute operations corresponding to the method according to any one of claims 1 to 6.
