Data analysis method and device, electronic equipment and storage medium
By introducing chain reasoning tasks of large language models into data analysis methods, the problem of insufficient data analysis efficiency and accuracy in the existing technology is solved, and an automated data analysis process is realized, which improves the efficiency and accuracy of data analysis.
Patent Information
- Application Number
- CN202411951240.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-03-28
AI Technical Summary
The efficiency and accuracy of data analysis methods in the prior art are poor, and traditional methods rely on manual operations and cannot handle complex business logic and analysis requirements in depth. Solutions based on large language models have shortcomings in complex query processing and context understanding.
By obtaining the requirements text and retrieving relevant candidate structured data, a large language model is used to perform chain reasoning tasks in turn, including field filtering, code generation and data analysis tasks, to generate accurate data analysis code and natural language interpretation, simplifying user operation process.
It greatly improves the efficiency and accuracy of data analysis. Users only need to enter query requirements, and the system can automatically complete the entire process from field retrieval to code generation and then to data analysis, which is suitable for complex and personalized data analysis needs.
Smart Images

Figure CN119721255A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence and big data analysis technology, and in particular to a data analysis method, device, electronic device and storage medium. Background Art
[0002] With the development of the education industry, the scale of schools continues to expand, and the accumulation of teaching data is increasing, making the management and data analysis of large-scale databases particularly important. In many aspects such as teacher management, teaching quality evaluation, and course scheduling, school decisions are increasingly dependent on big data analysis. However, teacher databases often contain multidimensional data, such as teachers' basic information, teaching activities, teaching results, class observation and evaluation records, etc. How to efficiently extract valuable information from these data has become a problem that needs to be solved urgently.
[0003] At present, traditional data analysis methods mainly rely on manual operations of data scientists, which greatly reduces the utilization rate of data. Traditional database query tools can only handle relatively simple queries and cannot deeply handle complex business logic and analysis needs. This limitation makes it impossible for users to obtain comprehensive analysis results through a single query, and often requires repeated queries and manual data processing, which greatly reduces work efficiency.
[0004] In recent years, technologies based on large language models have gradually emerged. By leveraging their powerful natural language processing capabilities, they can enable users to input natural language queries and automatically generate corresponding database query codes. This approach combines the data retrieval module, which can enhance the model's understanding of the database structure and content, and automatically generate data analysis codes and natural language interpretations. However, solutions based on large language models still face some problems, such as insufficient processing capabilities for complex queries and possible understanding biases in certain contexts. These shortcomings limit their comprehensive application in the field of data analysis. Summary of the invention
[0005] The present invention provides a data analysis method, device, electronic device and storage medium to solve the defects of poor efficiency and accuracy of data analysis methods in the prior art.
[0006] The present invention provides a data analysis method, comprising: Obtaining a demand text, and retrieving candidate structured data related to the demand text; Based on the requirement text and the candidate structured data, sequentially executing chained reasoning tasks corresponding to the requirement text through a large language model, wherein the chained reasoning tasks include at least one of a field screening task, a code generation task, and a data analysis task; Based on the output result of the tail-wheel reasoning task, a data analysis result for the requirement text is determined.
[0007] According to the data analysis method provided by the present invention, based on the requirement text and the candidate structured data, chain reasoning tasks corresponding to the requirement text are sequentially performed through a large language model, including: Determine prompt instructions for the current round of reasoning tasks based on the output results of the previous round of reasoning tasks, the requirement text, and the candidate structured data; Inputting the prompt instruction of the current round of reasoning task into the large language model to obtain the output result of the large language model for the current round of reasoning task; The output result of the current round of reasoning tasks is used as the output result of the previous round of reasoning tasks, and the chain reasoning tasks are executed in sequence until the output result of the last round of reasoning tasks is obtained.
[0008] According to the data analysis method provided by the present invention, the step of determining the prompt instruction for the current round of reasoning task based on the output result of the previous round of reasoning task, the requirement text and the candidate structured data includes: Determine a task description for a current round of reasoning tasks based on the output results of the previous round of reasoning tasks, the requirement text, and the candidate structured data; Determine a prompt instruction for the current round of reasoning task based on the process planning instruction of the chain reasoning task and the task description of the current round of reasoning task; The process planning instruction includes a workflow description of the chain reasoning task.
[0009] According to the data analysis method provided by the present invention, the retrieving and obtaining candidate structured data related to the requirement text includes: Extracting text features of the demand text and field features of fields in a preset database; Based on the similarity between the text feature and the field feature, a first related field table is retrieved from the preset database; Based on the first related field table, candidate structured data related to the requirement text is determined.
[0010] According to the data analysis method provided by the present invention, determining candidate structured data related to the requirement text based on the first related field table includes: Based on the keywords in the requirement text and / or based on a preset rule engine, retrieve and obtain a second related field table; Based on the first related field table, the second related field table, and the field descriptions and knowledge meta-information in the knowledge base, candidate structured data related to the requirement text is determined.
[0011] The data analysis method provided by the present invention further includes: Obtaining a code snippet generated by the large language model for the code generation task; The code snippet is run based on a code sandbox, and the code running result is returned to the large language model, so that the large language model performs the data analysis task based on the code running result.
[0012] According to the data analysis method provided by the present invention, the large language model performs the data analysis task based on the code running result, including: If the code running result indicates that the code running is successful, the large language model performs the data analysis task based on the code running result; If the code running result indicates that the code running fails, the large language model performs error analysis based on the code running result.
[0013] The present invention also provides a data analysis device, comprising: A retrieval unit, used to obtain a demand text and retrieve candidate structured data related to the demand text; An inference unit, configured to sequentially perform chained inference tasks corresponding to the requirement text through a large language model based on the requirement text and the candidate structured data, wherein the chained inference tasks include at least one of a field screening task, a code generation task, and a data analysis task; A determination unit is used to determine a data analysis result for the requirement text based on an output result of the tail wheel reasoning task.
[0014] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-mentioned data analysis methods when executing the computer program.
[0015] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the data analysis method described in any one of the above is implemented.
[0016] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the data analysis methods described above.
[0017] The data analysis method, device, electronic device and storage medium provided by the present invention can improve the efficiency of data retrieval by combining the advantages of traditional information retrieval systems with the functions of generative large-scale language models; based on chain reasoning, accurate data analysis codes and natural language interpretations are generated through large language models to simplify the user operation process. Users only need to input query requirements, and the system can automatically complete the entire process from field retrieval to code generation and then to data analysis, greatly improving the efficiency and accuracy of data analysis. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 It is one of the flow charts of the data analysis method provided by the present invention.
[0020] Figure 2 It is a flowchart of step 110 in the data analysis method provided by the present invention.
[0021] Figure 3 It is a schematic diagram of the chain reasoning process provided by the present invention.
[0022] Figure 4 It is a flowchart of the code sandbox operation provided by the present invention.
[0023] Figure 5 This is the second flow chart of the data analysis method provided by the present invention.
[0024] Figure 6 It is a structural schematic diagram of the data analysis device provided by the present invention.
[0025] Figure 7 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not 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.
[0027] At present, traditional data analysis methods mainly rely on manual operations by data scientists. These methods need to gradually complete the various links of field selection, code writing, data cleaning and analysis according to specific business needs. For educators without a data analysis background, it is almost impossible to complete these complex operations independently. This not only greatly reduces the utilization rate of data, but also seriously affects the decision-making efficiency of schools. Although some automated data analysis tools have been launched, there are still significant deficiencies in flexibility, intelligence and customization, and it is difficult to meet the complex and personalized data analysis needs in the education industry. Although there are many mature solutions in the field of database management and query tools, these tools usually require users to have a strong technical background, especially in data analysis and programming. Users not only need to clearly understand the database structure and the relationship between its tables, but also must be able to write corresponding analysis codes. For users who do not have these technical capabilities, even if they have rich knowledge of the education industry, it is difficult to efficiently extract the required data from the database and draw valuable conclusions. In addition, traditional database query tools can only handle relatively simple queries and cannot obtain complex business information through natural language. Even if some tools support natural language queries, the algorithms behind them usually only stay at simple surface queries and cannot deeply handle complex business logic and analysis needs. This limitation makes it impossible for users to obtain comprehensive analysis results through a single query, and often requires repeated queries and manual data processing, which greatly reduces work efficiency.
[0028] Data analysis based on the Large Language Model (LLM) is of great significance in the education industry. Through the combination of natural language processing and deep learning, LLM has greatly reduced the technical threshold for data analysis, allowing educators without programming or data analysis backgrounds to easily complete complex query tasks. In addition, the flexibility and customization capabilities of LLM can handle complex business logic and adapt to the personalized analysis needs of different schools, thereby improving data utilization and decision-making efficiency, and promoting data-driven management and teaching quality improvement in the education industry.
[0029] Existing data analysis technology solutions can be roughly divided into the following three categories: Based on the traditional data analysis solution: This solution mainly relies on SQL query language to extract and analyze data. The analysis process is usually carried out manually, by writing complex query statements to obtain the required data, and manually cleaning and analyzing the data. The limitation of this method is that it is inefficient, especially when faced with a large amount of data, manual analysis requires a lot of time and energy. In addition, traditional analysis methods often rely on static reports, which are difficult to quickly respond to users' dynamic query needs, limiting the timeliness of decision-making.
[0030] Data analysis solution based on machine learning: This solution introduces machine learning algorithms to build models by learning from historical data for prediction and analysis. It usually uses multiple algorithms such as supervised learning and unsupervised learning, and relies on feature engineering to optimize model performance. However, the disadvantage of this solution is that it requires a large amount of labeled data for training, which is time-consuming and requires professional domain knowledge. More importantly, machine learning models lack flexibility and are not responsive enough to real-time changing query requirements, resulting in poor user experience.
[0031] Data analysis solutions based on large language models: In recent years, technologies based on large language models have gradually emerged. By leveraging their powerful natural language processing capabilities, users can input natural language queries and automatically generate corresponding database query codes. This approach combines the data retrieval module, which can enhance the model's understanding of the database structure and content, and automatically generate data analysis codes and natural language interpretations. However, solutions based on large language models still face some problems, such as insufficient processing capabilities for complex queries and possible understanding biases in certain contexts. These shortcomings limit their comprehensive application in the field of data analysis.
[0032] In response to the above problems, an embodiment of the present invention proposes a data analysis method, in which candidate structured data related to the requirement text is first retrieved, and based on the requirement text and the candidate structured data, chain reasoning tasks corresponding to the requirement text are executed in sequence through a large language model, and the chain reasoning tasks include at least one of a field screening task, a code generation task and a data analysis task; based on the output result of the tail-wheel reasoning task, the data analysis result for the requirement text is determined.
[0033] The embodiment of the present invention combines the advantages of traditional information retrieval systems (such as databases) with the functions of generative large language models (LLMs), which can improve data retrieval efficiency; based on chain reasoning, accurate data analysis code and natural language interpretation are generated through large language models to simplify user operation processes. Users only need to enter query requirements, and the system can automatically complete the entire process from field retrieval to code generation and then to data analysis, greatly improving the efficiency and accuracy of data analysis.
[0034] The embodiments of the present invention can be applied to scenarios where data analysis is required, such as teacher portrait data analysis scenarios in the education industry. The execution subject of the method can be an electronic device such as a terminal device, a computer, a server, a server cluster, or a specially designed data analysis device, or a data analysis device set in the electronic device, which can be implemented by software, hardware, or a combination of the two.
[0035] In the description of the embodiments of the present invention, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0036] Figure 1 It is one of the flow charts of the data analysis method provided by the present invention, such as Figure 1 As shown, the method comprises the following steps: Step 110: Obtain the requirement text, and retrieve candidate structured data related to the requirement text.
[0037] Specifically, the requirement text refers to the data analysis requirements input by the user, which is used to describe the specific requirements of the data that the user wants to query or analyze, and may include requirements for specific fields, data types, analysis methods, etc. The requirement text is usually expressed in the form of natural language. For example, the requirement text can be "Please draw a pie chart of the proportion of teachers of different ethnic groups."
[0038] After obtaining the demand text, the system retrieves the structured data related to the demand text, namely the candidate structured data, through search engines or database queries. The candidate structured data is retrieved based on the demand text and is a collection of data related to the user's request. This data is usually stored in tables, database records or other structured formats to facilitate computer processing and analysis.
[0039] For example, if the requirement text is "Please draw a pie chart of the proportion of teachers of different nationalities", the retrieved candidate structured data may include a data table related to the field "nationality".
[0040] Step 120, based on the requirement text and the candidate structured data, chain reasoning tasks corresponding to the requirement text are executed in sequence through a large language model, and the chain reasoning tasks include at least one of a field screening task, a code generation task, and a data analysis task.
[0041] Step 130, based on the output result of the tail-wheel reasoning task, determine the data analysis result for the requirement text.
[0042] Specifically, existing data analysis technologies rely on multiple independent tools and platforms, resulting in cumbersome processes for data extraction, cleaning, and analysis. This requires users to have high technical capabilities and frequently switch between different systems, increasing learning costs and usage barriers. In addition, data analysis results often require multiple manual interventions, further reducing the degree of automation.
[0043] In addition, existing large models are insufficient in task adaptability, and many systems perform poorly under specific tasks, especially in educational applications. Existing models are difficult to update and optimize in real time, resulting in a lack of pertinence and practicality in analysis results, and users often find it difficult to obtain satisfactory analysis results.
[0044] Based on this, this embodiment sequentially executes chain reasoning tasks corresponding to the requirement text through a large language model based on the requirement text and the candidate structured data. Chain reasoning tasks are a series of reasoning tasks performed in sequence, and each task is based on the output of the previous task. In this process, chain reasoning tasks include at least one of field screening, code generation, and data analysis. That is, multiple rounds of chain reasoning tasks can be performed for at least one of the field screening, code generation, and data analysis tasks. For example, for the field screening task, multiple rounds of chain reasoning are performed until the fields that meet the requirements are obtained; or for the field screening and code generation tasks, multiple rounds of chain reasoning are performed until a code snippet that meets the requirements is generated.
[0045] The field screening task refers to screening out fields or data columns related to the requirement text from the candidate structured data. The code generation task refers to automatically generating code or scripts for data analysis based on the screened data. The data analysis task may include executing the generated code, conducting in-depth analysis on the screened data, and generating analysis results.
[0046] The data analysis result is the final output of the chain reasoning task. It is a response to the query or analysis requirement raised in the requirement text and is usually presented in the form of charts, reports or other visualizations.
[0047] For example, in response to the requirement text “Please draw a pie chart showing the proportion of each nationality among teachers”, the data analysis result can be a pie chart that reflects the proportion of each nationality among teachers.
[0048] The data analysis results can be achieved by inputting the requirement text and candidate structured data into a large language model. The large language model first performs a field screening task to determine which data fields are relevant; then, based on the screened data, it generates code for data analysis; finally, it executes the generated code to perform an in-depth analysis of the data. The code execution task here can be performed by a large language model, or it can be a code execution environment isolated from the large language model, which is responsible for running the code generated by the large language model. The embodiments of the present invention do not specifically limit this.
[0049] The last task of the chain reasoning task is the data analysis task, and its output is the data analysis result for the requirement text. The data analysis result can be used to generate reports, charts or other visualization forms for users to understand and use.
[0050] For example, when a user queries "the total number of teachers who participated in different types of class observation and evaluation this semester", the chain reasoning task planning will first identify the relevant fields through the field selection task, then generate the corresponding Python code through the code generation task, and finally interpret the running results through the data analysis task.
[0051] The method provided in the embodiment of the present invention generates accurate data analysis code and natural language interpretation based on chained reasoning tasks and large language models on the basis of obtaining candidate structured data through information retrieval, thereby simplifying the user operation process. The user only needs to enter the query requirements, and the system can automatically complete the entire process from field retrieval to code generation and then to data analysis, greatly improving the efficiency and accuracy of data analysis.
[0052] Based on any of the above embodiments, the candidate structured data related to the requirement text is retrieved in step 110, specifically including: Step 111, extracting text features of the demand text and field features of fields in a preset database; Step 112, based on the similarity between the text feature and the field feature, retrieve a first related field table from a preset database; Step 113: Determine candidate structured data related to the requirement text based on the first related field table.
[0053] Specifically, the retrieval of candidate structured data can be achieved through feature similarity. Natural language processing techniques such as bag-of-words model, TF-IDF, word embedding (such as Word2Vec, BERT), etc. are used to convert the demand text into vector representation. These vectors capture the vocabulary, grammar and semantic information in the text, thereby extracting the text features of the demand text.
[0054] For each field in the preset database, extract its name, data type, description and other metadata as field features. If the field contains text data, you can also use the same NLP technology as the demand text to extract the feature vector of the field content.
[0055] For each feature vector of the requirement text, similarity is calculated with the feature vector of each field in the preset database. Common similarity measurement methods include cosine similarity, Euclidean distance, etc. Based on the similarity calculation results, the N fields with the highest similarity are selected as fields related to the requirement text. These fields constitute the first related field table. A similarity threshold can be set, and only fields exceeding the threshold are considered related.
[0056] Optionally, the first relevant field table can be implemented through a dual-tower recall model. Based on the dual-tower architecture of the BERT model, the user's natural language query (demand text) and database fields are vectorized respectively. Through vector similarity retrieval, the model can accurately recall the fields most relevant to the query, that is, the first relevant field table. The training data is constructed in the form of (user query, database table: field name) pairs to ensure that the model can efficiently process query tasks. In actual applications, the recall rate of the top 10 fields reaches 97.8%.
[0057] Then, the first related field table can be directly determined as candidate structured data related to the demand text; the accuracy of recall can also be improved from different dimensions, and the amount of information in the search results can be further expanded through multi-channel recall and fusion retrieval technology. And combined with the first related field table, the candidate structured data related to the demand text can be determined.
[0058] The method provided by the embodiment of the present invention can accurately recall the fields most relevant to the demand text through feature similarity retrieval, thereby providing context support for the subsequent chain reasoning of large-scale language models, thereby improving the efficiency and accuracy of data analysis.
[0059] Based on any of the above embodiments, based on the first related field table, determining candidate structured data related to the requirement text, that is, step 113 specifically includes: Step 113-1, based on the keywords in the requirement text and / or based on a preset rule engine, retrieve and obtain a second related field table; Step 113 - 2 , based on the first related field table, the second related field table, and the field descriptions and knowledge meta-information in the knowledge base, determine candidate structured data related to the requirement text.
[0060] Specifically, after obtaining the first relevant field table, the candidate structured data can also be implemented in combination with multi-way recall and fusion retrieval technology, that is, keywords in the demand text, a preset rule engine, and information in the knowledge base.
[0061] Extract keywords or keyword phrases from the requirement text. These keywords can be nouns, verbs, or phrases, and they are usually closely related to the user's query intent. Use these keywords to search in a preset database or knowledge base to find fields that match these keywords. These fields form part of the second related field table.
[0062] A rule engine is preset, which contains a series of rules based on logic, syntax or semantics. These rules are used to parse the requirement text and recommend related fields based on the parsing results. The requirement text is input into the rule engine, which parses it according to the preset rules and outputs the fields related to the requirement text. These fields constitute another part of the second related field table.
[0063] The second related field table can be fields retrieved based on keywords in the requirement text, or fields retrieved based on a preset rule engine, or a combination of fields retrieved based on keywords and fields retrieved based on a rule engine. The merged table contains fields related to the requirement text at both the keyword and rule levels.
[0064] In addition, the system will combine the field description and knowledge meta-information in the knowledge base with the external database table structured information, and inject this information into the subsequent large model reasoning to help the system better understand the database structure and field meaning. The knowledge base contains knowledge meta-information such as detailed description of the field, data type, table to which it belongs, and relationship with other fields.
[0065] On this basis, the first relevant field table (obtained based on the similarity between text features and field features) and the second relevant field table (obtained based on keywords and rule engine), as well as the field descriptions and knowledge meta-information in the knowledge base are merged or intersected to obtain a more accurate set of relevant fields and candidate structured data that incorporates knowledge meta-information.
[0066] The method provided in the embodiment of the present invention can automatically locate relevant tables and fields in a complex database through multi-way recall and data fusion technology to meet user needs, thereby further improving the efficiency and accuracy of large-scale language model data analysis. In addition, the retrieval method has the ability to dynamically adapt to different database structures, showing strong scalability and versatility.
[0067] Based on any of the above embodiments, Figure 2 is a flow chart of step 110 in the data analysis method provided by the present invention, such as Figure 2 As shown, step 110 can be implemented by the RAG (Retrieval-Augmented Generation) module. The RAG module uses the dual-tower BERT model to intelligently retrieve database fields, combines vectorization and keyword matching for multi-way recall, and obtains knowledge meta-information of related tables and fields, thereby obtaining candidate structured data.
[0068] The RAG module not only relies on dense recall based on vector similarity, but also combines keyword recall and rule engine multi-way retrieval to improve the accuracy of recall from different dimensions. In addition, metadata supplementation technology is used to further expand the amount of information in the search results. Once the relevant fields are recalled, the system will combine the field description and knowledge meta-information in the knowledge base with the external database table structured information, and inject this information into the subsequent large model reasoning to help the system better understand the database structure and field meaning.
[0069] Based on any of the above embodiments, in step 120, based on the requirement text and the candidate structured data, chain reasoning tasks corresponding to the requirement text are sequentially performed by a large language model, specifically including: Step 121, based on the output result of the previous round of reasoning task, the requirement text and the candidate structured data, determine the prompt instruction of the current round of reasoning task; Step 122, inputting the prompt instruction of the current round of reasoning task into the large language model to obtain the output result of the large language model for the current round of reasoning task; Step 123, taking the output result of the current round of reasoning tasks as the output result of the previous round of reasoning tasks, and executing the chained reasoning tasks in sequence until the output result of the last round of reasoning tasks is obtained.
[0070] Specifically, chained reasoning tasks include field screening tasks, code generation tasks, and data analysis tasks. The prompt instructions for each round of reasoning tasks include not only the required text and the retrieved candidate structured data, but also the output results of the previous round of reasoning tasks. The prompt instructions are used to guide the large language model to perform specific tasks in the current round of reasoning. This instruction should be clear, specific, and closely related to the output of the previous round. Each round of reasoning is built on the previous round to ensure that the final generated results meet user needs and have high accuracy and readability.
[0071] For example, for the first round of reasoning field screening tasks, the prompt instructions for the field screening tasks can be determined based on the requirement text and the candidate structured data; the prompt instructions for the field screening tasks are input into the large language model to obtain the output results of the large language model for the field screening tasks, such as including the filtered data fields.
[0072] After the first round of reasoning field screening tasks are completed, the next round of reasoning code generation tasks is executed. Based on the filtered data fields, requirement text and candidate structured data output by the field screening task, the prompt instructions of the code generation task are determined; the prompt instructions of the code generation task are input into the large language model to obtain the output results of the large language model for the code generation task, and the output code snippets are obtained.
[0073] Then execute the next round of data analysis tasks. Based on the code snippets, requirement texts, and candidate structured data output by the code generation task, determine the prompt instructions for the data analysis task. Here, the code can be run in an external isolated environment, and the prompt instructions for the data analysis task can be determined based on the running results of the code snippets, requirement texts, and candidate structured data. Input the prompt instructions of the data analysis task into the large language model to obtain the output results of the large language model for the data analysis task. At this point, the end of the chain reasoning has been reached, that is, the last round of reasoning task, then the reasoning process is stopped, and the final data analysis results are output.
[0074] The training of large language models involves multi-step reasoning, instruction isolation, FSL (Few-shot learning), SFT (Supervised Fine-Tuning), and DPO (Direct Preference Optimization) to improve model performance. The application of these technologies not only improves the model's ability to generate code, but also enhances the model's ability to understand and handle complex data analysis tasks.
[0075] The core of instruction isolation is to generate an independent set of instructions for each user query task to ensure that the information between different tasks does not interfere with each other. The execution of each task has an independent context environment. When receiving instructions, the large model only processes the input related to the current task and does not carry the intermediate results or background information of the previous task, thus avoiding "leakage" of information between tasks or misoperation.
[0076] In large-model chain reasoning, the system gradually infers the corresponding database tables and fields based on the natural language query input by the user through modular design, and automatically generates Python code and analysis results. In this process, each step of the chain reasoning depends on the result generated by the previous step, and the independence between different steps is guaranteed by instruction isolation technology. Each step will receive the updated environment and information to ensure that the model can accurately grasp the current task status and finally complete the generation and execution of multi-step reasoning.
[0077] Figure 3 It is a schematic diagram of the chain reasoning process provided by the present invention, such as Figure 3 As shown in the figure, the large language model reasoned and processed user needs in multiple steps, mainly including three chain skills: field screening, code generation, and data analysis. Each skill depends on the output of the previous step and combines the field and knowledge meta-information provided by the RAG module.
[0078] The system uses multiple rounds of dialogue to gradually clarify analysis requirements with users. For example, the system first determines the tables and fields required for the query through field selection skills, then generates the corresponding Python code, and finally performs data analysis and interpretation based on the code execution results.
[0079] To achieve chain reasoning, we can introduce agent processes to simulate the thinking process of humans performing data analysis. This method greatly improves the performance of large models in data analysis tasks.
[0080] The method provided by the embodiment of the present invention enables a large language model to flexibly cope with various analysis tasks by designing a specific prompt instruction for each reasoning task. The designed multi-step reasoning and task chain can handle complex natural language queries and data analysis requirements.
[0081] Based on any of the above embodiments, based on the output result of the previous round of reasoning task, the requirement text and the candidate structured data, the prompt instruction of the current round of reasoning task is determined, that is, step 121 specifically includes: Step 121 - 1 , determining the task description of the current round of reasoning task based on the output result of the previous round of reasoning task, the requirement text and the candidate structured data; Step 121 - 1 , determining a prompt instruction for the current round of reasoning task based on the process planning instruction of the chain reasoning task and the task description of the current round of reasoning task; The process planning instructions include a workflow description of the chain reasoning task.
[0082] Specifically, the prompt instructions for the current round of reasoning tasks can be determined based on the process planning instructions of the chain reasoning tasks and the task description of the current round of reasoning tasks. The process planning instructions here are a series of predefined instructions or steps used to guide the entire chain reasoning process, which may include problem decomposition, knowledge combination, reasoning execution and other stages. The task description of the current round of reasoning tasks is a detailed description of the reasoning tasks that need to be performed, including the goals, inputs, outputs and constraints of the tasks, etc. It helps to clarify the specific requirements and expected results of the reasoning tasks. The process planning instructions of the chain reasoning tasks can be spliced with the task description of the current round of reasoning tasks to obtain the prompt instructions for the current round of reasoning tasks.
[0083] For the task description of the current round of reasoning tasks, the output results of the previous round of reasoning tasks, the requirement text and the candidate structured data can be concatenated.
[0084] In some embodiments, the process planning instructions may be designed as follows: Process planning instruction prompt: '''
background
[0085]
Complete workflow
[0086] The prompt command for the field screening task is: process planning command + task description of the field screening task. The task description of the field screening task can be displayed as: '''
Task
[0087] The prompt instruction for the code generation task is: process planning instruction + task description of the code generation task. The task description of the field screening task can be displayed as: '''
Task
[0088] The prompt instructions for the data analysis task are: process planning instructions + task description of the data analysis task. The task description of the data analysis task can be displayed as: ''' Please conduct the third round of responses in the workflow based on the following user requirements and code running results to generate analysis results that are highly interpretable and easy for users to understand; The current user's analysis requirements are: {{query}} The current code runs as follows: {{code_result}} '''.
[0089] The method provided by the embodiment of the present invention determines the prompt instructions of the current round of reasoning tasks based on the process planning instructions of the chain reasoning tasks and the task description of the current round of reasoning tasks. Each step will receive the updated environment and information, ensuring that the large language model can accurately grasp the current task status and ultimately complete the generation and execution of multi-step reasoning.
[0090] Based on any of the above embodiments, the data analysis method further includes: Get code snippets generated by large language models for code generation tasks; The code snippet is run based on the code sandbox, and the code running result is returned to the large language model, so that the large language model performs data analysis tasks based on the code running result.
[0091] Specifically, in order to further ensure system security, external dependencies are strictly restricted based on the code sandbox, and the pre-execution mechanism is used to improve the execution efficiency of the code. The code sandbox is mainly used to execute code snippets generated by large language models, such as Python code. Through a preset code execution environment, the code sandbox can load the database and run the code snippets generated by the model, and feed back the code running results to the reasoning module of the large language model, and generate the final analysis conclusion in combination with skill data analysis.
[0092] Figure 4 It is a schematic diagram of the flow of the code sandbox operation provided by the present invention, such as Figure 4 As shown in the figure, during the operation of the code sandbox, the relevant database tables will be loaded into memory (in the form of pandas DataFrame), and necessary dependency packages will be introduced. In addition, there are some customized plug-in functions based on business scenarios (such as calculating retirement age, school year statistics, job title classification, etc.). Then the Python code generated by the large model will be run, and the execution result or error information will be returned.
[0093] To ensure system security, the code sandbox strictly restricts external dependencies and uses a pre-execution mechanism to improve code execution efficiency.
[0094] The method provided by the embodiment of the present invention not only ensures the security of code execution through code sandbox, but also improves the running efficiency of the code through pre-execution and optimization.
[0095] Based on any of the above embodiments, the large language model performs a data analysis task based on the code running result, including: If the code running result indicates that the code running is successful, the large language model performs the data analysis task based on the code running result; If the code running result indicates that the code running fails, the large language model performs error analysis based on the code running result.
[0096] Specifically, if the code running result indicates that the code running is successful, the large language model performs the data analysis task based on the code running result. The large language model extracts data from the standard output of the code running or the generated file. Parse using the corresponding parsing library according to the data format (such as CSV, JSON, XML, etc.). Use statistical methods, machine learning algorithms or deep learning models to conduct in-depth analysis of the data and generate analysis results, such as statistical charts, prediction models, association rules, etc. The analysis results are presented to the user in a visual form (such as charts, reports) or text form. Provide explanations and background information of the analysis results to help users understand the analysis results.
[0097] If the code running result indicates that the code failed to run, the large language model performs error analysis based on the code running result. Read and parse the error information in the standard error output, identify the error type (such as syntax error, runtime error, logical error, etc.), extract the error location (such as file name, line number, function name, etc.), and locate the specific location in the code based on the information in the error log. Check the relevant code segments and analyze the cause of the error. Provide repair suggestions based on the error type and cause. If possible, provide corrected code examples or modification suggestions.
[0098] Based on any of the above embodiments, in the teacher portrait analysis in the education industry, existing data analysis technologies face significant challenges. First, low data retrieval efficiency is the main problem. The traditional analysis process requires users to manually query database tables and fields, which is cumbersome and error-prone. As the amount of data increases, users often encounter information overload and find it difficult to quickly find the required information. This inefficient retrieval mechanism directly affects the efficiency and accuracy of data analysis.
[0099] Secondly, the complexity of the data analysis process is also a major shortcoming. Existing technologies rely on multiple independent tools and platforms, resulting in cumbersome processes for data extraction, cleaning, and analysis. This requires users to have high technical capabilities and frequently switch between different systems, increasing learning costs and usage barriers. In addition, data analysis results often require multiple manual interventions, further reducing the degree of automation.
[0100] Existing technologies also face difficulties in data integration and knowledge extraction. Teacher portrait data comes from databases of multiple schools. The diversity and heterogeneity of the data make integration complicated. How to effectively integrate information from different databases and extract valuable knowledge has become an urgent problem to be solved. At the same time, the maintenance and updating of the knowledge base also faces challenges. Much knowledge information relies on manual processing, which affects the timeliness of the data and increases the risk of human error.
[0101] In addition, existing large models are insufficient in task adaptability, and many systems perform poorly under specific tasks, especially in educational applications. Existing models are difficult to update and optimize in real time, resulting in a lack of pertinence and practicality in analysis results, and users often find it difficult to obtain satisfactory analysis results.
[0102] To address these issues, the present invention aims to develop a data analysis assistant based on large model chain reasoning. The system will use the Retrieval-Augmented Generation (RAG) technology to improve data retrieval efficiency. RAG combines the advantages of traditional information retrieval systems (such as databases) with the functions of generative large language models (LLMs), aiming to improve the accuracy and reliability of the system in answering natural language questions.
[0103] Based on agent-based task planning and multi-skill chain reasoning, accurate Python data analysis code and natural language interpretation are generated through large language models to simplify user operation processes. Users only need to enter query requirements, and the system can automatically complete the entire process from field retrieval to code generation and then to data interpretation, greatly improving the efficiency and accuracy of data analysis, and significantly improving the efficiency and accuracy of teacher portrait data analysis to meet the needs of the education industry for data analysis.
[0104] Figure 5 This is the second flow chart of the data analysis method provided by the present invention, such as Figure 5 As shown, the method includes: S1, obtain the demand text, and retrieve the candidate structured data related to the demand text. Specifically including: extracting the text features of the demand text and the field features of the fields in the preset database; retrieving the first relevant field table from the preset database based on the similarity between the text features and the field features; retrieving the second relevant field table based on the keywords in the demand text and / or based on the preset rule engine; determining the candidate structured data related to the demand text based on the first relevant field table, the second relevant field table, and the field description and knowledge meta-information in the knowledge base. Through the dual-tower BERT model, intelligent retrieval of database fields is realized, and multi-way recall is performed in combination with vectorization and keyword matching to obtain the knowledge meta-information of related tables and fields.
[0105] S2, based on the requirement text and candidate structured data, the chain reasoning tasks corresponding to the requirement text are executed in sequence through a large language model. The chain reasoning tasks include field screening tasks, code generation tasks, and data analysis tasks. Based on the output results of the tail-wheel reasoning tasks, the data analysis results for the requirement text are determined. Specifically, it includes: Determine the task description of the current round of reasoning tasks based on the output results of the previous round of reasoning tasks, the requirement text, and the candidate structured data; Based on the process planning instructions of the chain reasoning task and the task description of the current round of reasoning task, determine the prompt instructions of the current round of reasoning task; wherein the process planning instructions include the workflow description of the chain reasoning task; Input the prompt instruction of the current round of reasoning task into the large language model to obtain the output result of the large language model for the current round of reasoning task; The output result of the current round of reasoning tasks is used as the output result of the previous round of reasoning tasks, and the chain reasoning tasks are executed in sequence until the output result of the last round of reasoning tasks is obtained.
[0106] S3, obtain the code snippet generated by the large language model for the code generation task; run the code snippet based on the code sandbox, and return the code running result to the large language model. If the code running result indicates that the code running is successful, the large language model performs the data analysis task based on the code running result; if the code running result indicates that the code running fails, the large language model performs error analysis based on the code running result.
[0107] The data analysis device provided by the present invention is described below. The data analysis device described below and the data analysis method described above can be referenced to each other.
[0108] Based on any of the above embodiments, Figure 6 is a schematic diagram of the structure of the data analysis device provided by the present invention, such as Figure 6 As shown, the data analysis device comprises: A retrieval unit 610 is used to obtain a demand text and retrieve candidate structured data related to the demand text; A reasoning unit 620, configured to sequentially perform chain reasoning tasks corresponding to the requirement text through a large language model based on the requirement text and the candidate structured data, wherein the chain reasoning tasks include at least one of a field screening task, a code generation task, and a data analysis task; The determination unit 630 is used to determine the data analysis result for the requirement text based on the output result of the tail-wheel reasoning task.
[0109] The data analysis device provided by the embodiment of the present invention obtains candidate structured data through information retrieval, generates accurate data analysis code and natural language interpretation through a large language model based on chain reasoning tasks, and simplifies the user operation process. The user only needs to enter the query requirements, and the system can automatically complete the entire process from field retrieval to code generation and then to data analysis, greatly improving the efficiency and accuracy of data analysis.
[0110] Based on any of the above embodiments, the reasoning unit is specifically used for: Determine prompt instructions for the current round of reasoning tasks based on the output results of the previous round of reasoning tasks, the requirement text, and the candidate structured data; Inputting the prompt instruction of the current round of reasoning task into the large language model to obtain the output result of the large language model for the current round of reasoning task; The output result of the current round of reasoning tasks is used as the output result of the previous round of reasoning tasks, and the chain reasoning tasks are executed in sequence until the output result of the last round of reasoning tasks is obtained.
[0111] Based on any of the above embodiments, the reasoning unit is specifically used for: Determine a task description for a current round of reasoning tasks based on the output results of the previous round of reasoning tasks, the requirement text, and the candidate structured data; Determine a prompt instruction for the current round of reasoning task based on the process planning instruction of the chain reasoning task and the task description of the current round of reasoning task; The process planning instruction includes a workflow description of the chain reasoning task.
[0112] Based on any of the above embodiments, the retrieval unit is specifically used for: Extracting text features of the demand text and field features of fields in a preset database; Based on the similarity between the text feature and the field feature, a first related field table is retrieved from the preset database; Based on the first related field table, candidate structured data related to the requirement text is determined.
[0113] Based on any of the above embodiments, the retrieval unit is specifically used for: Based on the keywords in the requirement text and / or based on a preset rule engine, retrieve and obtain a second related field table; Based on the first related field table, the second related field table, and the field descriptions and knowledge meta-information in the knowledge base, candidate structured data related to the requirement text is determined.
[0114] Based on any of the above embodiments, the device includes a code execution unit, which is used to: Obtaining a code snippet generated by the large language model for the code generation task; The code snippet is run based on a code sandbox, and the code running result is returned to the large language model, so that the large language model performs the data analysis task based on the code running result.
[0115] Based on any of the above embodiments, the reasoning unit is specifically used for: If the code running result indicates that the code running is successful, the large language model performs the data analysis task based on the code running result; If the code running result indicates that the code running fails, the large language model performs error analysis based on the code running result.
[0116] Figure 7 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 7As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730 and a communication bus 740, wherein the processor 710, the communication interface 720 and the memory 730 communicate with each other through the communication bus 740. The processor 710 may call the logic instructions in the memory 730 to execute the data analysis method, which includes: obtaining the requirement text, and retrieving the candidate structured data related to the requirement text; based on the requirement text and the candidate structured data, sequentially executing the chain reasoning tasks corresponding to the requirement text through a large language model, the chain reasoning tasks including at least one of a field screening task, a code generation task and a data analysis task; based on the output result of the tail wheel reasoning task, determining the data analysis result for the requirement text.
[0117] In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0118] On the other hand, the present invention also provides a computer program product, which includes a computer program, and the computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the data analysis method provided by the above-mentioned methods, and the method includes: obtaining a requirement text, and retrieving candidate structured data related to the requirement text; based on the requirement text and the candidate structured data, sequentially executing chain reasoning tasks corresponding to the requirement text through a large language model, and the chain reasoning task includes at least one of a field screening task, a code generation task and a data analysis task; based on the output result of the tail-wheel reasoning task, determining the data analysis result for the requirement text.
[0119] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the data analysis method provided by the above-mentioned methods, the method comprising: obtaining a requirement text, and retrieving candidate structured data related to the requirement text; based on the requirement text and the candidate structured data, sequentially executing chain reasoning tasks corresponding to the requirement text through a large language model, the chain reasoning tasks including at least one of a field screening task, a code generation task and a data analysis task; based on the output result of the tail-wheel reasoning task, determining the data analysis result for the requirement text.
[0120] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0121] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0122] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A data analysis method, characterized in that: include: Obtaining a demand text, and retrieving candidate structured data related to the demand text; Based on the requirement text and the candidate structured data, sequentially executing chained reasoning tasks corresponding to the requirement text through a large language model, wherein the chained reasoning tasks include at least one of a field screening task, a code generation task, and a data analysis task; Based on the output result of the tail-wheel reasoning task, a data analysis result for the requirement text is determined.
2. The data analysis method according to claim 1, characterized in that: The step of sequentially executing chained reasoning tasks corresponding to the requirement text through a large language model based on the requirement text and the candidate structured data includes: Determine prompt instructions for the current round of reasoning tasks based on the output results of the previous round of reasoning tasks, the requirement text, and the candidate structured data; Inputting the prompt instruction of the current round of reasoning task into the large language model to obtain the output result of the large language model for the current round of reasoning task; The output result of the current round of reasoning tasks is used as the output result of the previous round of reasoning tasks, and the chain reasoning tasks are executed in sequence until the output result of the last round of reasoning tasks is obtained.
3. The data analysis method according to claim 2, characterized in that: The step of determining the prompt instruction for the current round of reasoning task based on the output result of the previous round of reasoning task, the requirement text, and the candidate structured data includes: Determine a task description for a current round of reasoning tasks based on the output results of the previous round of reasoning tasks, the requirement text, and the candidate structured data; Determine a prompt instruction for the current round of reasoning task based on the process planning instruction of the chain reasoning task and the task description of the current round of reasoning task; The process planning instruction includes a workflow description of the chain reasoning task.
4. The data analysis method according to any one of claims 1 to 3, characterized in that: The retrieval obtains candidate structured data related to the requirement text, including: Extracting text features of the demand text and field features of fields in a preset database; Based on the similarity between the text feature and the field feature, a first related field table is retrieved from the preset database; Based on the first related field table, candidate structured data related to the requirement text is determined.
5. The data analysis method according to claim 4, characterized in that: The determining, based on the first related field table, candidate structured data related to the requirement text includes: Based on the keywords in the requirement text and / or based on a preset rule engine, retrieve and obtain a second related field table; Based on the first related field table, the second related field table, and the field descriptions and knowledge meta-information in the knowledge base, candidate structured data related to the requirement text is determined.
6. The data analysis method according to any one of claims 1 to 3, characterized in that: Also includes: Obtaining a code snippet generated by the large language model for the code generation task; The code snippet is run based on a code sandbox, and the code running result is returned to the large language model, so that the large language model performs the data analysis task based on the code running result.
7. The data analysis method according to claim 6, characterized in that: The large language model performs the data analysis task based on the code running result, including: If the code running result indicates that the code running is successful, the large language model performs the data analysis task based on the code running result; If the code running result indicates that the code running fails, the large language model performs error analysis based on the code running result.
8. A data analysis device, characterized in that: include: A retrieval unit, used to obtain a demand text and retrieve candidate structured data related to the demand text; An inference unit, configured to sequentially perform chained inference tasks corresponding to the requirement text through a large language model based on the requirement text and the candidate structured data, wherein the chained inference tasks include at least one of a field screening task, a code generation task, and a data analysis task; A determination unit is used to determine a data analysis result for the requirement text based on an output result of the tail wheel reasoning task.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the data analysis method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data analysis method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Task processing method, system and device based on large model, equipment and medium
CN120012948A
Task processing method, system, device, equipment and medium based on large model
CN120012948B