Natural language intelligent number asking method and device and storage medium
Through the natural language intelligent question-based method, using the pre-trained model of large language models and domain corpus fine-tuning, query elements in user input are extracted and optimized, and accurately mapped to database metrics, generating SQL query meta-verbs and association problems, solving the problem of solving The problem of insufficient ability to identify and structured analysis in user problems is improved, and the query accuracy is improved.
Patent Information
- Application Number
- CN202410996800.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-24
- Publication Date
- 2024-11-26
AI Technical Summary
In the prior art, user problem query elements are inaccurately identified and structured analysis capabilities are insufficient, resulting in low accuracy of query results.
Using the natural language intelligent numbering method, the large language model extracts and optimizes time elements, regional elements and indicator elements, maps them to the data indicators and associated indicators of the database table through the pre-trained language model fine-tuned by the domain corpus, and generates SQL queries Metaphor and association issues, ultimately populate the query results into the chart to form a visual text overview.
It realizes accurate identification and structured analysis of industry indicator elements, and improves query accuracy.
Smart Images

Figure CN119025552A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent data query technology, and in particular to a natural language intelligent data query method, device, equipment and computer storage medium. Background Art
[0002] With the continuous accumulation and enrichment of production data in various industries, accurate and efficient data query has become crucial. With the continuous increase in the dimensions of data indicators, how to accurately convert user query requirements into executable query statements is the key. Traditional solutions rely on a large number of experienced engineers to design query statements, which have many disadvantages such as long development cycle and high labor costs. With the development of large language models, Text2SQL technology has attracted much attention. With the powerful text semantic understanding and content generation capabilities of large-scale pre-trained language models, this technology attempts to convert input natural language text into executable computer code (SQL statements), and query local database table data by executing SQL statements. By using NL2SQL technology, traditional data query systems can be seamlessly transplanted into the current popular conversational human-computer interaction system, reducing data usage costs and improving data usage efficiency.
[0003] NL2SQL can be divided into two categories: Sketch-based methods and Seq2Seq-based methods.
[0004] The slot-filling generation method builds a SQL statement model consisting of three templates: the SELECT slot, the AGG slot, and the WHERE slot. Different modules are then used to predict and fill in the possible values in each slot. The SELECT slot represents the column name to be queried, the AGG slot represents the operation (such as SUM, MAX, etc.), and the WHERE slot represents the query condition.
[0005] In order to improve the slot filling method's ability to generate complex SQL statements, the sequence-to-sequence generation method directly uses the generation capability of the large language model to directly convert questions expressed in natural language into SQL statements. This method is based on three vocabularies (SQL keyword table V, user question vocabulary Q, and database table structure S). During generation, a token is selected from these three vocabularies each time until the end. In order to accurately understand the data indicators in the database table structure S in different business systems, it is necessary to improve the accuracy of the large model's understanding of industry indicator terms through technical means such as fine-tuning the model and enhancing the knowledge base.
[0006] Compared with the slot-filling generation method, the sequence-to-sequence generation method has better generalization performance. Although this method is still difficult to use on a large scale, thanks to the rapid development of NL2Code technology, the sequence-to-sequence generation method has attracted much attention and represents the development direction of this field in the future.
[0007] Both the slot filling generation method and the sequence-to-sequence generation method face the same problem, that is, the problem of accurately understanding the query elements in the user's question. This problem manifests itself in the following two aspects:
[0008] The problem of insufficient accuracy in query element recognition. On the one hand, due to differences in habits and cognition, the descriptions of query elements in user questions are colloquial and non-standardized, and these query elements often have strong domain specificity, which greatly increases the accuracy of large language models in understanding query elements. On the other hand, when the library table may contain a large number of table names or field names with similar semantics but different actual meanings, it is difficult for the generative model based on vector similarity calculation to accurately distinguish them. For example, "higher education school" and "ordinary undergraduate school" have high similarity in the vector space, but these are two completely different indicators.
[0009] Insufficient structural parsing capabilities for query elements. When the query elements in the user's question cannot be accurately mapped to the query indicator names in the database table, the possible reason is that the query element contains multiple query indicators. Although the entire table structure can be passed to the big model, at this stage, the big model's ability to understand such query indicators with inclusion relationships is obviously insufficient, which ultimately leads to query failure. For example, when querying "the number of higher education schools", in the actual business database, this query element corresponds to four query indicators: "the number of ordinary undergraduate colleges", "the number of undergraduate-level vocational schools", "the number of higher vocational (technical) colleges" and "the number of higher education institutions". It is difficult for the general big language model to accurately parse this query element. Summary of the invention
[0010] To this end, the technical problem to be solved by the present invention is to overcome the problem in the prior art of low query result accuracy caused by inaccurate recognition of user question query elements and insufficient structured parsing capability of query elements.
[0011] In order to solve the above technical problems, the present invention provides a natural language intelligent number asking method, comprising:
[0012] Get the natural language query text entered by the user;
[0013] Using a large language model to extract time elements, regional elements, and indicator elements from the natural language query text, and optimize them;
[0014] Mapping the optimized indicator elements to the data indicators of the database table and the associated indicators of the optimized indicator elements using a pre-trained language model fine-tuned by the domain corpus;
[0015] Based on the natural language query text, the data index, and the associated index, a large language model is used to generate SQL query primitives and associated questions;
[0016] A query result is obtained according to the SQL query primitive, and the query result is filled into a chart constructed based on the time element, the area element and the indicator element to form a visual text overview.
[0017] Preferably, the extracting time elements, regional elements and index elements in the natural language query text by using a large language model and optimizing them includes:
[0018] Based on a pre-designed prompt word template, a large language model is used to extract time elements, regional elements and indicator elements from the natural language query text;
[0019] Converting the time elements into a unified time element description format;
[0020] Replace the regional union name in the regional element with the corresponding specific administrative division name.
[0021] Preferably, the process of fine-tuning the pre-trained language model through the domain corpus includes:
[0022] Based on various types of document data in this field, we designed various question templates and strategies for creating positive and negative question-answer pairs, and built a data indicator corpus.
[0023] Fine-tuning the pre-trained language model based on the data indicator corpus;
[0024] The fine-tuned pre-trained language model is fused with the original model in a preset ratio to obtain a data indicator vectorization model;
[0025] Collecting table structure information of the database to be accessed, wherein the table structure information includes the table name, the field name in each table, and the remarks corresponding to the field name;
[0026] The data indicator vectorization model is used to calculate the latent vector of the annotation corresponding to the field name, and the cls position vector of the last layer of the latent vector is taken as the feature vector of the library table field;
[0027] The spatial distances between two vectors in the feature vector are calculated, and based on the vectors whose spatial distances are less than a preset threshold, a negative question-answer pair reinforcement operation is used to optimize and update the data indicator corpus, and the data indicator vectorization model is fine-tuned and updated again.
[0028] Preferably, the method of mapping the optimized indicator elements to the data indicators of the database table using the pre-trained language model fine-tuned by the domain corpus includes:
[0029] Use the final data index vectorization model to calculate the latent vector of the annotation corresponding to the field name, take the cls position vector of the last layer as the target feature vector of the library table field, and create an index;
[0030] The final data indicator vectorization model is used to calculate the latent vectors of the indicator elements respectively;
[0031] Calculating the maximum semantic similarity between the target feature vector of the library table field and the latent vector of the indicator element;
[0032] If the maximum semantic similarity is not less than a preset semantic similarity threshold, the library table field corresponding to the target feature vector is used as a data indicator;
[0033] If the maximum semantic similarity is less than a preset semantic similarity threshold, a direct sub-index of the query index in the database table is used as the main query index, and a pre-defined index map is selected based on the main query index;
[0034] Based on the most similar indicator of the indicator element matched by the indicator map, the most similar indicator is used as a search input, and all indicators included in the most similar indicator are searched as data indicators.
[0035] Preferably, the mapping of the optimized indicator elements to the associated indicators of the optimized indicator elements using the pre-trained language model fine-tuned by the domain corpus includes:
[0036] Taking the indicator element as the search input, find all the indicators containing the indicator element to construct a superordinate concept indicator set, find all the indicators parallel to the indicator element to construct a sibling concept indicator set, find all the indicators contained by the indicator element to construct a subordinate concept indicator set, and construct related indicators based on the superordinate concept indicator set, the sibling concept indicator set and the subordinate concept indicator set.
[0037] Preferably, the generating SQL query primitives and associated questions using a large language model based on the natural language query text, the data index, and the associated index comprises:
[0038] The table field name of the data indicator and the corresponding remarks of the field name and the name of the table where the field is located are intercepted to obtain the query table structure information;
[0039] Taking the query table structure information and a preset SQL statement generation prompt template as input, generating SQL query primitives using a large language model;
[0040] The relevance index and a preset relevance question generation prompt template are used as input, and a large language model is used to generate relevance questions.
[0041] Preferably, obtaining query results according to the SQL query primitives, and filling the query results into a chart constructed based on the time element, the area element, and the indicator element to form a visual text summary includes:
[0042] The regional element corresponding to each time element is used as the column indicator and the indicator element as the row indicator to construct a contingency table;
[0043] Obtain query results according to the SQL query primitive, and fill the query results into a contingency table;
[0044] Use the drawing tool interface to draw the contingency table of all time elements into a chart;
[0045] Sort the data in each contingency table according to the value of the indicator element and sum them by column, and calculate the proportion of each indicator element value to the total of the column;
[0046] Taking each contingency table and its corresponding summation and proportion calculation results as input, a text description of the indicator elements is generated using a large language model;
[0047] The text descriptions of each indicator element are stitched together to obtain the target text overview;
[0048] The diagram and the target text summary are used as the final output of this query, and the related questions are used as candidate questions for the next round of query recommended to the user.
[0049] The present invention also provides a natural language intelligent number asking device, comprising:
[0050] A query text acquisition module is used to acquire the natural language query text input by the user;
[0051] A query element extraction module, used to extract time elements, regional elements and indicator elements in the natural language query text using a large language model, and optimize them;
[0052] A query indicator identification and deconstruction module is used to map the optimized indicator elements to the data indicators of the database table and the associated indicators of the optimized indicator elements using a pre-trained language model fine-tuned by the domain corpus;
[0053] An SQL primitive and associated question generation module, used to generate SQL query primitives and associated questions based on the natural language query text, the data index, and the associated index using a large language model;
[0054] The data query and visualization module is used to obtain query results according to the SQL query primitives, and fill the query results into a chart constructed based on the time element, the area element and the indicator element to form a visual text overview.
[0055] The present invention also provides a natural language intelligent number-asking device, comprising:
[0056] Memory for storing computer programs;
[0057] A processor is used to implement the above-mentioned natural language intelligent number asking method steps when executing the computer program.
[0058] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned natural language intelligent number asking method are implemented.
[0059] The above technical solution of the present invention has the following advantages compared with the prior art:
[0060] The natural language intelligent query method described in the present invention first uses a local pre-trained language model that has been fine-tuned with domain corpus to achieve accurate matching of query elements to library table indicators, then generates SQL query primitives based on the matched library table indicators and original query text, then sorts columns according to the data query results returned by the SQL query primitives and generates data parsing text, finally calculates associated indicators according to the library table indicators in the current SQL query primitives, and outputs data query results, data parsing text and associated indicators as final query results; the present invention realizes accurate identification of industry indicator elements in natural language query statements, improves the structured parsing capability of query elements, and ultimately improves query accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] In order to make the content of the present invention more clearly understood, the present invention is further described in detail below according to specific embodiments of the present invention in conjunction with the accompanying drawings, wherein:
[0062] Figure 1 This is a flow chart for implementing a natural language intelligent number-asking method provided by the present invention;
[0063] Figure 2 It is a flow chart for creating a data indicator vectorization model;
[0064] Figure 3 It is a flowchart of library table indicator matching processing. DETAILED DESCRIPTION
[0065] The core of the present invention is to provide a natural language intelligent query method, device, equipment and computer storage medium, which effectively realizes the accurate identification of industry indicator elements in natural language query statements, improves the structured parsing ability of query elements, and ultimately improves the query accuracy.
[0066] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0067] Please refer to Figure 1 , Figure 1 This is a flow chart of the implementation of a natural language intelligent number-asking method provided by the present invention; the specific operation steps are as follows:
[0068] S101: Obtaining a natural language query text input by a user;
[0069] S102: extracting time elements, regional elements, and indicator elements from the natural language query text using a large language model, and optimizing them;
[0070] S103: Mapping the optimized indicator elements to the data indicators of the database table and the associated indicators of the optimized indicator elements using the pre-trained language model fine-tuned by the domain corpus;
[0071] S104: Based on the natural language query text, the data index, and the associated index, a large language model is used to generate SQL query primitives and associated questions;
[0072] S105: Obtain query results according to the SQL query primitive, and fill the query results into a chart constructed based on the time element, the area element and the indicator element to form a visual text overview.
[0073] Based on the above embodiments, this embodiment describes step S102 in detail:
[0074] This embodiment uses the natural language query text input by the user as input, and uses a large language model to extract query elements in the input text, including time elements, regional elements, and indicator elements, wherein the time element represents the time span of the data to be queried, in years, the regional element represents the spatial span of the data to be queried, expressed as an array of administrative division codes, and the indicator element represents the alias of the indicator name corresponding to the data to be queried. Due to the flexibility of natural language and the language habits of different users, the same indicator name may be expressed as an indicator element with certain semantic differences, which requires further precise parsing before it can be used to generate SQL query statements. The use of a large language model to extract the time element, regional element, and indicator element in the natural language query text and optimize it includes:
[0075] Based on the pre-designed prompt word template, a large language model is used to extract time elements, regional elements and indicator elements from the natural language query text:
[0076] Segment the query elements E from the natural language query text T input by the user, including the time element q y , regional element q r and indicator element q e , that is, E=(q y ,q r ,q e ). The implementation process of this step can be achieved by calling the local or online large model interface to design the prompt word template P e , the natural language query text T and the prompt word template P e Splice the input to the large model interface and extract the query element E from the returned results.
[0077] ·Convert the time elements into a unified time element description format:
[0078] This embodiment only considers the time element in years. The original time element q returned by the large model interface y There are three modes in form, namely single year mode: q y ={year_1}, interval mode 1: q y ={year_1,year_2} and interval pattern 2: q y ={N}, where year_i represents a four-digit year number, and N represents an Arabic numeral or a Chinese capital number.
[0079] The purpose of time element optimization is to convert the time elements of the above three modes into a unified time element description format to provide accurate query conditions for the SQL query primitive generation module. In this embodiment, the unified time element description format is defined as q' y={year_start,year_end}. During conversion, the three modes of the original time element are processed separately. If it is a single year mode, year_start=year_1, year_end=year_1; if it is interval mode 1, year_start=year_1, year_end=year_2; if it is interval mode 2, year_end=year_current, year_start=year_end-N. Use the converted time element q' y Update q y , the updated representation is q y ={year_start,year_end}, which will be used as the time condition for generating SQL query primitives.
[0080] Replace the name of the regional association in the regional element with the corresponding specific administrative division name:
[0081] The regional element refers to the name of the administrative division where the data to be queried comes from. In the database table, the administrative division where the data comes from is represented by the name of the province, municipality, special administrative region, etc. However, in the query element E, the regional element q r In addition to the above three types of administrative division names, they may also be described as names of economic or industrial circles (districts), names of geographic space divisions, and other regional consortium names. Therefore, the purpose of regional element optimization is to convert the above possible regional consortium names into corresponding specific administrative division names.
[0082] Considering that different business systems may have different definitions of the specific administrative divisions corresponding to the regional association, this embodiment defines the administrative division name corresponding to each regional association by establishing an administrative division mapping table. r The regional union name in is replaced with the corresponding specific administrative division name region. The updated regional element q r Represented as q r ={region1,region2,…}, which will be used as the region condition for generating SQL query primitives.
[0083] Based on the above embodiments, this embodiment describes step S103 in detail:
[0084] This embodiment is the key to accurately generate SQL query primitives, aiming to convert the index element q in the query element E into e Accurately map to the data index of the database table e and q e The correlation index r eDifferent from the general NL2SQL technology, this embodiment uses a data indicator vectorization model EduEM that has been fine-tuned with domain corpus to achieve library-table indicator matching and association calculation. The advantage is that EduEM is a language model that has been fine-tuned with the corpus in this field, and can more accurately identify and distinguish professional terms in this field, thereby improving the accuracy of library-table indicator matching.
[0085] The EduEM model is a fine-tuned pre-trained language model, mainly used for the indicator factor q e In order to make EduEM better represent the association and difference between the indicator terms in this field, this embodiment uses various types of document data in this field to build a training corpus Dataset, and uses the created corpus Dataset to fine-tune a 24-layer pre-trained language model, and obtains the data indicator vectorization model EduEM after fine-tuning. Figure 2 As shown, the specific processing includes: creation and optimization of data indicator question and answer pairs, fine-tuning of data indicator vectorization models, library and table indicator modeling, and spatial distribution analysis of library and table indicator vectors.
[0086] The process of fine-tuning the pre-trained language model through the domain corpus includes:
[0087] Based on various types of document data in this field, we design various question templates and strategies for creating positive and negative question-answer pairs, and build a data indicator corpus:
[0088] Using common data indicator system guidelines, statistical yearbooks, policies and regulations, news reports and other materials in this field, we design a variety of question templates and strategies for creating positive and negative question-answer pairs to build a data indicator corpus. In particular, for data indicators that are distributed relatively close to each other in the vector space, the positive question-answer pairs of these data indicators are automatically added to the negative question-answer pair set of the adjacent data indicators, and semantic rewriting is performed to achieve the purpose of strengthening the semantic differences of adjacent data indicators.
[0089] Fine-tune the pre-trained language model based on the data indicator corpus:
[0090] This example uses a 24-layer, 16-head attention module XLMRoberta model for fine-tuning, where the latent vector length is 1024 and the maximum sequence length is 8192. Use the data indicator question-answer pair created in the previous step to fine-tune the model, and set the epoch to 1000.
[0091] The fine-tuned pre-trained language model is merged with the original model in a preset ratio to obtain a data indicator vectorization model:
[0092] The parameters of the fine-tuned model and the original model are fused in a ratio of 0.5:0.5 to obtain the final data indicator vectorization model EduEM.
[0093] Collect the table structure information of the database to be accessed, including the table name, the field name in each table, and the notes corresponding to the field name:
[0094] Collect the table structure information db_Schema of the database to be accessed, including the table name t_Name, the field name t_Field in each table, and the comment t_Comment corresponding to the field name, recorded as db_Schema = (t_Name, t_Field, t_Comment), where t_Comment represents the complete Chinese name of t_Field, that is, the standardized indicator term name corresponding to t_Field.
[0095] Use the data index vectorization model to calculate the hidden vector of the annotation corresponding to the field name, and take the cls position vector of the last layer of the hidden vector as the feature vector of the library table field:
[0096] Use the hidden vector of the EduEM model t_Comment and take the cls position vector of the last layer of the hidden vector as the feature vector, denoted as v t , n is the total number of fields in the database.
[0097] Calculate the spatial distance between two vectors in the feature vector, and based on the vectors whose spatial distance is less than a preset threshold, use negative question-answer pair reinforcement operation to optimize and update the data indicator corpus, and fine-tune and update the data indicator vectorization model again:
[0098] Calculate v t The spatial distance between two vectors in the vector space is calculated. For vectors whose spatial distance is less than a threshold value D (in this embodiment, 0.01≤D≤0.05), the corresponding database field name is found, the negative question-answer pair reinforcement operation in the above step is enabled, the training corpus is optimized, and the model fine-tuning training and spatial distribution analysis of the database table indicator vector are performed again.
[0099] Considering that the names of table fields may be in Chinese, English, Pinyin, etc. when designing a table, it is impossible to directly use the table field names for semantic calculation. Therefore, this embodiment collects the remark information corresponding to the field as the basis for semantic calculation, and uses the remark information to connect the indicator elements in the query elements with the field names in the table. Figure 3 As shown) as follows:
[0100] Use the final data index vectorization model to calculate the hidden vector of the annotation corresponding to the field name, take the cls position vector of the last layer as the target feature vector of the library table field, and create an index:
[0101] Use the EduEM model to calculate the vector v of t_Comment in db_Schema = (t_Name, t_Field, t_Comment) t And create the index.
[0102] Use the final data indicator vectorization model to calculate the latent vectors of the indicator elements respectively:
[0103] Use the EduEM model to calculate the index factors q in the query factors respectively e The hidden vector of q .
[0104] Data indicator e It refers to the index element q in the query element e The table field t_Field that corresponds to or has the closest semantics. The database table index matching is divided into two steps: data index matching based on semantic similarity matching and index deconstruction based on graph retrieval. The specific process is as follows:
[0105] Calculate the maximum semantic similarity between the target feature vector of the library table field and the latent vector of the indicator element:
[0106] If the maximum semantic similarity is not less than the preset semantic similarity threshold, the library table field corresponding to the target feature vector is used as a data indicator:
[0107] According to the semantic similarity calculation, if MAX(sim(v q ,v t ))≥TH sim (TH sim is the preset semantic similarity threshold), then v t The corresponding table field t_Field is added to d e , that is, d e =t_Field;
[0108] Semantic similarity is calculated using the cosine formula. Calculate, where v q is the indicator factor q e The eigenvector of t It is the characteristic vector of the library table field t_Field.
[0109] If the maximum semantic similarity is less than the preset semantic similarity threshold, the direct sub-indices of the query indicator in the database table are used as the main query indicator, and the pre-defined indicator map is selected based on the main query indicator:
[0110] If MAX(sim(v q ,v t )) <TH sim , it means that the data of the indicator is not stored in the database table. It is necessary to further check whether there are direct sub-indicators of the indicator in the database table. If so, these direct sub-indicators are used as the main query indicators. The selection of the main query indicator based on the graph retrieval depends on the pre-defined indicator graph G = (P, R), where P is the set of data indicator names and R is the set of indicator relationships. The indicator relationship types include "belong to", "parallel" and "include". In the indicator graph G, the relationship between data indicators is represented by the triple g = (p i ,p j ,r ij ) indicates that p i ,p j ∈P,r ij ∈R.
[0111] Based on the indicator map, the most similar indicator of the indicator element is matched, the most similar indicator is used as the search input, and all indicators included in the most similar indicator are searched as data indicators.
[0112] The matching process uses a semantic similarity matching method similar to the previous step to match the indicator element q from the indicator graph G e The most similar indicator by To search for input, find all For "included" Right now
[0113] Taking the indicator element as the search input, find all indicators containing the indicator element to construct a superordinate concept indicator set, find all indicators parallel to the indicator element to construct a sibling concept indicator set, find all indicators contained by the indicator element to construct a subordinate concept indicator set, and construct related indicators based on the superordinate concept indicator set, the sibling concept indicator set and the subordinate concept indicator set:
[0114] Correlation index (r e ) refers to the index element q in the query element e The purpose of calculating related indicators is to obtain indicators that have business relevance to the current query indicator and recommend them to users, so as to help users quickly start the next round of question-and-answer dialogue. The calculation process of related indicators can adopt the semantic similarity matching method, with q e To retrieve the input, search from the index graph G: q e The superordinate concept index set I p , q e Brother Concept Index Set I s , q e The lower concept index set I c , The p e Corresponding I p ,I s ,I c Give r e , that is, r e =(I p ,I s ,I c ).
[0115] ·Indicator Schema(q e _Schema) interception refers to intercepting data indicators from the database table structure. e The table field name t_Field, comment t_Comment and the name of the table where the field is located t_Name. The indicator schema interception can be achieved by querying the table structure information db_Schema.
[0116] Based on the above embodiments, this embodiment describes step S104 in detail:
[0117] In this embodiment, the user's original query text T and the db_Schema, e As a joint input, a large model is used to generate SQL query primitives and associated questions. The generating SQL query primitives and associated questions using a large language model based on the natural language query text, the data index, and the associated index includes:
[0118] ·Intercept the table field name of the data indicator, the notes corresponding to the field name, and the name of the table where the field is located to obtain the query table structure information;
[0119] Taking the query table structure information and the preset SQL statement generation prompt template as input, the large language model is used to generate SQL query primitives:
[0120] Design SQL statement generation prompt template sql , splicing P sql With db_Schema as the input of the big model, generate SQL query primitive DSS sql .
[0121] Taking the relevance index and the preset relevance question generation prompt template as input, generating relevance questions using the large language model:
[0122] Design related questions to generate prompt template P question , splicing Pquestion The correlation index r e As the input of the large model, generate N related questions CEQ question .
[0123] Based on the above embodiments, this embodiment describes step S105 in detail:
[0124] The obtaining of query results according to the SQL query primitives, and filling the query results into a chart constructed based on the time element, the area element, and the indicator element to form a visual text overview includes:
[0125] Execute SQL query primitive DSS sql Get the query result Value and fill it into the area element q r and indicator element q e Contingency table ACM data In which the regional element q r As a column indicator, the indicator element q e As a row index. If there are multiple time elements q y , then for each time element q y Construct a contingency table. Call the drawing tool interface to draw the contingency table ACM ey Draw as a diagram FIG ey , and generate a text summary for each data in the contingency table ACM description :
[0126] ·For each time element, the regional element corresponding to the time element is used as the column indicator and the indicator element as the row indicator to construct a contingency table;
[0127] Obtain query results according to the SQL query primitives, and fill the query results into a contingency table;
[0128] Use the drawing tool interface to draw a contingency table of all time elements into a chart;
[0129] Text overview generation includes two stages: numerical preprocessing and numerical distribution analysis.
[0130] In the data preprocessing stage, the data in the contingency table are sorted by column, summed, and proportioned:
[0131] Sort the data in each contingency table by the value of the indicator element and sum them by column, and calculate the proportion of each indicator element value to the total of the column:
[0132] Sorting by columns is a contingency table ACM ey Each indicator element q in e Arrange the values in descending or ascending order to get The sum of columns is a contingency table ACM ey Each indicator element q in e The numerical value of is summed up to get Finding proportions by column is to calculate the contingency table ACM ey Each indicator element q in e The ratio of the value to the total value of the column is
[0133]
[0134] In the numerical distribution analysis phase:
[0135] Taking each contingency table and its corresponding summation and proportion calculation results as input, a large language model is used to generate a text description of the indicator elements;
[0136] ·Join the text descriptions of each indicator element together to get the target text overview:
[0137] Will and Input the big model to generate the indicator factor q e Text description of Each indicator element q e Text description of Stitched together to form the final text overview ACM description .
[0138] The diagram and the target text summary are used as the final output of this query, and the related questions are used as candidate questions for the next round of queries recommended to the user:
[0139] Finally, FIG ey and ACM description As the final output result of this query T, the associated question CEQ is also output question As candidate questions recommended to the user for the next round of queries.
[0140] In view of the problem that the existing Text2SQL method has insufficient understanding ability of query elements, the present invention proposes a natural language intelligent query system and method for industry applications. The method first uses a local pre-trained language model that has been fine-tuned with domain corpus to achieve accurate matching of query elements to library and table indicators, and then generates SQL query primitives based on the matched library and table indicators and the original query text, and then sorts the columns according to the data query results returned by the SQL query primitives and generates data parsing text, and finally calculates the correlation indicators according to the library and table indicators in the current SQL query primitives, and outputs the data query results, data parsing text and correlation indicators as the final query results.
[0141] Large language models perform well in the field of natural language understanding and generation, but in the field of Text-to-SQL, due to the limited quality and quantity of relevant training corpora, large language models are still difficult to directly handle SQL generation tasks in different industry fields. Although fine-tuning the large model by building industry corpora can effectively improve this dilemma, fine-tuning requires high technical and computing costs. The present invention fine-tunes a lightweight semantic vector model, constructs a collaborative working framework between the local vector model and the large model API, and realizes the accurate identification of industry indicator elements in natural language query statements.
[0142] Under the constraints of the first normal form, all indicators in the database are atomic. Although the large language model has strong semantic understanding capabilities, it is often unable to achieve effective association and reasoning when parsing non-atomic indicator elements, resulting in failure in parsing indicator elements. Based on the industry indicator map and the fine-tuned local semantic vector model, the present invention realizes the structured structures of the same level, similar, upper, and lower levels of industry indicator elements, and finally obtains the atomic level indicators of the query indicators, thereby improving the query accuracy.
[0143] The embodiment of the present invention further provides a natural language intelligent number asking device; the specific device may include:
[0144] A query text acquisition module is used to acquire the natural language query text input by the user;
[0145] A query element extraction module, used to extract time elements, regional elements and indicator elements in the natural language query text using a large language model, and optimize them;
[0146] A query indicator identification and deconstruction module is used to map the optimized indicator elements to the data indicators of the database table and the associated indicators of the optimized indicator elements using a pre-trained language model fine-tuned by the domain corpus;
[0147] An SQL primitive and associated question generation module, used to generate SQL query primitives and associated questions based on the natural language query text, the data index, and the associated index using a large language model;
[0148] The data query and visualization module is used to obtain query results according to the SQL query primitives, and fill the query results into a chart constructed based on the time element, the area element and the indicator element to form a visual text overview.
[0149] The natural language intelligent questioning device of this embodiment is used to implement the aforementioned natural language intelligent questioning method. Therefore, the specific implementation methods of the natural language intelligent questioning device can be seen in the implementation method part of the aforementioned natural language intelligent questioning method. For example, the query text acquisition module, the query element extraction module, the query indicator identification and deconstruction module, the SQL primitive and related question generation module, the data query and visualization module are respectively used to implement steps S101, S102, S103, S104 and S105 in the aforementioned natural language intelligent questioning method. Therefore, its specific implementation methods can refer to the description of the corresponding embodiments of each part, which will not be repeated here.
[0150] A specific embodiment of the present invention further provides a natural language intelligent number-asking device, comprising: a memory for storing a computer program; and a processor for implementing the steps of the above-mentioned natural language intelligent number-asking method when executing the computer program.
[0151] A specific embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned natural language intelligent number asking method are implemented.
[0152] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0153] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0154] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0155] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0156] Obviously, the above embodiments are merely examples for the purpose of clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the present invention.
Claims
1. A natural language intelligent number-asking method, characterized in that: include: Get the natural language query text entered by the user; Using a large language model to extract time elements, regional elements, and indicator elements from the natural language query text, and optimize them; Mapping the optimized indicator elements to the data indicators of the database table and the associated indicators of the optimized indicator elements using a pre-trained language model fine-tuned by the domain corpus; Based on the natural language query text, the data index, and the associated index, a large language model is used to generate SQL query primitives and associated questions; A query result is obtained according to the SQL query primitive, and the query result is filled into a chart constructed based on the time element, the area element and the indicator element to form a visual text overview.
2. The natural language intelligent number-asking method according to claim 1, characterized in that: The extracting of the time element, the region element and the index element in the natural language query text by using the large language model and optimizing the same includes: Based on a pre-designed prompt word template, a large language model is used to extract time elements, regional elements and indicator elements from the natural language query text; Converting the time elements into a unified time element description format; Replace the regional union name in the regional element with the corresponding specific administrative division name.
3. The natural language intelligent number-asking method according to claim 1, characterized in that: The process of fine-tuning the pre-trained language model through the domain corpus includes: Based on various types of document data in this field, we designed various question templates and strategies for creating positive and negative question-answer pairs, and built a data indicator corpus. Fine-tuning the pre-trained language model based on the data indicator corpus; The fine-tuned pre-trained language model is fused with the original model in a preset ratio to obtain a data indicator vectorization model; Collecting table structure information of the database to be accessed, wherein the table structure information includes the table name, the field name in each table, and the remarks corresponding to the field name; The data indicator vectorization model is used to calculate the latent vector of the annotation corresponding to the field name, and the cls position vector of the last layer of the latent vector is taken as the feature vector of the library table field; The spatial distances between two vectors in the feature vector are calculated, and based on the vectors whose spatial distances are less than a preset threshold, a negative question-answer pair reinforcement operation is used to optimize and update the data indicator corpus, and the data indicator vectorization model is fine-tuned and updated again.
4. The natural language intelligent number-asking method according to claim 3, characterized in that: The data indicators of the database table mapped to the optimized indicator elements by using the pre-trained language model fine-tuned by the domain corpus include: Use the final data index vectorization model to calculate the latent vector of the annotation corresponding to the field name, take the cls position vector of the last layer as the target feature vector of the library table field, and create an index; The final data indicator vectorization model is used to calculate the latent vectors of the indicator elements respectively; Calculating the maximum semantic similarity between the target feature vector of the library table field and the latent vector of the indicator element; If the maximum semantic similarity is not less than a preset semantic similarity threshold, the library table field corresponding to the target feature vector is used as a data indicator; If the maximum semantic similarity is less than a preset semantic similarity threshold, a direct sub-index of the query index in the database table is used as the main query index, and a pre-defined index map is selected based on the main query index; Based on the most similar indicator of the indicator element matched by the indicator map, the most similar indicator is used as a search input, and all indicators included in the most similar indicator are searched as data indicators.
5. The natural language intelligent number-asking method according to claim 4, characterized in that: The method of mapping the optimized indicator elements to the associated indicators of the optimized indicator elements by using the pre-trained language model fine-tuned by the domain corpus includes: Taking the indicator element as the search input, find all the indicators containing the indicator element to construct a superordinate concept indicator set, find all the indicators parallel to the indicator element to construct a sibling concept indicator set, find all the indicators contained by the indicator element to construct a subordinate concept indicator set, and construct related indicators based on the superordinate concept indicator set, the sibling concept indicator set and the subordinate concept indicator set.
6. The natural language intelligent number-asking method according to claim 5, characterized in that: The generating of SQL query primitives and related questions based on the natural language query text, the data index, and the related index by using a large language model includes: The table field name of the data indicator and the corresponding remarks of the field name and the name of the table where the field is located are intercepted to obtain the query table structure information; Taking the query table structure information and the preset SQL statement generation prompt template as input, Generate SQL query primitives using large language models; The relevance index and a preset relevance question generation prompt template are used as input, and a large language model is used to generate relevance questions.
7. The natural language intelligent number-asking method according to claim 1, characterized in that: The obtaining of query results according to the SQL query primitives, and filling the query results into a chart constructed based on the time element, the area element, and the indicator element to form a visual text overview includes: The regional element corresponding to each time element is used as the column indicator and the indicator element as the row indicator to construct a contingency table; Obtain query results according to the SQL query primitive, and fill the query results into a contingency table; Use the drawing tool interface to draw the contingency table of all time elements into a chart; Sort the data in each contingency table by the value of the indicator element and sum them by column, and Calculate the proportion of each indicator element value to the total value of the column; Taking each contingency table and its corresponding summation and proportion calculation results as input, a text description of the indicator elements is generated using a large language model; The text descriptions of each indicator element are stitched together to obtain the target text overview; The diagram and the target text summary are used as the final output of this query, and the related questions are used as candidate questions for the next round of query recommended to the user.
8. A natural language intelligent number-asking device, characterized in that: include: A query text acquisition module is used to acquire the natural language query text input by the user; A query element extraction module, used to extract time elements, regional elements and indicator elements in the natural language query text using a large language model, and optimize them; A query indicator identification and deconstruction module is used to map the optimized indicator elements to the data indicators of the database table and the associated indicators of the optimized indicator elements using a pre-trained language model fine-tuned by the domain corpus; An SQL primitive and associated question generation module, for generating SQL query primitives and associated questions using a large language model based on the natural language query text, the data index, and the associated index; The data query and visualization module is used to obtain query results according to the SQL query primitives, and fill the query results into a chart constructed based on the time element, the area element and the indicator element to form a visual text overview.
9. A natural language intelligent number-asking device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of a natural language intelligent number-asking method as claimed in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the natural language intelligent number-asking method as claimed in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Data retrieval method and device based on index platform, electronic equipment and medium
CN119848099A
Intelligent number asking implementation method and device based on analysis model and medium
CN120723875A
Data query method and device based on large language model, program product and medium
CN120804298A
Data query method, device, program product and medium based on large language model
CN120804298B
Method and system for performing natural language question and answer directly according to dimension value
CN121144446A
