Software development system based on machine learning algorithm

Through a software development system based on machine learning algorithms, recurrent neural networks are used for hierarchical training, combined with probability weighting algorithms and reinforcement learning algorithms, the problem that traditional code automatic completion methods are difficult to predict complex logical structures and semantic relationships is solved, and a more efficient and accurate code automatic completion effect is achieved.

CN119576336AInactive Publication Date: 2025-03-07QUANZHOU RONGXIN TECHNOLOGY CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411613897.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-13
Publication Date
2025-03-07
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Traditional code automatic completion methods are difficult to accurately predict complex logical structures and semantic relationships, which leads to developers still spending a lot of time manually entering and adjusting code.

Method used

A software development system based on machine learning algorithm is adopted to build a source code database through the acquisition and processing unit, and analyzing the code syntax structure is used to analyze the code grammar, extract variable names, function names and keywords, and construct code element vector representations. The model training unit uses recurrent neural networks for hierarchical training to learn the logical relationships and semantic connections between code elements of basic, intermediate and complex logical structures. The interactive prediction unit converts code snippets into vector form through a vector transformation algorithm, inputs the model to predict, and uses probability weighting algorithms and reinforcement learning algorithms to optimize model parameters.

Benefits of technology

It improves the intelligence and efficiency of automatic code completion, can predict subsequent code snippets more accurately, reduces the developer's manual input and adjustment time, and improves the efficiency and quality of software development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576336A_ABST
    Figure CN119576336A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of machine learning and software development, in particular to a software development system based on a machine learning algorithm, which comprises an acquisition processing unit, a model training unit, an interaction prediction unit and an optimization feedback unit, and is characterized in that the acquisition processing unit constructs a database, extracts key elements such as variable names and converts the key elements into vectors; the model training unit adopts recurrent neural network hierarchical training and gradually introduces intermediate and complex structure codes and learns logic relation and semantic relation from code snippets related to a basic grammar structure, the interaction prediction unit screens and extracts the code snippets according to code function module labels and historical use frequency, the code snippets are input into a model after vector conversion, and the model is used for prediction. A probability weighting algorithm is used for predicting subsequent fragments, an optimization feedback unit calculates the similarity between predicted fragments and actual fragments, an optimization mechanism is automatically triggered if a threshold value is not reached, parameters are adjusted by utilizing reinforcement learning, and prediction accuracy is used as a key part of a reward function so as to improve the system performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of machine learning and software development, and in particular, to a software development system based on a machine learning algorithm. Background Art

[0002] Machine learning and software development are important technologies. In the software development process, code completion is an important tool to improve development efficiency. Traditional code completion methods are often based on simple rule matching or limited code templates and have many limitations. For example, for complex logical structures and semantic relationships, it is impossible to accurately predict subsequent code snippets, resulting in developers still having to spend a lot of time manually entering and adjusting code. As the scale and complexity of software development projects continue to increase, the demand for smarter and more efficient code completion systems is becoming increasingly urgent.

[0003] Machine learning algorithms have significant advantages in dealing with complex pattern recognition and prediction problems. By learning from large amounts of source code data, machine learning models can dig out the potential logical relationships and semantic connections between code elements. Traditional software development systems tend to mix code data at different grammatical structure levels for training, and often transfer basic code structures to advanced training modules, causing the model to spend a lot of time on code data training, increasing the model's computational burden. For complex structured code, since the complexity of its code fragments exceeds the learning capacity of the basic training module, the complex code fragments cannot be fully learned, thereby reducing the performance of the model. In order to solve this technical problem, we provide a software development system based on machine learning algorithms. Summary of the invention

[0004] The purpose of the present invention is to provide a software development system based on a machine learning algorithm to solve the problems raised in the above background technology.

[0005] To achieve the above purpose, a software development system based on machine learning algorithm is provided, including an acquisition processing unit, a model training unit, an interactive prediction unit and an optimization feedback unit;

[0006] The acquisition processing unit constructs a source code database, uses syntax analysis to parse the code syntax structure, extracts variable names, function names and keywords, and constructs a code element vector representation;

[0007] The model training unit uses a recurrent neural network to perform hierarchical training on the constructed vectors. For the extracted code element vectors, code snippets related to the basic grammatical structure are selected for training, and the preliminary logical relationship and semantic connection between the basic code elements are learned. A basic model is established, and intermediate grammatical structure code snippets are introduced for training. Combined with the intermediate grammatical structure code data, the model parameters are optimized, and finally the code of the complex logical structure is learned to obtain the semantic connection and logical relationship of different code elements.

[0008] The interaction prediction unit extracts code snippets from the source code database, converts them into vector form through a vector conversion algorithm, and then inputs them into the model. The model predicts subsequent code snippets based on logical relationships and semantic connections and uses a probability weighted algorithm.

[0009] The optimization feedback unit calculates a similarity index between the predicted code snippet and the subsequent actual code snippet in the source code database. When the similarity does not reach a preset threshold, the optimization mechanism is automatically triggered to adjust the model parameters using a reinforcement learning algorithm.

