Data analysis method and system based on large language model, storage medium and program product
By introducing large language models and identification and distribution modules into the data analysis system, the shortcomings of existing data analysis methods in handling complex queries are solved, and more efficient and flexible data analysis capabilities are achieved.
Patent Information
- Application Number
- CN202411171470.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2025-03-14
AI Technical Summary
Existing data analysis methods are difficult to deal with when dealing with complex queries, and are not reusable and scalable.
Using a data analysis method based on a large language model, the query type is determined based on user queries through the identification and distribution module, and the tasks are distributed to the corresponding execution module. The execution module processes user queries in the preset mode, generates code and executes it in the database to generate query results.
It improves the flexibility and efficiency of data analysis, can better handle complex queries, lowers the threshold for data analysis, and improves the reusability and expansion of the system.
Smart Images

Figure CN119621740A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to data processing, and more specifically, to data processing technology based on a large language model. Background Art
[0002] Data analysis plays an important role in many industries, such as financial services. Currently, data analysis includes the following two categories: output analysis based on natural language models and data analysis based on rules.
[0003] Data analysis based on natural language models uses data analysis models pre-trained in natural language to train data analysis requests and historical data sets through methods such as recurrent neural networks. The trained data analysis model is used to parse data analysis requests, determine query elements, convert requests into structured query language, and obtain data analysis results.
[0004] The rule-based data processing method forms corresponding data rules by analyzing historical data and the data characteristics of the analysis object, and is suitable for processing scenarios with clear characteristics.
[0005] The above data analysis methods may be difficult to handle complex queries, or lack reusability and scalability. Summary of the invention
[0006] According to one aspect of the present application, a data analysis method based on a large language model is provided, characterized in that the method includes: determining a query type according to a user query; distributing a task for implementing the user query to an execution module corresponding to the type according to the determined type; the execution module that receives the task processes the user query according to a preset mode and generates a code for implementing the user query; executing the code in a database to generate a query result for feedback to the user; wherein the execution modules are arranged corresponding to the types so that one execution module processes one type of user query, and at least one of the execution modules is based on a large language model.
[0007] In the data analysis method, as an example or in addition, the execution module includes a first execution module for prediction, a second execution module for basic query and a third execution module for logical calculation.
[0008] The data analysis method, by way of example or in addition, when the execution module receiving the task is the first execution module, processes the user query and generates code according to a preset mode, including: obtaining a data base table, the base table including historical data labels; running a sub-model to make predictions based on the historical data involved in the base table; storing the prediction results in a database in the form of a data table; and generating code for querying the data table.
[0009] The data analysis method, by way of example or in addition, when the execution module receiving the task is the second execution module, processes the user input information according to a preset mode and generates code for implementing the task, including: obtaining a data base table, the base table including historical data tags; searching for the user queried data in the historical data involved in the base table; storing the queried data in the form of a data table in a database; and generating code for querying the data table.
[0010] The data analysis method, by way of example or in addition, when the execution module receiving the task is the third execution module, processes the user input information according to a preset mode and generates code for implementing the task, including: constructing the user query into a standard sentence, wherein the standard sentence is based on knowledge of a specific domain; generating prompt words for the standard sentence through a prompt word project, wherein the prompt word project is pre-configured with a knowledge base of the specific domain, and the prompt words include domain prompt words; and generating code by a large language model based on the domain prompt words and the content of the standard sentence.
[0011] The data analysis method, for example or in addition, generates prompt words for the standard sentence through prompt word engineering, including: matching the standard sentence with the prompt word module of the specific field to generate field prompt words. Further, matching the standard sentence with the prompt word module of the specific field to generate field prompt words includes: determining the data table required for the user query and generating a database statement; determining the index required for query and generating a logical calculation prompt; determining the query conditions and generating a data schema and value prompt; matching similar code samples from existing code.
[0012] The data analysis method, by way of example or in addition, constructs the user query into a standard statement, including: searching for standard terms for common words in the user query statement; replacing the common words with standard terms, and reassembling the user query statement with a standard query template to generate a standard query statement; wherein the standard terms are terms for common words in the specific field.
[0013] The data analysis method, by way of example or in addition, the query result is output to the user through the question-answering system of the large language model, and the user query comes from the interaction between the question-answering system of the large language model and the user.
[0014] According to another aspect of the present application, a data analysis system based on a large language model is provided, the system comprising: an identification and distribution module, used to determine a query type according to a user query, and, based on the determined type, distribute the task for implementing the user query according to the determined type; an execution module, used to process the user query according to a preset mode and generate a code, the code being executable by a database to generate a query result for feeding back to the user; wherein the execution modules are arranged corresponding to the types so that one execution module processes one type of user query, and at least one of the execution modules is based on a large language model.
[0015] According to another aspect of the present application, a data analysis system based on a large language model is also provided, which includes one or more processors and a memory. The memory is coupled to the processor and stores instructions. When the instructions are executed by the processor, any one of the data analysis methods described herein can be implemented.
[0016] According to another aspect of the present application, a non-transitory storage medium is also provided, on which program instructions are stored, and when the program instructions are executed by a processor, any one of the data analysis methods described herein can be implemented.
[0017] According to yet another aspect of the present application, a computer program product is also provided, which can implement any one of the data analysis methods described herein when executed by a processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The following will describe the embodiments of the present application in detail with reference to the accompanying drawings so that the present application can be more fully understood, wherein:
[0019] Figure 1 is a system structure diagram of a data analysis method based on a large language model that can be implemented according to some embodiments of the present application;
[0020] Figure 2 is a flow chart of a data analysis method according to some embodiments of the present application;
[0021] Figure 3 is a schematic diagram of the execution process of the first execution module;
[0022] Figure 4 is a schematic diagram of the execution process of the second execution module;
[0023] Figure 5 is a schematic diagram of the execution process of the third execution module;
[0024] Figure 6 is a structural diagram of a data analysis system 6 according to some examples of the present application;
[0025] Figure 7The present invention is a schematic diagram of a specific application process of the data analysis method according to an example of the present application. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the following will be combined with the accompanying drawings to clearly and completely describe the implementation methods of the present application. It should be noted that the described implementation methods are only part of the implementation methods of the technical solution of the present application, not all. All other implementation methods obtained by ordinary technicians in this field based on the implementation methods recorded in the application documents without paying creative work are covered by the protection scope of the present application.
[0027] Figure 1 is a system structure diagram of a data analysis method based on a large language model that can be implemented according to some embodiments of the present application. Figure 1 As shown, the system structure includes an interactive interface 10 , an identification and distribution module 12 , an execution module 14 , and a database 16 .
[0028] The interactive interface 10 receives user input, including questions or queries input by the user, and transmits the received user input to the recognition and distribution module 12. The interactive interface 10 also receives feedback on the user input, including responses to the questions or queries input by the user. The interactive interface 10 can be configured on electronic devices such as desktop computers, laptop computers, tablets, mobile phones, wearable devices, etc.
[0029] After receiving the user input, the identification and distribution module 12 determines the query type of the user query according to the user input information. For example, the query type of the user query can be determined according to the keywords in the user input information. The identification and distribution module 12 distributes the task for implementing the user query to the execution module corresponding to the determined type. The user query includes user search, user query, user question, etc. In other words, the user query is not limited to "querying a certain data" and the like, but also includes more user input related to search, calculation, problem solving, etc.
[0030] In this example, the user's query questions have been classified in advance, and an execution module or a path for processing user queries has been preset for each classified type. There is a corresponding relationship between the pre-classified query types and the execution modules, that is, the execution module 14 includes different execution modules corresponding to the query types. For example, the query types include Class A and Class B, and the execution module includes an execution module for Class A queries and an execution module for Class B queries. After receiving the task distributed to it, each of the execution modules 14 further parses and processes the user input information according to the preset processing mode, and then generates a code for implementing the user query. The code generated by the execution module 14 runs in the database 16, thereby generating a query result for feedback of the user query. The database is, for example, a MySQL database.
[0031] The identification and distribution module 12 is constructed as an identification and distribution model, which is trained to parse user input and classify user queries according to keywords. In a specific example according to the present application, the user query types include prediction, basic query, and logical calculation. Accordingly, the execution module includes a first execution module 141 for prediction, a second execution module 142 for basic query, and a third execution module 143 for logical calculation.
[0032] In some examples, the recognition and distribution model is trained to determine that the user query type is prediction when the user input includes the keyword "prediction" or the main intention of parsing the user query is "prediction", thereby the recognition and distribution module 12 assigns the task of implementing the user query to the first execution module 141; when the user input includes keywords such as "month-on-month" and "year-on-year" or the main intention of parsing the user query requires calculation based on logical processing such as comparison of data, the user query type is determined to be logical calculation, thereby the recognition and distribution module 12 assigns the task of implementing the user query to the third execution module 143; when the user input is a query from historical data or a simple calculation that does not require logical analysis, the user query type is determined to be a basic query, thereby the recognition and distribution module 12 assigns the task of implementing the user query to the second execution module 142.
[0033] According to the example of the present application, the recognition and distribution module 12 can be based on a large language model. Specifically, the recognition and distribution module 12 can be a question-answering system based on a large language model (LLM), which can accurately classify the user input through question-answering interaction with the user.
[0034] Furthermore, the execution module 14 may include a large language model, and may be provided with some small data models, basic data tables, etc. as required, as will be described in the following specific examples.
[0035] As an example, the identification and distribution module 12, the execution module 14, and the database 16 may be distributed, such as being located in the cloud. In some examples, the distribution module 12 and the execution module 14 may be set in the same electronic device, such as the same computer or the same server. The database 16 may be stored independently, or may be set in the same electronic device with any one or both of the identification and distribution module 12 and the execution module 14. This application does not limit this.
[0036] Figure 2 It is a flow chart of a data analysis method according to some embodiments of the present application. In step S100, the query type is determined according to the user query. The user query can be a query request input by the user through the interactive interface, and the input method can be text, voice, etc. The query type can be determined according to the keywords in the user query. For example, when the keyword of the user query is "prediction", it is determined that the user query type is related to prediction; when the user information includes "month-on-month" or "year-on-year", it is determined that the user wants to calculate based on existing data and historical data, and this type of query type is a logical calculation. In some examples, the query request input by the user through the interactive interface is identified by the LLM, and the LLM is pre-trained with financial payment domain knowledge so that it can better interact with the user, thereby accurately understanding the user query, thereby determining the user query category. In step S102, according to the determined query type, the task for implementing the user query is distributed to the execution module corresponding to the type. In step S104, the execution module that receives the task processes the user input information according to the preset processing mode and generates a code for implementing the user query. As an example, the execution module includes at least one execution module using a large language model, and may also include an execution model using an agent. Each module processes different types of users and has different processing methods. In step S106, the generated code is imported into a database, and the database runs the code to generate data that realizes the user's query intention, thereby generating query results for feedback to the user.
[0037] As an example, the query result can be output to the user through the question-answering system of the large language model. The user inputs the query question from the interactive interface. During this process, the question system of the large language model interacts with it, understands its input, outputs inferences during the interaction, and the user confirms or adjusts the inferences in further interactions. As a result, the question-answering system eventually forms an accurate user query. According to the example of the present application, the user query is processed by the execution block. In this example, the query result is output to the user by the question-answering system. In this way, the entire query process can be completed only through an electronic device including an interactive interface, and in the entire process, the query can be implemented only with the help of the interactive interface, which is convenient and friendly to the user.
[0038] Corresponding to the query type, in the example where the query type includes prediction, logical calculation and basic query, the execution module includes a first execution module, a second execution module and a third execution module. The first execution module processes prediction tasks, the second execution module processes basic query tasks, and the third execution module processes logical calculation tasks.
[0039] If, in step S104, the execution module that receives the task is the first execution module, the first execution module Figure 3 The process shown is as follows. Figure 3 As shown, a user query of the prediction type is distributed to the first execution module. After receiving the task, the first execution module obtains (step S300) the data base table according to the user query information included in the distributed task. The data base table is pre-stored and includes historical data tags. Run the sub-model to make predictions based on the historical data involved in the base table, as shown in step S302. The sub-model can index the required historical data through the tag, use it as a basis for prediction, and store the prediction results in the database in the form of a data table. The sub-model is, for example, a developed python package. In step S304, code is generated for querying the data table generated in step S302. For example, the code can be generated according to the query template. In this way, after the code is imported into the database, the code is executed, and data, that is, the query results, can be generated, so as to feedback the user and complete the user query.
[0040] If, in step S104, the execution module that receives the task is the second execution module, the second execution module Figure 4 The process shown is as follows. Figure 4 As shown, the user query of the basic query type is distributed to the second execution module. After receiving the task, the second execution module obtains (step S400) the data base table according to the user query information included in the distributed task, wherein the base table includes a historical data tag. In step S402, the user query data is searched from the historical data involved in the base table, and the query result is stored in the database in the form of a data table. In step S404, a code for querying the data table generated in step S402 is generated. In this way, after the code is imported into the database, the code is executed to generate data, that is, the query result, so as to feedback the user and complete the user query.
[0041] If, in step S104, the execution module that receives the task is the third execution module, the third execution module Figure 5 The process shown is as follows. Figure 5As shown, the user query of the basic query type is distributed to the third execution module. After receiving the task, the third execution module uses the retrieval-augmented generation (RAG) model to search the user input information, that is, the standard terms of the common words in the user query statement in step 500. According to the example of the present application, the financial payment domain knowledge is introduced in advance into the RAG model knowledge base, and the introduced financial payment domain knowledge corresponds to the knowledge of the training LLM financial payment domain prompt words. In step S502, the common words in the query statement are replaced with standard terms, and the user query statement is reassembled with the standard query template to form a standard query statement.
[0042] As an example, the following Table 1 shows some common words and standard terms, where the first column is common words, which may be abbreviations or ambiguous users; the second column lists the standard terms of the common words in the corresponding row in the first column. The common words and standard terms pre-set in the RAG model knowledge base are not limited to this example. In addition, during the execution of the method of this application, the RAG model is also constantly enriching the knowledge base based on feedback.
[0043] Table 1
[0044] Common words (fuzzy value) Standard term (standard value) Banks and Merchants UnionPay Business Silver Merchant UnionPay Business ICBC ICBC supermarket Supermarket convenience Supermarket Supermarket convenience Home Home Furnishing Home Improvement Home Furnishing
[0045] Back to Figure 5 . In step S504, prompt words for standard sentences are generated through the prompt word project. The prompt word project is pre-configured with a knowledge base of a specific field, and the generated prompt words include field prompt words. It should be understood that prompt words may also include general prompt words. In step S506, the large language model obtains the data base table according to the content of the field prompt words, general prompt words, and standard sentences, obtains data related to the user query from the historical data involved in the base table, and performs analysis, logical calculations, etc. according to the guidance of the prompt words, and stores the logical calculation results in the form of data tables in the database. In step S508, the large language model also generates code. The code generated in step S508 is input into the database, and the analysis results stored in the query data table are executed in the database to generate query results for feedback of user queries.
[0046] Through the prompt word engineering, we build the prompt words for the large language model LLM application in the field of financial payment, for example, and constrain the rules for the code generation of the large language model LLM, thereby forming domain prompt words, where the prompt words are composed of general code generation rules, code generation constraints, database declarations and table structures, keyword mappings, and thought connections. The prompt word engineering uses prompt words to help the large language model LLM understand the specific intention of the user's query and guide the LLM to execute the processing according to the prompt words, thereby generating code.
[0047] The logic computing ability of the basic large language model is relatively weak, and there is no knowledge for specific fields, which makes the basic LLM unable to solve the query problems in specific fields with high performance. In the example of this application, by expanding the knowledge base of the prompt word engineering, the prompt word engineering can give prompt words that are more in line with specific fields based on the basic prompt words for user queries, so that LLM can understand the query content more accurately and solve it accurately. Not only that, the design of the prompt words for specific fields can also decompose the complex logical problems in specific fields into multiple prompt words, guiding LLM to operate according to each prompt word without LLM having to perform complex logical analysis that it is not good at.
[0048] In a further example, generating prompt words for standard sentences through prompt word engineering in step 504 may include matching standard sentences with prompt word modules in a specific field to generate field prompt words. As an example, field prompt words may be generated through the following process: determining the data table required for the user query and generating a database statement; determining the index to be queried and generating a logical calculation prompt; determining the query conditions and generating a data schema and value prompt; matching similar code samples from existing codes. The following will illustrate this process with a specific example.
[0049] The data analysis method of the example of this application is executed. When a user question is received, it is first pre-processed to confirm the category of the user query, and then the user query is distributed to the execution module that handles the category according to the determined query category. The corresponding execution module processes the query, thus constructing an efficient question-and-answer data analysis model.
[0050] In addition, the data base table in each example of this application is a pre-set scenario-related data table. Through this base table, you can flexibly query scenario-related indicators, and quickly query data from multiple aspects such as time, indicators, and data subjects. Scenario, transaction time, data subject, etc. can all be used as labels for historical data. According to each example of this application, not only can data analysis results be generated by querying, analyzing, calculating, etc. based on the data base table, but database code can also be generated. In this way, the real-time and generalization of data analysis are improved, the threshold for data analysis is lowered, the repetitive work of data analysts is reduced, and the applicability and work efficiency of the scenario are improved.
[0051] In the example of this application, in addition to the data base table that may be repeatedly used due to overlapping data involved in user queries, the sub-model of the second execution module, the prompt words and standard sentences in the third execution module are also reusable, which saves computing resources and enables faster data analysis.
[0052] Furthermore, in the example of the present application, both the RAG model and the prompt word engineering introduce knowledge of specific fields (such as the financial payment field), which makes the standard sentences constructed based on the RAG model easier to be processed by the prompt word engineering and matched with the prompt word module. Accordingly, accurate and targeted field prompt words can simplify complex logical problems and guide LLM to perform logical analysis and processing quickly and accurately.
[0053] Figure 2 The examples of the methods shown can be implemented by Figure 1 For example, a user inputs a user query through the interactive interface 10. After receiving the user query, the identification and distribution module 12 determines (step S100) the query type, and distributes (step S102) the task for implementing the user query to the execution module according to the determined query type. The execution module 14 that receives the task processes the user query according to the preset processing mode and generates a code for implementing the user query, as shown in step S104. The generated code is imported into the database 16, and the code is executed in the database to generate data for implementing the user query, and then the query result for feeding back to the user is generated, as shown in step S106. The generated query result is fed back to the user interface 10.
[0054] Figure 6 is a structural diagram of a data analysis system 6 according to some other examples of the present application. The data analysis system 6 performs the above combined with the attached Figures 2 to 5 In some embodiments, the data analysis system 6 provides some functions according to the examples described in this application or in the examples of this application. Figure 1 The described system may be partially or completely integrated into the data analysis system 6, for example, the identification and distribution module is provided in the system 6, while the execution module is not included in the system 6. In some cases, the modules, processors, memories, etc. in the system may be implemented in the same electronic device. In other cases, the data analysis system 6 is distributed, that is, the modules, processors, memories, etc. in the system are implemented in different electronic devices, or are provided in the cloud.
[0055] In the specific example of the example, the data analysis system 6 includes a processor 600, a memory 602, and a communication interface 604. The memory 602 is coupled to the processor 600, for example, via a bus connection. The communication interface 604 is used for the data analysis system 6 to communicate with external devices. The processor 600 can obtain instructions stored in the memory 602 and execute these instructions. In the process of executing these instructions, the processor 600 can implement the following process: determine the query type according to the user query; according to the determined type, distribute the task of implementing the user query to the execution module corresponding to the type; and enable the execution module that receives the task to process the user query according to the preset mode and generate code. The processor 600 can transmit the generated code to the database 700 through the communication interface 604, so that the database 700 executes the code and generates a query result for feedback to the user. The database 700 is set separately from the data analysis system 6. As an alternative, the database 700 can be a component of the data analysis system. The database 700 includes memory hardware for storing data and software for managing data.
[0056] The data analysis system 6 can communicate with a large language model, an execution module, and other sub-models trained for data analysis set up in the cloud. Alternatively, the large language model, the execution module, the sub-model, etc. can be set in the data analysis system 6, or partially set in the system 6. For example, the large language model is set in the cloud, and the execution module is set in the data analysis system 6. Users can interact with the data analysis system 6 through an interactive interface set on electronic products such as mobile phones, tablets, and computers. The number of processors can be one or more, and the memory can also include multiple and different storage types.
[0057] In some examples, some of the instructions stored in the memory 602 can implement the identification and distribution module 12 (see Figure 1 ) so that the processor 600 parses the user input and determines the type of question the user is querying when executing these instructions. In these examples, the instructions are program instructions of the trained recognition and distribution model. In other examples, the recognition of the query information input by the user can be performed by a large language model.
[0058] In some examples, the processor 600 can also perform the following operations when executing the instructions: in the process of implementing the task, provide feedback to the large language model so that the large language model can improve the prompt words for the specific field; and / or provide feedback to the execution module so as to improve the execution module. The feedback includes user feedback on whether the query result is accurate or not, etc.
[0059] The above description of the recognition and distribution module 12 and the large language model is applicable to each embodiment of this article and will not be repeated. Similarly, the examples of the first execution module, the second execution module, and the third execution module described above in conjunction with the accompanying drawings are applicable to all embodiments of this article and will not be repeated.
[0060] In some examples, some of the instructions stored in the memory 602 can implement the functions of the execution module, so that the processor 600 can process the received tasks for implementing the user query in a preset manner when executing these instructions. In the example where the execution module cannot be implemented by the system 6, the processor 600 distributes the tasks for implementing the user query to the execution module disposed outside the system 6 via the communication interface 604 after identifying the question type of the user query.
[0061] According to an example of the present application, a storage medium is also provided, on which program instructions are stored. When the program instructions are executed, the methods of the examples described in the present application can be implemented.
[0062] According to the examples of the present application, a computer program product is also provided, which, when executed by a processor, can implement the methods of each example described in the present application. The computer product is, for example, an application program, which is loaded in a user's mobile phone, computer, tablet or other electronic product and executed by the electronic product through its processor.
[0063] Figure 7 This is a schematic diagram of the specific application of the data analysis method according to the example of this application. In this example, the data analysis method is applied in the field of financial payment. Please also refer to Figure 7 and Figure 1 .
[0064] The user inputs the user question through the client, specifically, the user inputs the user question through the client's interactive interface 10. In this example, the identification and distribution module 12 is a question-answering system based on LLM, which interacts with the user, analyzes the user question and gives prompt words. LLM better understands the user according to the prompt words, identifies (S700) the main intention of the user query, and then accurately classifies the user query, and distributes (S700) the task for realizing the user query to the corresponding execution module.
[0065] One of the received user queries is "How much did ICBC's offline consumption revenue grow year-on-year last month?", hereinafter referred to as User Query Example 1. Another received user query is "Predict the number of offline consumption transactions this month?", hereinafter referred to as User Query Example 2.
[0066] For the user query example 1, the identification and distribution module 12 identifies that it involves relatively complex logical calculations and determines that it should be executed by the third execution module. Accordingly, the task for implementing the query is distributed to the third execution module 143.
[0067] For the second user query example, the identification and distribution module 12 identifies it as a prediction and determines that it should be executed by the first execution module 141. Accordingly, the task for implementing the query is distributed to the first execution module 141.
[0068] The execution module that receives the task executes (S702) the task according to the preset processing method. In this example, multiple data base tables have been pre-stored. Each data base table includes at least a historical data tag, and the historical data involved in each base table is transaction data in different scenarios in the financial payment field. According to the example of this application, the data base table is configurable, that is, it can be added, modified, deleted, etc.
[0069] For user query example 1, the third execution module 143 first searches for standard terms corresponding to common words in the user query sentence using the RAG model in step S7021A, wherein the standard terms are pre-configured. The standard terms corresponding to "ICBC", "acquiring institution", and "income" in the query sentence are "ICBC", "acquiring institution", and "offline consumption income" respectively.
[0070] In step S7022A, a standard query statement is constructed. Specifically, the common words in the query statement are replaced with standard users, and the user query statement is reassembled with a standard query template. The setting of standard query templates and standard terms makes it easier, more accurate, and faster for the large language model to understand user queries in subsequent processing. In this example, the constructed standard statement is transformed into "In March 2024, what is the year-on-year increase in the revenue of the acquirer for ICBC?"
[0071] In step S7023A, the constructed standard sentence is matched with the prompt word module through the prompt word engineering to provide the general prompt words and the field prompt words in the financial payment field for the user's query. Specifically including:
[0072] (1) Determine the data base table to be queried and generate a database statement. The data statement generated for this user query example 1 is as follows:
[0073] Database name: bus i ness
[0074] Table structure definition: ['indicators(trade_month(trading month),
[0075] branch, acqui rer, scene,
[0076] trade_count (number of transactions), trade_amount (transaction amount),
[0077] income(income)), and table comment: consumption table']
[0078] (2) Determine the indicator to be queried and generate a logical calculation prompt. Based on the fact that the user query includes "year-on-year", the logical calculation prompt generated for the user query example 1 is as follows:
[0079] 1. Get this month's income
[0080] 2. Get the income of last year in that month
[0081] 3. Calculate the value of "this month's income - last year's month's income"
[0082] 4. Calculate "income_dif / last year's income" to get the year-on-year income
[0083] (3) Determine the query conditions and generate data schema and value prompts. Some fields in the data base table need to be valued, such as date, organization name, etc. The third execution module generates prompts for this purpose to execute the query faster. The data schema and value prompts generated for the user query example 1 are as follows:
[0084] 1. Transaction date (trade_date): 2024-03-09, 2024-04-01;
[0085] 2.Trade month (trade_month): 2024-03, 2023-11, 2023-03, 2023-05;
[0087] 3. Branch: Shanghai Branch, Jilin Branch;
[0088] 4. Acquirer: Bank of Communications;
[0089] 5. Transaction scene: department store
[0090] (4) Matching code samples similar to user queries. As an example, code samples have been generated for some common user queries, and the third execution module uses them as prompts to help quickly generate code later. In addition, each code generated for a user query can be used as a code sample. The sample matched for the user query example 1:
[0091] -User question: "Calculate the total revenue of 'XX Branch' in March 2024 (2024-03), query from the consumption table (indicators)"
[0092] -Generate SQL: "se l ect sum(i ncome)as tota l_i ncome from
[0093] i nd i cators where trade_month='2024-03'and branch=
[0094] 'XX branch';"
[0095] (5) Generate general prompt words. In addition to the domain prompt words, the third execution module also generates general prompt words. The general prompt words generated for the user query example 1 are as follows:
[0096] 1. Always limit queries to a maximum of 50 results unless the user specifies a specific number of rows they wish to obtain in the question.
[0097] 2. It is prohibited to fabricate information at will.
[0098] Based on the above prompts, generate complete prompt words, including field prompt words and general prompt words.
[0099] In step S7024A, the large language model obtains the required data based on the complete prompt words (including general prompt words and domain prompt words) and the constructed standard sentence of the user query sentence, analyzes it, and generates code.
[0100] In step S7025A, the generated code is run in the MySQL database to reply the query result of the user's query. The query result is fed back to the user. As an example, the query result can be output to the user by a question-answering system of a large language model.
[0101] For user query example 2, the first execution module 141 first obtains the required data base table from the database in step S7021 B, which includes historical transaction data tags. In step S7022B, the sub-model is run, which is a developed python package that makes predictions based on historical transaction conditions. In step S7023B, the prediction results of the sub-model are stored in the database as a data table. In step S7024B, based on the query template, a query code that meets the user query requirements is generated. For user query example 2, the generated code is as follows:
[0102] select ____trade_amount___
[0103] from target_forecast
[0104] where trade_month='__2024-05__'and branch='__XX__'
[0105] In step S7025B, the generated code is input into the MySQL database for execution to generate a query result suitable for the user's query. The query result is fed back to the user, and as an example, can be output to the user through a question-answering system of a large language model.
[0106] Although specific embodiments of the present application have been shown and described in detail to illustrate the principles of the present application, it should be understood that the present application may be implemented in other ways without departing from such principles, for example, the technical features of the various embodiments / examples / examples of the present application may be combined with each other to form new implementation methods.
Claims
1. A data analysis method based on a large language model, characterized in that: The method comprises: Determine the query type based on the user query; Distributing, according to the determined type, the task for implementing the user query to an execution module corresponding to the type; The execution module receiving the task processes the user query according to a preset mode and generates a code for implementing the user query; Execute the code in the database to generate query results for feedback to the user; The execution modules are arranged corresponding to the types so that one execution module processes one type of user query, and at least one of the execution modules is based on a large language model.
2. The method according to claim 1, characterized in that The execution module includes a first execution module for prediction, a second execution module for basic query and a third execution module for logical calculation.
3. The method according to claim 2, characterized in that When the execution module receiving the task is the first execution module, the user query is processed according to a preset mode and a code is generated, including: Obtaining a data base table, wherein the base table includes historical data tags; Running a sub-model to make predictions based on the historical data involved in the base table; Storing the prediction results in a database in the form of a data table; Generate code for querying the data table.
4. The method according to claim 2, characterized in that: When the execution module receiving the task is the second execution module, processing the user input information according to a preset mode and generating a code for implementing the task, including: Obtaining a data base table, wherein the base table includes historical data tags; Searching for the data queried by the user in the historical data involved in the basic table; The queried data is stored in the database in the form of a data table; Generate code for querying the data table.
5. The method according to claim 2, characterized in that: When the execution module receiving the task is the third execution module, processing the user input information according to a preset mode and generating a code for implementing the task includes: constructing the user query into a standard sentence, wherein the standard sentence is based on knowledge in a specific field; Generate prompt words for the standard sentence through a prompt word project, wherein the prompt word project is pre-configured with a knowledge base of the specific field, and the prompt words include field prompt words; A code is generated by a large language model according to the domain prompt words and the content of the standard sentence.
6. The method according to claim 5, characterized in that Generating prompt words of the standard sentence through prompt word engineering includes: The standard sentence is matched with the prompt word module of the specific field to generate field prompt words.
7. The method according to claim 6, characterized in that Matching the standard sentence with the prompt word module of the specific field to generate a field prompt word includes: Determine the data table required by the user query and generate a database statement; Determine the indicators that need to be queried and generate logical calculation prompts; Determine the query conditions and generate data schema and value prompts; Match similar code samples from existing code.
8. The method according to claim 5, characterized in that The user query is constructed into a standard statement, including: Search for standard terms commonly used in user query statements; The common words are replaced with standard terms, and the user query statement is reassembled with a standard query template to generate a standard query statement; The standard terms are commonly used terms in the specific field.
9. The method according to any one of claims 1 to 8, characterized in that The query result is output to the user through the question-answering system of the large language model, and the user query comes from the interaction between the question-answering system of the large language model and the user.
10. A data analysis system based on a large language model, characterized in that: The system comprises: an identification and distribution module, configured to determine a query type according to a user query, and, based on the determined type, distribute tasks for implementing the user query according to the determined type; An execution module, used to process the user query according to a preset mode and generate a code, wherein the code can be executed by the database to generate a query result for feeding back to the user; The execution modules are arranged corresponding to the types so that one execution module processes one type of user query, and at least one of the execution modules is based on a large language model.
11. The system according to claim 10, characterized in that The execution module includes a first execution module for prediction, a second execution module for basic query and a third execution module for logic calculation.
12. The system according to claim 11, characterized in that The first execution module is used to process the user query and generate a code for implementing the task through the following process: Obtaining a data base table, wherein the base table includes historical data tags; Running a sub-model to make predictions based on the historical data involved in the base table; The prediction result is stored in the database in the form of a data table; Generate code for querying the data table.
13. The system according to claim 11, characterized in that The second execution module is used to process the user query and generate code through the following process: Obtaining a data base table, wherein the base table includes historical data tags; Searching for the data queried by the user in the historical data involved in the basic table; The queried data is stored in the database in the form of a data table; Generate code for querying the data table.
14. The system according to claim 11, characterized in that The third execution module is used to process the user query and generate a code through the following process: constructing the user query into a standard sentence, wherein the standard sentence is based on knowledge in a specific field; Generate prompt words for the standard sentence through a prompt word project, wherein the prompt word project is pre-configured with a knowledge base of the specific field, and the prompt words include field prompt words; A code is generated by a large language model according to the domain prompt words and the content of the standard sentence.
15. The system according to claim 14, characterized in that The third execution module is used to generate a domain prompt word by matching the standard sentence with the prompt word module of the specific domain.
16. The system according to claim 15, characterized in that The third execution module is used to match the standard sentence with the prompt word module of the specific field to generate a field prompt word through the following process: Determine the data table required by the user query and generate a database statement; Determine the indicators that need to be queried and generate logical calculation prompts; Determine the query conditions and generate data schema and value prompts; Match similar code samples from existing code.
17. The system according to claim 14, characterized in that The third execution module is configured to construct the user query into a standard statement through the following process: Search for standard terms commonly used in user query statements; The common words are replaced with standard terms, and the user query statement is reassembled with a standard query template to generate a standard query statement; The standard terms are commonly used terms in the specific field.
18. A data analysis system based on a large language model, characterized in that: The system comprises: one or more processors; A memory coupled to the processor, the memory comprising instructions executable by the processor, wherein the processor can implement the method according to any one of claims 1 to 9 when executing the instructions.
19. The system according to claim 18, characterized in that The processor can also perform the following operations when executing the instructions: In the process of achieving the task, providing feedback to the large language model so that the large language model can improve the prompt words for the specific field; and / or providing feedback to the execution module so as to improve the execution module.
20. A non-transitory storage medium, characterized in that: The storage medium stores program instructions, which can implement the method according to any one of claims 1 to 9 when executed.
21. A computer program product, characterized in that When the computer program product is executed by a processor, the method according to any one of claims 1 to 9 can be executed.
Citation Information
Cited By
Multi-modal auxiliary precision manufacturing database interaction method based on large model
CN120104817A
Data intelligent auxiliary analysis method, system, equipment and medium
CN120407603A
Construction method of business meta-knowledge base and local data analysis method based on business meta-knowledge base
CN121301583A