Intelligent response method and device, terminal equipment and storage medium
By extracting database entities and generating SQL statements in intelligent response technology, the problem of insufficient accuracy in SQL statement generation in the prior art is solved, and the accuracy of intelligent response is improved.
Patent Information
- Application Number
- CN202411131992.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2024-12-31
AI Technical Summary
The generation accuracy of SQL statements in existing intelligent response technologies is low, resulting in insufficient accuracy of intelligent responses.
By obtaining the problem information to be answered, extracting the entities of the preset type, determining the target database table, and generating SQL statements based on the problem information, table name and scheme information, and executing them to obtain the response result. This method uses a pre-trained entity extraction model and SQL statement generation model, combining word vectors, sentence vectors and position vectors to optimize the entity extraction and SQL generation process.
It improves the accuracy of intelligent responses, the generated SQL statements are more accurate, can effectively find problem information, and improves the quality of response results.
Smart Images

Figure CN119226326A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of artificial intelligence technology, and in particular, relates to an intelligent response method, apparatus, terminal device and storage medium. Background Art
[0002] At present, with the continuous development of artificial intelligence, intelligent answers are increasingly widely used in people's lives. In some intelligent answer implementation methods, it is necessary to obtain the target database table based on the question information to be answered, and then generate an SQL statement for finding the answer result of the question information based on the question information and the target database table information. In actual applications, we found that the generation accuracy of SQL statements is low, which reduces the accuracy of intelligent answers. Summary of the invention
[0003] In view of this, the embodiments of the present application provide an intelligent response method, apparatus, terminal device and storage medium to solve the technical problem of low accuracy of intelligent response in the prior art.
[0004] In a first aspect, an embodiment of the present application provides an intelligent response method, including:
[0005] Get information about questions to be answered;
[0006] Extracting entities of a preset type from the question information;
[0007] Determine a target database table according to the extracted entity;
[0008] Obtain the table name and Scheme information of the target database table;
[0009] Generate an SQL statement for searching for a response result of the question information according to the question information, the table name and Scheme information of the target database table;
[0010] Execute the SQL statement to obtain the response result.
[0011] Optionally, extracting entities of a preset type in the question information includes:
[0012] The query content entity, query condition entity and query target entity in the question information are extracted through a pre-trained target entity extraction model.
[0013] Optionally, the target entity extraction model is trained in the following way:
[0014] Obtaining a training data set and a pre-trained entity extraction model; wherein the training data set includes a plurality of sample questions in which query content entities, query condition entities, and query target entities have been identified;
[0015] Convert each of the sample questions into a corresponding word vector, sentence vector and position vector respectively;
[0016] According to the word vectors, sentence vectors and position vectors corresponding to each of the multiple sample questions, combined with the query content entities, query condition entities and query target entities corresponding to each of the multiple sample questions, the pre-trained entity extraction model is optimized and trained, and the pre-trained entity extraction model after optimization and training is determined as the target entity extraction model.
[0017] Optionally, determining a target database table according to the extracted entity includes:
[0018] According to the extracted entity, respectively calculate the relevance between the entity and each table in the database;
[0019] The table with the highest correlation is selected from the various tables as the target database table.
[0020] Optionally, the step of calculating, based on the extracted entity, the relevance between the entity and each table in the database includes:
[0021] Converting the extracted entity into a first vector;
[0022] For each table in the database, the relevance between the table and the entity is calculated based on the second vector of the table and the first vector; wherein the second vector is a vector converted based on the table name of the table.
[0023] Optionally, calculating the relevance between the table and the entity according to the second vector and the first vector of the table includes:
[0024] Determine each first sub-vector in the first vector, each second sub-vector in the second vector, and a corresponding relationship between each first sub-vector and each second sub-vector;
[0025] For each of the first sub-vectors, calculate the product of the first sub-vector and the corresponding second sub-vector;
[0026] Determine a sum of products of each of the first sub-vectors and the corresponding second sub-vector as a first value;
[0027] The product of the modulus of the first vector and the modulus of the second vector is determined as a second value, and the ratio of the first value to the second value is determined as the relevance of the table to the entity.
[0028] Optionally, generating an SQL statement for searching for a response result to the question information according to the question information, the table name and Scheme information of the target database table includes:
[0029] Using a preset text prompt word template, the question information, the table name of the target database table and Scheme information are combined into a prompt text;
[0030] The prompt text is input into a trained SQL statement generation model for processing to generate the SQL statement.
[0031] In a second aspect, an embodiment of the present application provides an intelligent response device, including:
[0032] A question information acquisition unit, used to acquire question information to be answered;
[0033] An entity extraction unit, used to extract entities of a preset type from the question information;
[0034] A table determination unit, used to determine a target database table according to the extracted entity;
[0035] A table information acquisition unit, used to acquire the table name and Scheme information of the target database table;
[0036] An SQL statement generating unit, configured to generate an SQL statement for searching for a response result of the question information according to the question information, the table name and Scheme information of the target database table;
[0037] The response result obtaining unit is used to execute the SQL statement to obtain the response result.
[0038] In a third aspect, an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements each step of the intelligent response method as described in any one of the first aspects above when executing the computer program.
[0039] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, each step in the intelligent response method as described in any one of the first aspects above is implemented.
[0040] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on a terminal device, the terminal device executes each step of the method described in the first aspect or any optional method of the first aspect.
[0041] The intelligent response method, apparatus, terminal device and storage medium provided in the embodiments of the present application have the following features:
[0042] Beneficial effects:
[0043] The intelligent answering method provided by the embodiment of the present application obtains the question information to be answered, extracts the entities of the preset type in the question information, and determines the target database table according to the extracted entities, and then obtains the table name and Scheme information of the target database table, and then generates an SQL statement for finding the answer result of the question information according to the question information, the table name and Scheme information of the target database table, and finally executes the SQL statement to obtain the answer result. The intelligent answering method of the present application comprehensively considers the question information, the table name and Scheme information of the target database table when generating the SQL statement, and can generate more accurate SQL statements, thereby improving the accuracy of the intelligent answer. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0045] Figure 1 A flowchart of an implementation of an intelligent response method provided in an embodiment of the present application;
[0046] Figure 2 A schematic diagram of the structure of an intelligent response device provided in an embodiment of the present application;
[0047] Figure 3 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0048] It should be noted that the terms used in the embodiments of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application. In the description of the embodiments of the present application, unless otherwise specified, "multiple" refers to two or more than two, and "at least one", "one or more" refers to one, two or more. The terms "first" and "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, it is defined that the "first" and "second" features can explicitly or implicitly include one or more of the features.
[0049] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present application. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear at different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0050] The execution subject of the intelligent response method provided in the embodiment of the present application may be a terminal device, such as a mobile phone, a tablet computer, a laptop computer, a desktop computer, or other terminal devices.
[0051] The intelligent response method provided in the embodiment of the present application can be applied in various intelligent response scenarios. When the user requires the terminal device to implement intelligent response (such as the user needs to obtain certain information), the user can input the question information to be answered into the terminal device, and the terminal device can execute the various steps of the intelligent response method provided in the embodiment of the present application, thereby realizing intelligent response and improving the accuracy of intelligent response.
[0052] See also Figure 1 , Figure 1 The following is a flowchart of an implementation of an intelligent response method provided in an embodiment of the present application. The intelligent response method may include S101 to S106, which are described in detail as follows:
[0053] In S101, information on questions to be answered is obtained.
[0054] In the embodiment of the present application, the user can input the question information to be answered into the terminal device, so that the terminal device can obtain the question information to be answered.
[0055] In S102, entities of a preset type are extracted from the question information.
[0056] In an embodiment of the present application, after obtaining the question information to be answered, the terminal device can extract entities of a preset type in the question information.
[0057] In a possible implementation, the terminal device can extract the query content entity, query condition entity and query target entity in the question information through a pre-trained target entity extraction model. The query content entity can be used to represent the query content information in the question information to be answered, the query condition entity can be used to represent the query condition information in the question information to be answered, and the query target entity can be used to represent the query target information in the question information to be answered.
[0058] Among them, the terminal device can be trained through steps a to c to obtain the target entity extraction model.
[0059] Details are as follows:
[0060] In step a, a training dataset and a pre-trained entity extraction model are obtained.
[0061] In this implementation, the training data set may include a plurality of sample questions in which query content entities, query condition entities, and query target entities have been identified.
[0062] In actual applications, the user can manually mark the query content entity, query condition entity and query target entity for each sample question in the training data set. After the marking is completed, the user can input the training data set including multiple sample questions with identified query content entities, query condition entities and query target entities into the terminal device, so that the terminal device can obtain the training data set including multiple sample questions with identified query content entities, query condition entities and query target entities.
[0063] In addition, the user can input the pre-trained entity extraction model into the terminal device so that the terminal device can obtain the pre-trained entity extraction model. The pre-trained entity extraction model can be obtained by the user through pre-training in advance, or by obtaining an existing entity extraction model.
[0064] In step b, each sample question is converted into a corresponding word vector, sentence vector, and position vector.
[0065] In actual applications, after the terminal device obtains the training data set and the pre-trained entity extraction model, each sample question can be converted into corresponding word vectors (Token Embeddings), sentence vectors (Segment Embeddings), and position vectors (Position Embeddings).
[0066] For example, the terminal device can obtain the text vector sequence X=(x1, x2, x3, ..., x n), the vector sequence may include word vectors, sentence vectors, and position vectors, which can effectively extract text features of sample questions and include the relationship between words in the sample questions and context information.
[0067] In step c, the pre-trained entity extraction model is optimized and trained according to the word vectors, sentence vectors and position vectors corresponding to each of the multiple sample questions, combined with the query content entities, query condition entities and query target entities corresponding to each of the multiple sample questions, and the optimized pre-trained entity extraction model is determined as the target entity extraction model.
[0068] In this implementation, after the terminal device converts each sample question into a corresponding word vector, sentence vector and position vector respectively, it can optimize the training of the pre-trained entity extraction model based on the word vectors, sentence vectors and position vectors corresponding to each of the multiple sample questions, combined with the query content entities, query condition entities and query target entities corresponding to each of the multiple sample questions.
[0069] Exemplarily, the pre-trained entity extraction model can be a bidirectional long short-term memory network (Long Short-Term Memory, LSTM) model. Based on this, the text vector sequence obtained in step b can be used as the input of each time step of the bidirectional LSTM model to obtain a bidirectional LSTM hidden state sequence (forward) and (Backward), after all the forward and backward processing is completed, each hidden state sequence can be spliced according to the position to obtain a complete hidden state sequence, which is recorded as h t =(h1, h2, h3, ..., h n )∈R n ×m , and then the linear output layer maps the complete hidden state sequence to s dimensions (assuming the label Y = (y1, y2, ..., y s ), s is the number of labels) and the sequence after all the extracted sentences are mapped is L = (l1, l2, l3, ..., l n )∈R n×s , l i ∈R s , where l ij Represents x i Each corresponding label y j The probability value of .
[0070] After that, the CRF layer in the bidirectional LSTM model can be used to model the probability value of each label obtained above through conditional probability. The final loss function is expressed as:
[0071]
[0072] Among them, P RealPath Represents the true path probability value of the text sequence, the denominator is P1+P2+...+P N Probability values for all paths.
[0073] The terminal device can obtain the minimum value of the loss function and use gradient descent and back propagation to adjust the preset parameters of the entity extraction model. Finally, the entity extraction model with the highest accuracy can be determined as the target entity extraction model.
[0074] In S103, a target database table is determined according to the extracted entities.
[0075] In an embodiment of the present application, after extracting an entity, the terminal device can determine a target database table based on the extracted entity.
[0076] In a possible implementation, the terminal device may determine the target database table through steps d to e. The details are as follows:
[0077] In step d, based on the extracted entities, the relevance between the entities and each table in the database is calculated respectively.
[0078] In this implementation, the terminal device may calculate the relevance between each table in the database and the extracted entity according to the extracted entity.
[0079] Specifically, the terminal device may first convert the extracted entity into a first vector. The specific conversion method may be set according to actual needs and is not limited here.
[0080] After converting the extracted entity into the first vector, the terminal device can calculate the correlation between the table and the extracted entity for each table in the database according to the second vector of the table and the obtained first vector. The second vector is a vector converted according to the table name of the table. In actual applications, the terminal device can convert each table into the second vector in advance. The specific conversion method can be set according to actual needs and is not limited here.
[0081] More specifically, the terminal device may calculate the correlation between the table and the extracted entity according to the second vector of the table and the obtained first vector in the following manner:
[0082] First, the terminal device may determine each first sub-vector in the first vector, each second sub-vector in the second vector, and the corresponding relationship between each first sub-vector and each second sub-vector. Afterwards, the terminal device may calculate the product of each first sub-vector and the corresponding second sub-vector for each first sub-vector. Afterwards, the terminal device may determine the sum of the products of each first sub-vector and the corresponding second sub-vector as a first value. Finally, the terminal device may determine the product of the modulus of the first vector and the modulus of the second vector as a second value, and determine the ratio of the first value to the second value as the relevance of the table to the entity.
[0083] In step e, the table with the highest correlation is selected from various tables as the target database table.
[0084] In this implementation, after calculating the relevance between each table in the database and the extracted entity, the terminal device may select a table with the highest relevance from each table as the target database table.
[0085] In S104, the table name and Scheme information of the target database table are obtained.
[0086] In the embodiment of the present application, after determining the target database table, the terminal device can obtain the table name and Scheme information of the target database table.
[0087] The Scheme information may include a table creation statement of a target database table. Exemplarily, the Scheme information may include a field name, data type, and description of the target database table.
[0088] In S105, an SQL statement for searching for a response result of the question information is generated according to the question information, the table name of the target database table, and the Scheme information.
[0089] In an embodiment of the present application, after obtaining the table name and Scheme information of the target database table, the terminal device can generate an SQL statement for finding a response result to the question information based on the question information, the table name and Scheme information of the target database table.
[0090] In a possible implementation, the terminal device can generate an SQL statement through step f and step g. The details are as follows:
[0091] In step f, a preset text prompt word template is used to combine the question information, the table name of the target database table and the Scheme information into a prompt text.
[0092] In this implementation, the terminal device can input the question information, the table name of the target database table, and the Scheme information into corresponding positions in the preset text prompt word template, so as to obtain the prompt text.
[0093] In practical applications, the preset text prompt word template can be set according to actual needs and is not specifically limited here.
[0094] In step g, the prompt text is input into the trained SQL statement generation model for processing to generate an SQL statement.
[0095] In this implementation, after obtaining the prompt text, the terminal device can input the prompt text into a trained SQL statement generation model for processing, and obtain the SQL statement generated by the SQL statement generation model.
[0096] Optionally, a pre-trained SQL statement generation model may be obtained, and the pre-trained SQL statement generation model may be fine-tuned using the obtained training data set in a LoRA manner to obtain a trained SQL statement generation model.
[0097] The trained SQL statement generation model may be a Text2SQL model.
[0098] In S106, the SQL statement is executed to obtain a response result.
[0099] In an embodiment of the present application, after generating an SQL statement for searching for a response result to question information, the terminal device can execute the SQL statement to obtain the response result.
[0100] After obtaining the response result, the terminal device can feed back the obtained response result to the user so that the user can obtain the response result.
[0101] From the above, it can be seen that the intelligent answering method provided by the embodiment of the present application obtains the question information to be answered, extracts the entities of the preset type in the question information, and determines the target database table based on the extracted entities, and then obtains the table name and Scheme information of the target database table, and then generates an SQL statement for finding the answer result of the question information based on the question information, the table name and Scheme information of the target database table, and finally executes the SQL statement to obtain the answer result. The intelligent answering method of the present application comprehensively considers the question information, the table name and Scheme information of the target database table when generating the SQL statement, and can generate more accurate SQL statements, thereby improving the accuracy of the intelligent answer.
[0102] Based on the intelligent response method provided in the above embodiment, the present application further provides an intelligent response device for implementing the above method embodiment. Figure 2 , Figure 2 This is a schematic diagram of the structure of an intelligent response device provided in an embodiment of the present application. Figure 2 As shown, the intelligent answering device 20 may include a question information acquisition unit 21, an entity extraction unit 22, a table determination unit 23, a table information acquisition unit 24, an SQL statement generation unit 25, and a response result acquisition unit 26. Among them:
[0103] The question information obtaining unit 21 is used to obtain question information to be answered.
[0104] The entity extraction unit 22 is used to extract entities of a preset type in the question information.
[0105] The table determination unit 23 is used to determine the target database table according to the extracted entities.
[0106] The table information acquisition unit 24 is used to acquire the table name and Scheme information of the target database table.
[0107] The SQL statement generating unit 25 is used to generate an SQL statement for searching for a response result of the question information according to the question information, the table name and Scheme information of the target database table.
[0108] The response result acquisition unit 26 is used to execute the SQL statement to acquire the response result.
[0109] Optionally, the entity extraction unit 22 is specifically used for:
[0110] The query content entity, query condition entity and query target entity in the question information are extracted through the pre-trained target entity extraction model.
[0111] Optionally, the intelligent response device 20 may also include a target entity extraction model training unit.
[0112] Among them, the target entity extraction model training unit is specifically used for:
[0113] Obtaining a training data set and a pre-trained entity extraction model; wherein the training data set includes a plurality of sample questions in which query content entities, query condition entities, and query target entities have been identified;
[0114] Convert each sample question into corresponding word vector, sentence vector and position vector respectively;
[0115] According to the word vectors, sentence vectors and position vectors corresponding to multiple sample questions, and combined with the query content entities, query condition entities and query target entities corresponding to the multiple sample questions, the pre-trained entity extraction model is optimized and trained, and the optimized pre-trained entity extraction model is determined as the target entity extraction model.
[0116] Optionally, the table determination unit 23 is specifically configured to:
[0117] According to the extracted entities, the relevance between the entities and each table in the database is calculated respectively;
[0118] Select the table with the highest relevance from each table as the target database table.
[0119] Optionally, the table determination unit 23 is specifically configured to:
[0120] Convert the extracted entity into a first vector;
[0121] For each table in the database, the relevance between the table and the entity is calculated based on the second vector and the first vector of the table; wherein the second vector is a vector converted based on the table name of the table.
[0122] Optionally, the table determination unit 23 is specifically configured to:
[0123] Determine each first sub-vector in the first vector, each second sub-vector in the second vector, and a corresponding relationship between each first sub-vector and each second sub-vector;
[0124] For each first sub-vector, calculate the product of the first sub-vector and the corresponding second sub-vector;
[0125] Determine the sum of the products of each first sub-vector and the corresponding second sub-vector as a first value;
[0126] The product of the modulus of the first vector and the modulus of the second vector is determined as a second value, and the ratio of the first value to the second value is determined as the relevance of the table to the entity.
[0127] Optionally, the SQL statement generating unit 25 is specifically used for:
[0128] Use the preset text prompt word template to combine the question information, the table name of the target database table and the Scheme information into a prompt text;
[0129] The prompt text is input into the trained SQL statement generation model for processing to generate an SQL statement.
[0130] It should be noted that the information interaction, execution process and other contents between the above-mentioned units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be specifically referred to the method embodiment part and will not be repeated here.
[0131] See also Figure 3 , Figure 3 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application. Figure 3 As shown, the terminal device 3 provided in this embodiment may include: a processor 30, a memory 31, and a computer program 32 stored in the memory 31 and executable on the processor 80. For example, a program corresponding to smart answering. When the processor 30 executes the computer program 32, the steps applied in the smart answering embodiment are implemented, for example Figure 1 Alternatively, when the processor 30 executes the computer program 32, the functions of each module / unit in the above-mentioned embodiment of the intelligent response device 20 are realized, for example Figure 2 The functions of the units 21 to 26 are shown.
[0132] Exemplarily, the computer program 32 may be divided into one or more modules / units, one or more modules / units are stored in the memory 31 and executed by the processor 30 to complete the present application. The one or more modules / units may be a series of computer program instruction segments that can complete specific functions, and the instruction segments are used to describe the execution process of the computer program 32 in the terminal device 3. For example, the computer program 32 may be divided into a question information acquisition unit 21, an entity extraction unit 22, a table determination unit 23, a table information acquisition unit 24, an SQL statement generation unit 25, and a response result acquisition unit 26. For the specific functions of each unit, please refer to Figure 2 The relevant descriptions in the corresponding embodiments are not repeated here.
[0133] Those skilled in the art will understand that Figure 3 It is only an example of the terminal device 3 and does not constitute a limitation on the terminal device 3. The terminal device 3 may include more or less components than shown in the figure, or a combination of certain components, or different components.
[0134] The processor 30 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc.
[0135] The memory 31 may be an internal storage unit of the terminal device 3, such as a hard disk or memory of the terminal device 3. The memory 31 may also be an external storage device of the terminal device 3, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, or a flash card, etc., equipped on the terminal device 3. Further, the memory 31 may also include both an internal storage unit and an external storage device of the terminal device 3. The memory 31 is used to store computer programs and other programs and data required by the terminal device. The memory 31 may also be used to temporarily store data that has been output or is to be output.
[0136] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units is used as an example for illustration. In actual applications, the above-mentioned functions can be assigned to different functional units as needed, that is, the internal structure of the intelligent response device can be divided into different functional units to complete all or part of the functions described above. The functional units in the embodiment can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0137] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0138] An embodiment of the present application provides a computer program product. When the computer program product is executed on a terminal device, the terminal device implements the steps in the above-mentioned various method embodiments.
[0139] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0140] Those of ordinary skill in the art will appreciate that the units and algorithm 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 this application.
[0141] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. An intelligent answering method, characterized in that: include: Get information about questions to be answered; Extracting entities of a preset type from the question information; Determine a target database table according to the extracted entity; Obtain the table name and Scheme information of the target database table; Generate an SQL statement for searching for a response result of the question information according to the question information, the table name and Scheme information of the target database table; Execute the SQL statement to obtain the response result.
2. The method according to claim 1, characterized in that The extracting entities of a preset type from the question information includes: The query content entity, query condition entity and query target entity in the question information are extracted through a pre-trained target entity extraction model.
3. The method according to claim 2, characterized in that The target entity extraction model is trained in the following way: Obtaining a training data set and a pre-trained entity extraction model; wherein the training data set includes a plurality of sample questions in which query content entities, query condition entities, and query target entities have been identified; Convert each of the sample questions into a corresponding word vector, sentence vector and position vector respectively; According to the word vectors, sentence vectors and position vectors corresponding to each of the multiple sample questions, combined with the query content entities, query condition entities and query target entities corresponding to each of the multiple sample questions, the pre-trained entity extraction model is optimized and trained, and the pre-trained entity extraction model after optimization and training is determined as the target entity extraction model.
4. The method according to claim 1, characterized in that Determining a target database table according to the extracted entity includes: According to the extracted entity, respectively calculate the relevance between the entity and each table in the database; The table with the highest correlation is selected from the various tables as the target database table.
5. The method according to claim 4, characterized in that The step of calculating the relevance between the extracted entity and each table in the database includes: Converting the extracted entity into a first vector; For each table in the database, the relevance of the table to the entity is calculated based on the second vector of the table and the first vector; wherein the second vector is a vector converted based on the table name of the table.
6. The method according to claim 5, characterized in that The calculating, based on the second vector of the table and the first vector, the relevance between the table and the entity comprises: Determine each first sub-vector in the first vector, each second sub-vector in the second vector, and a corresponding relationship between each first sub-vector and each second sub-vector; For each of the first sub-vectors, calculate the product of the first sub-vector and the corresponding second sub-vector; Determine a sum of products of each of the first sub-vectors and the corresponding second sub-vector as a first value; The product of the modulus of the first vector and the modulus of the second vector is determined as a second value, and the ratio of the first value to the second value is determined as the relevance of the table to the entity.
7. The method according to claim 1, characterized in that The step of generating an SQL statement for searching for a response result to the question information according to the question information, the table name and Scheme information of the target database table comprises: Using a preset text prompt word template, the question information, the table name of the target database table and Scheme information are combined into a prompt text; The prompt text is input into a trained SQL statement generation model for processing to generate the SQL statement.
8. An intelligent answering device, characterized in that: include: A question information acquisition unit, used to acquire question information to be answered; An entity extraction unit, used to extract entities of a preset type from the question information; A table determination unit, used to determine a target database table according to the extracted entity; A table information acquisition unit, used to acquire the table name and Scheme information of the target database table; An SQL statement generating unit, configured to generate an SQL statement for searching for a response result of the question information according to the question information, the table name and Scheme information of the target database table; The response result obtaining unit is used to execute the SQL statement to obtain the response result.
9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, each step of the intelligent response method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, each step of the intelligent response method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Intelligent question answering method, apparatus, computer device and storage medium
CN109522393A
Data query method and device, electronic equipment and storage medium
CN116303537A
Interaction response method and device based on intention recognition, equipment and storage medium
CN116541493A
Automated few-shot learning techniques for artificial intelligence-based query answering systems
US20230186147A1