[0010] As a further improvement of the technical solution, the acquisition processing unit uses syntax analysis to parse the code syntax structure, extract variable names, function names and keywords, and construct a code element vector, as follows:

[0011] According to the grammatical rules of the preset programming language, a syntax tree is constructed using the recursive descent analysis method, and variable names, function names, and keywords are extracted by traversing the syntax tree nodes. The variable names are standardized, the full names and the classes to which they belong are extracted from the function names, and the keywords are classified and recorded by type.

[0012] The dimension of the vector is determined according to the number of variable names, function names, and keywords. Each dimension corresponds to an element feature. The keywords are encoded using one-hot encoding. For function names and variable names, they are converted into low-dimensional dense vectors using word embedding technology.

[0013] As a further improvement of the present technical solution, the model training unit includes a basic training module. When the basic training module selects code snippets related to the basic grammatical structure for training, it introduces a code snippet complexity evaluation algorithm, which is as follows:

[0014] The code snippet complexity evaluation algorithm classifies code snippets into basic levels by analyzing the number of code lines, the number of nested levels of control structures, and the number of variables used. At the same time, for the training data set of basic grammatical structure code snippets, data enhancement technology is used to generate variant data. The variant data includes operations such as randomly replacing variable names and adjusting statement order without changing logic.

[0015] As a further improvement of the present technical solution, the model training unit includes an intermediate training module, and the intermediate training module adopts an adaptive parameter adjustment strategy in the process of optimizing model parameters in combination with the intermediate grammatical structure code data, as follows:

[0016] The intermediate grammatical structure code fragment is input into the basic model, and the predicted output of the basic model is monitored in real time. The predicted output and the actual intermediate grammatical structure code data are compared by mean square error to obtain the loss function, and a window size is set. The window size represents the range of the number of consecutive training iterations considered when calculating the descent rate. The loss function values ​​of the first and last iterations are recorded in each window. The descent rate is calculated according to the difference ratio of the loss function values ​​of the first and last iterations, and a threshold is set. When the descent rate is less than the threshold, it is determined that the descent rate of the loss function slows down, and the parameter adjustment mechanism is automatically triggered. The parameter adjustment mechanism is specifically as follows:

[0017] First, the number of hidden layer nodes of the basic model is dynamically adjusted, that is, the hidden nodes are increased and decreased according to the complexity of the intermediate grammatical structure;

[0018] Secondly, the activation function selection mechanism of the base model is optimized to automatically switch between Sigmoid and ReLU activation functions according to the code data.

[0019] As a further improvement of the technical solution, the model training unit further includes an advanced training module, which establishes a multimodal learning model when the code of the complex logical structure is learned, as follows:

[0020] Graph neural networks are introduced to process the structural features of the code and convert the code into an abstract syntax tree graph structure. Graph neural networks obtain logical relationships by learning the relationship features between code elements and elements.

[0021] At the same time, a cross-modal fusion layer is designed to fuse the features learned by the recurrent neural network and the graph neural network to obtain different types of semantic connections in the logical structure.

[0022] As a further improvement of the technical solution, the method of obtaining the logical relationship and semantic connection is as follows:

[0023] During the learning process of the graph neural network, the node update formula is: Where N (v) is the set of neighbor nodes of node v, α vu is the attention coefficient, which indicates the degree of attention of node v to its neighbor node u;

[0024]

[0025] W is the weight matrix, a is the attention vector, represents vector concatenation, σ is the activation function, h u is the feature vector of neighbor node u, and LeakyReLU is the activation function;

[0026] The design of the cross-modal fusion layer is as follows:

[0027] Suppose the sequence feature vector learned by the recurrent neural network is x rnn , the graph structure feature vector learned by the graph neural network is x gnn , the cross-modal fusion layer uses the following method to perform feature fusion:

[0028]

[0029] where x ρ represents the feature vector after fusion through the cross-modal fusion layer, W r , W g , W f is the weight matrix, b r , b g , b f is the bias term, ε is the activation function, Represents vector concatenation.

[0030] As a further improvement of the technical solution, when the interaction prediction unit extracts code snippets from the source code database, it screens and extracts the code snippets according to the functional module labels of the codes and the historical usage frequencies of the code snippets, as follows:

[0031] Code snippets with clear functional module labels are extracted first, and are sorted from high to low according to historical usage frequency;

[0032] In the vector conversion algorithm, the extracted code snippets are first pre-classified and divided into different categories according to the grammatical structure type of the code, and different vector conversion rules are set for different categories.

[0033] As a further improvement of the technical solution, the interaction prediction unit uses a probability weighted algorithm to predict the subsequent code snippet, as follows:

[0034] First, calculate the frequency of each possible subsequent code element in the training data set as the basic probability value;

[0035] Then, a weighted adjustment is performed based on the semantic similarity between the current input code snippet and similar code snippets in the training data set. The semantic similarity is obtained by calculating the cosine similarity between code element vectors. The specific calculation method is as follows:

[0036] Let the basic probability value be P i, the semantic similarity is S i , the weighted probability value P ωi =P i ×(1+k×S i ), where k is the adjustment coefficient. Finally, several code snippets with the highest weighted probability values ​​are selected as the prediction result output.

