Code modification strategy determination method and device, equipment, medium and program product

Key code features are extracted through the random forest model, the support vector machine model generates optimization suggestions, and the retrieval enhancement generation model automatically adjusts the code, solving the problems of code optimization accuracy and inefficiency in the existing technology, and achieving efficient and automatic code optimization.

CN119513709AActive Publication Date: 2025-02-25CHINA LIFE INSURANCE CO LTD

Patent Information

Application Number
CN202411717013.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-02-25
Estimated Expiration
2044-11-27

AI Technical Summary

Technical Problem

The prior art has low accuracy in the process of business code optimization, and often requires manual in-depth intervention, resulting in inefficiency.

Method used

The key code features are extracted based on the random forest model, the support vector machine model is classified, optimization suggestions are generated, and the code is automatically adjusted using the search enhancement generation model.

Benefits of technology

It improves the accuracy and efficiency of code optimization, and realizes automatic positioning and automatic modification of the code to be optimized.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119513709A_ABST
    Figure CN119513709A_ABST
Patent Text Reader

Abstract

The invention relates to a code modification strategy determination method and device, equipment, a medium and a program product. The code modification strategy determination method comprises the steps of extracting key code features in a to-be-optimized code based on a random forest model; based on a support vector machine model, classifying the key code features to obtain a target optimization suggestion to which the to-be-optimized code belongs; and based on the retrieval enhancement generation model, according to the target optimization suggestion, adjusting the to-be-optimized code to obtain a target code. By means of the method, automatic positioning and automatic modification of the to-be-optimized points of the to-be-optimized codes are achieved, and the accuracy and optimization efficiency of the to-be-optimized codes are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of code optimization, and in particular to a method, device, equipment, medium and program product for determining a code modification strategy. Background Art

[0002] With the continuous advancement of science and technology, the complexity of business codes is increasing, making code error correction and optimization more and more critical.

[0003] In traditional technologies, rule engines and static analysis are widely used in the optimization process of business codes to identify common code problems. However, although these tools can detect basic business rule conflicts and code irregularities, the accuracy of code optimization is low and often requires deep manual intervention to complete the optimization work, which undoubtedly reduces the efficiency of code optimization. Summary of the invention

[0004] Based on this, it is necessary to provide a code modification strategy determination method, device, equipment, medium and program product that can improve code optimization efficiency and optimization accuracy in response to the above technical problems.

[0005] In a first aspect, the present application provides a method for determining a code modification strategy, comprising:

[0006] Based on the random forest model, key code features in the code to be optimized are extracted;

[0007] Based on the support vector machine model, key code features are classified to obtain target optimization suggestions for the code to be optimized;

[0008] Based on the retrieval enhanced generation model, the code to be optimized is adjusted according to the target optimization suggestions to obtain the target code.

[0009] In one of the embodiments, the random forest model is trained in the following manner: a first training sample and an optimization suggestion category to which the first training sample belongs are obtained; wherein the first training sample includes at least one of the following features corresponding to the first sample code: business characteristic features, system performance features, code structure features, and user behavior features; the first sample code includes a business code and a general code; feature extraction is performed on the first training sample to obtain target sample features; the target sample features are used as model input, and the optimization suggestion category to which the first training sample belongs is used as a label to perform model training on a pre-built random forest model.

[0010] In one of the embodiments, the support vector machine model is trained in the following manner: obtaining a second training sample and an optimization suggestion category to which the second training sample belongs; wherein the second training sample includes at least one of the following features corresponding to the second sample code: business characteristic features, system performance features, code structure features, and user behavior features; the second sample code includes business code and general code; performing feature extraction on the second training sample according to a random forest model to obtain key sample features; using the key sample features as model input, and using the optimization suggestion category to which the second training sample belongs as a label, and performing model training on a pre-built support vector machine model.

[0011] In one of the embodiments, based on the retrieval enhanced generation model and according to the target optimization suggestion, the code to be optimized is adjusted to obtain the target code, including: based on the retrieval enhanced generation model and according to the target optimization suggestion, determining the code segment to be modified and the code adjustment strategy of the code segment to be modified corresponding to the code to be optimized; according to the code adjustment strategy of the code segment to be modified, adjusting the code segment to be modified to obtain the target code.

[0012] In one of the embodiments, based on the retrieval enhanced generation model and according to the target optimization suggestion, the code segment to be modified and the code adjustment strategy of the code segment to be modified corresponding to the code to be optimized are determined, including: based on the encoding network in the retrieval enhanced generation model, feature encoding the target optimization suggestion to obtain the suggestion vector feature of the target optimization suggestion; and, feature encoding the code to be optimized to obtain the code vector feature of the code to be optimized; based on the enhanced retrieval network in the retrieval enhanced generation model, according to the suggestion vector feature, searching in the code vector feature to obtain the code segment to be modified in the code to be optimized and the code adjustment strategy of the code segment to be modified.

