LLM model-based natural language chart generation method and system, and medium
Through the combination of semantic embedding model and LLM model, the problems of database dependence, security risk and adaptability of NL2SQL technology are solved, the direct generation of natural language into charts is realized, and the processing capability and security of the system are enhanced.
Patent Information
- Application Number
- CN202410960732.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2024-10-01
AI Technical Summary
NL2SQL technology is highly dependent on the database structure, is difficult to handle complex queries related to multiple tables, poses security risks, and requires frequent fine-tuning to adapt to different scenarios or databases, resulting in high resource consumption and deployment costs.
Use the semantic embedding model to vectorize natural language, calculate the similarity between the semantic vector and the key phrase vector in the vector database, obtain the metadata ID of the chart function with the highest similarity, and use the LLM model to infer and generate the chart to avoid directly executing SQL queries. Obtain and process data through predefined function calls.
It achieves efficient processing of multi-source and multi-structure data, reduces security risks and resource consumption, improves user interaction experience and system practicality, and is suitable for a wider range of application scenarios.
Smart Images

Figure CN118733612A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, system, device and medium for generating charts from natural language based on an LLM model. Background Art
[0002] With the rapid development of information technology, data visualization has become a key means to understand complex data sets, gain insights into trends, and make decisions. However, the traditional data-to-chart conversion process is highly dependent on professional software and user skills, which not only limits the participation of people with non-technical backgrounds, but also reduces the efficiency and popularity of insights and analysis from data. NL2Chart (Natural Language To Chart) technology came into being, allowing users to ask questions in natural language and automatically converting user query intentions into intuitive, easy-to-understand statistical charts, such as tables, line charts, bar charts, or pie charts, greatly simplifying the process of data exploration and communication.
[0003] Researchers' breakthroughs in the field of artificial intelligence have made LLM (Large Language Model) models a new engine to promote the development of natural language processing technology. These models are "large" in the number of parameters and training data. These models often have billions or even tens of billions or hundreds of billions of parameters. They are trained on TBs of data and have cross-domain knowledge understanding, context perception, and fluent text generation capabilities. In the field of NL2Chart, the application of the LLM model marks an important turning point. It enables the system to not only understand the user's specific needs for data visualization, but also generate icons that meet user needs without explicit programming instructions. The key to achieving this capability lies in the powerful semantic understanding ability of large models, which can capture subtle differences in language and understand complex logic.
[0004] Although NL2SQL performs well in improving data access convenience and obtaining data in real time, it also has the following significant disadvantages:
[0005] 1. It is highly dependent on the database structure and has difficulty processing complex queries involving multiple tables, which limits its application scope in complex data environments.
[0006] 2. The execution permission problem of the SQL language itself introduces potential security risks. That is, NL2SQL directly generates and executes SQL queries, exposing potential security vulnerabilities.
[0007] 3. It involves fine-tuning the model, which makes it difficult to quickly adapt to new scenarios or databases. In other words, in order to meet the customized requirements of different usage scenarios or business database systems, the NL2SQL model needs to be fine-tuned to ensure better results. Frequent model fine-tuning is not only time-consuming but also requires a large amount of labeled data and inference computing power. Summary of the invention
[0008] In order to overcome the problems existing in the related art, the present disclosure provides a natural language generation chart method, system, device and medium based on the LLM model to solve the technical problems in the related art that NL2SQL is highly dependent on the database, easily causes potential security risks, requires fine-tuning for different usage scenarios, and is difficult to quickly adapt to new scenarios or databases.
[0009] One or more embodiments of this specification provide a method for generating graphs from natural language based on an LLM model, which uses a semantic embedding model to vectorize the received natural language to obtain a semantic vector;
[0010] Calculating the vector similarity between the semantic vector and the key phrase vector in the vector database, and obtaining the chart function metadata ID corresponding to the key phrase vector with the highest similarity;
[0011] According to the chart function metadata ID, corresponding function metadata is acquired from the vector database, and the fields in the function metadata are extracted to construct prompt words of the LLM model, and the LLM model is inferred according to the prompt words to obtain the inference result;
[0012] A chart function calling parameter is constructed according to the inference result, and a chart is generated using the chart function calling parameter and the chart function metadata ID.
[0013] Preferably, each function metadata is standardized to obtain a function structure containing several fields, and the fields and the contents corresponding to the fields are obtained to form a chart function json file, wherein the fields include key phrases, wherein the function metadata includes functional description information and input parameter description information of the chart function, and the chart function is defined with code instructions for data acquisition logic and chart display logic.
[0014] Preferably, the method further comprises the following steps:
[0015] The key phrase vector data is obtained by calculating the vector representation of the key phrase through a semantic embedding model, and the key phrase vector data and the associated chart function metadata ID are stored in the vector database.
[0016] Preferably, extracting the fields in the function metadata to construct the prompt words of the LLM model, and the LLM model inferring the inference results according to the prompt words, specifically includes the following steps:
[0017] Phase 1: Extract dimensions, indicators, and example fields from the function metadata to construct the first prompt word. The LLM model performs reasoning based on the first prompt word to obtain dimension field values and indicator field values.
[0018] The second stage: extract the dimensions and example fields in the function metadata to construct the second prompt word. The LLM model performs inference based on the second prompt word to obtain the filter condition field value.
[0019] The third stage: extract the sorting method and data quantity limit fields in the function metadata, and construct a third prompt word with the dimension field value and the indicator field value. The LLM model performs reasoning based on the third prompt word to obtain the sorting method field value and the data quantity limit field value;
[0020] The fourth stage: extracting the chart style field in the function metadata, constructing a fourth prompt word with the dimension field value and the indicator field value, and the LLM model performs reasoning based on the fourth prompt word to obtain the chart style field value;
[0021] The reasoning results of each stage are used as the reasoning results obtained by the LLM model according to the prompt words.
[0022] Preferably, the step of generating a chart using the chart function call parameters and the chart function metadata ID specifically includes the following steps:
[0023] Generate a chart according to the chart function call parameters;
[0024] Obtaining chart data according to the chart function metadata ID;
[0025] The chart data is displayed in a chart.
[0026] One or more embodiments of this specification provide a natural language generation chart system based on the LLM model, including:
[0027] A language receiving module, used for vectorizing the received natural language using a semantic embedding model to obtain a semantic vector;
[0028] A metadata ID acquisition module, used to calculate the vector similarity between the semantic vector and the key phrase vector in the vector database, and obtain the chart function metadata ID corresponding to the key phrase vector with the highest similarity;
[0029] An inference module, used for acquiring corresponding function metadata from the vector database according to the chart function metadata ID, extracting the fields in the function metadata to construct the prompt words of the LLM model, and the LLM model inferring the inference results according to the prompt words;
[0030] The chart display module is used to construct chart function calling parameters according to the inference result, and generate a chart using the chart function calling parameters and the chart function metadata ID.
[0031] Preferably, it also includes a metadata standardization module, which is used to standardize each function metadata to obtain a function structure containing several fields, obtain the fields and the contents corresponding to the fields to form a chart function json file, and the fields include key phrases, wherein the function metadata includes functional description information and input parameter description information of the chart function, and the chart function is defined with code instructions for data acquisition logic and chart display logic.
[0032] Preferably, it also includes a database construction module: used to calculate the vector corresponding to the key phrase in the chart function json file through the semantic embedding model, that is, the key phrase vector, construct an index relationship between the key phrase vector and the corresponding function metadata ID, and store it in the vector database.
[0033] One or more embodiments of the present specification provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, a method for generating graphs from a natural language based on an LLM model as described above is implemented.
[0034] One or more embodiments of the present specification provide a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the steps of the above-mentioned method for generating a graph from a natural language based on an LLM model are implemented.
[0035] The method, system, device and medium for generating charts from natural language based on the LLM model provided by the present invention have the advantages of using a semantic embedding model to vectorize the received natural language to obtain a semantic vector, which can efficiently understand the user's intention and adapt to new scenarios without frequent fine-tuning or pre-defining tags, significantly reducing the consumption of data resources and computing resources and deployment costs; calculating the vector similarity between the semantic vector and the key phrase vector in the vector database, obtaining the chart function metadata ID corresponding to the key phrase vector with the highest similarity, which can achieve matching between natural language queries and pre-defined function metadata, avoiding direct execution of SQL queries, thereby reducing potential security risks, and obtaining and processing data through pre-defined function calls, which can Better control of data access rights to ensure information security; obtain corresponding function metadata from the vector database according to the chart function metadata ID, extract fields in the function metadata to construct prompt words of the LLM model, and the LLM model infers the inference results based on the prompt words. By leveraging the advanced semantic analysis capabilities and embedding technology of the LLM model, it can more accurately capture the user's implicit needs, greatly improving the user interaction experience and system practicality; construct chart function call parameters according to the inference results, and generate charts using the chart function call parameters and the chart function metadata ID, which reflects the leap from natural language description to chart generation, enhances the system's ability to process multi-source and multi-structure data, and is suitable for a wider range of application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate one or more embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0037] Figure 1 A flowchart of a method for generating a graph from a natural language based on an LLM model provided in one or more embodiments of this specification;
[0038] Figure 2 A semantic matching flow chart provided for one or more embodiments of this specification;
[0039] Figure 3 A system architecture diagram of a method for generating graphs from natural language based on an LLM model provided in one or more embodiments of this specification;
[0040] Figure 4 Example diagram of function metadata provided for one or more embodiments of this specification;
[0041] Figure 5 A flow chart for constructing a vector database provided for one or more embodiments of this specification;
[0042] Figure 6 A schematic diagram of LLM model reasoning provided for one or more embodiments of this specification;
[0043] Figure 7 A multi-stage reasoning diagram provided for one or more embodiments of this specification, wherein: Figure 7 (a) is the first stage reasoning diagram. Figure 7 (b) is the second stage reasoning diagram. Figure 7 (c) is the third stage reasoning diagram. Figure 7 (d) is the fourth stage reasoning diagram;
[0044] Figure 8 A schematic diagram of a specific operation example provided for one or more embodiments of this specification, wherein: Figure 8 (a) is a schematic diagram of the running example of a user asking "Help me count the number of events in Jinshui District in the past six months". Figure 8 (b) is a schematic diagram of an operation example in which a user inquires about “the overdue rate and total number of events in Jinshui District in the past six months”;
[0045] Fig. 9 A structural diagram of a natural language generation chart system based on an LLM model provided for one or more embodiments of this specification;
[0046] Fig.10 A schematic diagram of the structure of a computer device provided for one or more embodiments of this specification. DETAILED DESCRIPTION
[0047] In order to enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the technical solutions in one or more embodiments of this specification will be clearly and completely described below in conjunction with the drawings in one or more embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on one or more embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0048] The present application is described in detail below in conjunction with specific implementation methods and drawings.
[0049] Method Embodiment
[0050] The core of this solution is to transform the NL2Chart task into a function call, and combine the function parameter reasoning capability of the large language model with the embedding technology to realize the automatic process from natural language input to chart generation. In order to ensure high-quality semantic understanding and generation capabilities, it is necessary to match the large language model, embedding model and system architecture, as follows:
[0051] Pre-processing flow:
[0052] 1. Select the appropriate large language model and embedding model: closed source models such as OpenAI's GPT-4 model, or open source models such as the Qwen series models; for embedding models, there are also similar closed source models, such as OpenAI's text-Emdedding-ada-v2, or open source models such as BAAI's bge series models. Use Qwen1.5-32B-Chat as the LLM model and bge-large-zh-v1.5 as the embedding model.
[0053] 2. Select appropriate Web applications and front-end application frameworks: The implemented system involves the front-end and back-end. For front-end services, use the React framework and E-charts as the chart rendering framework; for back-end services, use FastAPI based on Python as the Web application framework.
[0054] 3. Select a suitable vector database: Semantic matching is a key part. The user's natural language description and the description of the preset function template are vectorized through the embedding model, and then the similarity between the vectors is calculated. The similarity score is used as the semantic similarity implementation method. The user's semantic vector mapping is real-time, but the vector mapping of the description of the preset function template is cached offline, which can greatly increase the calculation efficiency of the matching. In order to achieve vector caching, it is necessary to select a suitable vector database for storage. The vector database is specially optimized for vector matching scenarios, which can improve the efficiency and accuracy of calculations. This solution uses Milvus as the vector database.
[0055] According to an embodiment of the present application, a method for generating a graph from a natural language based on an LLM model is provided, such as Figure 1 As shown, it is a schematic diagram of the flow of the method for generating a chart from a natural language based on the LLM model provided in this embodiment. According to the method for generating a chart from a natural language based on the LLM model in this embodiment of the application, the following steps are included:
[0056] S110, using a semantic embedding model to vectorize the received natural language to obtain a semantic vector.
[0057] S120, calculating the vector similarity between the semantic vector and the key phrase vector in the function metadata that has been cached in the vector database, sorting the vector similarities from large to small, and obtaining the chart function metadata ID corresponding to the key phrase vector with the highest similarity. This matching process utilizes the underlying vector processing capabilities in the vector database, selects cosine similarity as the measure of vector similarity, and selects it from the returned vector sorting list as the final result, such as Figure 2 As shown, it is a semantic matching flow chart provided in this embodiment.
[0058] S130. Obtain corresponding function metadata from the vector database according to the chart function metadata ID, extract all fields in the function metadata to construct prompt words of the LLM model, and the LLM model infers the prompt words to obtain inference results, thereby realizing the construction of prompt words.
[0059] S140: Construct chart function calling parameters according to the inference result, and generate a chart using the chart function calling parameters and the chart function metadata ID.
[0060] like Figure 3 As shown, it is a system architecture diagram of a natural language diagram generation method based on the LLM model provided in this embodiment.
[0061] The method provided in this embodiment uses a semantic embedding model to vectorize the received natural language to obtain a semantic vector, which can efficiently understand the user's intention and adapt to new scenarios without frequent fine-tuning or pre-defining tags, etc., significantly reducing the consumption of data resources and computing resources and deployment costs; calculating the vector similarity between the semantic vector and the key phrase vector in the vector database, sorting the vector similarities from large to small, and obtaining the chart function metadata ID corresponding to the key phrase vector with the highest similarity, which can achieve matching between natural language queries and predefined function metadata, avoid directly executing SQL queries, thereby reducing potential security risks, and obtain and process data by calling predefined functions, which can better control data access. Ask for permission to ensure information security; obtain the corresponding function metadata from the vector database according to the chart function metadata ID, extract the fields in the function metadata to construct the prompt words of the LLM model, and the LLM model infers the inference results according to the prompt words. By borrowing the advanced semantic analysis ability and embedding technology of the LLM model, it can more accurately capture the implicit needs of users, greatly improving the user interaction experience and system practicality; construct chart function call parameters according to the inference results, and generate charts using the chart function call parameters and the chart function metadata ID, which reflects the leap from natural language description to chart generation, enhances the system's ability to process multi-source and multi-structure data, and is suitable for a wider range of application scenarios.
[0062] The core of this embodiment is to define the logic of data acquisition, chart display, etc. in the code instructions inside the Function. These contents are not perceived by the large language model. The LLM model only needs to know the functional description of a certain Function and infer the corresponding function input parameters. Therefore, the functional description of the Function and the description of the input parameters are the core contents. These contents are called function metadata (Function Schema). When building the chart function metadata file, developers need to fill in the corresponding information according to the given structure (fill in fields such as ID, name_for_human, name_for_model, description_for_model, keyphrases, parameters and examples).
[0063] In one embodiment, the following steps are also included:
[0064] Each function metadata is standardized to obtain a function structure containing several fields, and the fields and the contents corresponding to the fields are obtained to form a chart function json file, where the fields include key phrases, wherein the function metadata includes functional description information and input parameter description information of the chart function, and the chart function defines code instructions for data acquisition logic and chart display logic, such as Figure 4 As shown, it is an example diagram of the function metadata provided in this embodiment.
[0065] The following example illustrates the structure of icon function metadata:
[0066] Each function metadata is standardized into several fields, and the database structure description is maintained in a unified JSON format file to ensure data uniformity and easy management. Each function structure contains the following fields:
[0067] -ID: Function ID, unique identifier.
[0068] -name_for_human: Function name that is easy for humans to understand, expressed in Chinese, such as "Event different state statistical indicator chart function".
[0069] -name_for_model: The code-style name used to display the large model, usually represented by a word with an underscore, such as "event_status_metrics".
[0070] -description_for_model: Detailed description of the function displayed to the large model.
[0071] -keyphrases: A collection of key phrases. These key phrases will be cached offline as vectors using the semantic embedding model to match the user's questions. These key phrases are various expressions of the user's core questions that the current function can solve, such as: "Query the number of events on each street", "What is the number of pending events", "What is the trend of the number of pending events", etc. A different collection of key phrases should be defined for each chart function.
[0072] -parameters: Function parameters. This part is the input parameter of the function, which means that the big model needs to infer the appropriate function call parameters based on the description of the input parameter. The parameters field is divided into the following fields.
[0073] -dimensions: Dimensions, which represent the statistical dimensions of indicators. In the chart, dimensions correspond to the x-axis, such as time dimension, event type, event source, etc. The large model needs to select dimensions that meet the user's requirements based on the user's questions.
[0074] -metrics: Indicators, indicating the name of the indicator. In the chart, the indicator corresponds to the y-axis, such as: total number of events, total population, month-on-month change rate, etc. The large model needs to select indicators that meet the user's requirements based on the user's questions.
[0075] -filters: filter conditions. The data that users are concerned about usually needs to be filtered, so a filter condition field is needed. For example, for a question like "the trend of the number of events in Jinshui District in the past 6 months", the data range needs to be limited to Jinshui District and the time range is the past 6 months. Therefore, there are two corresponding filter conditions. The large model also needs to determine the corresponding filter conditions based on the user's question.
[0076] -orders: Sorting method. Indicates which dimensions and indicators the chart should be sorted by, and whether it should be sorted in ascending or descending order. A large model is required to infer the sorting method based on the user's question. For example, a question like "The trend of the number of events in Jinshui District in the past 6 months" implies that it needs to be sorted in ascending order according to the time dimension. Although the user did not explicitly request such sorting, such implicit requirements can be processed and analyzed in combination with semantics. This is also something that previous methods based on NL2SQL and intent recognition cannot do.
[0077] -limit: data quantity limit. Limit the amount of data obtained. Usually, users only care about the top-k or maximum and minimum data, so the limit parameter is needed. Large models need to infer the appropriate limit parameter based on the user's problem.
[0078] -chart_type: Chart style. The large model needs to choose the most reasonable chart style according to the user's question, supporting four styles: bar chart, line chart, pie chart and table. It is also very easy to expand more chart styles. You only need to use text to clearly describe what kind of scenario this type of chart is suitable for.
[0079] Each of the above dimensions, metrics, filters, orders, limit, and chart_type fields also needs to maintain a description field in the schema file, which describes the meaning of the field and some applicable scenarios in detail in natural language. For the dimensions and metrics fields, an attribute field is also maintained to indicate all the values of the two fields of the current function. The description combined with the attribute information will be used as a construction prompt word for the xx module, etc.
[0080] -examples: In order to improve the accuracy of the algorithm, an example field needs to be maintained. This field contains 1 to 3 input parameter examples for reference by the large model, thereby improving the accuracy of input parameter determination.
[0081] For each chart function, it is necessary to sort out these fields and the corresponding contents of the fields to form a json file. Some of these contents can be automatically generated by obtaining them directly from the database through code, and some require manual participation. Usually, only the keyphrases and descriptions of each field need to be maintained manually, and the amount of manual work involved is not much. Maintaining all functions with unified fields avoids the problem of generalization difficulties caused by different database table structures.
[0082] The method provided in this embodiment ensures the uniformity and ease of management of data and improves the accuracy of input parameter determination by standardizing the icon function into a function structure of several fields.
[0083] In one embodiment, the following steps are also included:
[0084] The vector corresponding to the key phrase in the chart function json file is calculated by the semantic embedding model, that is, the key phrase vector, and an index relationship between the key phrase vector and the corresponding chart function metadata ID is constructed and stored in the vector database.
[0085] like Figure 5 As shown in FIG. 1 , a flow chart of constructing a vector database provided in this embodiment is provided, wherein the construction of the vector database includes the following steps:
[0086] Traverse each function metadata in the function metadata json file, obtain the ID and key phrase collection in the function metadata, use the semantic embedding model to process the key phrases in each key phrase collection, obtain the corresponding semantic vector - key phrase vector, associate the semantic vector with the ID (build an index), and store it in the vector database to form a vector database.
[0087] The method provided in this embodiment vectorizes the user's natural language description and the description of the preset function template through an embedding model, and makes special optimization for the vector matching scenario, which can improve the efficiency and accuracy of the calculation.
[0088] In one embodiment, the extracting of the fields in the function metadata constructs the prompt words of the LLM model, and the LLM model infers the inference results according to the prompt words. Figure 6 The LLM model reasoning diagram provided for this embodiment adopts a segmented reasoning strategy. The LLM model is only responsible for the dimension and indicator fields in the reasoning function parameters, which specifically includes the following steps:
[0089] S131, the first stage: extract the dimension, indicator and example fields in the function metadata to construct the first prompt word, and the LLM model performs reasoning based on the first prompt word to obtain the dimension field value and the indicator field value, such as Figure 7 (a) is a schematic diagram of the first stage reasoning provided in this embodiment.
[0090] S132, second stage: extract the dimension and example fields in the function metadata to construct the second prompt word, and the LLM model performs reasoning based on the second prompt word to obtain the filter condition field value, such as Figure 7 (b) is a schematic diagram of the second stage reasoning provided in this embodiment.
[0091] S133, the third stage: extracting the sorting method and data quantity limit fields in the function metadata, and constructing a third prompt word with the dimension field value and the indicator field value. The LLM model performs reasoning based on the third prompt word to obtain the sorting method field value and the data quantity limit field value, such as Figure 7 (c) is a schematic diagram of the third stage reasoning provided in this embodiment.
[0092] S134, the fourth stage: extracting the chart style field in the function metadata, constructing a fourth prompt word with the dimension field value and the indicator field value, and the LLM model inferring according to the fourth prompt word to obtain the chart style field value, such as Figure 7 (d) is a schematic diagram of the fourth stage of reasoning provided in this embodiment.
[0093] S135. Finally, the first stage infers the dimension and indicator field values involved in the user question, the second stage infers the filters field value involved in the user question, the third stage infers the orders and limit field values, and the fourth stage infers the chart_type field value. The reasoning results of each stage are used as the reasoning results obtained by the LLM model according to the prompt word reasoning.
[0094] The method provided in this embodiment divides the reasoning process into four sections and splits the prompt words into four sections. Each stage can focus on one task, and the prompt words can be precise to achieve better accuracy. The LLM model reasoning results are gradually obtained, and the large model is guided to infer the dimensions and indicators that the user cares about according to the user's questions as chart data.
[0095] In one embodiment, the back-end framework pushes the inferred function input parameter values to the front-end through the Web program framework. The front-end writes relevant code logic such as obtaining corresponding data and displaying charts that meet the parameter requirements based on the parameter values to realize the generation of charts. The front-end processing module can be regarded as the internal implementation of the chart function and exposes some parameters. For the LLM model, this module is like a function. It only needs to care about the determination of parameters, not the internal implementation logic. After the front-end processing module is successfully executed to display the chart, the execution ends. The use of the chart function call parameters and the chart function metadata ID to generate a chart specifically includes the following steps:
[0096] S141, generating a chart according to the chart function calling parameters.
[0097] S142. Obtain chart data according to the chart function metadata ID.
[0098] S143, displaying the chart data in a chart.
[0099] In order to handle the code exceptions in the system, an exception handling step is designed: the exception is distinguished by the code field in the return body, code 0 means no exception, 1 means there is an exception; for the backend, the exception thrown is captured by the frontend, and the exception is handled according to different exception messages (err_msg field in the return body), or the user is reminded or some fallback logic is handled; for the frontend, the exception thrown by the frontend prompts the user according to different exception situations, which improves the usability and friendliness of the program. After the system executes the exception handling module, the execution ends.
[0100] The effectiveness and advantages of the method of this embodiment are illustrated below through specific cases. Figure 8 As shown, there are two specific operating example schematic diagrams provided in this embodiment.
[0101] Example 1: A user asks "Help me count the number of events in Jinshui District in the past six months". Through the above steps, it can be determined that the dimension of the graph is date, the indicator is the number of events, the filters are the six months from 2024-01 to 2024-06, and the data is from Jinshui District. In addition, it is inferred that the most suitable graphical representation (chart_type) for the user's needs is a line graph (because of the change over time), sorted by time (orders field), such as Figure 8 (a) is a schematic diagram of an operation example in which a user asks "Help me count the number of events in Jinshui District in the past six months".
[0102] Example 2: The user asks "the overdue rate and total number of events in Jinshui District in the past 6 months". Through the above steps, it can be determined that the dimensions of the graph are date, the indicators are event volume and event overdue rate, the filters are the six months from 2024-01 to 2024-06, and the data is from Jinshui District. In addition, it is inferred that the chart_type that best meets the user's needs is a mixed bar chart and line chart (because of the changes over time, but because the event volume is a numerical indicator and the overdue rate is a percentage indicator, the two have different dimensions and need to be displayed as a bar chart and a line chart respectively), sorted by time (orders field), such as Figure 8 (b) is a schematic diagram of an operation example in which a user inquires about “the overdue rate and total number of events in Jinshui District in the past 6 months”.
[0103] System Example
[0104] According to an embodiment of the present application, a natural language generation chart system based on the LLM model is provided, such as Fig. 9 As shown, it is a structural diagram of a natural language generation chart system based on an LLM model provided in this embodiment. According to the natural language generation chart system based on an LLM model in this embodiment of the application, it includes:
[0105] The language receiving module 910 is used to vectorize the received natural language using a semantic embedding model to obtain a semantic vector.
[0106] The metadata ID acquisition module 920 is used to calculate the vector similarity between the semantic vector and the key phrase vector in the vector database, sort the vector similarities from large to small, and obtain the chart function metadata ID corresponding to the key phrase vector with the highest similarity.
[0107] The reasoning module 930 is used to obtain the corresponding function metadata from the vector database according to the chart function metadata ID, extract the fields in the function metadata to construct the prompt words of the LLM model, and the LLM model infers the inference results according to the prompt words.
[0108] The chart display module 940 is used to construct chart function calling parameters according to the inference result, and generate a chart using the chart function calling parameters and the chart function metadata ID.
[0109] In the system provided by this embodiment, the language receiving module 910 obtains a semantic vector by vectorizing the received natural language using a semantic embedding model, which can efficiently understand the user's intention and adapt to new scenarios without frequent fine-tuning or pre-defining tags, etc., significantly reducing the consumption of data resources and computing resources and deployment costs; the metadata ID acquisition module 920 calculates the vector similarity between the semantic vector and the key phrase vector in the vector database, sorts the vector similarities from large to small, and obtains the chart function metadata ID corresponding to the key phrase vector with the highest similarity, which can achieve matching between natural language queries and predefined function metadata, avoids directly executing SQL queries, and thus reduces potential security risks. By acquiring and processing data through predefined function calls, better control can be achieved. Data access rights ensure information security; the reasoning module 930 obtains the corresponding function metadata from the vector database according to the chart function metadata ID, extracts the fields in the function metadata to construct the prompt words of the LLM model, and the LLM model obtains the reasoning results based on the prompt words. By using the advanced semantic analysis capabilities and embedding technology of the LLM model, it can more accurately capture the user's implicit needs, greatly improving the user interaction experience and system practicality; the chart display module 940 constructs the chart function call parameters according to the reasoning results, and generates the chart using the chart function call parameters and the chart function metadata ID, which reflects the leap from natural language description to chart generation, enhances the system's ability to process multi-source and multi-structure data, and is suitable for a wider range of application scenarios.
[0110] In one embodiment, it also includes a metadata standardization module 950, which is used to standardize each function metadata to obtain a function structure including several fields, obtain the fields and the contents corresponding to the fields to form a chart function json file, and the fields include key phrases, wherein the function metadata includes functional description information and input parameter description information of the chart function, and the chart function is defined with code instructions for data acquisition logic and chart display logic.
[0111] The system provided in this embodiment ensures the uniformity and ease of management of data and improves the accuracy of input parameter determination by standardizing the icon function into a function structure of several fields.
[0112] In one embodiment, a database construction module 960 is also included: used to calculate the vector corresponding to the key phrase in the chart function json file through a semantic embedding model, that is, the key phrase vector, construct an index relationship between the key phrase vector and the corresponding chart function metadata ID, and store it in the vector database.
[0113] The system provided in this embodiment vectorizes the user's natural language description and the description of the preset function template through an embedding model, and makes special optimizations for vector matching scenarios, thereby improving the efficiency and accuracy of calculations.
[0114] The embodiment of the present application is a system embodiment corresponding to the above-mentioned method embodiment. The specific operations of the processing steps of each module can be understood by referring to the description of the method embodiment, and will not be repeated here.
[0115] like Fig.10 As shown, the present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for generating charts from a natural language based on the LLM model in the above-mentioned embodiment is implemented; or when the computer program is executed by a processor, the method for generating charts from a natural language based on the LLM model in the above-mentioned embodiment is implemented. When the computer program is executed by the processor, the steps of the above method are implemented.
[0116] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0117] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The device and system embodiments described above are merely schematic, 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.
[0118] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application 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 replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application, and the contents not described in detail in the specification of the present application belong to the common knowledge of those skilled in the art.
Claims
1. A method for generating graphs from natural language based on LLM model, characterized in that: The following steps are involved: The received natural language is vectorized using a semantic embedding model to obtain a semantic vector; Calculating the vector similarity between the semantic vector and the key phrase vector in the vector database, and obtaining the chart function metadata ID corresponding to the key phrase vector with the highest similarity; According to the chart function metadata ID, corresponding function metadata is acquired from the vector database, and the fields in the function metadata are extracted to construct prompt words of the LLM model, and the LLM model is inferred according to the prompt words to obtain the inference result; A chart function calling parameter is constructed according to the inference result, and a chart is generated using the chart function calling parameter and the chart function metadata ID.
2. A method for generating graphs from natural language based on an LLM model as claimed in claim 1, characterized in that: The following steps are also included: Each function metadata is standardized to obtain a function structure containing several fields, and the fields and the contents corresponding to the fields are obtained to form a chart function json file, where the fields include key phrases, wherein the function metadata includes functional description information and input parameter description information of the chart function, and the chart function is defined with code instructions for data acquisition logic and chart display logic.
3. A method for generating graphs from natural language based on LLM model as claimed in claim 2, characterized in that: The following steps are also included: The vector corresponding to the key phrase in the chart function json file, namely the key phrase vector, is calculated by the semantic embedding model, and an index relationship between the key phrase vector and the corresponding chart function metadata ID is constructed and stored in the vector database.
4. A method for generating graphs from natural language based on LLM model as claimed in claim 1, characterized in that: The extracting of the fields in the function metadata to construct the prompt words of the LLM model, and the LLM model inferring the inference results according to the prompt words, specifically includes the following steps: Phase 1: Extract dimensions, indicators, and example fields from the function metadata to construct the first prompt word. The LLM model performs reasoning based on the first prompt word to obtain dimension field values and indicator field values. The second stage: extract the dimensions and example fields in the function metadata to construct the second prompt word. The LLM model performs inference based on the second prompt word to obtain the filter condition field value. The third stage: extract the sorting method and data quantity limit fields in the function metadata, and construct a third prompt word with the dimension field value and the indicator field value. The LLM model performs reasoning based on the third prompt word to obtain the sorting method field value and the data quantity limit field value; The fourth stage: extracting the chart style field in the function metadata, constructing a fourth prompt word with the dimension field value and the indicator field value, and the LLM model performs reasoning based on the fourth prompt word to obtain the chart style field value; The reasoning results of each stage are used as the reasoning results obtained by the LLM model according to the prompt words.
5. The method for generating graphs from natural language based on the LLM model as claimed in claim 1, characterized in that: The step of generating a chart by using the chart function calling parameters and the chart function metadata ID specifically includes the following steps: Generate a chart according to the chart function call parameters; Obtaining chart data according to the chart function metadata ID; The chart data is displayed in a chart.
6. A natural language generation chart system based on the LLM model, characterized in that: include: A language receiving module, used for vectorizing the received natural language using a semantic embedding model to obtain a semantic vector; A metadata ID acquisition module, used to calculate the vector similarity between the semantic vector and the key phrase vector in the vector database, and obtain the chart function metadata ID corresponding to the key phrase vector with the highest similarity; An inference module, used for acquiring corresponding function metadata from the vector database according to the chart function metadata ID, extracting the fields in the function metadata to construct the prompt words of the LLM model, and the LLM model inferring the inference results according to the prompt words; The chart generation module is used to construct chart function calling parameters according to the inference result, and generate a chart using the chart function calling parameters and the chart function metadata ID.
7. A natural language generation chart system based on LLM model as claimed in claim 6, characterized in that: It also includes a metadata standardization module, which is used to standardize each function metadata to obtain a function structure containing several fields, obtain the fields and the contents corresponding to the fields to form a chart function json file, and the fields include key phrases, wherein the function metadata includes functional description information and input parameter description information of the chart function, and the chart function definition has code instructions for data acquisition logic and chart display logic.
8. A natural language generation chart system based on LLM model as claimed in claim 7, characterized in that: It also includes a database construction module: used to calculate the vector corresponding to the key phrase in the chart function json file through a semantic embedding model, that is, the key phrase vector, construct an index relationship between the key phrase vector and the corresponding chart function metadata ID, and store it in the vector database.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, a method for generating graphs from natural language based on an LLM model as described in any one of claims 1 to 5 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of a method for generating graphs from natural language based on an LLM model as claimed in any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Data chart generation method based on natural language processing and related device
CN110222194A
Method and system for constructing visual chart based on natural language
CN116126312A
Financial analysis task reasoning method based on large language model, terminal and medium
CN117744804A
Intelligent number asking and reading method, system and equipment based on large language model and medium
CN117874181A
Cited By
Chart generation method and device, storage medium and electronic equipment
CN119152072A
Method and system for generating chart through question and answer dialogue and storage medium
CN119578392A
Chart generation method, multi-modal data platform, computing equipment and computer readable storage medium
CN119903215A
Legend generation system and method based on LLM model
CN121074481A
