Query statement generation method and device, model training method and device, and medium
By combining the encoding and generation modules of dialogue records and database information, semantic features are deeply mined, solving the problem of low accuracy of query statements in existing technologies, and realizing the generation of accurate query statements in dialogue interaction.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- PING AN TECH (SHENZHEN) CO LTD
- Filing Date
- 2022-07-29
- Publication Date
- 2026-07-03
Smart Images

Figure CN115238143B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a query statement generation method and apparatus, a model training method, device, and medium. Background Technology
[0002] With the development of big data, interaction between natural language and databases has become a new technological hotspot. Currently, keywords are extracted from users' natural language, and query statements can be generated based on these keywords. This allows users to quickly retrieve the content they need from massive amounts of data in the database. However, this method is prone to losing complex semantic information, resulting in lower accuracy of the generated query statements. Summary of the Invention
[0003] The main objective of this application is to provide a query statement generation method and apparatus, model training method, device, and medium that can improve the accuracy of generated query statements.
[0004] To achieve the above objectives, a first aspect of this application proposes a query statement generation method, the method comprising:
[0005] The process involves: acquiring dialogue records and database information, wherein the dialogue records include first dialogue information and second dialogue information, the first dialogue information including the most recently sent dialogue information in the dialogue records, and the second dialogue information including all other dialogue information in the dialogue records except for the first dialogue information; acquiring a statement generation model, wherein the statement generation model includes an encoding module and a generation module; inputting the first dialogue information and the database information into the encoding module for encoding processing to obtain target sequence information; inputting the second dialogue information and the database information into the encoding module for encoding processing to obtain historical sequence information; and inputting the dialogue records, the target sequence information, and the historical sequence information into the generation module for statement generation to obtain a target query statement.
[0006] In some implementations, the encoding module includes an encoding network, a first attention network, and a sequence generation network; the step of inputting the first dialogue information and the database information into the encoding module for encoding processing to obtain target sequence information includes:
[0007] The first dialogue information and the database information are input into the encoding network for word vector encoding to obtain a first word vector corresponding to the first dialogue information and a second word vector corresponding to the database information; the first word vector and the second word vector are input into the first attention network for processing to obtain a first attention result; the first word vector and the first attention result are input into the sequence generation network for processing to obtain target sequence information.
[0008] In some implementations, the database information includes the name of at least one data table and data item information of the data table, the data item information being used to determine the data items included in the data table, and the second word vector including a first sub-vector corresponding to the data table and a second sub-vector corresponding to the data item information; the step of inputting the first word vector and the second word vector into the first attention network for processing to obtain a first attention result includes:
[0009] The first word vector and the first sub-vector are input into the first attention network for processing to obtain a first attention result; the first word vector and the second sub-vector are input into the first attention network for processing to obtain a second attention result; the first attention result and the second attention result are determined as the first attention result.
[0010] In some implementations, the step of inputting the first dialogue information and the database information into the encoding network for word vector encoding to obtain a first word vector corresponding to the first dialogue information and a second word vector corresponding to the database information includes:
[0011] The first dialogue information is segmented to obtain a segmentation set; at least one table name and data item information of the data table are obtained from the database information, the data item information being used to determine the data items included in the data table; a table set is constructed based on all the table names; a data item set is constructed based on the data item information of the data table; the segmentation set, the table set, and the data item set are concatenated into an input sequence; the input sequence is input into the encoding network for word vector encoding to obtain a first word vector corresponding to the first dialogue information and a second word vector corresponding to the database information.
[0012] In some implementations, the generation module includes a second attention network, a splicing module, and a decoding module; the step of inputting the dialogue record, the target sequence information, and the historical sequence information into the generation module for sentence generation to obtain the target query statement includes:
[0013] The target sequence information is input into the second attention network for processing to obtain the first weight information corresponding to the target sequence information; the first weight information and the dialogue record are concatenated by the concatenation module to obtain the statement feature vector; the statement feature vector is input into the decoding module for decoding to obtain the target query statement.
[0014] In some implementations, the step of concatenating the first weight information and the dialogue record through the splicing module to obtain a statement feature vector includes:
[0015] Historical question information and historical response information are obtained from the second dialogue information, wherein the historical response information is used to respond to the historical question information; based on the historical question information and the first dialogue information, feedback information corresponding to the historical response information is analyzed, wherein the feedback information is used to indicate the degree of matching between the historical response information and the historical question information; based on the feedback information, second weight information of the historical response information is determined; and the first weight information, the second weight information, and the dialogue record are concatenated by the splicing module to obtain a statement feature vector.
[0016] To achieve the above objectives, a second aspect of this application proposes a model training method for training a statement generation model as described in the first aspect of this application, the method comprising:
[0017] Obtain a dialogue sample and its corresponding initial query statement, wherein the dialogue sample includes at least two dialogue messages; obtain database information and determine query syntax rules based on the database information; convert the initial query statement into a reference query statement according to the query syntax rules, wherein the reference query statement satisfies the syntax structure corresponding to the query syntax rules; input the dialogue sample, the database information, and the reference query statement into a preset generation model for training processing to obtain a statement generation model.
[0018] To achieve the above objectives, a third aspect of this application provides a query statement generation apparatus, the apparatus comprising:
[0019] The first acquisition module is used to acquire dialogue records and database information. The dialogue records include first dialogue information and second dialogue information. The first dialogue information includes the most recently sent dialogue information in the dialogue records, and the second dialogue information includes dialogue information in the dialogue records other than the first dialogue information. The module also acquires a statement generation model, which includes an encoding module and a generation module.
[0020] The first encoding module is used to input the first dialogue information and the database information into the encoding module for encoding processing to obtain target sequence information;
[0021] The second encoding module is used to input the second dialogue information and the database information into the encoding module for encoding processing to obtain historical sequence information;
[0022] The generation module is used to input the dialogue record, the target sequence information and the historical sequence information into the generation module to generate a statement and obtain the target query statement.
[0023] To achieve the above objectives, a fourth aspect of the present application provides an electronic device including at least one memory;
[0024] At least one processor;
[0025] At least one computer program;
[0026] The computer program is stored in the memory, and the processor executes the at least one computer program to achieve:
[0027] The query statement generation method as described in any of the embodiments of the first aspect; or
[0028] The model training method as described in the second aspect embodiment.
[0029] To achieve the above objectives, a fifth aspect of this application also provides a computer-readable storage medium storing computer-executable instructions for causing a computer to perform:
[0030] The query statement generation method as described in any of the embodiments of the first aspect; or
[0031] The model training method as described in the second aspect embodiment.
[0032] The query statement generation method, apparatus, model training method, device, and medium proposed in this application pre-train a statement generation model, which includes an encoding module and a generation module. The first dialogue information and the second dialogue information, along with database information, are input into the encoding module for encoding to obtain target sequence information and historical sequence information. Then, the dialogue records, target sequence information, and historical sequence information are input into the generation module to generate the target query statement. This allows for in-depth analysis of the correlation between each dialogue message and database information within a dialogic context, without losing complex semantic information. It also enables better handling of complex database query structures such as nesting and multi-table joins based on database information, thereby improving the accuracy of the generated query statement. Attached Figure Description
[0033] Figure 1 This is a flowchart of the query statement generation method provided in the embodiments of this application;
[0034] Figure 2 yes Figure 1 A specific flowchart of step S103;
[0035] Figure 3 This is a schematic diagram illustrating the application of a statement generation model in an embodiment of this application;
[0036] Figure 4 yes Figure 1 A schematic diagram of a specific process for step S105;
[0037] Figure 5 This is a flowchart of the model training method provided in the embodiments of this application;
[0038] Figure 6 This is a block diagram of the query statement generation device provided in the embodiments of this application;
[0039] Figure 7 This is a block diagram of the model training device provided in the embodiments of this application;
[0040] Figure 8 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0041] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0042] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0043] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0044] First, let's analyze some of the terms used in this application:
[0045] Artificial Intelligence (AI) is a new branch of computer science that studies, develops, and applies theories, methods, technologies, and systems to simulate, extend, and expand human intelligence. It aims to understand the essence of intelligence and produce intelligent machines that can react in a way similar to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing, and expert systems. AI can simulate the information processes of human consciousness and thought. Furthermore, AI utilizes digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceiving the environment, acquiring knowledge, and using that knowledge to achieve optimal results.
[0046] Natural Language Processing (NLP): NLP uses computers to process, understand, and utilize human language (such as Chinese and English). It is a branch of artificial intelligence and an interdisciplinary field of computer science and linguistics, often referred to as computational linguistics. NLP includes syntactic analysis, semantic analysis, and discourse understanding. It is commonly used in machine translation, handwritten and printed character recognition, speech recognition and text-to-speech conversion, information retrieval, information extraction and filtering, text classification and clustering, sentiment analysis, and opinion mining. It involves data mining, machine learning, knowledge acquisition, knowledge engineering, artificial intelligence research, and linguistic research related to language computation.
[0047] BERT (Bidirectional Encoder Representation from Transformers) model: The BERT model further enhances the generalization ability of word embedding models, fully describing character-level, word-level, sentence-level, and even inter-sentence relationship features, and is built based on Transformers. BERT has three types of embeddings: Token Embedding, Segment Embedding, and Position Embedding. Token Embeddings are word vectors, with the first word as a CLS marker, which can be used for subsequent classification tasks. Segment Embeddings are used to distinguish between two types of sentences because pre-training involves not only LM but also classification tasks with two sentences as input. Position Embeddings, where the positional word vectors are not trigonometric functions from Transformer, but rather learned by BERT during training. However, BERT directly trains a Positionembedding to preserve positional information. A vector is randomly initialized for each position and added to the model training, resulting in an embedding containing positional information. Finally, BERT chooses to directly concatenate this Position embedding with the word embedding.
[0048] With the development of big data, interaction between natural language and databases has become a new technological hotspot. Currently, keywords are extracted from users' natural language, and query statements can be generated based on these keywords. This allows users to quickly retrieve the content they need from massive amounts of data in the database. However, this method is prone to losing complex semantic information, resulting in lower accuracy of the generated query statements.
[0049] Based on this, embodiments of this application provide a query statement generation method and apparatus, a model training method, a device, and a medium, which can improve the accuracy of generated query statements.
[0050] This application provides a query statement generation method and apparatus, a model training method, a device, and a medium, which are specifically described through the following embodiments. First, the query statement generation method in this application is described.
[0051] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence is the theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0052] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0053] The query statement generation method and model training method provided in this application relate to the field of artificial intelligence technology, and particularly to the field of data processing technology. The query statement generation method or model training method provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, or smartwatch, etc.; the server can be an independent server or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms; the software can be an application implementing the query statement generation method or model training method, but is not limited to the above forms.
[0054] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0055] The following describes the query statement generation method and model training method provided in the embodiments of this application, taking the terminal as an example.
[0056] Firstly, please refer to Figure 1 , Figure 1This is a flowchart of a query statement generation method provided in an embodiment of this application. The query statement generation method includes steps S101 to S105. It should be understood that the query statement generation method in this embodiment includes, but is not limited to, steps S101 to S105. The following is in conjunction with... Figure 1 A detailed introduction will be provided.
[0057] Step S101: Obtain dialogue records and database information. The dialogue records include first dialogue information and second dialogue information.
[0058] This application's embodiments are applicable to various dialogue interaction scenarios, such as online conversations (e.g., at least two users conversing through social media) and human-computer dialogues (e.g., online customer service, automated Q&A, and robot tutoring). The dialogue records can include all dialogue information from at least two conversational partners, or N newly published or selected dialogue messages that meet specified filtering criteria. N is a positive integer and is set manually, without specific limitations. For example, each conversational partner can be a user on a different terminal, suitable for applications such as private chats or group chats; or, the at least two conversational partners include a first conversational partner and a second conversational partner, where the first conversational partner can refer to a user and the second conversational partner can refer to a terminal, suitable for applications of human-computer dialogue.
[0059] Based on this, the dialogue log is divided into first dialogue information and second dialogue information. First dialogue information includes the most recently sent dialogue information in the log, while second dialogue information includes all dialogue information except for the first dialogue information; that is, the second dialogue information was sent before the first dialogue information. Methods for obtaining dialogue logs may include, but are not limited to: 1. The terminal has software or plugins with dialogue communication capabilities installed (such as customer service robots, outbound call robots, voice assistants, and other third-party social communication software). The terminal can then obtain dialogue information manually or verbally input by the user, as well as receive dialogue information sent by other terminals, through the front end of the aforementioned software (or plugins). 2. The terminal responds to a statement generation command and directly obtains the information content corresponding to the statement generation command as the dialogue log. The triggering method for the statement generation command may include, but is not limited to, text operations, image operations, or other preset operations, such as the user selecting a piece of text in the terminal's interface. 3. The terminal obtains the dialogue log file input by the user and parses the dialogue log from the file. The dialogue log file can be a file exported from third-party social communication software, used to record dialogue information in a specified format (such as text format or database file).
[0060] The dialogue log may contain identifying information, including but not limited to the speaking account, separator, and timestamp. The terminal can then determine the first and second dialogue information from the dialogue log according to the instructions of the identifying information. For example, the dialogue information corresponding to the latest timestamp can be used as the first dialogue information, and the dialogue information in the dialogue log other than the first dialogue information can be used as the second dialogue information.
[0061] In this embodiment of the application, the database information may include a database schema, which is used to describe the logical structure and characteristics of all data in the database. The database information may also include the table name of the data table and the data item information of the data table. The data item information is used to determine the data items included in the data table. The data item may refer to the row data or column data included in the data table. Therefore, the data item information may include the data row name or the data column name, etc., without any specific limitation.
[0062] Step S102: Obtain the statement generation model, which includes an encoding module and a generation module.
[0063] In this embodiment, the encoding module combines dialogue information and database information to encode sequence information, thereby fully mining the semantic features of the dialogue information, the pattern features of the database, and the correlation features between the dialogue information and the database; the generation module generates query statements based on the sequence information. The encoding module can use pre-trained language models such as the Transform model or the BERT model, and the generation module can use models such as the Generative Adversarial Network (GAN) model or the Seq2Seq model, etc., without specific limitations.
[0064] Step S103: Input the first dialogue information and database information into the encoding module for encoding processing to obtain the target sequence information.
[0065] Step S104: Input the second dialogue information and database information into the encoding module for encoding processing to obtain historical sequence information.
[0066] Step S105: Input the dialogue record, target sequence information and historical sequence information into the generation module to generate the statement and obtain the target query statement.
[0067] In this embodiment, the target query statement can be a statement that conforms to the query syntax rules of the database. The database can be MySQL, Hive, SQL Server, Redis, Kafka, etc., and correspondingly, the target query statement can be Structured Query Language (SQL) or other database languages, adjusted according to the type of database, without specific limitations. In practical applications, the terminal can directly execute the target query statement to perform query operations on the database. For example, assuming the database is MySQL, if the dialogue record is "Please help me find product A suitable for people aged 60 and older," then the target query statement can be "select product from database where age≥60 and productNo='A'".
[0068] As can be seen, the query statement generation method proposed in this application can, in the context of dialogue interaction, combine the context information of the dialogue to deeply explore the correlation between each dialogue message and the database information. This way, complex semantic information is not lost, and complex database query structures such as nesting and multi-table joins can be better handled based on the database information, thereby improving the accuracy of the generated query statement.
[0069] In step S103 of some embodiments, the encoding module may include an encoding network, a first attention network, and a sequence generation network. See also... Figure 2 , Figure 2 yes Figure 1 A schematic diagram of a specific process for step S103. For example... Figure 2 As shown, step S103 may include, but is not limited to, the following steps S201 to S203.
[0070] Step S201: Input the first dialogue information and the database information into the encoding network for word vector encoding to obtain the first word vector corresponding to the first dialogue information and the second word vector corresponding to the database information.
[0071] Specifically, the encoding network can be a BERT network. Figure 3 Let's take an example to illustrate. Figure 3 This is a schematic diagram illustrating the application of a statement generation model in an embodiment of this application. For example... Figure 3 As shown, by inputting the first dialogue information and database information into the encoding network, the first word vector H output by the encoding network can be obtained. q1 Second word vector H d1 .
[0072] In some embodiments, step S201 may include, but is not limited to, the following steps:
[0073] First, the first dialogue information is segmented to obtain a segmentation set. This segmentation set includes at least two words extracted from the first dialogue information; for example, the segmentation set Q = {q1, q2, q3…q}. n}, where n is a positive integer. Word segmentation methods may include, but are not limited to: using word segmentation tools, such as hanlp and Baidu NLP; employing dictionary-based segmentation methods, such as forward maximum matching and shortest path methods; and employing statistical segmentation methods, such as hidden Markov models and N-grams.
[0074] Furthermore, it retrieves the table name and data item information of at least one data table from the database information, thereby constructing a table set based on all table names, and a data item set based on the data item information of the data tables. For example, the table set T = {t1, t2, t3, ..., t...} x}, collection of data items Where x is the total number of data tables. This refers to the information of the m-th data item included in the first data table. Let x be the information of the y-th data item included in the x-th data table, where x, m, and y are all positive integers.
[0075] Next, the word segmentation set, table set, and data item set are concatenated into the input sequence. Specifically, the word segmentation set Q, table set T, and data item set C can be concatenated using a preset delimiter to obtain the input sequence X = [CLS]Q[SEP]TC[SEP], where [CLS] is the start marker of the input sequence, and [SEP] is the preset delimiter used to separate different types of information to ensure the accuracy of the concatenation process.
[0076] Finally, the input sequence is fed into the encoding network for word vector encoding to obtain the first word vector corresponding to the first dialogue information and the second word vector corresponding to the database information.
[0077] It is evident that concatenating the vocabulary in the first dialogue information with the data tables and data items in the database information to form an input sequence facilitates the generation of deep bidirectional language representations.
[0078] Step S202: Input the first word vector and the second word vector into the first attention network for processing to obtain the first attention result.
[0079] Specifically, the first attention network can employ attention mechanisms, including but not limited to key-value pair attention, multi-head attention, and self-attention. The first attention network focuses on the association features between the first and second word vectors, ignoring unimportant parts. The first attention result can be used to represent the attention weights assigned to the first word vector.
[0080] In step S202 of some embodiments, the database information includes the table name of at least one data table and the data item information of the data table, and the second word vector includes a first sub-vector corresponding to the data table and a second sub-vector corresponding to the data item information. Therefore, step S202 may include, but is not limited to, the following steps: inputting the first word vector and the first sub-vector into a first attention network for processing to obtain a first processing result; inputting the first word vector and the second sub-vector into the first attention network for processing to obtain a second processing result; and concatenating the first processing result and the second processing result into a first attention result.
[0081] In some optional implementations, if the first attention network adopts a multi-head attention mechanism, then when the first word vector and the first sub-vector are input into the first attention network for processing, the j-th first head attention... The calculation formula is as follows:
[0082] Where j is a positive integer and j∈[1, n], W q W k and W v Here are the three weight matrices of the first attention network, H Q H is the first word vector. T d is the first subvector; k W q With W k The dimension of the attention serves a normalization function, preventing excessively large attention values from causing partial derivatives to approach 0. It also satisfies the data distribution conditions of expectation being 0 and variance being 1, thereby stabilizing the variance of the vector dot product to 1. Based on this, the first processing result is obtained by concatenating all the first head attention values.
[0083] Similarly, when the first word vector and the second sub-vector are input into the first attention network for processing, the j-th second head attention... The calculation formula is as follows:
[0084] Among them, H C This is the second sub-vector. Based on this, the second processing result is obtained by concatenating all the second head attentions.
[0085] Step S203: Input the first word vector and the first attention result into the sequence generation network for processing to obtain the target sequence information.
[0086] Specifically, in step S203, the first word vector and the first attention result can be concatenated first, and then the concatenated result can be input into the sequence generation network for processing to obtain a question representation containing dialogue information and database information interaction. The sequence generation network can be a recurrent neural network (RNN), a bidirectional long short-term memory network (BiLSTM), or a convolutional neural network (CNN), etc., without specific limitations.
[0087] As can be seen, in the above steps S201 to S203, by using the attention mechanism to mine the key correlation features between dialogue information and database information, and then combining the dialogue information to generate a sequence, it is beneficial to further improve the accuracy of the subsequent generated query statements.
[0088] It is understood that, similar to the implementation of step S103, in some embodiments, step S104 may include, but is not limited to, the following steps: inputting the second dialogue information and database information into an encoding network for word vector encoding to obtain the third word vector corresponding to the second dialogue information and the fourth word vector corresponding to the database information, such as... Figure 3 The third word vector H shown q2 and the fourth word vector H d2 The third and fourth word vectors are input into the first attention network for processing to obtain the second attention result. The third word vector and the second attention result are then input into the sequence generation network for processing to obtain historical sequence information. It can be understood that if the second dialogue information includes multiple dialogue pieces, then the historical sequence information includes the sequence information encoded from each of the above dialogue pieces. In other words, each dialogue piece included in the second dialogue information is input into the encoding network along with the database information for word vector encoding.
[0089] Furthermore, the fourth word vector includes the third sub-vector corresponding to the data table and the fourth sub-vector corresponding to the data item information. Similar to the implementation of step S202, the third and fourth word vectors are input into the first attention network for processing to obtain the second attention result. This may include, but is not limited to, the following steps: inputting the third word vector and the third sub-vector into the first attention network for processing to obtain a third processing result; inputting the third word vector and the fourth sub-vector into the first attention network for processing to obtain a fourth processing result; and concatenating the third and fourth processing results to form the second attention result.
[0090] In step S105 of some embodiments, the generation module may include a second attention network, a splicing module, and a decoding module. See also... Figure 4 , Figure 4 yes Figure 1A schematic diagram of a specific process for step S105. For example... Figure 4 As shown, step S105 may include, but is not limited to, the following steps S401 to S403.
[0091] Step S401: Input the target sequence information and historical sequence information into the second attention network for processing to obtain the first weight information.
[0092] The second attention network is used to perform attention processing on the correlation features between the target sequence information and the historical sequence information. The details of the second attention network can be found in the description of the first attention network, and will not be repeated here.
[0093] Step S402: The first weight information and the dialogue record are concatenated by the concatenation module to obtain the statement feature vector.
[0094] Steps S401 and S402 utilize the sequence information of historical dialogues to process the sequence information of the latest dialogue, thereby aligning and supplementing the dialogue context information. In one implementation, the first weight information includes weight information corresponding to the first dialogue information and weight information corresponding to the second dialogue information. The first dialogue information is processed using the weight information corresponding to the first dialogue information to obtain a first weighted result. The second dialogue information is then weighted using the weight information corresponding to the second dialogue information to obtain a second weighted result. Based on this, the first weighted result and the second weighted result are concatenated into a sentence feature vector. This allows for weighting of the first and second dialogue information separately based on their correlation before concatenation. In another implementation, the first weight information can also be concatenated with the first dialogue information to form a sentence feature vector. Therefore, the second attention network can directly weight the first dialogue information based on its correlation with the second dialogue information, emphasizing the enhancement effect on the first dialogue information.
[0095] In some embodiments, step S402 may include, but is not limited to, the following steps:
[0096] First, retrieve historical question information and historical response information from the second dialogue information. The historical response information is used to answer the historical question information.
[0097] Optionally, the conversation object corresponding to each conversation message in the second conversation information can be obtained; that is, each conversation message is sent by the corresponding conversation object. Conversation messages with the first preset object as the conversation object are added to the historical question information, and conversation messages with the second preset object as the conversation object are added to the historical response information. The first and second preset objects are different and can both be manually set and adjusted. For example, in a human-computer dialogue scenario, the first preset object is the user, and the second preset object is the terminal.
[0098] For example, the content of a single dialogue interaction might be as follows:
[0099] Q1: Could you please help me find products suitable for people aged 60 and above?
[0100] A1: Returns a list of product names applicable to ages 60 and up, such as Category A products and Category B products.
[0101] Q2: What are the specific uses, prices, and shelf life of Category A products?
[0102] A2: Returns a data table related to the use, price, and shelf life of Class A products.
[0103] Q3: What's the difference between Category B products and this?
[0104] Therefore, in the above multi-round dialogue interaction, Q1 and Q2 are historical question information, A1 and A2 are historical response information, and Q3 is the first dialogue information.
[0105] Next, based on the historical question information and the first dialogue information, the feedback information corresponding to the historical response information is analyzed. The feedback information is used to indicate the degree of matching between the historical response information and the historical question information. Based on the feedback information, the second weight information of the historical response information is determined.
[0106] Optionally, evaluation keywords, such as "yes" or "no," can be extracted from historical question information and initial dialogue information. Matching values are then obtained for different evaluation keywords, and second weighting information is calculated based on these matching values. For example, second weighting information = sum of matching values for all evaluation keywords ÷ F, where F represents the preset total matching value, which is determined based on the number and / or type of all evaluation keywords.
[0107] Alternatively, historical response information, historical question information, and first dialogue information can be input into a deep learning model composed of DQN and Bellman equations to obtain second weight information. This deep learning model is used to calculate the matching value between historical response information and historical question information.
[0108] Finally, the concatenation module concatenates the first weight information, the second weight information, and the dialogue record to obtain the sentence feature vector. Specifically, the first weight information is used to weight the dialogue record to obtain the third weighted result, and the second weight information is used to weight the second dialogue information in the dialogue record to obtain the fourth weighted result. The third weighted result and the fourth weighted result are then concatenated to form the sentence feature vector.
[0109] As can be seen, by introducing the first weight information, the content of the first dialogue information can be completed by connecting it with the context information of multiple rounds of dialogue, such as parsing the relationship between "this" and "A-type product" in Q3. By introducing the second weight information, the feedback effect of historical response information can be effectively analyzed, and the weight ratio of historical response information in the generation of statement feature vectors can be adaptively adjusted according to the feedback effect, ensuring that the generated query statement can fully consider the actual response effect of the second dialogue information and improve the accuracy of the query statement.
[0110] Step S403: Input the statement feature vector into the decoding module for decoding processing to obtain the target query statement.
[0111] The decoding module can be a decoder that combines the query syntax rules of the database and is built based on a neural network. It is trained and used in conjunction with the encoding module.
[0112] Secondly, please refer to Figure 5 , Figure 5 This is a flowchart of a model training method provided in an embodiment of this application. This model training method is used to train a sentence generation model as shown in the above method embodiment. The model training method includes, but is not limited to, steps S501 to S504. The following is in conjunction with… Figure 5 A detailed introduction will be provided.
[0113] Step S501: Obtain the dialogue sample and the initial query statement corresponding to the dialogue sample.
[0114] The dialogue sample includes at least two dialogue messages.
[0115] Step S502: Obtain database information and determine query syntax rules based on the database information.
[0116] It is understandable that the specific query syntax rules are related to the databases and their types included in the database information.
[0117] Step S503: Convert the initial query statement into a reference query statement according to the query syntax rules.
[0118] The initial query statement is used to retrieve the target data indicated by the dialogue sample, while the reference query statement conforms to the database's query syntax structure. For example, if the initial query statement is "query product A", the reference query statement is obtained by converting the initial query statement into SQL.
[0119] Step S504: Input the dialogue sample, database information and reference query statement into the preset generation model for training processing to obtain the statement generation model.
[0120] Specifically, in step S504, the dialogue sample and database information are input into a preset generation model to generate a statement, resulting in an output query statement. The similarity between the output query statement and the reference query statement is calculated using the loss function of the preset generation model. Based on the similarity, the loss function of the preset generation model is optimized. The model loss of the loss function is backpropagated, and the model parameters are continuously adjusted until the similarity is greater than or equal to the similarity threshold. At this point, the optimization of the preset generation model is stopped, resulting in a statement generation model that meets the requirements.
[0121] Please refer to Figure 6 , Figure 6 This is a block diagram of a query statement generation apparatus provided in an embodiment of this application. In some embodiments, the query statement generation apparatus includes a first acquisition module 601, a first encoding module 602, a second encoding module 603, and a generation module 604.
[0122] The first acquisition module 601 is used to acquire dialogue records and database information. The dialogue records include first dialogue information and second dialogue information. The first dialogue information includes the most recently sent dialogue information in the dialogue records, and the second dialogue information includes dialogue information in the dialogue records other than the first dialogue information. The module also acquires a statement generation model, which includes an encoding module and a generation module.
[0123] The first encoding module 602 is used to input the first dialogue information and database information into the encoding module for encoding processing to obtain the target sequence information.
[0124] The second encoding module 603 is used to input the second dialogue information and database information into the encoding module for encoding processing to obtain historical sequence information.
[0125] The generation module 604 is used to input the dialogue record, target sequence information and historical sequence information into the generation module to generate the statement and obtain the target query statement.
[0126] It should be noted that the query statement generation device in this application corresponds to the aforementioned query statement generation method. For the specific training process, please refer to the aforementioned query statement generation method, which will not be described in detail here.
[0127] Please refer to Figure 7 , Figure 7 This is a block diagram of a model training apparatus provided in an embodiment of this application. In some embodiments, the model training apparatus includes a second acquisition module 701, a determination module 702, a conversion module 703, and a training module 704.
[0128] The second acquisition module 701 is used to acquire dialogue samples and the initial query statements corresponding to the dialogue samples, wherein the dialogue samples include at least two dialogue information items; and to acquire database information.
[0129] The determination module 702 is used to determine the query syntax rules based on the database information.
[0130] The conversion module 703 is used to convert the initial query statement into a reference query statement according to the query syntax rules. The reference query statement satisfies the syntax structure corresponding to the query syntax rules.
[0131] Training module 704 is used to input dialogue samples, database information and reference query statements into a preset generation model for training processing to obtain a statement generation model.
[0132] It should be noted that the model training device in this application corresponds to the aforementioned model training method. For specific model training steps, please refer to the aforementioned model training method, which will not be repeated here.
[0133] This application also provides an electronic device, including:
[0134] At least one memory;
[0135] At least one processor;
[0136] At least one program;
[0137] The program is stored in memory, and the processor executes at least one program to implement the query statement generation method or model training method described above in this disclosure. The electronic device can be any smart terminal, including mobile phones, tablets, personal digital assistants (PDAs), and in-vehicle computers.
[0138] The electronic device according to the embodiments of this application will be described in detail below with reference to the figures.
[0139] like Figure 8 , Figure 8 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes:
[0140] The processor 801 can be implemented using a general-purpose central processing unit (CPU), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.
[0141] The memory 802 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 802 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 802 and is called and executed by the processor 801 using the query statement generation method or model training method of the embodiments of this application.
[0142] The 803 input / output interface is used to implement information input and output.
[0143] The communication interface 804 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0144] Bus 805 transmits information between various components of the device (e.g., processor 801, memory 802, input / output interface 803, and communication interface 804);
[0145] The processor 801, memory 802, input / output interface 803, and communication interface 804 are connected to each other within the device via bus 805.
[0146] This application also provides a storage medium, which is a computer-readable storage medium storing computer-executable instructions for causing a computer to execute the above-described query statement generation method or model training method.
[0147] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0148] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0149] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0150] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0151] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0152] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0153] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0154] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0155] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0156] Furthermore, the functional units in the various embodiments of this application 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 integrated unit can be implemented in hardware or as a software functional unit.
[0157] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause an electronic device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0158] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A query statement generation method characterized by comprising: The method includes: Acquire dialogue records and database information. The dialogue records include first dialogue information and second dialogue information. The first dialogue information includes the most recently sent dialogue information in the dialogue records. The second dialogue information includes dialogue information in the dialogue records other than the first dialogue information. The dialogue records record identification information, which is used to identify the first dialogue information and the second dialogue information. The database information includes at least one of the following: database schema, table name, and data item information of the table. Obtain a statement generation model, which includes an encoding module and a generation module; The first dialogue information and the database information are input into the encoding module for encoding processing to obtain the target sequence information; The second dialogue information and the database information are input into the encoding module for encoding processing to obtain historical sequence information; The dialogue record, the target sequence information, and the historical sequence information are input into the generation module to generate a statement, thereby obtaining the target query statement. The encoding module includes an encoding network and a first attention network; the step of inputting the first dialogue information and the database information into the encoding module for encoding processing to obtain target sequence information includes: The first dialogue information and the database information are input into the encoding network for word vector encoding to obtain the first word vector corresponding to the first dialogue information and the second word vector corresponding to the database information. The first word vector and the second word vector are input into the first attention network for processing to obtain the first attention result; The database information includes at least one table name and data item information of the data table, wherein the data item information is used to determine the data items included in the data table, and the second word vector includes a first sub-vector corresponding to the data table and a second sub-vector corresponding to the data item information; the step of inputting the first word vector and the second word vector into the first attention network for processing to obtain a first attention result includes: The first word vector and the first sub-vector are input into the first attention network for processing to obtain the first processing result; The first word vector and the second sub-vector are input into the first attention network for processing to obtain the second processing result; The first processing result and the second processing result are concatenated to form the first attention result.
2. The method of claim 1, wherein, The encoding module further includes a sequence generation network; the step of inputting the first dialogue information and the database information into the encoding module for encoding processing to obtain target sequence information further includes: The first word vector and the first attention result are input into the sequence generation network for processing to obtain the target sequence information.
3. The method of claim 2, wherein, The step of inputting the first dialogue information and the database information into the encoding network for word vector encoding to obtain a first word vector corresponding to the first dialogue information and a second word vector corresponding to the database information includes: The first dialogue information is processed by word segmentation to obtain a word segmentation set; Obtain the table name of at least one data table and the data item information of the data table from the database information, wherein the data item information is used to determine the data items included in the data table; Construct a table set based on all the table names mentioned; Based on the data item information in the data table, construct a data item set; The word segmentation set, the table set, and the data item set are concatenated into an input sequence; The input sequence is input into the encoding network for word vector encoding to obtain a first word vector corresponding to the first dialogue information and a second word vector corresponding to the database information.
4. The method according to any one of claims 1 to 3, characterized in that, The generation module includes a second attention network, a splicing module, and a decoding module; the step of inputting the dialogue record, the target sequence information, and the historical sequence information into the generation module to generate a statement and obtain a target query statement includes: The target sequence information and the historical sequence information are input into the second attention network for processing to obtain the first weight information; The first weight information and the dialogue record are concatenated using the splicing module to obtain a statement feature vector. The feature vector of the statement is input into the decoding module for decoding processing to obtain the target query statement.
5. The method of claim 4, wherein, The step of concatenating the first weight information and the dialogue record using the concatenation module to obtain a statement feature vector includes: Historical question information and historical answer information are obtained from the second dialogue information, and the historical answer information is used to answer the historical question information; Based on the historical question information and the first dialogue information, the feedback information corresponding to the historical response information is analyzed, and the feedback information is used to indicate the degree of matching between the historical response information and the historical question information; Based on the feedback information, determine the second weight information of the historical response information; The splicing module splices the first weight information, the second weight information, and the dialogue record to obtain a statement feature vector.
6. A model training method, comprising: The method for training the sentence generation model as described in any one of claims 1 to 5 includes: Obtain a dialogue sample and the initial query statement corresponding to the dialogue sample, wherein the dialogue sample includes at least two dialogue messages; Obtain database information and determine query syntax rules based on the database information; According to the query syntax rules, the initial query statement is converted into a reference query statement; The dialogue sample, the database information, and the reference query statement are input into a preset generation model for training to obtain a statement generation model.
7. A query statement generating apparatus characterized by comprising: The device includes: A first acquisition module is used to acquire dialogue records and database information. The dialogue records include first dialogue information and second dialogue information. The first dialogue information includes the most recently sent dialogue information in the dialogue records, and the second dialogue information includes dialogue information in the dialogue records other than the first dialogue information. The dialogue records contain identification information used to identify the first dialogue information and the second dialogue information. The database information includes at least one of the following: database schema, table name, and data item information of the table. The module also acquires a statement generation model, which includes an encoding module and a generation module. The first encoding module is used to input the first dialogue information and the database information into the encoding module for encoding processing to obtain target sequence information; The second encoding module is used to input the second dialogue information and the database information into the encoding module for encoding processing to obtain historical sequence information; The generation module is used to input the dialogue record, the target sequence information and the historical sequence information into the generation module to generate a statement and obtain the target query statement; The encoding module includes an encoding network and a first attention network; the step of inputting the first dialogue information and the database information into the encoding module for encoding processing to obtain target sequence information includes: The first dialogue information and the database information are input into the encoding network for word vector encoding to obtain the first word vector corresponding to the first dialogue information and the second word vector corresponding to the database information. The first word vector and the second word vector are input into the first attention network for processing to obtain the first attention result; The database information includes at least one table name and data item information of the data table, wherein the data item information is used to determine the data items included in the data table, and the second word vector includes a first sub-vector corresponding to the data table and a second sub-vector corresponding to the data item information; the step of inputting the first word vector and the second word vector into the first attention network for processing to obtain a first attention result includes: The first word vector and the first sub-vector are input into the first attention network for processing to obtain the first processing result; The first word vector and the second sub-vector are input into the first attention network for processing to obtain the second processing result; The first processing result and the second processing result are concatenated to form the first attention result.
8. An electronic device, comprising: include: At least one memory; At least one processor; At least one computer program; The computer program is stored in the memory, and the processor executes the at least one computer program to achieve: The query statement generation method as described in any one of claims 1 to 5; or The model training method as described in claim 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions for causing a computer to perform: The query statement generation method as described in any one of claims 1 to 5; or The model training method of claim 6.