[0013] In one of the embodiments, feature encoding is performed on the code to be optimized to obtain code vector features of the code to be optimized, including: dividing the code to be optimized into at least one code block according to the code structure of the code to be optimized; feature encoding is performed on each code block to obtain code block features of the corresponding code block; wherein the code vector features of the code to be optimized include code block features of at least one code block; correspondingly, according to the recommended vector features, a search is performed in the code vector features to obtain a code segment to be modified in the code to be optimized, including: according to the recommended vector features, feature matching is performed in the code block features of at least one code block, and according to the matching result, the code segment to be modified in the code to be optimized is determined.

[0014] In a second aspect, the present application also provides a code modification strategy determination device, including:

[0015] The first processing module is used to extract key code features in the code to be optimized based on the random forest model;

[0016] The second processing module is used to classify key code features based on a support vector machine model to obtain target optimization suggestions for the code to be optimized;

[0017] The third processing module is used to adjust the code to be optimized based on the retrieval enhancement generation model and the target optimization suggestion to obtain the target code.

[0018] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:

[0019] Based on the random forest model, key code features in the code to be optimized are extracted;

[0020] Based on the support vector machine model, key code features are classified to obtain target optimization suggestions for the code to be optimized;

[0021] Based on the retrieval enhanced generation model, the code to be optimized is adjusted according to the target optimization suggestions to obtain the target code.

[0022] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:

[0023] Based on the random forest model, key code features in the code to be optimized are extracted;

[0024] Based on the support vector machine model, key code features are classified to obtain target optimization suggestions for the code to be optimized;

[0025] Based on the retrieval enhanced generation model, the code to be optimized is adjusted according to the target optimization suggestions to obtain the target code.

[0026] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:

[0027] Based on the random forest model, key code features in the code to be optimized are extracted;

[0028] Based on the support vector machine model, key code features are classified to obtain target optimization suggestions for the code to be optimized;

[0029] Based on the retrieval enhanced generation model, the code to be optimized is adjusted according to the target optimization suggestions to obtain the target code.

[0030] The above-mentioned code modification strategy determination method, device, equipment, medium and program product extract key code features in the code to be optimized through the random forest model, effectively reducing the interference of noise and redundant data. Then, by classifying the key code features through the support vector machine model, it is possible to more accurately and effectively generate target optimization suggestions for the code to be optimized. Among them, the random forest model has the ability to identify complex nonlinear characteristic relationships, which is conducive to improving the accuracy of key code feature extraction. At the same time, the support vector machine model has strong classification and regression capabilities, which improves the generation efficiency of target optimization suggestions. In addition, based on the retrieval enhancement generation model, the code to be optimized is adjusted according to the target optimization suggestion, which realizes the automatic positioning and automatic modification of the points to be optimized of the code to be optimized, and improves the optimization efficiency of the code to be optimized. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions 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 related drawings can be obtained based on these drawings without paying creative work.

[0032] Figure 1 A schematic diagram of a flow chart of a method for determining a code modification strategy in an embodiment;

[0033] Figure 2 A flowchart of steps for determining a code adjustment strategy in one embodiment;

[0034] Figure 3 A schematic diagram of a flow chart of a method for determining a code modification strategy in another embodiment;

[0035] Figure 4 A structural block diagram of a device for determining a code modification strategy in an embodiment;

[0036] Figure 5 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0038] In one embodiment, Figure 1As shown, a method for determining a code modification strategy is provided. This embodiment uses the method applied to a terminal as an example for illustration. It can be understood that the method can also be applied to a server, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:

[0039] S110. Based on the random forest model, extract key code features in the code to be optimized.

[0040] Among them, the Random Forest Model (RFM) is an integrated learning method that combines the prediction results of multiple decision trees to improve the accuracy and stability of the model and has the ability to identify complex nonlinear characteristic relationships. Key code features can be understood as code features in the code to be optimized that are of the same type as the pre-determined key sample features. Key sample features can be screened from all sample features based on the feature contribution of each sample feature in the split decision calculated by the random forest model.

[0041] In an optional embodiment, the random forest model is trained in the following manner: obtaining a first training sample and an optimization suggestion category to which the first training sample belongs; wherein the first training sample includes at least one of the following features corresponding to the first sample code: business characteristic features, system performance features, code structure features, and user behavior features; the first sample code includes business code and general code; performing feature extraction on the first training sample to obtain target sample features; using the target sample features as model input, and using the optimization suggestion category to which the first training sample belongs as a label, and performing model training on a pre-built random forest model.

[0042] Optionally, the feature contribution of each sample feature in the split decision can be calculated based on the random forest model; the sample feature importance ranking is generated according to the feature contribution corresponding to each sample feature, and the importance of the sample feature is used to measure the influence of the sample feature on the prediction result; and key sample features are selected from all sample features according to the sample feature importance ranking. Accordingly, extracting key code features in the code to be optimized based on the random forest model includes: extracting key code features of the same type as the key sample features in the code to be optimized.

