Example selection method, problem identification model training method, device and equipment
By identifying the question intent and calculating the similarity of the input text in the Text-to-SQL task, the target example is obtained, which solves the problems of high cost and low efficiency of example selection in the existing technology, improves the accuracy of the query statement, and is applicable Suitable for multiple databases and multiple rounds of text-to-SQL scenarios.
Patent Information
- Application Number
- CN202410660686.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-24
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-05-24
Smart Images

Figure CN118626587A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an example selection method, a training method, a device and equipment for a problem recognition model. Background Art
[0002] The Text-to-SQL task is to convert natural language questions in text into SQL query statements through a large language model (LLM). It can lower the threshold for database use and greatly improve data processing efficiency. When processing the Text-to-SQL task, adaptive examples will be provided in the input prompts of the large language model, thereby improving the accuracy of the query statements output by the large language model.
[0003] In some example selection schemes for Text-to-SQL tasks, examples are manually selected from pre-annotated examples and applied to all question texts. However, in this scheme, the query statements output by the large language model have low accuracy and high labor costs. Summary of the invention
[0004] The present application provides an example selection method, a training method, a device and equipment for a problem recognition model, so as to solve the problems of high cost and low efficiency of example selection.
[0005] In a first aspect, the present application provides an example selection method, comprising:
[0006] Perform question intent recognition on the input text to obtain the target question text;
[0007] Determine a target question data table corresponding to the target question text; wherein the target question data table includes at least one example, and the example includes a question text and a query statement;
[0008] Obtaining a first similarity between the target question text and the example question text in the target question data table, and obtaining a second similarity between a reference query statement and the example question text in the target question data table; wherein the reference query statement is a query statement obtained by inputting a large language model into the target question text;
[0009] A target example is obtained from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table.
[0010] In an implementable manner, the number of the input texts is multiple, and the step of performing question intent recognition on the input texts to obtain a target question text includes:
[0011] Multiple texts are sequentially input into the pre-trained question recognition model, and the target question text corresponding to each text is obtained accordingly;
[0012] The target question text of the first text indicates the question intent of the first text, and the target question text of the second text indicates the question intent of the second text, or indicates the question intent of the second text and a text input to the pre-trained question recognition model before the second text;
[0013] The first text is the first text input into the pre-trained question recognition model, and the second text is the text other than the second text among the multiple texts.
[0014] In an implementable manner, after obtaining a target example from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table, the method further includes:
[0015] Acquire prompt information based on the target example;
[0016] The prompt information and the target question text are input into the large language model to obtain a target query sentence of the target question text.
[0017] In an implementable manner, the acquiring prompt information based on the target example includes:
[0018] Generate an instruction; wherein the instruction is used to instruct the large language model to generate a target query statement according to the target example and the target question data table where the target example is located;
[0019] The instruction, the target example and the target problem data table where the target example is located are used as the prompt information.
[0020] In an implementable manner, the number of examples in the target question data table is multiple; and obtaining a target example from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table includes:
[0021] assigning a first weight to the first similarity and assigning a second weight to the second similarity;
[0022] Determine a similarity value of the corresponding example based on the first similarity, the second similarity, the first weight, and the second weight of each example;
[0023] Based on the magnitude of the similarity values of the examples, a target example is determined from the plurality of examples.
[0024] In one achievable manner, the step of determining the target question data table corresponding to the target question text includes:
[0025] The target question text and multiple question data tables are input into a pre-trained pattern recognition model to obtain the target question data table; wherein,
[0026] The pre-trained pattern recognition model is obtained by inputting the training question text and the multiple question data tables into the initial pattern recognition model to perform training based on the training labels of the training question text.
[0027] In a second aspect, the present application provides a method for training a question recognition model, comprising:
[0028] Obtain a first training set and a second training set; wherein the first training set includes a plurality of first training texts, there is a sequence relationship between the plurality of first training texts, a first label of the first first training text in the sequence relationship represents the real question intention of the first first training text, a first label of a non-first first training text in the sequence relationship represents the real question intention of the corresponding first training text and the first training text located before the corresponding first training text, and the second training set includes a plurality of second training texts and a second label of each second training text, and the second label represents the real question intention of the corresponding second training text;
[0029] The first training text in the first training set and the second training text in the second training set are sequentially input into an initial question recognition model, so as to train the initial question recognition model based on the labels corresponding to each text in the first training text and the second training text to obtain a question recognition model, which is used to recognize the question intent of the input text.
[0030] In a third aspect, the present application provides an example selection device, comprising: an intention recognition module, configured to perform question intention recognition on an input text to obtain a target question text;
[0031] A data table acquisition module, used to determine a target question data table corresponding to the target question text; wherein the target question data table includes at least one example, and the example includes a question text and a query statement;
[0032] A similarity calculation module is used to obtain a first similarity between the target question text and the example question text in the target question data table, and to obtain a second similarity between a reference query statement and the example question text in the target question data table; wherein the reference query statement is a query statement obtained by inputting a large language model into the target question text;
[0033] The target example acquisition module is used to acquire the target example from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table.
[0034] In a fourth aspect, the present application provides an electronic device, comprising: a processor and a memory; the memory is used to store instructions; the processor is used to execute the instructions in the memory, so that the electronic device executes the method as described in the first aspect and the second aspect.
[0035] In a fifth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the methods described in the first and second aspects.
[0036] In a sixth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the method described in the first and second aspects.
[0037] The example selection method, question recognition model training method, device and equipment provided in the present application perform intent recognition on the input text to determine the target text question corresponding to the text, thereby determining the required target question data table based on the target text question, and then selecting examples of target question texts from the examples in the target question data table, calculating the similarity between the question text in the example and the target question text, and calculating the similarity between the question query statement predicted by the large language model and the query statement of the example. Through the two similarities, the target example of the target question text is determined in a low-cost, efficient and accurate manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0039] Figure 1 This is an implementation scenario diagram shown for an exemplary embodiment;
[0040] Figure 2 A flowchart of an exemplary selection method is shown as an exemplary embodiment;
[0041] Figure 3 A flowchart of a method for training an intent recognition model is shown as an exemplary embodiment;
[0042] Figure 4 A structural diagram of an exemplary selection device is shown as an exemplary embodiment;
[0043] Figure 5 The present invention is a block diagram of an electronic device showing an exemplary embodiment.
[0044] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0045] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0046] It should be noted that the texts, data tables, examples and other data involved in this application (including but not limited to data used for analysis, stored data, displayed data, etc.) are all information and data understood and authorized by the relevant users or fully authorized by all parties, and the collection, use, processing, transmission, provision, disclosure and application of the relevant data comply with relevant laws, regulations and standards, take necessary confidentiality measures, do not violate public order and good morals, and comply with the principles of legality, legitimacy and necessity.
[0047] First, the terms involved in this application are explained:
[0048] Large Language Model (LLM) User Profile: It consists of an artificial neural network with many parameters (usually billions of weights or more). The LLM is generally a general model and is not targeted at specific task scenarios.
[0049] Text-to-SQL: Convert the natural language used for communication into executable SQL query statements. SQL is a structured query statement.
[0050] In Context Learning (ICL): A language model learns a task through several examples or instructions organized in the form of demonstrations.
[0051] Large language models (LLMs) are often used in the field of natural language processing. LLMs can be pre-trained on massive text corpora and can complete many downstream tasks, such as text-to-SQL task scenarios. The purpose of text-to-SQL is to automatically convert natural language questions into SQL query statements. It can build a bridge between non-technical professionals and database systems, and convert the input text into query statements to query the data in the database, which lowers the threshold for database use and greatly improves data processing efficiency.
[0052] The large language model has excellent ICL (In Context Learning) capabilities, that is, the LLM can learn task patterns and output corresponding outputs only through contextual examples. The key to developing ICL capabilities is to provide appropriate and effective examples in the prompts input into the large model. The general ICL prompt project is to manually select examples from the labeled data and apply them to all test samples. This approach is both labor-intensive and limits the ICL performance of the large model. Therefore, it is necessary to select appropriate example data from the labeled data for different test samples to help the large model achieve better performance when completing the task.
[0053] It should be considered that the text-to-SQL task is different from the common LLM natural language question-answering task. Its scenario is special. It is necessary to output examples when inputting into the large language model. When converting text to SQL, the large language model will refer to the input examples to complete the task, thereby achieving more accurate and efficient text-to-SQL capabilities.
[0054] Some example selection methods only consider question similarity, which results in low accuracy and high cost. In addition, there may be multiple database scenarios. When converting text to SQL, it is difficult to select appropriate examples in multiple database scenarios, which can easily lead to inconsistency between the selected examples and the database to which the user's question belongs. This will cause the large model to understand the database structure and generate query statements, adding additional noise, resulting in low output accuracy of the large language model. In addition, this method cannot be adapted to multiple rounds of text-to-SQL scenarios.
[0055] Based on this, this embodiment proposes an example selection method, a training method, a device and a device for a problem recognition model, aiming to solve the problems of low example selection accuracy, high cost and low efficiency.
[0056] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0057] The training method and example selection method of the problem recognition model provided in this application can be applied to Figure 1 The implementation environment shown is Figure 1 As shown, the implementation environment may include a terminal and a server, and the terminal and the server are communicatively connected.
[0058] Understandably, Figure 1 The number of terminals and servers shown in the figure is 1. In some embodiments, the number of terminals may be one or more. In other embodiments, the number of servers may be one or more.
[0059] In this embodiment, the terminal can receive text, which can be text entered by the user in the terminal. The terminal sends the text to the server, and the server selects examples based on the text and finally obtains the target example. The target example can be returned to the terminal for display through the terminal's own visual structure.
[0060] In some embodiments, after receiving the text, the server performs question intent recognition on the input text to obtain a target question text; determines a target question data table corresponding to the target question text; wherein the target question data table includes at least one example, and the example includes a question text and a query statement; obtains a first similarity between the target question text and the question text of the example in the target question data table, and obtains a second similarity between a reference query statement and the question text of the example in the target question data table; wherein the reference query statement is a query statement obtained by inputting a large language model into the target question text; and obtains a target example from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table.
[0061] In other embodiments, the terminal may receive the first training set and the second training set, and send the first training set and the second training set to the server, so that the server trains a question recognition model based on the first training set and the second training set, and the question recognition model can be used to recognize question intent in text.
[0062] In some embodiments, the server obtains a first training set and a second training set; wherein the first training set includes multiple first training texts, there is a sequence relationship between the multiple first training texts, the first label of the first first training text in the sequence relationship represents the real question intention of the first first training text, the first label of the non-first first training text in the sequence relationship represents the real question intention of the corresponding first training text and the first training text located before the corresponding first training text, the second training set includes multiple second training texts and a second label of each second training text, the second label represents the real question intention of the corresponding second training text; the first training text in the first training set and the second training text in the second training set are sequentially input into an initial question recognition model, so as to train the initial question recognition model based on the labels corresponding to each text in the first training text and the second training text to obtain a question recognition model, and the question recognition model is used to recognize the question intention of the input text.
[0063] In some embodiments, the terminal may be a wired terminal or a wireless terminal with a visual structure. In other embodiments, the terminal may be an electronic device with a visual structure such as a mobile phone, a computer, a tablet, or a vehicle-mounted device.
[0064] In some embodiments, the server may be a physical server, a server cluster, a cloud server, etc., and no specific limitation is given here.
[0065] It is understandable that the example selection device and the training device of the problem recognition model can be set at Figure 1 The server in the embodiment shown in FIG. Figure 1 The implementation environment shown is only exemplary. In other embodiments, the example selection method and the problem identification model training method can also be applied to other implementation environments. The example selection device and the problem identification model training device can also be set in other structures in other implementation environments. No specific limitations are made here.
[0066] Figure 2 is a flowchart of an exemplary selection method shown in an exemplary embodiment, applied to Figure 1 Servers in Figure 2 As shown, the method includes steps S210 to S270, which are described in detail as follows:
[0067] Step S210: performing question intent recognition on the input text to obtain the target question text.
[0068] In this embodiment, question intent recognition is to process the input text to obtain a more direct and standard question expression, such as judging the true inquiry intent of the current text in combination with the context, and converting the text into a more direct target question text through means such as subject completion.
[0069] In some embodiments, the input text can be multiple rounds, that is, the number of input texts is multiple, and the multiple texts are sequentially subjected to question intent recognition to obtain the target question text corresponding to each text. It can be understood that the number of texts is multiple, which means that each of the multiple texts undergoes corresponding example selection, and enters the large language model to obtain the target query statement, and the multiple texts undergo multiple rounds of example selection.
[0070] In some embodiments, question intent recognition is achieved through a pre-trained question recognition model, and text is input into the question recognition model to obtain a target question text.
[0071] Of course, when there are multiple input texts, the multiple texts enter the pre-trained question recognition model in sequence to obtain the target question text corresponding to each text.
[0072] In some embodiments, the question intentions corresponding to multiple texts may be related. For example, the text currently entering the question recognition model is proposed based on the text that was previously input into the question recognition model. Therefore, when the question recognition model recognizes the question intention of the current text, it will also analyze the connection between the text that was previously input into the question recognition model and the current text, and output the question intention of the current text, that is, the target question text.
[0073] The first text among multiple texts input into the pre-trained question recognition model is taken as the first text, and the text among the multiple texts except the second text is taken as the second text. Then, the target question text of the first text indicates the question intention of the first text, and the target question text of the second text indicates the question intention of the second text, or indicates the question intention of the second text and the text input into the pre-trained question recognition model before the second text.
[0074] That is, except for the first text input into the pre-trained question recognition model, the subsequent text may be related to the text previously input into the pre-trained question recognition model, so the target question text output indicates the question intent of the text and the text input into the pre-trained question recognition model before the text, while the subsequent text may not be related to the text previously input into the pre-trained question recognition model, so the target question text output indicates the question intent of the text.
[0075] For example, in some embodiments, the text input into the pre-trained question recognition model for the first time is "Which city has the largest population?", then the question intent indicated by its target question text is "Which city has the largest population", and the text input into the pre-trained question recognition model for the second time is "Which province is it located in? Tell the name of the province and the area.", and there is a connection between the text input for the second time and the text input for the first time, then the question intent indicated by its target question text is "Which province does the city with the largest population belong to? Tell the name of the province and the area", which also indicates the question intent of the text input into the pre-trained question recognition model for the first time.
[0076] Step S230: Determine a target question data table corresponding to the target question text; wherein the target question data table includes at least one example, and the example includes a question text and a query statement.
[0077] In this embodiment, after obtaining the target question text, the target question data table corresponding to the target question text can be determined, that is, pattern recognition is performed on the target question text, and the target question data table corresponding to the target question text is determined from multiple question data tables, thereby reducing the interference of other question data tables on the example selection of the target question text, and subsequent example selection or conversion to the target query statement only processes the data in the target question data table to improve efficiency.
[0078] It can be understood that the number of the target question data tables is one or more. When there is one, the target question data table is the data table for querying the question corresponding to the text to obtain the query result. If there are multiple, further subsequent example selection is required, and the target question data table where the target example is located is the data table that should be queried for the question corresponding to the text to obtain the query result.
[0079] In some embodiments, a target question data table of a text is predicted by a pattern recognition model. In some embodiments, the target question text and multiple question data tables are input into a pre-trained pattern recognition model to obtain a target question data table; wherein the pre-trained pattern recognition model is obtained by inputting training question text and multiple question data tables into an initial pattern recognition model, and training based on training labels of the training question text.
[0080] The training question text can be a training text for question intent recognition, and the obtained target question text, the training label corresponding to the training question text is at least one question data table among multiple question data tables, that is, the training question text and the multiple question data tables are input into an initial pattern recognition model, and the initial pattern recognition model outputs a predicted question data table, so as to train the initial pattern recognition model based on the predicted question data table and the question data table corresponding to the training label.
[0081] In this embodiment, each problem data table includes at least one example. The examples corresponding to different problem data tables may be the same or different. It can be understood that the examples corresponding to the problem data table are related to the attributes and data in the problem data table.
[0082] The examples include question text and query statements. An example includes a question text and a query statement, that is, the question text in an example is mapped to a query statement, and the query statement is related to the data in the corresponding question data table, such as the row and column attributes in the question data table. The structure in the query statement is associated with the row and column attributes, so that the data in the question data table can be queried through the query statement.
[0083] The question raised above is intended to be a target question text of "Which city has the largest population?", and the number of target question data tables obtained is one, and the target question data table is "city". In the target question data table, it includes a "city id (city identification)" attribute, and the "city id" serves as the primary key of the question data table. The "city id" attribute has a text showing the id of each city, a "name" attribute, and the "name" attribute has the name corresponding to each city id, an "area" attribute, and the "area" attribute has the area corresponding to each city id, and a "population" attribute, and the "population" attribute has the population corresponding to each city id, etc. Of course, the target question data table can also have a contractual relationship with other question data tables, and the data in other question data tables can be accessed through the data in the target question data table; correspondingly, the query statement corresponding to the example in the target question data table depends on the data in the target question data to be implemented, such as the judgment conditions and specified columns in the query statement, which are all generated based on the target question data table.
[0084] Step S250: obtaining a first similarity between the target question text and the example question text in the target question data table, and obtaining a second similarity between the reference query statement and the example question text in the target question data table.
[0085] In this embodiment, after determining the target question data table corresponding to the target question text, the target example corresponding to the target question text can be determined from the examples in the target question data table. The target example needs to well demonstrate the mapping relationship between the target question text and the target query statement to be converted into the target question text. Thus, the subsequent large language model can learn the mapping relationship between the question text and the query statement in the target example, and accurately convert the target question text into the target query statement.
[0086] In this embodiment, a first similarity between the target question text and the example question text in the target question data table is considered, and a second similarity between the reference query statement and the example question text in the target question data table is considered, and the target example corresponding to the target question text is determined by the two similarities.
[0087] The reference query statement is a query statement obtained by inputting the target question text into the large language model. At this time, the large language model receives the target question text and outputs a reference query statement. Of course, the large language model can also accept the target question text and a prompt instructing the large language model to convert the target question text into a query statement, thereby outputting a reference query statement. It can be understood that the large language model at this time does not accept examples of the target question text. Therefore, the obtained reference query statement is not the final result of converting the target question text into a query statement, that is, it is only used to screen query statements with high similarity in the examples of the target question data table.
[0088] Step S270: Obtain a target example from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table.
[0089] In this embodiment, the number of examples in the target problem data table is at least one, a first weight is assigned to the first similarity, and a second weight is assigned to the second similarity; the similarity value of the corresponding example is determined based on the first similarity, the second similarity, the first weight and the second weight of each example; based on the size of the similarity value of each example, a target example is determined from multiple examples.
[0090] In some embodiments, the similarity value of each example may be calculated in the following manner:
[0091] S i =k1P(q * ,q i )+k2P(sql * ,sql i )
[0092] Among them, S i is the similarity value of the i-th example, k1 is the first weight, k2 is the second weight, q * is the target question text, q i is the question text of the i-th example, P(q * ,q i ) is the first similarity of the i-th example, which can be the likelihood function score, P(sql * ,sql i ) is the second similarity of the i-th example, sql * For reference query statements, sql i is the query statement of the i-th example.
[0093] In this embodiment, the example with the largest similarity value is selected as the target example.
[0094] In this embodiment, an example selection method is proposed to perform intent recognition on the input text and determine the target text question corresponding to the text, so as to determine the required target question data table according to the target text question. Subsequently, examples of the target question text are selected from the examples in the target question data table to reduce the amount of data processed for subsequent example selection. Subsequently, similarity calculation is performed with the examples in the target question data table, which not only calculates the similarity of the question text, but also calculates the similarity between the question query statement predicted by the large language model and the query statement of the example. Through the two similarities, the target example of the target question text is determined efficiently and accurately, and the process is low-cost.
[0095] Furthermore, it is proposed that when there are multiple text data, when the text is subjected to question intent recognition, the intent recognition result obtained from the previous text will be referred to, thereby improving the accuracy of question recognition and improving the accuracy of subsequent example selection.
[0096] In some embodiments, after obtaining the target example, the target question text may be converted into a query statement using the target example. The conversion process may include:
[0097] S10: Obtain prompt information based on the target example.
[0098] S11: Input the prompt information and the target question text into the large language model to obtain a target query sentence of the target question text.
[0099] In this embodiment, the prompt information may indicate the operation that the large language model needs to perform on the input target question text, and the prompt information includes instructions, target examples, and a target question data table.
[0100] In some embodiments, an instruction is first generated; wherein the instruction is used to instruct the large language model to generate a target query statement based on a target example and a target question data table where the target example is located; and the instruction, the target example, and the target question data table where the target example is located are used as prompt information.
[0101] For example, in one embodiment, the target question text is "Which city has the largest population?", the name of the target question data table is "city", and the target example obtained is "question text: Which city has the smallest population? Query statement: SELECT field name FROM city ORDER BY population ASC LIMIT 1". In this query statement, SELECT is used to query the field name, FROM is used to identify the name of the target question data table for the query, ORDER BY refers to the sorting of the corresponding fields, and ORDER BY population means sorting the data of the population attribute in the target question data corresponding to the city, and ASC LIMIT means that the query results are arranged in ascending order, and 1 means taking the top record.
[0102] The corresponding instruction can be "Please generate an SQL statement for the target question text based on the structure in the target question data table named city and the target example". The prompt information and the target question text are input into the large language model together, and the target query statement can be obtained.
[0103] It can be understood that the target problem data table in the prompt information is the data table where the target example is located, that is, when there are multiple target problem data tables obtained in step S230, the generated prompt information only includes the target problem data table where the last target example is located.
[0104] Figure 3 is a flowchart of a method for training a problem recognition model shown in an exemplary embodiment. The method can be applied to Figure 1 In the server shown, Figure 3 As shown, the method includes steps S310 to S330, which are explained in detail as follows:
[0105] Step S310: obtaining a first training set and a second training set; wherein the first training set includes a plurality of first training texts, and the second training set includes a plurality of second training texts.
[0106] In this embodiment, the training of the intent recognition model may include a first training set and a second training set. There is a correlation between the training texts in the first training set, that is, there is a correlation between the questions in the first training text and the questions in the second training text, and there is no correlation between the questions in the training texts in the second training set.
[0107] For the labels corresponding to each training text in the first training set, there is a sequence relationship between multiple first training texts, which represents the training order of each training text in the first training set input into the initial intent recognition model. The first label of the first first training text in the sequence relationship represents the true question intent of the first first training text, and the first label of the non-first first training text in the sequence relationship represents the true question intent of the corresponding first training text and the first training text located before the corresponding first training text.
[0108] In this embodiment, the first labels of the first training texts in the first training set, except the first first training text, all represent the real question intentions of the first training texts themselves and the first training texts before the corresponding first training text. It can be understood that since the real question intentions of the other first training texts in the first training set, except the first first training text, all include the real question intentions of the previous first training text, even if a first training text is actually associated with the questions of all the first training texts before the first training text, it is only necessary to refer to the real question intention of the previous first training text. For example, there are 3 training texts in the first training set. For the third first training text, it is associated with the first two first training texts, but its corresponding first label represents the real question intentions of the corresponding first training text and the second first training text, because the first label of the second first training text represents the real question intentions of the second first training text and the first first training text.
[0109] For the second training set, the second training set includes a plurality of second training texts and a second label for each second training text, and the second label represents the real question intention corresponding to the second training text.
[0110] Step S330: input the first training text in the first training set and the second training text in the second training set into the initial question recognition model in sequence, so as to train the initial question recognition model based on the labels corresponding to each text in the first training text and the second training text, and obtain a question recognition model.
[0111] In this embodiment, the first training text in the first training set and the second training text in the second training set are input into the initial question recognition model in sequence. When the first training text in the first training set is input into the initial question recognition model, the initial question recognition model inputs the first prediction label for each first training text, and the initial question recognition model is trained by the first prediction label and the corresponding first label. The first training set is used to allow the initial question recognition model to learn how to learn the true question intention of the text when there is a correlation between the questions of multiple texts.
[0112] When the second training text in the second training set is input into the initial question recognition model, the initial question recognition model inputs the second prediction label for each second training text, and trains the initial question recognition model through the second prediction label and the corresponding second label. The second training set is used to allow the initial question recognition model to learn how to learn the true question intent of the text when there is no correlation between the questions of multiple texts.
[0113] The question recognition model is used to perform question intent recognition on the input text, such as the question intent recognition in step S210.
[0114] Figure 4 4 is a structural diagram of an exemplary selection device shown in an exemplary embodiment. The exemplary selection device 400 includes:
[0115] The intention recognition module 410 is used to perform question intention recognition on the input text to obtain the target question text;
[0116] The data table acquisition module 430 is used to determine the target question data table corresponding to the target question text; wherein the target question data table includes at least one example, and the example includes the question text and the query statement;
[0117] A similarity calculation module 450 is used to obtain a first similarity between the target question text and the example question text in the target question data table, and to obtain a second similarity between the reference query sentence and the example question text in the target question data table; wherein the reference query sentence is a query sentence obtained by inputting the target question text into the large language model;
[0118] The target example acquisition module 470 is used to acquire a target example from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table.
[0119] In one possible implementation, the number of input texts is multiple, and the intention recognition module includes:
[0120] The intention recognition unit is used to input multiple texts into the pre-trained question recognition model in sequence, and obtain the target question text corresponding to each text; wherein,
[0121] The target question text of the first text indicates the question intent of the first text, and the target question text of the second text indicates the question intent of the second text, or indicates the question intent of the second text and a text input to a pre-trained question recognition model before the second text;
[0122] The first text is the first text input into the pre-trained question recognition model, and the second text is the text other than the second text among the multiple texts.
[0123] In one possible implementation, the example selection device further includes:
[0124] A prompt information acquisition module, used to acquire prompt information based on a target example;
[0125] The query sentence acquisition module is used to input the prompt information and the target question text into the large language model to obtain the target query sentence of the target question text.
[0126] In one possible implementation, the prompt information acquisition module includes:
[0127] An instruction generation unit, used to generate instructions; wherein the instructions are used to instruct the large language model to generate a target query statement according to the target example and the target question data table where the target example is located;
[0128] The prompt information acquisition unit is used to use the instruction, the target example and the target problem data table where the target example is located as prompt information.
[0129] In one possible implementation, the number of examples in the target problem data table is multiple; the target example acquisition module includes:
[0130] a weight assigning unit, configured to assign a first weight to the first similarity and assign a second weight to the second similarity;
[0131] A similarity value calculation unit, configured to determine a similarity value of a corresponding example based on the first similarity, the second similarity, the first weight, and the second weight of each example;
[0132] The target example acquisition unit is used to determine the target example from the multiple examples based on the magnitude of the similarity values of the examples.
[0133] In one possible implementation, the data table acquisition module includes:
[0134] The data table acquisition unit is used to input the target question text and multiple question data tables into the pre-trained pattern recognition model to obtain the target question data table; wherein,
[0135] The pre-trained pattern recognition model is obtained by inputting a training question text and a plurality of question data tables into an initial pattern recognition model and performing training based on training labels of the training question text.
[0136] The example selection device provided in this embodiment can be used to execute the above-mentioned example selection method. Its implementation principle and technical effect are similar, and this embodiment will not be repeated here.
[0137] It can be understood that a training device for a problem recognition model may also be shown to include:
[0138] A training data acquisition module is used to acquire a first training set and a second training set; wherein the first training set includes a plurality of first training texts, there is a sequence relationship between the plurality of first training texts, the first label of the first first training text in the sequence relationship represents the real question intention of the first first training text, the first label of the non-first first training text in the sequence relationship represents the real question intention of the corresponding first training text and the first training text located before the corresponding first training text, the second training set includes a plurality of second training texts and a second label of each second training text, the second label represents the real question intention of the corresponding second training text;
[0139] A training module is used to input the first training text in the first training set and the second training text in the second training set into an initial question recognition model in sequence, so as to train the initial question recognition model based on the labels corresponding to each text in the first training text and the second training text, and obtain a question recognition model, which is used to recognize the question intent of the input text.
[0140] The training device for the problem identification model provided in this embodiment can be used to execute the training method for the problem identification model mentioned above. Its implementation principle and technical effects are similar and will not be described in detail in this embodiment.
[0141] Figure 5 is a block diagram of an electronic device according to an exemplary embodiment. Figure 5 The electronic device 500 may include: a processor 51 and a memory 52, wherein the processor 51 and the memory 52 can communicate; illustratively, the processor 51 and the memory 52 communicate via a communication bus 53, the memory 52 is used to store instructions, and the processor 51 is used to call the instructions in the memory to execute the training method or example selection method of the problem recognition model shown in any of the above method embodiments.
[0142] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the present application may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
[0143] The present application provides a computer-readable storage medium having computer execution instructions stored thereon; when the computer execution instructions are executed by a processor, they are used to implement a training method or an example selection method for a problem recognition model as in any of the above-mentioned embodiments.
[0144] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the training method or example selection method of the above-mentioned question recognition model.
[0145] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0146] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. An example selection method, characterized in that: include: Perform question intent recognition on the input text to obtain the target question text; Determine a target question data table corresponding to the target question text; wherein the target question data table includes at least one example, and the example includes a question text and a query statement; Obtaining a first similarity between the target question text and the example question text in the target question data table, and obtaining a second similarity between a reference query statement and the example question text in the target question data table; wherein the reference query statement is a query statement obtained by inputting a large language model into the target question text; A target example is obtained from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table.
2. The method according to claim 1, characterized in that The number of the input texts is multiple, and the question intent recognition is performed on the input texts to obtain the target question text, including: Multiple texts are sequentially input into the pre-trained question recognition model, and the target question text corresponding to each text is obtained accordingly; The target question text of the first text indicates the question intent of the first text, and the target question text of the second text indicates the question intent of the second text, or indicates the question intent of the second text and a text input to the pre-trained question recognition model before the second text; The first text is the first text input into the pre-trained question recognition model, and the second text is the text other than the second text among the multiple texts.
3. The method according to claim 1, characterized in that After acquiring a target example from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table, the method further includes: Acquire prompt information based on the target example; The prompt information and the target question text are input into the large language model to obtain a target query sentence of the target question text.
4. The method according to claim 3, characterized in that The acquiring prompt information based on the target example includes: Generate an instruction; wherein the instruction is used to instruct the large language model to generate a target query statement according to the target example and the target question data table where the target example is located; The instruction, the target example and the target problem data table where the target example is located are used as the prompt information.
5. The method according to claim 1, characterized in that The number of examples in the target question data table is multiple; obtaining a target example from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table includes: assigning a first weight to the first similarity and assigning a second weight to the second similarity; Determine a similarity value of the corresponding example based on the first similarity, the second similarity, the first weight, and the second weight of each example; Based on the magnitude of the similarity values of the examples, a target example is determined from the plurality of examples.
6. The method according to claim 1, characterized in that The step of determining the target question data table corresponding to the target question text includes: The target question text and multiple question data tables are input into a pre-trained pattern recognition model to obtain the target question data table; wherein, The pre-trained pattern recognition model is obtained by inputting the training question text and the multiple question data tables into the initial pattern recognition model to perform training based on the training labels of the training question text.
7. A method for training a question recognition model, characterized in that: include: Obtain a first training set and a second training set; wherein the first training set includes a plurality of first training texts, there is a sequence relationship between the plurality of first training texts, a first label of the first first training text in the sequence relationship represents the real question intention of the first first training text, a first label of a non-first first training text in the sequence relationship represents the real question intention of the corresponding first training text and the first training text located before the corresponding first training text, and the second training set includes a plurality of second training texts and a second label of each second training text, and the second label represents the real question intention of the corresponding second training text; The first training text in the first training set and the second training text in the second training set are sequentially input into an initial question recognition model, so as to train the initial question recognition model based on the labels corresponding to each text in the first training text and the second training text to obtain a question recognition model, which is used to recognize the question intent of the input text.
8. An exemplary selection device, characterized in that: include: The intention recognition module is used to recognize the question intention of the input text and obtain the target question text; A data table acquisition module, used to determine a target question data table corresponding to the target question text; wherein the target question data table includes at least one example, and the example includes a question text and a query statement; A similarity calculation module is used to obtain a first similarity between the target question text and the example question text in the target question data table, and to obtain a second similarity between a reference query statement and the example question text in the target question data table; wherein the reference query statement is a query statement obtained by inputting a large language model into the target question text; The target example acquisition module is used to acquire the target example from the examples in the target question data table based on the first similarity and the second similarity of the examples in the target question data table.
9. An electronic device, characterized in that: The electronic device comprises: a processor and a memory; the memory is used to store instructions; the processor is used to execute the instructions in the memory, so that the electronic device executes the method as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.
11. A computer program product, characterized in that The method comprises a computer program, which implements the method according to any one of claims 1 to 7 when being executed by a processor.
Citation Information
Patent Citations
Problem processing method and device, computer equipment and storage medium
CN111400470A
Language transformation model training method and device
CN114168619A
Database query method and device, computer equipment and storage medium
CN114253990A
Method, system and device for converting natural language query into SQL and storage medium
CN114547072A
Text processing method and device based on artificial intelligence, electronic equipment and medium
CN116795973A