[0037] As a further improvement of the technical solution, the optimization feedback unit adopts a method based on combining edit distance and semantic vector cosine similarity when calculating the similarity index between the predicted code snippet and the subsequent actual code snippet in the source code database, as follows:

[0038] The edit distance is calculated to measure the difference between code snippets at the character operation level. The smaller the edit distance, the higher the code structure similarity.

[0039] At the same time, the predicted code snippets and the actual code snippets are converted into semantic vectors, and the similarity at the semantic level is measured by calculating the cosine similarity between the semantic vectors.

[0040] Combining these two similarity indices, the final similarity index is obtained by weighted summation, and the formula is:

[0041] S = ω1 × E + ω2 × C;

[0042] Where S is the comprehensive similarity, E is the edit distance similarity, C is the semantic vector cosine similarity, ω1 and ω2 are weight coefficients, ω1+ω2=1.

[0043] As a further improvement of the technical solution, when the optimization feedback unit automatically triggers the optimization mechanism to adjust the model parameters using the reinforcement learning algorithm, the prediction accuracy of the model is used as the key part of the reward function, as follows:

[0044] Assume that the prediction accuracy is η, and the reward function R is defined as: when the similarity between the predicted code snippet and the actual code snippet reaches a preset threshold, R = η × r1 + r2; where r1 is the accuracy reward coefficient, and r2 is a basic reward value. When the similarity does not reach the preset threshold, R = η × r3, where r3 < r1 is a penalty reward coefficient. The model adjusts its own parameters through this reward mechanism to obtain the maximum cumulative reward, which is used to optimize the prediction effect of subsequent code snippets.

[0045] Compared with the prior art, the present invention has the following beneficial effects:

[0046] 1. The software development system based on machine learning algorithm adopts a hierarchical training code training method to avoid the problem that the model transfers basic code fragments containing basic code structures to advanced training modules, causing the model to spend a lot of time on code data training, thereby reducing the computational burden of the model. Through hierarchical training, the basic code structure, intermediate grammatical structure and complex logical structure are respectively transferred to the corresponding training modules, avoiding the problem that complex code fragments cannot be fully learned because the complexity of the code fragment exceeds the learning ability of the training module, thereby improving the performance of the model.

[0047] 2. In the process of optimizing model parameters in combination with intermediate grammatical structure code data, the intermediate training module adopts an adaptive parameter adjustment strategy, which can dynamically adjust the model parameters according to the actual situation of the intermediate grammatical structure code data, avoiding the problem of overfitting or underfitting of the model to the intermediate grammatical structure code data due to fixed parameter settings, thereby improving the performance of the model more comprehensively.

[0048] 3. When the advanced training module is in the learning stage of codes with complex logical structures, a graph neural network is introduced to process the code structure features and combined with a recurrent neural network, which improves the ability to understand codes with complex logical structures and enables the model to better learn the logical relationships and semantic connections between code elements, avoiding the limitations of relying solely on a single modality to learn code features and learning codes more comprehensively and accurately. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 It is an overall block diagram of the present invention.

[0050] The meaning of each number in the figure is:

[0051] 1. Acquisition and processing unit; 2. Interactive prediction unit; 21. Basic training module; 22. Intermediate training module; 23. Advanced training module; 3. Interactive prediction unit; 4. Optimization feedback unit. DETAILED DESCRIPTION

[0052] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0053] Example 1

[0054] The present invention provides a software development system based on machine learning algorithms, please refer to Figure 1As shown, it includes a collection and processing unit 1, a model training unit 2, an interactive prediction unit 3 and an optimization feedback unit 4;

[0055] Machine learning algorithms need structured data as input to effectively learn the patterns and rules of code. The source code itself is a complex text form. The acquisition and processing unit 1 builds a source code database, uses syntax analysis to parse the code syntax structure, extracts variable names, function names and keywords, and constructs a code element vector representation. It can present the key information of the code in a structured manner suitable for machine learning algorithm processing, thereby providing high-quality input data for the model training unit 2.

[0056] The acquisition processing unit 1 uses syntax analysis to parse the code syntax structure, extract variable names, function names and keywords, and construct a code element vector, as follows:

[0057] According to the grammatical rules of the preset programming language, the syntax tree is constructed using the recursive descent analysis method, which can accurately parse the grammatical structure of the code and provide a basis for extracting key elements;

[0058] Recursive descent analysis method formula:

[0059] Suppose the grammar rules are χ→aAb, A→c|d, where χ is the starting symbol, A is a non-terminal symbol, and a, b, c, d are terminal symbols. When parsing the code, start from the starting symbol χ and recursively parse the substructure according to the rules. For example, when the input string meets acb, first determine whether it meets the rules of χ, and then further determine whether A meets its rules, that is, A→c. The advantages of this method are that it is simple and intuitive, easy to implement and understand. It can accurately parse the grammatical structure of the code according to the grammatical rules, construct a syntax tree, and clearly display the grammatical hierarchy and logical relationship of the code.