[0043] Optionally, extracting features from the first training sample to obtain target sample features may include the following steps: cleaning and preprocessing the first training sample; and extracting key target sample features from the cleaned and preprocessed first training sample. The target sample features may include at least one of code complexity features, execution time features, module dependency features, memory usage features, and abnormal frequency features.

[0044] Optionally, the pre-built random forest model is obtained by the following steps: obtaining an initial random forest model; setting initial parameters of the initial random forest model, which may include the number of decision trees, maximum tree depth, and minimum number of leaf samples of the initial random forest model; using a grid search method to determine the parameter combinations of the initial random forest model; using a cross-validation method to test the test performance of the initial random forest model of each parameter combination, the test performance includes the accuracy and generalization ability of the model; selecting the parameter combination corresponding to the optimal test performance to generate a random forest model. The parameter combination includes the number of decision trees, the maximum tree depth, the minimum number of leaf samples, and other related parameters.

[0045] Optionally, the target sample feature is used as a model input, and the optimization suggestion category to which the first training sample belongs is used as a label. Model training for the pre-built random forest model may include: building multiple decision trees, each decision tree is trained by random sampling of the target sample feature, and the decision tree stops growing after reaching a preset maximum depth or minimum number of leaf nodes. Optionally, before the target sample feature is used as a model input, the target sample feature may also be normalized and feature encoded, and used as a model input in the form of a feature vector.

[0046] Exemplarily, the general code may be obtained from a production code library, and the general code may include at least one of adopted recommended code, modified and optimized code content, the latest general code from the external network, and high-quality code with a rating greater than a preset level.

[0047] Exemplarily, the business characteristic features may include at least one of the following: policy type features, policy effective date and validity period features, claim frequency features, claim amount features, and customer stratification features. Among them, the policy type feature is also the type of policy, and different types of policies usually have different optimization requirements; the policy effective date and validity period features will affect the business logic and processing efficiency of the code; the claim frequency and claim amount features are used to optimize the processing efficiency of the code in high-frequency claims or large claims; the customer stratification feature is obtained by stratifying the customer according to age and risk preference.

[0048] Exemplarily, the system performance characteristics may include at least one of execution time characteristics, memory usage characteristics, and processing complexity characteristics, etc. Among them, the execution time characteristic refers to the execution time of a code block or a specific function, which can be used to identify performance bottlenecks; the memory usage characteristic is a key performance characteristic in large-scale data processing; the processing complexity characteristic refers to the complexity of the code logic, which is used to identify parts that may need to be optimized.

[0049] Exemplarily, the code structure feature may include at least one of a module dependency feature, an exception capture frequency feature, and a code modification frequency feature. The module dependency feature is used to identify the dependency between key code modules; the exception capture frequency feature is the frequency and distribution of exception capture, which is used to identify unstable parts in the code; and the code modification frequency feature is used to identify frequently modified code modules for further optimization.

[0050] Exemplarily, user behavior features may include at least one of a recommendation adoption rate feature, an optimization feedback feature, and a usage frequency feature. Among them, the recommendation adoption rate feature is used to record the adoption of code optimization suggestions by the business team; the optimization feedback feature is used to record the adoption effect of optimization suggestions fed back by users; the usage frequency feature is used to record the usage frequency of code modules. The higher the usage frequency, the greater the impact on the business and the higher the optimization priority.

[0051] S120. Based on the support vector machine model, key code features are classified to obtain target optimization suggestions for the code to be optimized.

[0052] Among them, the support vector machine model (SVM) is a supervised learning algorithm, mainly used for classification and regression analysis. Its basic model is defined as a linear classifier with the largest interval in a specific space, and its learning strategy is to maximize the interval, which can eventually be transformed into a solution to a convex quadratic programming problem.

[0053] In an optional embodiment, the support vector machine model is trained in the following manner: obtain a second training sample and an optimization suggestion category to which the second training sample belongs; wherein the second training sample includes at least one of the following features corresponding to the second sample code: business characteristic features, system performance features, code structure features, and user behavior features; the second sample code includes business code and general code; perform feature extraction on the second training sample according to a random forest model to obtain key sample features; use the key sample features as model input, use the optimization suggestion category to which the second training sample belongs as a label, and perform model training on a pre-built support vector machine model.

[0054] The first training sample and the second training sample can be the same training sample or different training samples. Optionally, extracting features from the second training sample according to the random forest model to obtain key sample features can include the following steps: calculating the feature contribution of each sample feature in the second training sample in the split decision based on the random forest model; generating a sample feature importance ranking based on the feature contribution corresponding to each sample feature, the importance of the sample feature being used to measure the impact of the sample feature on the prediction result; and selecting key sample features from all sample features based on the sample feature importance ranking.

