Code generation method and device, equipment and storage medium
By obtaining the new monitoring requirements of the model and the syntax tree of the code repository, and using the large language model to generate corresponding code, the problem of low efficiency of manual code writing by developers in the existing technology is solved, and more efficient and accurate code generation is achieved.
Patent Information
- Application Number
- CN202411750100.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-02
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-12-02
AI Technical Summary
When business needs change, existing model monitoring methods rely on developers to manually analyze and write code, resulting in high workload and low efficiency.
By obtaining the new monitoring requirements of the model and the syntax tree of the code repository, split the requirements into sub-demands, determine the code information and knowledge graph of the sub-demands, use the large language model to determine the longest inference path from the knowledge graph, and generate the corresponding code.
It improves the efficiency and accuracy of the code generation corresponding to the new monitoring requirements of the model, reduces the workload of developers, and enhances the degree of automation of code.
Smart Images

Figure CN119690394A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, apparatus, device and storage medium for generating code. Background Art
[0002] The purpose of model monitoring is to ensure that the performance of machine learning models in actual applications meets expectations, and to provide real-time analysis and monitoring of models and rules for model personnel and policy personnel, as well as data support for subsequent iterative optimization of models and rules, so that model personnel and policy personnel can determine whether to make corresponding adjustments to model parameters. For example, taking the user credit score financial model as an example, the model is used to output the corresponding credit score based on the user's cash flow. Financial institution staff can use the credit score output by the model as a basis to determine whether to lend to the user; assuming that after inputting user A's cash flow into the model, the output corresponding credit score of user A is higher, and it is finally decided to lend to user A. After the loan, user A did not repay on time. If the model is monitored, it can be found that the accuracy of the model is low, which is convenient for model personnel to optimize the model in a timely manner.
[0003] In actual work, business needs or business requirements are often adjusted frequently. Accordingly, the calculation of model monitoring indicators and monitoring reports will also change with the changes in business needs. For example, at the beginning, the business only requires monitoring the stability of the model, so the monitoring report only includes indicators or data related to model stability. As the business develops, after a period of time, it is required not only to monitor the stability of the model, but also to monitor the accuracy of the model. In this case, the monitoring report also needs to display new accuracy-related content as business needs change.
[0004] In the existing model monitoring method, when business requirements change, it mainly relies on developers to analyze the new requirements and write code for the new requirements, which is a large workload and low efficiency. Summary of the invention
[0005] The present application provides a method, apparatus, device and storage medium for generating code, so as to improve the generation efficiency and accuracy of code corresponding to the newly added monitoring requirements of the model.
[0006] In a first aspect, the present application provides a method for generating a code, the method comprising:
[0007] Obtain new monitoring requirements for the model and the syntax tree corresponding to the code repository source code of the model;
[0008] Determine each sub-requirement corresponding to the newly added monitoring requirement according to the newly added monitoring requirement, and determine the code information corresponding to each sub-requirement according to the syntax tree;
[0009] Determine, through a large language model, from the knowledge graph corresponding to each of the sub-demands, the longest reasoning path with the highest semantic similarity to the newly added monitoring demand;
[0010] The longest reasoning path, the code information corresponding to the longest reasoning path, and the target reasoning path are input into the large language model to obtain the code information corresponding to the target reasoning path as the code corresponding to the newly added monitoring requirement; wherein, the code information corresponding to the longest reasoning path is determined based on the code information corresponding to each sub-requirement, and the target reasoning path includes each sub-requirement.
[0011] The method for generating code provided in the present application, after obtaining the newly added monitoring requirements, first splits the newly added monitoring requirements into sub-requirements, and determines the code information and knowledge graph corresponding to each sub-requirement, the large language model performs reasoning based on the knowledge graph corresponding to each sub-requirement, and determines the longest reasoning path with the highest semantic similarity to the newly added monitoring requirements from the final reasoning result, and then inputs the longest reasoning path, the code information corresponding to the longest reasoning path, and the target reasoning path into the large language model, and obtains the code corresponding to the newly added monitoring requirements through the large language model. Compared with the existing methods that rely on manual development based on the newly added monitoring requirements, the present application obtains the code corresponding to the newly added monitoring requirements through the large language model, which reduces the workload of developers and improves the automation and efficiency of code generation; in addition, the longest reasoning path is determined by the large language model based on the knowledge graph corresponding to each requirement, which improves the rationality and accuracy of the longest reasoning path, thereby improving the rationality and accuracy of the code corresponding to the newly added monitoring requirements.
[0012] In a possible design, determining the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement from the knowledge graph corresponding to each sub-requirement through the large language model includes:
[0013] In the first round of reasoning, the knowledge graph corresponding to each sub-requirement is input into the large language model to determine the reasoning result corresponding to the first round of reasoning;
[0014] In the i-th round of reasoning, the reasoning result obtained after the i-1th round of reasoning and the knowledge graph corresponding to each sub-requirement are input into the large language model to determine the reasoning result corresponding to the i-th round of reasoning; wherein the length of any reasoning path in the reasoning result corresponding to the i-th round of reasoning is longer than the length of any reasoning path in the reasoning result corresponding to the i-1th round of reasoning; i is a positive integer and i is greater than 1;
[0015] From at least one longest reasoning path obtained in the last round of reasoning, determine the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement.
[0016] In the first round of reasoning, the large language model's reasoning is based on the knowledge graph corresponding to each sub-requirement, which improves the accuracy of the first round of reasoning results. In each subsequent round of reasoning, the large language model is based on the reasoning results of the previous round and the knowledge graph corresponding to each sub-requirement. Reasoning improves the accuracy of each round of reasoning results, thereby improving the accuracy of at least one reasoning path obtained in the last round of reasoning.
[0017] In a possible design, any reasoning path in the reasoning results corresponding to the i-th round of reasoning is obtained by merging the first reasoning path and the second reasoning path in the reasoning results corresponding to the i-1-th round of reasoning, and the correlation between the first reasoning path and the second reasoning path is greater than a preset correlation threshold.
[0018] When the correlation between the first reasoning path and the second reasoning path is greater than a preset correlation threshold, the first reasoning path and the second reasoning path can be merged to obtain a new reasoning path, thereby improving the rationality of determining the new reasoning path.
[0019] In a possible design, the process of determining the knowledge graph corresponding to each sub-requirement is as follows:
[0020] Determine the keyword set corresponding to any sub-requirement;
[0021] According to the keyword set corresponding to the sub-demand, at least one triple corresponding to the sub-demand is obtained as the knowledge graph corresponding to the sub-demand;
[0022] Any triple includes a first keyword as a head entity, a relationship between the head entity and a tail entity, and a second keyword as a tail entity; the first keyword and the second keyword are two keywords in a keyword set corresponding to the sub-demand.
[0023] The present application determines at least one triple corresponding to each sub-requirement based on the keyword set corresponding to each sub-requirement, as the knowledge graph corresponding to each sub-requirement, any triple includes a head entity, the relationship between the head entity and the tail entity, and the tail entity. Therefore, according to the knowledge graph corresponding to the sub-requirement, the association relationship between the keywords in the keyword set corresponding to the sub-requirement can be determined; and the keyword set here is a filtered keyword set, and the filtered keyword set contains keywords that are highly relevant to the sub-requirements. In this way, the knowledge graph determined according to the filtered keyword set can more accurately characterize the characteristics of the sub-requirements, that is, the knowledge graph corresponding to each sub-requirement in the present application has a higher accuracy.
[0024] In a possible design, a keyword set corresponding to any sub-requirement is determined, including:
[0025] For any one of the sub-demands, input the sub-demand into a preset word segmentation component to obtain a keyword set corresponding to the sub-demand;
[0026] The keyword set corresponding to the sub-requirement is filtered according to the correlation between the annotation information corresponding to the code information corresponding to each keyword in the keyword set corresponding to the sub-requirement and the function to be realized by the sub-requirement, so as to obtain a filtered keyword set.
[0027] The keyword set corresponding to each sub-requirement in this application can be obtained through a preset word segmentation component, which improves the efficiency of obtaining the keyword set, thereby improving the efficiency of determining the knowledge graph and code information corresponding to each subsequent sub-requirement, which is equivalent to improving the efficiency of generating the code corresponding to the newly added monitoring requirement.
[0028] In a possible design, the syntax tree is composed of code files having an ownership relationship, classes included in the code files, and functions included in the classes;
[0029] The determining, according to the syntax tree, the code information corresponding to each sub-requirement includes:
[0030] For any sub-demand, determine a keyword set corresponding to the sub-demand;
[0031] Determine, according to the syntax tree, the class and function corresponding to each keyword in the keyword set corresponding to the sub-requirement;
[0032] According to the classes and functions corresponding to the keywords in the sub-requirements, the code information corresponding to the sub-requirements is determined.
[0033] The syntax tree can display complex source codes in an orderly manner and is easy to process. Compared with directly determining the code information corresponding to each sub-requirement based on the warehouse source code, determining the code information corresponding to each sub-requirement based on the syntax tree reduces the difficulty of determining the code information and improves the accuracy of the code information corresponding to each sub-requirement.
[0034] In a possible design, after obtaining the code corresponding to the newly added monitoring requirement, the following is further included:
[0035] Design unit test cases for the code corresponding to the newly added monitoring requirements and perform testing on the code corresponding to the newly added monitoring requirements, and adjust and optimize the code corresponding to the newly added monitoring requirements based on the test results.
[0036] The codes corresponding to the newly added monitoring requirements directly output by the large language model may have some code implementation effects or performance that do not meet expectations. Therefore, test cases can be designed for the codes corresponding to the newly added monitoring requirements for testing, and the codes that do not meet the test requirements can be modified until the test requirements are met, so as to obtain the final implementation code corresponding to the newly added monitoring requirements.
[0037] In a second aspect, the present application further provides a device for generating a code, the device comprising: a processing unit and a transceiver unit;
[0038] The transceiver unit is used to obtain the newly added monitoring requirements for the model and the syntax tree corresponding to the code repository source code of the model;
[0039] The processing unit is used to determine each sub-requirement corresponding to the newly added monitoring requirement according to the newly added monitoring requirement, and determine the code information corresponding to each sub-requirement according to the syntax tree;
[0040] The processing unit is further configured to determine, from the knowledge graph corresponding to each sub-requirement, the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement through a large language model;
[0041] The transceiver unit is also used to input the longest reasoning path, the code information corresponding to the longest reasoning path, and the target reasoning path into the large language model to obtain the code information corresponding to the target reasoning path as the code corresponding to the newly added monitoring requirement; wherein the code information corresponding to the longest reasoning path is determined based on the code information corresponding to each sub-requirement, and the target reasoning path includes each sub-requirement.
[0042] In a possible design, the transceiver unit is specifically used to: during the first round of reasoning, input the knowledge graph corresponding to each sub-requirement into the large language model to determine the reasoning result corresponding to the first round of reasoning;
[0043] In the i-th round of reasoning, the reasoning result obtained after the i-1th round of reasoning and the knowledge graph corresponding to each sub-requirement are input into the large language model to determine the reasoning result corresponding to the i-th round of reasoning; wherein the length of any reasoning path in the reasoning result corresponding to the i-th round of reasoning is longer than the length of any reasoning path in the reasoning result corresponding to the i-1th round of reasoning; i is a positive integer and i is greater than 1;
[0044] From at least one longest reasoning path obtained in the last round of reasoning, determine the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement.
[0045] In a possible design, any reasoning path in the reasoning results corresponding to the i-th round of reasoning is obtained by merging the first reasoning path and the second reasoning path in the reasoning results corresponding to the i-1-th round of reasoning, and the correlation between the first reasoning path and the second reasoning path is greater than a preset correlation threshold.
[0046] In a possible design, the processing unit is used to determine the knowledge graph corresponding to each sub-demand:
[0047] Determine the keyword set corresponding to any sub-requirement;
[0048] According to the keyword set corresponding to the sub-demand, at least one triple corresponding to the sub-demand is obtained as the knowledge graph corresponding to the sub-demand;
[0049] Any triple includes a first keyword as a head entity, a relationship between the head entity and a tail entity, and a second keyword as a tail entity; the first keyword and the second keyword are two keywords in a keyword set corresponding to the sub-demand.
[0050] In a possible design, the transceiver unit is specifically used to input any one of the sub-requirements into a preset word segmentation component to obtain a keyword set corresponding to the sub-requirement; the processing unit is specifically used to filter the keyword set corresponding to the sub-requirement according to the degree of correlation between the annotation information corresponding to the code information corresponding to each keyword in the keyword set corresponding to the sub-requirement and the function to be implemented by the sub-requirement, so as to obtain a filtered keyword set.
[0051] In one possible design, the syntax tree is composed of code files that have an affiliation, classes included in the code files, and functions included in the classes; the processing unit is specifically used to determine, for any sub-requirement, a keyword set corresponding to the sub-requirement; determine, based on the syntax tree, classes and functions corresponding to each keyword in the keyword set corresponding to the sub-requirement; and determine, based on the classes and functions corresponding to each keyword in the sub-requirement, code information corresponding to the sub-requirement.
[0052] In a possible design, the processing unit is also used to design unit test cases for the code corresponding to the newly added monitoring requirements, and adjust and optimize the code corresponding to the newly added monitoring requirements according to the test results.
[0053] In a third aspect, the present application further provides a device for generating code, the device comprising: a processor, and a memory communicatively connected to the processor;
[0054] The memory stores computer-executable instructions;
[0055] The processor executes the computer-executable instructions stored in the memory to implement the method described in the first aspect above.
[0056] In a fourth aspect, the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a program, and when the program is executed on a device, the device executes the method as described in any one of the above-mentioned first aspects.
[0057] In a fifth aspect, the present application further provides a computer program product, wherein the computer program product comprises a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0059] Figure 1 A schematic diagram of a method for generating code according to an embodiment of the present application;
[0060] Figure 2 A schematic diagram of a syntax tree provided for an embodiment of the present application;
[0061] Figure 3 A schematic diagram of a knowledge graph corresponding to the sub-requirements provided in the embodiment of the present application;
[0062] Figure 4 Schematic diagram of the reasoning path corresponding to the sub-requirements provided in the embodiment of the present application Figure 1 ;
[0063] Figure 5 Schematic diagram of the reasoning path corresponding to the sub-requirements provided in the embodiment of the present application Figure 2 ;
[0064] Figure 6 The structure of the device for generating code provided in the embodiment of the present application is shown as follows Figure 1 ;
[0065] Figure 7 The structure of the device for generating code provided in the embodiment of the present application is shown as follows Figure 2 . DETAILED DESCRIPTION
[0066] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0067] The application scenarios described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. It is known to those skilled in the art that with the emergence of new application scenarios, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems. In the description of the present application, unless otherwise specified, the meaning of "multiple" is two or more.
[0068] In order to solve the problem of low code efficiency corresponding to the new monitoring requirements of the existing acquisition model, this application proposes the following Figure 1 The method shown in the figure can be executed by a server, a chip in the server, or a functional module in the server, which is not limited in the present application. The following description is made by taking the execution subject as a server as an example. The method includes:
[0069] Step 101: Obtain the new monitoring requirements for the model and the syntax tree corresponding to the code repository source code of the model.
[0070] For example, with the rapid development of big model technology, various big models have very wide applications in work and life. For example, as described in the background technology section, in financial institutions, big models can be used to estimate users' credit scores based on their cash flow to formulate business strategies, or use big models to perform related data analysis work, which greatly reduces the workload of relevant staff. In order to ensure that the model performance meets expectations, the model is usually monitored in terms of performance, stability, accuracy, etc., and the model parameters are adjusted in a timely manner based on the monitoring results. As the actual business continues to grow, the demand for model monitoring will continue to increase. Relevant staff can fill in the new monitoring requirements on the server according to the preset template and submit them. Correspondingly, the server obtains the new monitoring requirements of the model.
[0071] For example, suppose that the server obtains the new monitoring requirement of the model, which is "calculate the performance monitoring predicted defect rate and actual defect rate indicators in the model monitoring module, and display a line chart with time as the dimension."
[0072] Exemplarily, the server also needs to parse the code repository source code corresponding to the model to obtain a syntax tree. The syntax tree is an abstract representation of the syntax structure of the source code, which expresses the syntax structure of the programming language in a tree form. Each node in the syntax tree represents a structure in the source code, such as a statement, an expression, or a declaration. The generation of a syntax tree usually includes three stages: lexical analysis, grammatical analysis, and semantic analysis. Among them, lexical analysis is the first stage of the code compilation process. The source code is input as a character stream in sequence, and the read-in character sequence is scanned and analyzed, and finally converted into a word sequence output. Lexical analysis provides symbolic nodes for the generation of the syntax tree; grammatical analysis is the second stage of the code compilation process, which is mainly to perform logical analysis on the code. The main task of this stage is to analyze the basic syntax structure of the code based on the word sequence generated in the lexical analysis stage and according to the grammatical rules of the analyzed language, such as methods, variables, expressions, and other ways of composing the code; semantic analysis is the third stage of the code compilation process, which is mainly to perform logical analysis on the code. The main analysis method is to perform context-related property verification and type verification on the source code to determine whether the source code is semantically accurate.
[0073] For example, if you need to obtain the syntax tree corresponding to the code repository source code more quickly, you can also install a syntax analyzer tool on the server to obtain the syntax tree corresponding to the code repository source code. This application does not limit the type of syntax analyzer tool used; for example, you can obtain the syntax tree by installing the ANTLR tool. The syntax tree corresponding to the repository source code in this application is as follows: Figure 2 As shown, it consists of code files with a relationship of belonging, classes included in the code files, and functions included in the classes. A code file includes at least one class, which can also be called a Class. A class includes at least one function, which can also be called a function or method. When developers write the source code of the model, they usually add corresponding comments to the code files, classes, and functions to explain the code accordingly. For example, the functions to be implemented by the code are explained in the comments to improve the readability of the code.
[0074] Step 102: Determine each sub-requirement corresponding to the newly added monitoring requirement according to the newly added monitoring requirement, and determine the code information corresponding to each sub-requirement according to the syntax tree.
[0075] Exemplarily, after the server obtains the new monitoring requirements of the model through step 101, it first splits the new monitoring requirements to obtain sub-requirements corresponding to the new monitoring requirements. The splitting process can be completed through a large language model. The new monitoring requirements are input into the large language model, and the large language model splits the new monitoring requirements and outputs multiple sub-requirements obtained after the splitting; wherein the large language model can also be called an LLM model. This application does not limit the type of the large language model used. For example, it can be a GPT series or a BERT series.
[0076] For example, taking the newly added monitoring requirement "calculate the performance monitoring predicted defect rate and actual defect rate indicators in the model monitoring module, and display a line chart with time as the dimension" as an example, assuming that after the newly added monitoring requirement is input into the large language model, the sub-requirements output by the large language model include: implementing the performance monitoring indicator calculation function in the model monitoring module, implementing data processing and chart display functions, comparing the actual defect rate with the predicted defect rate, and generating a line comparison chart with time as the dimension. For the convenience of description, the above sub-requirements are recorded as sub-requirements A to D.
[0077] Exemplarily, after obtaining the sub-requirements corresponding to the newly added monitoring requirements, the keyword set corresponding to each sub-requirement is then determined; specifically, for any one of the sub-requirements, the sub-requirement is input into a preset word segmentation component to obtain the keyword set corresponding to the sub-requirement; it should be noted that this application does not limit the type of word segmentation component used.
[0078] For example, the preset word segmentation component can be an Elasticsearch component (ES component for short), and sub-requirements A to D are input into the ES component to obtain a keyword set corresponding to each sub-requirement in sub-requirements A to D. Assume that the keyword set corresponding to sub-requirement A output by the ES component is {model monitoring, performance monitoring, function implementation}, the keyword set corresponding to sub-requirement B is {indicator calculation, data processing, chart display}, the keyword set corresponding to sub-requirement C is {actual defective rate, predicted defective rate, difference comparison}, and the keyword set corresponding to sub-requirement D is {time dimension, line chart, trend comparison}.
[0079] Further exemplarily, after obtaining the keyword set corresponding to each sub-requirement output by the preset analysis component, the class and function corresponding to each keyword in the keyword set are determined according to the syntax tree as the code information corresponding to each keyword. For example, according to the syntax tree, the class and function corresponding to each keyword in the keyword set {model monitoring, performance monitoring, function implementation} corresponding to sub-requirement A can be determined as the code information corresponding to each keyword; similarly, according to the syntax tree, the class and function corresponding to each keyword in the keyword set {indicator calculation, data processing, chart display} corresponding to sub-requirement B can be determined as the code information corresponding to each keyword... and according to the syntax tree, the class and function corresponding to each keyword in the keyword set {time dimension, line chart, trend comparison} corresponding to sub-requirement D can be determined as the code information corresponding to each keyword.
[0080] Then, the keyword set corresponding to the sub-requirement is filtered according to the degree of correlation between the annotation information corresponding to the code information corresponding to each keyword in the keyword set corresponding to the sub-requirement and the function to be implemented by the sub-requirement, so as to obtain a filtered keyword set; wherein the degree of correlation between the annotation information corresponding to the code information corresponding to each keyword and the function to be implemented by the sub-requirement can be determined by calculating the semantic similarity between the annotation information corresponding to the code information and the function to be implemented by the sub-requirement.
[0081] For example, assuming that the semantic similarity threshold is set to 0.7, taking sub-requirement A as an example, if the calculated result of the semantic similarity between the keyword "function implementation" in the keyword set corresponding to sub-requirement A and the function to be implemented by sub-requirement A is 0.6, then the keyword "function implementation" is removed from the keyword set corresponding to sub-requirement A; if the calculated result of the semantic similarity between the keyword "function implementation" in the keyword set corresponding to sub-requirement A and the function to be implemented by sub-requirement A is 0.74, then the keyword "function implementation" is retained. Through the above screening process, the filtered keyword set corresponding to each sub-requirement can be determined. Assume that the filtered keyword set corresponding to sub-requirement A is {model monitoring, performance monitoring}, the filtered keyword set corresponding to sub-requirement B is {indicator calculation, data processing}, the filtered keyword set corresponding to sub-requirement C is {actual defect rate, predicted defect rate}, and the filtered keyword set corresponding to sub-requirement D is {time dimension, line chart, trend comparison}.
[0082] Finally, according to the classes and functions corresponding to each keyword in the keyword set corresponding to each sub-requirement, the code information corresponding to each sub-requirement is determined. It should be noted that the keyword set corresponding to each sub-requirement here is a filtered keyword set (hereinafter, the keyword set corresponding to each sub-requirement refers to the filtered keyword set corresponding to each sub-requirement), that is, according to the classes and functions corresponding to each keyword in the filtered keyword set corresponding to each sub-requirement, for example, the classes and functions corresponding to each keyword in the filtered keyword set are merged and deduplicated to obtain the code information corresponding to each sub-requirement.
[0083] For example, taking sub-requirement A as an example, the filtered keyword set corresponding to sub-requirement A is {model monitoring, performance monitoring}. The classes and functions corresponding to the keywords "model monitoring" and "performance monitoring" can be merged and deduplicated to obtain the code information corresponding to sub-requirement A; the process of determining the code information corresponding to sub-requirements B to D refers to the process of determining the code information corresponding to sub-requirement A, and will not be repeated here.
[0084] The keyword set corresponding to each sub-requirement obtained by the preset word segmentation component may contain some keywords with low correlation with the sub-requirement. Therefore, more preferably, the present application also filters the keyword set corresponding to each sub-requirement output by the preset word segmentation component to obtain a filtered keyword set, thereby ensuring that the keywords in the filtered keyword set have a high correlation with the sub-requirements, thereby improving the accuracy of the code information and knowledge graph determination corresponding to the subsequent sub-requirements.
[0085] Step 103: Determine the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement from the knowledge graph corresponding to each sub-requirement through the large language model.
[0086] Exemplarily, after obtaining the keyword set corresponding to each sub-requirement, the knowledge graph corresponding to each sub-requirement can be determined according to the keyword set corresponding to each sub-requirement; specifically, for any sub-requirement among the sub-requirements, according to the keyword set corresponding to the sub-requirement, at least one triple corresponding to the sub-requirement is obtained as the knowledge graph corresponding to the sub-requirement; any triple includes a first keyword as a head entity, a relationship between the head entity and the tail entity, and a second keyword as a tail entity; the first keyword and the second keyword are two keywords in the keyword set corresponding to the sub-requirement, that is, the triple is expressed in the form of (head entity, relationship between the head entity and the tail entity, tail entity).
[0087] Natural Language Processing (NLP) models have wide applications in information extraction. NLP models can extract information of interest to users from specified documents or massive documents, such as entities, relationships, events, etc., for further analysis and processing; therefore, the present application can use the NLP model to obtain at least one triple corresponding to each sub-requirement, that is, the knowledge graph corresponding to each sub-requirement.
[0088] For example, taking sub-requirement D as an example, assuming that the keyword set {time dimension, line chart, trend comparison} corresponding to sub-requirement D is input into the pre-trained NLP model, at least one triple corresponding to sub-requirement D is obtained as shown in the following table:
[0089] Triple ① (Time dimension, relationship between time dimension and line chart, line chart) Triple ② (Time dimension, relationship between time dimension and trend comparison, trend comparison) Triple ③ (Line chart, relationship between line chart and trend comparison, trend comparison)
[0090] Table 1
[0091] The conversion of the triples shown in Table 1 into a graph representation can be referred to Figure 3 , Figure 3 The line between any two nodes in represents the relationship between the two nodes.
[0092] Exemplarily, after obtaining the knowledge graph corresponding to each sub-requirement, multiple rounds of reasoning are performed through the large language model to determine the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement. The number of rounds of reasoning is determined according to the number of sub-requirements. If there are n sub-requirements, the large language model needs to perform n-1 rounds of reasoning. For example, taking sub-requirements A to D as an example, there are 4 sub-requirements in total, so the large language model needs to perform 3 rounds of reasoning.
[0093] The following explains the reasoning process of the large language model:
[0094] In the first round of reasoning, the knowledge graph corresponding to each sub-requirement is input into the large language model to determine the reasoning result corresponding to the first round of reasoning. Any reasoning path included in the reasoning result corresponding to the first round of reasoning only includes a single sub-requirement; in other words, the number of reasoning paths included in the reasoning result corresponding to the first round of reasoning is equal to the number of sub-requirements. For example, after the large language performs the first round of reasoning on sub-requirements A to D, the reasoning results obtained include a total of 4 reasoning paths, namely the reasoning path corresponding to sub-requirement A, the reasoning path corresponding to sub-requirement B, the reasoning path corresponding to sub-requirement C, and the reasoning path corresponding to sub-requirement D. Figure 4 Shown is a possible example of the four reasoning paths.
[0095] Each subsequent round of reasoning is associated with the reasoning result of the previous round. In the i-th round of reasoning, the reasoning result obtained after the i-1th round of reasoning and the knowledge graph corresponding to each sub-requirement are input into the large language model to determine the reasoning result corresponding to the i-th round of reasoning. Any reasoning path in the reasoning result corresponding to the i-th round of reasoning is obtained by merging the first reasoning path and the second reasoning path in the reasoning result corresponding to the i-1th round of reasoning, wherein the correlation between the first reasoning path and the second reasoning path is greater than the preset correlation threshold. Therefore, the length of any reasoning path in the reasoning result corresponding to the i-th round of reasoning is longer than the length of any reasoning path in the reasoning result corresponding to the i-1th round of reasoning; i is a positive integer and i is greater than 1.
[0096] Further exemplarily, during the reasoning process, the large language model traverses each reasoning path of the input, calculates the correlation between the triple corresponding to the last node included in each reasoning path and the triple corresponding to the first node included in other reasoning paths, and the two reasoning paths can be merged as long as one of the correlation calculation results between multiple triples is greater than a preset correlation threshold.
[0097] For example, during the second round of reasoning, the reasoning results corresponding to the first round of reasoning and the knowledge graphs corresponding to each sub-requirement are input into the large language model. The large language model has four reasoning paths corresponding to sub-requirements A to D. When processing the reasoning path corresponding to sub-requirement A, it is necessary to calculate the correlation between the triple corresponding to the last node in the reasoning path corresponding to sub-requirement A and the triple corresponding to the first node in the reasoning path corresponding to sub-requirement B. It is also necessary to calculate the correlation between the triple corresponding to the last node in the reasoning path corresponding to sub-requirement A and the triple corresponding to the first node in the reasoning path corresponding to sub-requirement C. As well as the correlation between the triple corresponding to the last node in the reasoning path corresponding to sub-requirement A and the triple corresponding to the first node in the reasoning path corresponding to sub-requirement D.
[0098] by Figure 4Taking the reasoning paths corresponding to the sub-requirements shown in the figure as an example, the last node of the reasoning path corresponding to sub-requirement A is "performance monitoring", and the triple corresponding to "performance monitoring" is (model monitoring, the relationship between model monitoring and performance monitoring, performance monitoring). The first node of the reasoning path corresponding to sub-requirement D is "time dimension", and the triple corresponding to "time dimension" is (time dimension, the relationship between time dimension and trend comparison, trend comparison) and (time dimension, the relationship between time dimension and line chart, line chart). Therefore, it is necessary to calculate (model monitoring, the relationship between model monitoring and performance monitoring, performance monitoring) and (time dimension, time dimension The correlation between the dimension and the trend comparison, trend comparison), and the correlation between (model monitoring, the relationship between model monitoring and performance monitoring, performance monitoring) and (time dimension, the relationship between the time dimension and the line chart, line chart) need to be calculated. A total of two correlation calculation results are obtained. If the preset correlation threshold is 0.7, as long as one of the two correlation calculation results is greater than 0.7, the reasoning path of sub-requirement A and the reasoning path of sub-requirement D can be merged. The reasoning path obtained after the merger can be called the reasoning path corresponding to sub-requirement A and sub-requirement D. The reasoning path corresponding to sub-requirement A and sub-requirement D can refer to Figure 5 ; If the two correlation calculation results are both less than 0.7, the reasoning paths corresponding to sub-requirements A and D cannot be merged.
[0099] Assuming that the large language model undergoes the second round of reasoning, the reasoning results corresponding to the second round of reasoning include 4 reasoning paths, which are respectively recorded as: ① Reasoning path AB: the reasoning path corresponding to sub-requirement A and the reasoning path corresponding to sub-requirement B are combined; ② Reasoning path AC: the reasoning path corresponding to sub-requirement A and the reasoning path corresponding to sub-requirement C are combined; ③ Reasoning path BC: the reasoning path corresponding to sub-requirement B and the reasoning path corresponding to sub-requirement C are combined; ④ Reasoning path CD: the reasoning path corresponding to sub-requirement C and the reasoning path corresponding to sub-requirement D are combined.
[0100] Similar to the reasoning process of the second round, when performing the third round of reasoning, the reasoning results corresponding to the second round of reasoning and the knowledge graphs corresponding to each sub-requirement are input into the large language model to obtain the reasoning results corresponding to the third round of reasoning. The length of any reasoning path in the reasoning results corresponding to the third round of reasoning is longer than the length of any reasoning path in the reasoning results corresponding to the second round of reasoning. For example, the length of any reasoning path in the reasoning results corresponding to the third round of reasoning is longer than the length of any reasoning path among reasoning path AB, reasoning path AC, reasoning path BC, and reasoning path CD... After the last round of reasoning by the large language model, the reasoning path included in the obtained reasoning result can be called the longest reasoning path, and then the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement is determined from at least one longest reasoning path obtained by the last round of reasoning. The number of longest reasoning paths with the highest semantic similarity can be one or more.
[0101] For example, for sub-requirements A to D, the third round of reasoning is the last round of reasoning. Assume that the reasoning results corresponding to the last round of reasoning include a total of three longest reasoning paths, which are recorded as: ① Reasoning path ABC: obtained by merging reasoning path AB and reasoning path BC; ② Reasoning path ACD: obtained by merging reasoning path AC and reasoning path CD; ③ Reasoning path BCD: obtained by merging reasoning path BC and reasoning path CD; Assume that the longest reasoning paths with the highest semantic similarity to the newly added monitoring requirements determined from the three longest reasoning paths are reasoning paths ABC and reasoning paths BCD.
[0102] Step 104: Input the longest reasoning path, the code information corresponding to the longest reasoning path, and the target reasoning path into the large language model to obtain the code information corresponding to the target reasoning path as the code corresponding to the newly added monitoring requirement; wherein, the code information corresponding to the longest reasoning path is determined based on the code information corresponding to each sub-requirement, and the target reasoning path includes each sub-requirement.
[0103] Exemplarily, the code information corresponding to the longest reasoning path is obtained by merging the code information corresponding to the sub-requirements included in the longest reasoning path. For example, the code information of the longest reasoning path ABC is obtained by merging the code information corresponding to sub-requirements A to C, and the code information of the longest reasoning path BCD is obtained by merging the code information corresponding to sub-requirements B to D.
[0104] Exemplarily, the target reasoning path includes each sub-requirement corresponding to the newly added monitoring requirement. For example, the target reasoning path includes sub-requirement A to sub-requirement D, which is recorded as target reasoning path ABCD.
[0105] Further exemplarily, the longest reasoning path, the code information corresponding to the longest reasoning path, and the target reasoning path are input into the large language model to obtain the code information corresponding to the target reasoning path. For example, the longest reasoning paths ABC and BCD, the code information corresponding to the longest reasoning paths ABC and BCD, and the target reasoning path ABCD are input into the large language model to obtain the code information corresponding to the target reasoning path ABCD, that is, the code corresponding to the newly added monitoring requirement.
[0106] In addition, after obtaining the code corresponding to the newly added monitoring requirements, unit test cases can be designed for the code corresponding to the newly added monitoring requirements for testing, and the code corresponding to the newly added monitoring requirements can be adjusted and optimized according to the test results. For example, the code whose test results do not meet the test requirements can be modified until the test requirements are met. The code corresponding to the newly added monitoring requirements can also be run to obtain the corresponding monitoring results, and the monitoring results can be displayed in the form of reports, so that relevant staff can intuitively perceive the model effect, and dynamically adjust the model parameters according to the monitoring results to improve the model performance.
[0107] The method for generating code proposed in this application obtains the code corresponding to the newly added monitoring requirement through a large language model, thereby improving the degree of automation and efficiency of code acquisition; and the knowledge graph corresponding to the sub-requirement is combined with the large language model, and the code corresponding to the newly added monitoring requirement is obtained after the large language model is inferred based on the knowledge graph corresponding to the sub-requirement, thereby improving the rationality and accuracy of the code corresponding to the newly added monitoring requirement.
[0108] Figure 6 and Figure 7 The schematic diagram of the structure of the possible code generating device provided by the embodiment of the present application. These code generating devices can be used to implement the functions of the server in the above method embodiment, and thus can also achieve the beneficial effects possessed by the above method embodiment.
[0109] like Figure 6 As shown, the device 600 for generating a code includes a processing unit 610 and a transceiver unit 620. The device 600 for generating a code is used to implement the above Figure 1 The functions of the server in the method embodiment shown are:
[0110] The transceiver unit 620 is used to obtain the newly added monitoring requirements for the model and the syntax tree corresponding to the code repository source code of the model;
[0111] The processing unit 610 is used to determine each sub-requirement corresponding to the newly added monitoring requirement according to the newly added monitoring requirement, and determine the code information corresponding to each sub-requirement according to the syntax tree;
[0112] The processing unit 610 is further configured to determine, from the knowledge graph corresponding to each sub-requirement, the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement through a large language model;
[0113] The transceiver unit 620 is also used to input the longest reasoning path, the code information corresponding to the longest reasoning path, and the target reasoning path into the large language model to obtain the code information corresponding to the target reasoning path as the code corresponding to the newly added monitoring requirement; wherein, the code information corresponding to the longest reasoning path is determined based on the code information corresponding to each sub-requirement, and the target reasoning path includes each sub-requirement.
[0114] In a possible design, the transceiver unit 620 is specifically used to: during the first round of reasoning, input the knowledge graph corresponding to each sub-requirement into the large language model to determine the reasoning result corresponding to the first round of reasoning;
[0115] In the i-th round of reasoning, the reasoning result obtained after the i-1th round of reasoning and the knowledge graph corresponding to each sub-requirement are input into the large language model to determine the reasoning result corresponding to the i-th round of reasoning; wherein the length of any reasoning path in the reasoning result corresponding to the i-th round of reasoning is longer than the length of any reasoning path in the reasoning result corresponding to the i-1th round of reasoning; i is a positive integer and i is greater than 1;
[0116] From at least one longest reasoning path obtained in the last round of reasoning, determine the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement.
[0117] In a possible design, any reasoning path in the reasoning results corresponding to the i-th round of reasoning is obtained by merging the first reasoning path and the second reasoning path in the reasoning results corresponding to the i-1-th round of reasoning, and the correlation between the first reasoning path and the second reasoning path is greater than a preset correlation threshold.
[0118] In a possible design, the processing unit 610 is used to determine the knowledge graph corresponding to each sub-requirement: determine a keyword set corresponding to any sub-requirement; obtain at least one triple corresponding to the sub-requirement according to the keyword set corresponding to the sub-requirement as the knowledge graph corresponding to the sub-requirement;
[0119] Any triple includes a first keyword as a head entity, a relationship between the head entity and a tail entity, and a second keyword as a tail entity; the first keyword and the second keyword are two keywords in a keyword set corresponding to the sub-demand.
[0120] In a possible design, the transceiver unit 620 is specifically used to input any one of the sub-requirements into a preset word segmentation component to obtain a keyword set corresponding to the sub-requirement; the processing unit 610 is specifically used to filter the keyword set corresponding to the sub-requirement according to the degree of correlation between the annotation information corresponding to the code information corresponding to each keyword in the keyword set corresponding to the sub-requirement and the function to be implemented by the sub-requirement, so as to obtain a filtered keyword set.
[0121] In one possible design, the syntax tree is composed of code files that have an affiliation, classes included in the code files, and functions included in the classes; the processing unit 610 is specifically used to determine, for any sub-requirement, a keyword set corresponding to the sub-requirement; determine, based on the syntax tree, classes and functions corresponding to each keyword in the keyword set corresponding to the sub-requirement; and determine the code information corresponding to the sub-requirement based on the classes and functions corresponding to each keyword in the sub-requirement.
[0122] In a possible design, the processing unit 610 is also used to design unit test cases for the code corresponding to the newly added monitoring requirement, and adjust and optimize the code corresponding to the newly added monitoring requirement according to the test results.
[0123] For more detailed description of the processing unit 610 and the transceiver unit 620, please refer to Figure 1 The relevant description in the method embodiment shown is directly obtained and will not be repeated here.
[0124] like Figure 7 As shown, the device 700 for generating code includes a processor 710 and an interface circuit 720. The processor 710 and the interface circuit 720 are coupled to each other. It is understood that the interface circuit 720 can be a transceiver or an input-output interface. Optionally, the device 700 for generating code can also include a memory 730 for storing instructions executed by the processor 710 or storing input data required by the processor 710 to execute instructions or storing data generated after the processor 710 executes instructions.
[0125] When the device 700 for generating code is used to implement Figure 1 When the method is shown, the processor 710 is used to implement the function of the above-mentioned processing unit 610, and the interface circuit 720 is used to implement the function of the above-mentioned transceiver unit 620.
[0126] The division of units in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, each functional unit in each embodiment of the present application may be integrated into a processor, or may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0127] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0128] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for generating a code, characterized in that: The method includes: Obtain new monitoring requirements for the model and the syntax tree corresponding to the code repository source code of the model; Determine each sub-requirement corresponding to the newly added monitoring requirement according to the newly added monitoring requirement, and determine the code information corresponding to each sub-requirement according to the syntax tree; Determine, through a large language model, from the knowledge graph corresponding to each of the sub-demands, the longest reasoning path with the highest semantic similarity to the newly added monitoring demand; The longest reasoning path, the code information corresponding to the longest reasoning path, and the target reasoning path are input into the large language model to obtain the code information corresponding to the target reasoning path as the code corresponding to the newly added monitoring requirement; wherein, the code information corresponding to the longest reasoning path is determined based on the code information corresponding to each sub-requirement, and the target reasoning path includes each sub-requirement.
2. The method according to claim 1, characterized in that The determining, from the knowledge graphs corresponding to the sub-demands, the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement by the large language model includes: In the first round of reasoning, the knowledge graph corresponding to each sub-requirement is input into the large language model to determine the reasoning result corresponding to the first round of reasoning; In the i-th round of reasoning, the reasoning result obtained after the i-1th round of reasoning and the knowledge graph corresponding to each sub-requirement are input into the large language model to determine the reasoning result corresponding to the i-th round of reasoning; wherein the length of any reasoning path in the reasoning result corresponding to the i-th round of reasoning is longer than the length of any reasoning path in the reasoning result corresponding to the i-1th round of reasoning; i is a positive integer and i is greater than 1; From at least one longest reasoning path obtained in the last round of reasoning, determine the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement.
3. The method according to claim 2, characterized in that Any reasoning path in the reasoning results corresponding to the i-th round of reasoning is obtained by merging the first reasoning path and the second reasoning path in the reasoning results corresponding to the i-1-th round of reasoning, and the correlation between the first reasoning path and the second reasoning path is greater than a preset correlation threshold.
4. The method according to any one of claims 1 to 3, characterized in that The process of determining the knowledge graph corresponding to each sub-demand is as follows: Determine the keyword set corresponding to any sub-requirement; According to the keyword set corresponding to the sub-demand, at least one triple corresponding to the sub-demand is obtained as the knowledge graph corresponding to the sub-demand; Any triple includes a first keyword as a head entity, a relationship between the head entity and a tail entity, and a second keyword as a tail entity; the first keyword and the second keyword are two keywords in a keyword set corresponding to the sub-demand.
5. The method according to claim 4, characterized in that Determine the keyword set corresponding to any sub-requirement, including: For any one of the sub-demands, input the sub-demand into a preset word segmentation component to obtain a keyword set corresponding to the sub-demand; The keyword set corresponding to the sub-requirement is filtered according to the correlation between the annotation information corresponding to the code information corresponding to each keyword in the keyword set corresponding to the sub-requirement and the function to be realized by the sub-requirement, so as to obtain a filtered keyword set.
6. The method according to any one of claims 1 to 3, characterized in that The syntax tree is composed of code files with belonging relationships, classes included in the code files, and functions included in the classes; The determining, according to the syntax tree, the code information corresponding to each sub-requirement includes: For any sub-demand, determine a keyword set corresponding to the sub-demand; Determine, according to the syntax tree, the class and function corresponding to each keyword in the keyword set corresponding to the sub-requirement; The code information corresponding to the sub-requirement is determined according to the class and function corresponding to each keyword in the keyword set corresponding to the sub-requirement.
7. The method according to any one of claims 1 to 3, characterized in that After obtaining the code corresponding to the newly added monitoring requirement, it also includes: Design unit test cases for the code corresponding to the newly added monitoring requirements and perform testing on the code corresponding to the newly added monitoring requirements, and adjust and optimize the code corresponding to the newly added monitoring requirements based on the test results.
8. A device for generating a code, characterized in that: The device comprises: a processing unit and a transceiver unit; The transceiver unit is used to obtain the newly added monitoring requirements for the model and the syntax tree corresponding to the code repository source code of the model; The processing unit is used to determine each sub-requirement corresponding to the newly added monitoring requirement according to the newly added monitoring requirement, and determine the code information corresponding to each sub-requirement according to the syntax tree; The processing unit is further configured to determine, from the knowledge graph corresponding to each sub-requirement, the longest reasoning path with the highest semantic similarity to the newly added monitoring requirement through a large language model; The transceiver unit is also used to input the longest reasoning path, the code information corresponding to the longest reasoning path, and the target reasoning path into the large language model to obtain the code information corresponding to the target reasoning path as the code corresponding to the newly added monitoring requirement; wherein the code information corresponding to the longest reasoning path is determined based on the code information corresponding to each sub-requirement, and the target reasoning path includes each sub-requirement.
9. A device for generating a code, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.
11. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 7 when being executed by a processor.
Citation Information
Patent Citations
Knowledge graph-based large language model generation method, system and device and medium
CN117609391A
Code generation method and related device
CN117632116A
Software test driven code generation method and device
CN118445212A
Methods, systems, articles of manufacture and apparatus to identify code semantics
US20220107792A1