[0060] The code is converted into an abstract syntax tree graph structure G = (V, E), where the node set V represents the code elements, and the edge set E represents the relationship between the elements. For the node feature vector h v The construction of the code elements can intuitively display the logical structure and hierarchical relationship of the code.

[0061] Let variable name encoding vector be n bl , the keyword encoding vector is t gj , the function name encoding vector is s hm , then the node initial feature vector h v =f(n bl , t gj ,s hm), where f is the fusion function. In the process of graph neural network learning, this structural information and feature vector construction method help improve the learning effect. The graph neural network obtains the logical relationship of the code by learning the relationship features between nodes and the feature representation of the nodes themselves.

[0062] By traversing the syntax tree nodes, variable names, function names, and keywords are extracted, and variable names are standardized to facilitate subsequent vector construction and model processing. The full name and class of the function name are extracted, and keywords are classified and recorded by type to facilitate subsequent vector construction and model processing. Different coding styles may result in different representations of variable names or function names with the same semantics. Standardization can eliminate such differences.

[0063] The dimension of the vector is determined according to the number of variable names, function names, and keywords, so that the vector can accurately represent the characteristics of the code. Each dimension corresponds to an element feature. The keywords are encoded using one-hot encoding to clearly represent their categories. For function names and variable names, they are converted into low-dimensional dense vectors through word embedding technology to capture the semantic similarity between elements.

[0064] The code has different levels of grammatical structure and semantic complexity. Model training unit 2 uses a recurrent neural network to perform hierarchical training on the constructed vectors. The model can learn on code data at different levels, so as to better generalize to various actual code scenarios. For the extracted code element vectors, code snippets related to the basic grammatical structure are selected for training, and the preliminary logical relationship and semantic connection between the basic code elements are learned. A basic model is established, and intermediate grammatical structure code snippets are introduced for training. Combined with the intermediate grammatical structure code data, the model parameters are optimized. Finally, the code with complex logical structure is learned to obtain the semantic connection and logical relationship of different code elements. This method can make the model more focused on learning the code logic and semantic relationship at a specific level, avoid interference from different hierarchical structures, and improve learning efficiency. Through hierarchical training, the model can learn the logical relationship and semantic connection of the code more deeply.

[0065] Although the code snippets related to the basic grammatical structure are relatively simple, they are still diverse. The introduction of the complexity evaluation algorithm can better screen out the code snippets that truly meet the basic training requirements and avoid overly complex code snippets interfering with the learning of the basic model. The model training unit 2 includes a basic training module 21. When the basic training module 21 selects the code snippets related to the basic grammatical structure for training, the code snippet complexity evaluation algorithm is introduced, as follows:

[0066] For a large number of given code snippets, record the total number of lines from the start line to the end line of each code snippet, then analyze the control structures in the code, such as if-else statements, for loops, while loops, and calculate their nesting levels. For example, if an if statement is nested inside a for loop, the nesting level of this code snippet in this regard is 2;

[0067] At the same time, count the number of variables used in the code snippet, identify the variable names through the lexical analysis tool, and count different variable names to determine the number of variables used;

[0068] According to the statistical results of the number of lines, the number of nested control structures and the number of variables used, corresponding thresholds are set to classify code snippets. For example, if the number of lines is less than 20, the number of nested control structures is no more than 1, and the number of variables used is no more than 5, the code snippet is classified as the basic level. By screening out suitable basic code snippets through the complexity evaluation algorithm, the basic model can be more focused on learning the real basic grammatical structure and logical relationship, thereby improving the accuracy and stability of the basic model.

[0069] In actual code datasets, the number of code snippets with basic grammatical structures may be limited. By generating variant data, the model can learn on more diverse basic data and improve the generalization ability of the model.

[0070] At the same time, for the training data set of the basic grammatical structure code snippet, data augmentation technology is used to generate variant data. The variant data includes operations such as randomly replacing variable names and adjusting the order of statements without changing the logic. The details are as follows:

[0071] For random replacement of variable names, set a variable name replacement rule, for example, randomly select a variable name from a predefined variable name set to replace the variable name in the original code snippet. This predefined set can include some common basic variable names, such as var1, var2;

[0072] In terms of adjusting the order of statements, we determine which statements can be adjusted in order without changing the logic according to the logical structure of the code. For example, for some consecutive assignment statements, their execution order does not affect the final result, so we can randomly adjust the order of these statements. The variant data generated by data augmentation technology increases the diversity of training data, enabling the model to learn more basic grammatical structures in different forms, so as to better generalize to actual code scenarios and improve the model's adaptability to different codes.

[0073] The model training unit 2 includes an intermediate training module 22. The intermediate training module 22 adopts an adaptive parameter adjustment strategy in the process of optimizing model parameters in combination with the intermediate grammatical structure code data. The adaptive parameter adjustment strategy can dynamically adjust the model parameters according to the actual situation of the intermediate grammatical structure, so as to better adapt to this complexity, as follows:

[0074] Input the intermediate grammatical structure code snippet into the basic model, and monitor the predicted output of the basic model in real time. Compare the predicted output with the actual intermediate grammatical structure code data by mean square error to obtain the loss function. Set every 10 iterations as a window. At the end of each window, calculate the loss function decrease rate. The decrease rate can be obtained by calculating the difference between the last value and the first value of the loss function value in the current window and dividing it by the first value. If the decrease rate is less than 0.01, the parameter adjustment mechanism is automatically triggered. The parameter adjustment mechanism is as follows:

[0075] Define the complexity index of the intermediate grammatical structure. For example, the number of different grammatical elements and the number of nested layers in the intermediate grammatical structure can be comprehensively considered, and the complexity index is compared with a preset threshold. If the complexity index is higher than a certain threshold, the number of hidden layer nodes is increased. The increased number can be determined in proportion to the difference between the complexity index and the threshold or 5 nodes are increased each time. If the complexity index is lower than the threshold, the number of hidden layer nodes is reduced, and the reduction method is similar to the increase method.

[0076] Secondly, analyze the characteristics of the intermediate grammatical structure code data to observe whether the data is concentrated in a certain interval and whether the data changes dramatically. If the data is concentrated in a narrow interval and the change is relatively gentle, select the Sigmoid activation function; if the data is widely distributed and changes dramatically, select the ReLU activation function. Reasonable adjustment of the number of hidden layer nodes and the activation function selection mechanism can make the model better fit the intermediate grammatical structure code data, thereby improving the accuracy and generalization ability of the model.

[0077] The model training unit 2 also includes an advanced training module 23. The advanced training module 23 establishes a multimodal learning model when learning the code of the complex logical structure, as follows:

[0078] The structural features of the code are crucial to understanding the logical relationship of the code. Traditional recurrent neural networks have limitations in processing code structural information. Graph neural networks can process graph structure data well. By converting the code into an abstract syntax tree graph structure and using graph neural network learning, the structural features and logical relationships of the code can be effectively captured.

[0079] A graph neural network is introduced to process the structural features of the code and convert the code into an abstract syntax tree graph structure. Each syntax element in the code is regarded as a node of the tree, and the syntax relationship between the elements is regarded as an edge. For example, if a function calls another function, then in the abstract syntax tree, there will be an edge connecting the node representing the calling function and the node representing the called function. The GAT-based graph neural network initializes the node feature vector of the abstract syntax tree. The node feature vector can be obtained by encoding the code elements, and the logical relationship is obtained by learning the relationship features between code elements and elements.

[0080] During the training process, the graph neural network updates the node feature vector according to its own algorithm rules. By calculating the attention coefficient between nodes and performing weighted summation on the feature vectors of neighboring nodes, the node’s own feature vector is updated. The specific formula is as follows:

[0081] During the learning process of the graph neural network, the node update formula is: Where N (v) is the set of neighbor nodes of node v, α vu is the attention coefficient, which indicates the degree of attention of node v to its neighbor node u;

[0082]

[0083] W is the weight matrix, a is the attention vector, represents vector concatenation, σ is the activation function, h u is the feature vector of the neighbor node u, and LeakyReLU is the activation function. By iterating this formula multiple times, the graph neural network can learn the relationship features between nodes and the higher-level feature representations of the nodes themselves, thereby obtaining the structural logical relationship of the code. By integrating the features of the recurrent neural network and the graph neural network, the sequence and structural logical relationship of the code can be further integrated, thereby better capturing the overall logical relationship of the code and improving the ability to understand the code.

[0084] Code has both execution order and structural features. Recurrent neural networks are good at processing sequence information, while graph neural networks are good at processing structural information. By designing a cross-modal fusion layer to fuse the features learned by the two networks, we can comprehensively utilize the two modal information of the code and obtain the semantic connection and logical relationship of the code more comprehensively.

[0085] The design of the cross-modal fusion layer is as follows:

[0086] First, determine the feature vectors learned by the recurrent neural network and the graph neural network. Let the sequence feature vector learned by the recurrent neural network be x rnn , the graph structure feature vector learned by the graph neural network is xgnn , the cross-modal fusion layer sets the weight matrix and bias term, linearly combines the two feature vectors and adds the bias term to perform feature fusion:

[0087]

[0088] where x ρ represents the feature vector after fusion through the cross-modal fusion layer, W r , W g , W f is the weight matrix, b r , b g , b f is the bias term, ε is the activation function, Representation vector concatenation organically combines the features learned from two different modalities through such a fusion method. It can comprehensively utilize the sequence information and structural information of the code to obtain different types of semantic connections in the logical structure, and provide more comprehensive and accurate feature representation for subsequent code analysis, completion and other tasks.

[0089] The interaction prediction unit 3 extracts code snippets from the source code database, converts them into vector form through a vector conversion algorithm, and then inputs them into the model. The model predicts subsequent code snippets based on logical relationships and semantic connections and uses a probability weighted algorithm.