[0055] Optionally, the pre-built support vector machine model can be obtained by the following steps: according to the key sample features, select the kernel function of the appropriate support vector machine model, the kernel function may include at least one of the linear kernel, polynomial kernel and Gaussian kernel, etc.; determine the relevant parameters of the selected kernel function, the relevant parameters may include the order of the polynomial kernel or the γ parameter in the Gaussian kernel; determine the combination of regularization parameter values ​​of the support vector machine model based on the grid search method; tune the regularization parameter value of the support vector machine model based on the cross-validation method to determine the optimal regularization parameter value; obtain the pre-built support vector machine model based on the selected kernel function and the optimal regularization parameter value. Among them, the γ parameter is an adjustable parameter used to control the width of the Gaussian kernel. In the above steps, based on the cross-validation method, the performance of the support vector machine model is tested by combining different regularization parameter values, so as to find the best balance between the complexity and generalization ability of the support vector machine model to avoid overfitting or underfitting.

[0056] Optionally, model training of a pre-built support vector machine model may include: learning support vectors and decision boundaries based on a second training sample and an optimization suggestion to which the second training sample belongs, and constructing an optimal interface for classification or regression based on maximizing the distance from the support vector to the decision boundary. Optionally, after model training of a pre-built support vector machine model, it also includes testing the performance indicators of the support vector machine model on a validation data set, and evaluating the classification or regression effect of the support vector machine model based on the performance indicators. Among them, the performance indicators include the precision and recall rate of the support vector machine model, etc. Optionally, after evaluating the classification or regression effect of the support vector machine model, it also includes: saving the final support vector machine model and embedding it into an intelligent code generation tool for generating code optimization suggestions or business (such as insurance, finance, etc.) related analysis.

[0057] S130, based on the retrieval enhancement generation model, according to the target optimization suggestion, the code to be optimized is adjusted to obtain the target code.

[0058] Among them, the Retrieval-Augmented Generation (RAG) model is a processing technology that combines retrieval and generation functions.

[0059] In an optional embodiment, based on the retrieval enhancement generation model and according to the target optimization suggestion, the code to be optimized is adjusted to obtain the target code, including: based on the retrieval enhancement generation model and according to the target optimization suggestion, determining the code segment to be modified and the code adjustment strategy of the code segment to be modified corresponding to the code to be optimized; according to the code adjustment strategy of the code segment to be modified, the code segment to be modified is adjusted to obtain the target code. Through the above steps, the automatic positioning and automatic modification of the code segment to be modified are achieved, and the optimization efficiency of the code to be optimized is improved. Exemplarily, for example, the code segment to be modified corresponding to the function with higher complexity in the code to be optimized is located, and the performance of the code segment to be modified is optimized based on the target optimization suggestion. For example, the code segment to be modified with potential security issues in the code to be optimized is located, and the performance of the code segment to be modified is optimized based on the target optimization suggestion.

[0060] In an optional embodiment, after the code to be optimized is adjusted to obtain the target code, it also includes: generating an automatic modification log for subsequent review and tracking. The modification log may include at least one of the specific content of the adjustment to the code to be optimized, the modification reason, and the modification location.

[0061] In an optional embodiment, after adjusting the code to be optimized to obtain the target code, it also includes: verifying and evaluating the target code. Exemplarily, verifying and evaluating the target code may include the following steps: marking the code area of ​​the target code that has been automatically modified on the IDE side (Integrated Development Environment); running the code to be optimized and the target code in the IDE side respectively, and collecting the performance data of the actual runtime; comparing the performance data of the code to be optimized and the target code to evaluate the optimization effect. Among them, the mark may include comments and tags, etc., which are used to determine the accuracy of the modification and ensure that all modifications are clearly recorded. The performance data may include at least one of execution time, memory consumption and error log, etc., which is used to verify the optimization effect of the code modification. Evaluating the optimization effect, for example, checking whether the execution time is reduced, whether the memory usage is reduced, or whether the number of exceptions in the error log is reduced. Optionally, when the optimization effect is to achieve the expected effect, feedback information is generated, and the feedback information is used as the basis for optimizing the retrieval enhancement generation model, and the retrieval enhancement generation model is continuously updated and iterated to further improve the accuracy of the retrieval enhancement generation model.

[0062] In an optional implementation, the code modification strategy determination method further includes: pushing the target code, recording the push adoption of the target code, and generating a user behavior log. Optionally, an annotation file is used to record the user's code adoption behavior such as annotations, change content, and timestamp information of specific code lines of the target code. Exemplarily, it can be saved in binary format.

[0063] In an optional implementation, the code modification strategy determination method also includes: continuously iteratively optimizing the random forest model, the support vector machine model, and the retrieval enhancement generation model based on the optimization effect evaluation results of the target code and the push adoption status of the target code to improve the quality of the target optimization suggestions.

[0064] In the embodiment of the present application, the key code features in the code to be optimized are extracted by the random forest model, which effectively reduces the interference of noise and redundant data. Then, by classifying the key code features through the support vector machine model, the target optimization suggestions to which the code to be optimized belongs can be generated more accurately and effectively. Among them, the random forest model has the ability to identify complex nonlinear characteristic relationships, which is conducive to improving the accuracy of key code feature extraction. At the same time, the support vector machine model has strong classification and regression capabilities, which improves the generation efficiency of target optimization suggestions. In addition, based on the retrieval enhancement generation model, the code to be optimized is adjusted according to the target optimization suggestion, which realizes the automatic positioning and automatic modification of the points to be optimized of the code to be optimized, and improves the optimization efficiency of the code to be optimized.

[0065] Based on the technical solutions of the above embodiments, the present application also provides an optional embodiment, in which the steps for determining the code adjustment strategy are refined.

[0066] See also Figure 2 The steps for determining the code adjustment strategy shown include:

[0067] S210, based on the encoding network in the retrieval enhancement generation model, feature encoding is performed on the target optimization suggestion to obtain a suggestion vector feature of the target optimization suggestion.

[0068] S220 , feature encoding is performed on the code to be optimized to obtain code vector features of the code to be optimized.

[0069] In an optional embodiment, feature encoding is performed on the code to be optimized to obtain code vector features of the code to be optimized, including: dividing the code to be optimized into at least one code block according to the code structure of the code to be optimized; and feature encoding is performed on each code block to obtain code block features of the corresponding code block. The code vector features of the code to be optimized include code block features of at least one code block.

[0070] Exemplarily, the code structure of the code to be optimized may be a code framework of the code to be optimized, so that the target optimization suggestion can be directly applied to the corresponding code framework and part of the content in the code framework can be automatically modified, which is conducive to improving the optimization efficiency.

[0071] S230. Based on the enhanced retrieval network in the retrieval enhancement generation model, according to the suggestion vector features, a search is performed in the code vector features to obtain the code segment to be modified in the code to be optimized and the code adjustment strategy for the code segment to be modified.

[0072] In an optional embodiment, based on the suggested vector features, a search is performed in the code vector features to obtain the code segment to be modified in the code to be optimized, including: based on the suggested vector features, feature matching is performed in the code block features of at least one code block, and based on the matching results, the code segment to be modified in the code to be optimized is determined.

[0073] Optionally, based on the suggested vector feature, feature matching is performed in the code block features of at least one code block, including: calculating the vector similarity between the suggested vector feature and the code block feature, and when the vector similarity is greater than a preset similarity value, determining that the suggested vector feature matches the code block feature, and determining the code segment to be modified in the code to be optimized by locating the code block feature that matches the suggested vector feature.

[0074] In the embodiment of the present application, by introducing the coding network in the retrieval enhancement generation model and performing feature encoding on the target optimization suggestion and the code to be optimized, a matching basis is provided for locating the code segment to be modified of the code to be optimized. Based on the enhanced retrieval network in the retrieval enhancement generation model, according to the suggestion vector feature, a search is performed in the code vector feature, thereby obtaining the code segment to be modified in the code to be optimized and the code adjustment strategy of the code segment to be modified, which improves the efficiency of locating the code segment to be modified and facilitates the optimization and modification of the code segment to be modified.

[0075] Based on the technical solutions of the above embodiments, the present application also provides an optional embodiment, in which another specific implementation method of the code modification strategy determination method is provided.

[0076] See also Figure 3 The code modification strategy determination method shown includes:

[0077] S301, obtaining a first training sample and an optimization suggestion category to which the first training sample belongs; wherein the first training sample includes at least one of the following features corresponding to a first sample code: a business characteristic feature, a system performance feature, a code structure feature, and a user behavior feature; and the first sample code includes a business code and a general code;

[0078] S302: Extract features from the first training sample to obtain target sample features.

[0079] S303: Using the target sample feature as a model input, using the optimization suggestion category to which the first training sample belongs as a label, and performing model training on a pre-built random forest model.

[0080] S304, obtaining a second training sample and an optimization suggestion category to which the second training sample belongs; wherein the second training sample includes at least one of the following features corresponding to the second sample code: business characteristic features, system performance features, code structure features, and user behavior features; the second sample code includes a business code and a general code.

[0081] S305: Extract features of the second training sample according to the random forest model to obtain key sample features.

[0082] S306: Using the key sample features as model input, using the optimization suggestion category to which the second training sample belongs as a label, and performing model training on the pre-built support vector machine model.

[0083] S307. Based on the random forest model, extract key code features in the code to be optimized.

[0084] S308. Based on the support vector machine model, key code features are classified to obtain target optimization suggestions for the code to be optimized.

[0085] S309: Based on the retrieval enhancement generation model and according to the target optimization suggestion, determine the code segment to be modified and the code adjustment strategy of the code segment to be modified corresponding to the code to be optimized.

[0086] S310: According to the code adjustment strategy of the code segment to be modified, the code segment to be modified is adjusted to obtain a target code.

[0087] The detailed technical contents of the above steps S301 - S310 have been recorded in the above embodiments and will not be repeated here.

[0088] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0089] Based on the same inventive concept, the embodiment of the present application also provides a code modification strategy determination device for implementing the code modification strategy determination method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the one or more code modification strategy determination device embodiments provided below can refer to the limitations of the code modification strategy determination method above, and will not be repeated here.