[0090] Filtering and extracting code snippets based on function module labels and historical usage frequencies can make the extracted code snippets more in line with the needs of the current development task. Function module labels can ensure that the extracted code snippets are related to the function modules currently being developed. Code snippets with high historical usage frequencies are often used frequently in actual development and are more likely to meet the current development scenario, thereby improving the relevance of the interaction prediction unit for subsequent code snippet predictions.

[0091] When the interaction prediction unit 3 extracts code snippets from the source code database, it screens and extracts them according to the functional module labels of the codes and the historical usage frequencies of the code snippets, as follows:

[0092] First, the code in the source code database is labeled with functional modules. For example, for a software development project, the code can be divided into user login module, data processing module, interface display module, etc. according to function, and corresponding labels are added to the code snippets of each module.

[0093] By analyzing the code submission records in the project's version control system to obtain the number of times each code snippet is used, its historical usage frequency can be determined. Code snippets with clear functional module labels and high historical usage frequency can be extracted first, which can reduce unnecessary code snippet processing and improve system operation efficiency.

[0094] When extracting code snippets, give priority to code snippets with clear functional module labels. For code snippets with the same functional module labels, sort them from high to low according to their historical usage frequency and then select them in turn.

[0095] In the vector conversion algorithm, the extracted code snippets are analyzed for grammatical structures, such as conditional judgment structures, loop structures, and function call structures, and the code snippets are divided into different categories according to these types. Different vector conversion rules are set for different categories, which can make the vector conversion process more efficient and further improve system efficiency.

[0096] For example, for code snippets with conditional judgment structures, we focus on extracting the conditional expression part and converting it into a specific vector representation. We can encode the variable names, operators, etc. in the conditional expression and then combine them into a vector. For code snippets with loop structures, we can extract key information such as loop variables, loop conditions, loop bodies, etc., and convert them into vectors using corresponding encoding methods. After the above processing, the model can more accurately predict subsequent code snippets, and the prediction results are more in line with the needs of the current development tasks, reducing the number of incorrect predictions and improving the quality of automatic code completion.

[0097] The interaction prediction unit 3 uses a probability weighted algorithm to predict the subsequent code snippets, as follows:

[0098] First, calculate the frequency of each possible subsequent code element in the training data set as the basic probability value;

[0099] The basic probability value reflects the frequency of occurrence of each possible subsequent code element in the historical training data, which is a kind of information based on statistical laws. However, considering the frequency alone is not enough, and it is also necessary to combine the semantic similarity between the current input code snippet and similar code snippets in the historical data. Because the writing of code depends not only on the frequency of occurrence of elements, but also on the context semantics, by combining these two kinds of information, the subsequent code snippets can be predicted more comprehensively.

[0100] Then, a weighted adjustment is performed based on the semantic similarity between the current input code snippet and the similar code snippet in the training data set. Cosine similarity is a method for measuring the angle between two vectors in vector space. It can well reflect the semantic similarity of the code elements represented by the two vectors, thereby providing a reasonable basis for weighted adjustment. The semantic similarity is obtained by calculating the cosine similarity between the code element vectors. The specific calculation method is as follows:

[0101] Let the basic probability value be P i , the semantic similarity is S i , the weighted probability value Pωi =P i ×(1+k×S i ); k is the adjustment coefficient. Finally, several code snippets with the highest weighted probability values ​​are selected as the prediction results for output display. Since semantic similarity is taken into account, this method can better adapt to different code writing scenarios and context environments. No matter how the specific content of the code changes, as long as the semantics are related, the prediction results can be adjusted by calculating semantic similarity, thereby improving the adaptability of the prediction algorithm to different scenarios.

[0102] In order to measure the closeness between the predicted code snippet and the actual code snippet, the optimization feedback unit 4 calculates the similarity index between the predicted code snippet and the subsequent actual code snippet in the source code database, so as to evaluate the accuracy of the prediction. If the similarity does not reach the preset threshold, it means that the prediction result may have a large deviation and needs to be adjusted to improve the prediction quality. When the similarity does not reach the preset threshold, in order to enable the model to learn and improve adaptively, the optimization mechanism is automatically triggered, and the model parameters are adjusted using the reinforcement learning algorithm. As the code data continues to increase and change, the model needs to continuously adjust its own parameters to adapt to new situations and improve the prediction ability for different code scenarios.

[0103] In order to guide the model to optimize in the direction of improving prediction accuracy, the optimization feedback unit 4 automatically triggers the optimization mechanism to adjust the model parameters using the reinforcement learning algorithm. The prediction accuracy of the model is used as the key part of the reward function. The model adjusts its own parameters to improve the prediction accuracy by pursuing the maximization of the cumulative reward, because accurate predictions will bring higher rewards, as follows:

[0104] Assume that the prediction accuracy is η, and the reward function R is defined as: when the similarity between the predicted code snippet and the actual code snippet reaches the preset threshold, R = η × r1 + r2; where r1 is the accuracy reward coefficient. In order to obtain higher rewards, the model will actively explore different parameter settings, so as to learn the correct prediction mode faster and improve learning efficiency. r2 is a basic reward value. When the similarity does not reach the preset threshold, R = η × r3, where r3 < r1 is a penalty reward coefficient. The model adjusts its own parameters through this reward mechanism to obtain the maximum cumulative reward. By dynamically adjusting the reward coefficient, the model can dynamically optimize according to its own learning progress and actual situation. This dynamic optimization mechanism can make the model better adapt to various code scenarios, improve the accuracy and reliability of prediction, and maximize the cumulative reward to optimize the prediction effect of subsequent code snippets. In the process of reinforcement learning, the similarity index is recalculated every fixed number of training steps and the reward coefficient is adjusted according to the result to dynamically adapt to the optimization process of the model. The prediction accuracy of subsequent code snippets will be significantly improved, which is more in line with the logic and semantics of the actual code snippets, reduces the situation of wrong prediction, and improves the quality of code automatic completion.

[0105] In the present invention, the acquisition processing unit builds a database, extracts key elements such as variable names and converts them into vectors, the model training unit adopts recurrent neural network hierarchical training, starts from the basic grammatical structure related code fragments, gradually introduces intermediate and complex structure codes, and learns logical relationships and semantic connections, the interactive prediction unit screens and extracts code fragments according to the code function module labels and historical usage frequencies, inputs the code fragments after vector conversion, and uses the probability weighted algorithm to predict subsequent fragments, the optimization feedback unit calculates the similarity between the prediction and the actual fragment, and automatically triggers the optimization mechanism if the threshold is not reached, and uses reinforcement learning to adjust the parameters, and uses the prediction accuracy as the key part of the reward function to improve the system performance.

[0106] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited by the above embodiments, and the above embodiments and descriptions are only preferred examples of the present invention, and are not intended to limit the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, and these changes and improvements all fall within the scope of the present invention to be protected.

Claims

1. A software development system based on machine learning algorithms, characterized in that: It includes a collection and processing unit (1), a model training unit (2), an interactive prediction unit (3) and an optimization feedback unit (4); The acquisition processing unit (1) constructs a source code database, uses syntax analysis to parse the code syntax structure, extracts variable names, function names and keywords, and constructs a code element vector representation; The model training unit (2) uses a recurrent neural network to perform hierarchical training on the constructed vectors. For the extracted code element vectors, code snippets related to the basic grammatical structure are selected for training, and the preliminary logical relationship and semantic connection between the basic code elements are learned. A basic model is established, and intermediate grammatical structure code snippets are introduced for training. The model parameters are optimized in combination with the intermediate grammatical structure code data, and finally the code of the complex logical structure is learned to obtain the final semantic connection and logical relationship of different code elements. The interaction prediction unit (3) extracts code snippets from the source code database, converts them into vector form through a vector conversion algorithm, and then inputs them into the model. The model predicts subsequent code snippets based on logical relationships and semantic connections and uses a probability weighted algorithm. The optimization feedback unit (4) calculates a similarity index between the predicted code snippet and the subsequent actual code snippet in the source code database, and when the similarity does not reach a preset threshold, automatically triggers an optimization mechanism to adjust the model parameters using a reinforcement learning algorithm.

2. The software development system based on machine learning algorithm according to claim 1, characterized in that: The acquisition processing unit (1) uses syntax analysis to parse the code syntax structure, extract variable names, function names and keywords, and construct a code element vector, specifically as follows: According to the grammatical rules of the preset programming language, a syntax tree is constructed using the recursive descent analysis method, and variable names, function names, and keywords are extracted by traversing the syntax tree nodes. The variable names are standardized, the full names and the classes to which they belong are extracted from the function names, and the keywords are classified and recorded by type. The dimension of the vector is determined according to the number of variable names, function names, and keywords. Each dimension corresponds to an element feature. The keywords are encoded using one-hot encoding. For function names and variable names, they are converted into low-dimensional dense vectors using word embedding technology.

3. The software development system based on machine learning algorithm according to claim 1, characterized in that: The model training unit (2) comprises a basic training module (21). When the basic training module (21) selects code snippets related to the basic grammatical structure for training, it introduces a code snippet complexity evaluation algorithm, which is specifically as follows: The code snippet complexity evaluation algorithm classifies code snippets into basic grammatical structures, intermediate grammatical structures, and complex logical structures by analyzing the number of code lines, the number of nested levels of control structures, and the number of variables used. At the same time, for the training data set of basic grammatical structure code snippets, data enhancement technology is used to generate variant data, and the variant data includes operations such as randomly replacing variable names and adjusting statement order without changing logic.

4. The software development system based on machine learning algorithm according to claim 1, characterized in that: The model training unit (2) comprises an intermediate training module (22). The intermediate training module (22) adopts an adaptive parameter adjustment strategy in the process of optimizing model parameters in combination with the intermediate grammatical structure code data, which is specifically as follows: The intermediate grammatical structure code fragment is input into the basic model, and the predicted output of the basic model is monitored in real time. The predicted output and the actual intermediate grammatical structure code data are compared by mean square error to obtain the loss function, and a window size is set. The window size represents the range of the number of consecutive training iterations considered when calculating the descent rate. The loss function values ​​of the first and last iterations are recorded in each window. The descent rate is calculated according to the difference ratio of the loss function values ​​of the first and last iterations, and a threshold is set. When the descent rate is less than the threshold, it is determined that the descent rate of the loss function slows down, and the parameter adjustment mechanism is automatically triggered. The parameter adjustment mechanism is specifically as follows: First, the number of hidden layer nodes of the basic model is dynamically adjusted, that is, the hidden nodes are increased and decreased according to the complexity of the intermediate grammatical structure; Secondly, the activation function selection mechanism of the base model is optimized to automatically switch between Sigmoid and ReLU activation functions according to the code data.