[0090] In an exemplary embodiment, Figure 4 As shown, a code modification strategy determination device is provided, including: a first processing module 410, a second processing module 420 and a third processing module 430, wherein:

[0091] The first processing module 410 is used to extract key code features in the code to be optimized based on the random forest model;

[0092] The second processing module 420 is used to classify key code features based on a support vector machine model to obtain target optimization suggestions for the code to be optimized;

[0093] The third processing module 430 is used to adjust the code to be optimized based on the retrieval enhancement generation model and the target optimization suggestion to obtain the target code.

[0094] In one embodiment, the code modification strategy determination device also includes: a first acquisition module, used to obtain a first training sample and an optimization suggestion category to which the first training sample belongs; wherein the first training sample includes at least one of the following features corresponding to the first sample code: business characteristic features, system performance features, code structure features, and user behavior features; the first sample code includes business code and general code; a first extraction module, used to perform feature extraction on the first training sample to obtain target sample features; a first training module, used to use the target sample features as model input and the optimization suggestion category to which the first training sample belongs as a label to perform model training on a pre-built random forest model.

[0095] In one embodiment, the code modification strategy determination device also includes: a second acquisition module, used to obtain a second training sample and an optimization suggestion category to which the second training sample belongs; wherein the second training sample includes at least one of the following features corresponding to the second sample code: business characteristic features, system performance features, code structure features, and user behavior features; the second sample code includes business code and general code; a second extraction module, used to extract features from the second training sample according to a random forest model to obtain key sample features; a second training module, used to use the key sample features as model input and the optimization suggestion category to which the second training sample belongs as a label to perform model training on a pre-built support vector machine model.

[0096] In one embodiment, the third processing module 430 includes: a first determination unit, which is used to determine the code segment to be modified and the code adjustment strategy of the code segment to be modified corresponding to the code to be optimized based on the retrieval enhancement generation model and according to the target optimization suggestion; a first adjustment unit, which is used to adjust the code segment to be modified according to the code adjustment strategy of the code segment to be modified to obtain the target code.

[0097] In one embodiment, the first determination unit includes: a first encoding subunit, which is used to feature encode the target optimization suggestion based on the encoding network in the retrieval enhancement generation model to obtain the suggestion vector feature of the target optimization suggestion; and, a second encoding subunit, which is used to feature encode the code to be optimized to obtain the code vector feature of the code to be optimized; the first retrieval subunit is used to search in the code vector feature based on the enhanced retrieval network in the retrieval enhancement generation model according to the suggestion vector feature to obtain the code segment to be modified in the code to be optimized and the code adjustment strategy of the code segment to be modified.

[0098] In one embodiment, the second encoding subunit is specifically used to divide the code to be optimized into at least one code block according to the code structure of the code to be optimized; perform feature encoding on each code block to obtain the code block feature of the corresponding code block; wherein the code vector feature of the code to be optimized includes the code block feature of at least one code block; the first retrieval subunit is specifically used to perform feature matching in the code block features of at least one code block according to the recommended vector feature, and determine the code segment to be modified in the code to be optimized according to the matching result.

[0099] Each module in the above-mentioned code modification strategy determination device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0100] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Figure 5 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a method for determining a code modification strategy is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.

[0101] Those skilled in the art will understand that Figure 5The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0102] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:

[0103] Based on the random forest model, key code features in the code to be optimized are extracted;

[0104] Based on the support vector machine model, key code features are classified to obtain target optimization suggestions for the code to be optimized;

[0105] Based on the retrieval enhanced generation model, the code to be optimized is adjusted according to the target optimization suggestions to obtain the target code.

[0106] In one embodiment, when the processor executes the computer program, the following steps are also implemented: obtaining a first training sample and an optimization suggestion category to which the first training sample belongs; wherein the first training sample includes at least one of the following features corresponding to the first sample code: business characteristic features, system performance features, code structure features, and user behavior features; the first sample code includes a business code and a general code; performing feature extraction on the first training sample to obtain target sample features; using the target sample features as model input, and using the optimization suggestion category to which the first training sample belongs as a label, and performing model training on a pre-built random forest model.

[0107] In one embodiment, when the processor executes the computer program, the following steps are also implemented: obtaining a second training sample and an optimization suggestion category to which the second training sample belongs; wherein the second training sample includes at least one of the following features corresponding to the second sample code: business characteristic features, system performance features, code structure features, and user behavior features; the second sample code includes a business code and a general code; performing feature extraction on the second training sample according to a random forest model to obtain key sample features; using the key sample features as model input and the optimization suggestion category to which the second training sample belongs as a label to perform model training on a pre-built support vector machine model.

[0108] In one embodiment, when the processor executes the computer program, the following steps are also implemented: based on the retrieval enhancement generation model, according to the target optimization suggestion, the code segment to be modified and the code adjustment strategy of the code segment to be modified corresponding to the code to be optimized are determined; according to the code adjustment strategy of the code segment to be modified, the code segment to be modified is adjusted to obtain the target code.