5. The software development system based on machine learning algorithm according to claim 3, characterized in that: The model training unit (2) further comprises an advanced training module (23), wherein the advanced training module (23) establishes a multimodal learning model when the code of the complex logical structure is learned, specifically as follows: Graph neural networks are introduced to process the structural features of the code and convert the code into an abstract syntax tree graph structure. Graph neural networks obtain logical relationships by learning the relationship features between code elements and elements. At the same time, a cross-modal fusion layer is designed to fuse the features learned by the recurrent neural network and the graph neural network to obtain different types of semantic connections in the logical structure.

6. The software development system based on machine learning algorithm according to claim 5, characterized in that: The method of obtaining the logical relationship and semantic connection is as follows: During the learning process of the graph neural network, the node update formula is: Where N (v) is the set of neighbor nodes of node v, α vu is the attention coefficient, which indicates the degree of attention of node v to its neighbor node u; W is the weight matrix, a is the attention vector, represents vector concatenation, σ is the activation function, h u is the feature vector of neighbor node u, and LeakyReLU is the activation function; The design of the cross-modal fusion layer is as follows: Suppose the sequence feature vector learned by the recurrent neural network is x rnn , the graph structure feature vector learned by the graph neural network is x gnn , the cross-modal fusion layer uses the following method to perform feature fusion: where x ρ represents the feature vector after fusion through the cross-modal fusion layer, W r , W g , W f is the weight matrix, b r 、b g 、b f is the bias term, ε is the activation function, Represents vector concatenation.

7. The software development system based on machine learning algorithm according to claim 1, characterized in that: When the interaction prediction unit (3) extracts code snippets from the source code database, it screens and extracts the code snippets according to the functional module labels of the codes and the historical usage frequencies of the code snippets, as follows: Code snippets with clear functional module labels are extracted first, and are sorted from high to low according to historical usage frequency; In the vector conversion algorithm, the extracted code snippets are first pre-classified and divided into different categories according to the grammatical structure type of the code, and different vector conversion rules are set for different categories.

8. The software development system based on machine learning algorithm according to claim 1, characterized in that: The interaction prediction unit (3) predicts the subsequent code snippet using a probability weighted algorithm, as follows: First, calculate the frequency of each possible subsequent code element in the training data set as the basic probability value; Then, a weighted adjustment is performed based on the semantic similarity between the current input code snippet and similar code snippets in the training data set. The semantic similarity is obtained by calculating the cosine similarity between code element vectors. The specific calculation method is as follows: Let the basic probability value be P i , the semantic similarity is S i , the weighted probability value P ωi =P i ×(1+k×S i ), where k is the adjustment coefficient. Finally, several code snippets with the highest weighted probability values ​​are selected as the prediction result output.

9. The software development system based on machine learning algorithm according to claim 1, characterized in that: The optimization feedback unit (4) uses a method based on combining edit distance and semantic vector cosine similarity when calculating the similarity index between the predicted code snippet and the subsequent actual code snippet in the source code database, specifically as follows: The edit distance is calculated to measure the difference between code snippets at the character operation level. The smaller the edit distance, the higher the code structure similarity. At the same time, the predicted code snippets and the actual code snippets are converted into semantic vectors, and the similarity at the semantic level is measured by calculating the cosine similarity between the semantic vectors. Combining these two similarity indices, the final similarity index is obtained by weighted summation, and the formula is: S = ω1 × E + ω2 × C; Where S is the comprehensive similarity, E is the edit distance similarity, C is the semantic vector cosine similarity, ω1 and ω2 are weight coefficients, ω1+ω2=1.

10. The software development system based on machine learning algorithm according to claim 1, characterized in that: When the optimization feedback unit (4) automatically triggers the optimization mechanism to adjust the model parameters using the reinforcement learning algorithm, the prediction accuracy of the model is used as the key part of the reward function, as follows: Assume that the prediction accuracy is η, and the reward function R is defined as: when the similarity between the predicted code snippet and the actual code snippet reaches a preset threshold, R = η × r1 + r2; where r1 is the accuracy reward coefficient, and r2 is a basic reward value. When the similarity does not reach the preset threshold, R = η × r3, where r3 < r1 is a penalty reward coefficient. The model adjusts its own parameters through this reward mechanism to obtain the maximum cumulative reward, which is used to optimize the prediction effect of subsequent code snippets.

Citation Information

Cited By

  • Reinforcement learning model training method and device based on dynamic evaluation indexes

    CN120875086A

  • Intelligent agent management method and system for low-code design

    CN121029228A