[0109] In one embodiment, based on the encoding network in the retrieval enhanced generation model, feature encoding is performed on the target optimization suggestion to obtain the suggestion vector feature of the target optimization suggestion; and feature encoding is performed on the code to be optimized to obtain the code vector feature of the code to be optimized; based on the enhanced retrieval network in the retrieval enhanced generation model, retrieval is performed in the code vector feature according to the suggestion vector feature to obtain the code segment to be modified in the code to be optimized and the code adjustment strategy for the code segment to be modified.

[0110] In one embodiment, the code to be optimized is divided into at least one code block according to the code structure of the code to be optimized; feature encoding is performed on each code block to obtain code block features of the corresponding code block; wherein the code vector features of the code to be optimized include code block features of at least one code block; feature matching is performed in the code block features of at least one code block according to the recommended vector features, and based on the matching results, the code segment to be modified in the code to be optimized is determined.

[0111] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0112] Based on the random forest model, key code features in the code to be optimized are extracted;

[0113] Based on the support vector machine model, key code features are classified to obtain target optimization suggestions for the code to be optimized;

[0114] Based on the retrieval enhanced generation model, the code to be optimized is adjusted according to the target optimization suggestions to obtain the target code.

[0115] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: obtaining a first training sample and an optimization suggestion category to which the first training sample belongs; wherein the first training sample includes at least one of the following features corresponding to the first sample code: business characteristic features, system performance features, code structure features, and user behavior features; the first sample code includes a business code and a general code; performing feature extraction on the first training sample to obtain target sample features; using the target sample features as model input, and using the optimization suggestion category to which the first training sample belongs as a label, and performing model training on a pre-built random forest model.

[0116] In one embodiment, a second training sample and an optimization suggestion category to which the second training sample belongs are obtained; wherein the second training sample includes at least one of the following features corresponding to the second sample code: business characteristic features, system performance features, code structure features, and user behavior features; the second sample code includes a business code and a general code; features of the second training sample are extracted according to a random forest model to obtain key sample features; the key sample features are used as model input, and the optimization suggestion category to which the second training sample belongs is used as a label to perform model training on a pre-built support vector machine model.

[0117] In one embodiment, based on the retrieval enhancement generation model and according to the target optimization suggestion, the code segment to be modified corresponding to the code to be optimized and the code adjustment strategy of the code segment to be modified are determined; according to the code adjustment strategy of the code segment to be modified, the code segment to be modified is adjusted to obtain the target code.

[0118] In one embodiment, based on the encoding network in the retrieval enhanced generation model, feature encoding is performed on the target optimization suggestion to obtain the suggestion vector feature of the target optimization suggestion; and feature encoding is performed on the code to be optimized to obtain the code vector feature of the code to be optimized; based on the enhanced retrieval network in the retrieval enhanced generation model, retrieval is performed in the code vector feature according to the suggestion vector feature to obtain the code segment to be modified in the code to be optimized and the code adjustment strategy for the code segment to be modified.

[0119] In one embodiment, the code to be optimized is divided into at least one code block according to the code structure of the code to be optimized; feature encoding is performed on each code block to obtain code block features of the corresponding code block; wherein the code vector features of the code to be optimized include code block features of at least one code block; feature matching is performed in the code block features of at least one code block according to the recommended vector features, and based on the matching results, the code segment to be modified in the code to be optimized is determined.

[0120] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:

[0121] Based on the random forest model, key code features in the code to be optimized are extracted;

[0122] Based on the support vector machine model, key code features are classified to obtain target optimization suggestions for the code to be optimized;

[0123] Based on the retrieval enhanced generation model, the code to be optimized is adjusted according to the target optimization suggestions to obtain the target code.

[0124] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: obtaining a first training sample and an optimization suggestion category to which the first training sample belongs; wherein the first training sample includes at least one of the following features corresponding to the first sample code: business characteristic features, system performance features, code structure features, and user behavior features; the first sample code includes a business code and a general code; performing feature extraction on the first training sample to obtain target sample features; using the target sample features as model input, and using the optimization suggestion category to which the first training sample belongs as a label, and performing model training on a pre-built random forest model.

[0125] In one embodiment, a second training sample and an optimization suggestion category to which the second training sample belongs are obtained; wherein the second training sample includes at least one of the following features corresponding to the second sample code: business characteristic features, system performance features, code structure features, and user behavior features; the second sample code includes a business code and a general code; features of the second training sample are extracted according to a random forest model to obtain key sample features; the key sample features are used as model input, and the optimization suggestion category to which the second training sample belongs is used as a label to perform model training on a pre-built support vector machine model.

[0126] In one embodiment, based on the retrieval enhancement generation model and according to the target optimization suggestion, the code segment to be modified corresponding to the code to be optimized and the code adjustment strategy of the code segment to be modified are determined; according to the code adjustment strategy of the code segment to be modified, the code segment to be modified is adjusted to obtain the target code.

[0127] In one embodiment, based on the encoding network in the retrieval enhanced generation model, feature encoding is performed on the target optimization suggestion to obtain the suggestion vector feature of the target optimization suggestion; and feature encoding is performed on the code to be optimized to obtain the code vector feature of the code to be optimized; based on the enhanced retrieval network in the retrieval enhanced generation model, retrieval is performed in the code vector feature according to the suggestion vector feature to obtain the code segment to be modified in the code to be optimized and the code adjustment strategy for the code segment to be modified.

[0128] In one embodiment, the code to be optimized is divided into at least one code block according to the code structure of the code to be optimized; feature encoding is performed on each code block to obtain code block features of the corresponding code block; wherein the code vector features of the code to be optimized include code block features of at least one code block; feature matching is performed in the code block features of at least one code block according to the recommended vector features, and based on the matching results, the code segment to be modified in the code to be optimized is determined.

[0129] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method 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 the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0130] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0131] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for determining a code modification strategy, characterized in that: include: Based on the random forest model, key code features in the code to be optimized are extracted; Based on the support vector machine model, the key code features are classified to obtain target optimization suggestions for the code to be optimized; Based on the retrieval enhancement generation model, the code to be optimized is adjusted according to the target optimization suggestion to obtain the target code.

2. The method according to claim 1, characterized in that: The random forest model is trained in the following way: Obtaining a first training sample and an optimization suggestion category to which the first training sample belongs; wherein the first training sample includes at least one of the following features corresponding to a first sample code: a business characteristic feature, a system performance feature, a code structure feature, and a user behavior feature; and the first sample code includes a business code and a general code; Extracting features from the first training sample to obtain target sample features; The target sample feature is used as a model input, and the optimization suggestion category to which the first training sample belongs is used as a label to perform model training on a pre-built random forest model.

3. The method according to claim 1, characterized in that The support vector machine model is trained in the following way: Obtaining a second training sample and an optimization suggestion category to which the second training sample belongs; wherein the second training sample includes at least one of the following features corresponding to the second sample code: a business characteristic feature, a system performance feature, a code structure feature, and a user behavior feature; and the second sample code includes a business code and a general code; Performing feature extraction on the second training sample according to the random forest model to obtain key sample features; The key sample features are used as model input, and the optimization suggestion category to which the second training sample belongs is used as a label to perform model training on a pre-built support vector machine model.

4. The method according to claim 1, characterized in that: The retrieval-enhanced generation model is used to adjust the code to be optimized according to the target optimization suggestion to obtain the target code, including: Based on the retrieval enhancement generation model, according to the target optimization suggestion, determine the code segment to be modified in the code to be optimized and the code adjustment strategy of the code segment to be modified; According to the code adjustment strategy of the code segment to be modified, the code segment to be modified is adjusted to obtain the target code.

5. The method according to claim 4, characterized in that The retrieval-enhanced generation model is based on the target optimization suggestion, and determines the code segment to be modified corresponding to the code to be optimized and the code adjustment strategy of the code segment to be modified, including: Based on the encoding network in the retrieval enhancement generation model, feature encoding is performed on the target optimization suggestion to obtain a suggestion vector feature of the target optimization suggestion; and Performing feature encoding on the code to be optimized to obtain code vector features of the code to be optimized; Based on the enhanced retrieval network in the retrieval enhancement generation model, a search is performed in the code vector features according to the suggestion vector features to obtain the code segment to be modified in the code to be optimized and the code adjustment strategy for the code segment to be modified.

6. The method according to claim 5, characterized in that The feature encoding of the code to be optimized to obtain the code vector feature of the code to be optimized includes: According to the code structure of the code to be optimized, dividing the code to be optimized into at least one code block; Perform feature encoding on each code block to obtain a code block feature of the corresponding code block; wherein the code vector feature of the code to be optimized includes the code block feature of the at least one code block; Correspondingly, searching in the code vector features according to the suggestion vector features to obtain the code segment to be modified in the code to be optimized includes: According to the suggestion vector feature, feature matching is performed in the code block features of the at least one code block, and according to the matching result, a code segment to be modified in the code to be optimized is determined.

7. A device for determining a code modification strategy, characterized in that: The device comprises: The first processing module is used to extract key code features in the code to be optimized based on the random forest model; The second processing module is used to classify the key code features based on a support vector machine model to obtain target optimization suggestions for the code to be optimized; The third processing module is used to adjust the code to be optimized based on the retrieval enhancement generation model and the target optimization suggestion to obtain the target code.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Computer hardware fault replacement part recommendation method

    CN114218402A

  • Method and device for automatically detecting malicious codes and computer readable storage medium

    CN116010945A

  • Automatic code merging and deploying method

    CN117609100A

  • Method and device for analyzing application performance, computer equipment and storage medium

    CN118227434A

  • Automatic unit test generation method and device based on retrieval enhancement technology

    CN118585440A

Cited By

  • Software reconstruction method, device and equipment based on artificial intelligence and storage medium

    CN120540697A

  • Artificial intelligence-based software refactoring method, device, equipment and storage medium

    CN120540697B