Code warehouse commit query language automatic generation method based on auxiliary task enhancement
By using abstract syntax tree AST and auxiliary task enhancement model in the code repository, the automatic generation of natural language to commit query language is achieved, which solves the inefficiency problem caused by syntax complexity during query, and significantly improves the query results. Match degree and generation accuracy.
Patent Information
- Application Number
- CN202410702254.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-02
- Publication Date
- 2024-08-20
AI Technical Summary
When programmers use code repositories, it is difficult to obtain high matching results when searching for commits required for queries, which is limited by the complex commit query language syntax, resulting in wasting time and energy.
The abstract syntax tree AST is used as the intermediate representation, and the auxiliary task enhancement model is used to realize the automatic generation of natural language to commit query language, and the transformation system is used for syntax guidance and data set construction, combining with the neural encoder-decoder network that enhances loop connections. Optimize the model to improve generation accuracy.
It saves programmers time to learn and use commit query language syntax, improves the search, management and use efficiency of code repository, and significantly improves the accuracy and accuracy of automatic generation of commit query language.
Smart Images

Figure CN118519639A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, especially the field of natural language processing (NLP). The present invention proposes a method for automatically generating a code repository commit query language based on auxiliary task enhancement, which uses a conversion system to complete the conversion of natural language input to an abstract syntax tree AST, and completes the conversion of the abstract syntax tree AST to the commit query language according to the syntax of the commit query language, thereby realizing the automatic generation of the commit query language. Background Art
[0002] With the rapid development of the Internet and the continuous improvement of network technology in today's society, the market demand for programming is also growing. When programmers develop a software, they usually apply more existing code modules, make some changes and combinations to complete the code project that meets the requirements. Therefore, code warehouses are born out of this situation. Programmers can use code warehouses to better call existing code segments in the warehouse, greatly improving their own programming efficiency and code utilization. In addition, code warehouses can well manage the codes submitted by programmers and store them effectively, which has a great degree of progressive significance for the development of code programming and software engineering.
[0003] When programmers use code repositories for programming development, a common problem is that when searching for the commits they need, they enter a query that matches the commit records they expect to obtain. The results returned by the code repository to the programmer may be different from their expected goals, and there may be some irrelevant and useless information, making it difficult to obtain the desired commit records. In order to obtain commit records with a high degree of matching, programmers need to enter the matching commit query language according to the syntax of the commit query language. However, the syntax of the commit query language is relatively complex, and corresponding learning is required to better apply the query language in this special field, which greatly affects the efficiency of programmers' application of the code repository and causes unnecessary waste of time and energy. Therefore, it is very important to propose a method to realize the generation from natural language to commit query language for the current development of code repositories.
[0004] An effective solution to this problem is to use the abstract syntax tree AST as the intermediate representation of natural language and commit query language, based on the transition conversion system, add auxiliary tasks for reinforcement learning, so that the model can make better predictions, and realize the conversion and generation from natural language to abstract syntax tree AST under the guidance of the abstract syntax description language ASDL constructed for the commit query language. Under the guidance of the commit query language grammar, realize the conversion and generation from abstract syntax tree AST to commit query language, thereby completing the automatic generation of commit query language. When programmers perform search queries, they can enter the corresponding natural language, so that they can directly obtain commit results that are more matched with the expected goals, saving the time and energy of learning the commit query language grammar and detailed usage methods, and improving the search, management and use efficiency of code repositories.
[0005] The present invention mainly uses the abstract syntax tree AST as the intermediate representation and optimizes the model through auxiliary tasks to complete the conversion and generation of the natural language to the domain-specific language commit query language. For the query function in the code repository, it saves programmers' time and energy in learning the syntax and usage of the commit query language, effectively helps programmers complete search query operations and better complete development tasks. Summary of the invention
[0006] The main work of the present invention is to propose a method for automatically generating a code repository commit query language based on auxiliary task enhancement. First, the present invention mainly studies and analyzes how to use an abstract syntax tree as an intermediate representation to realize the transformation from natural language to a domain-specific language commit query language, and realizes the automatic generation of a commit query language. Secondly, the present invention needs to construct a corresponding abstract syntax description language ASDL for the grammatical structure of the commit query language, which is used for grammatical guidance in the subsequent conversion system. Then, according to the grammar of the commit query language, the required corresponding data set is constructed, and the questions in the form of natural language and the answers to the commit query language are used as a pair of data content in the data text format of the text pair, and a data set containing two thousand pieces of data is constructed for the training of the conversion system and model. Next, the transition conversion system in the present invention is under the guidance of the abstract syntax description language ASDL, and different tokens in the natural language become a node in the abstract syntax tree after passing through the tree constructor, so as to achieve the purpose of converting the input natural language into the corresponding abstract syntax tree AST. Then, in order to further optimize the model and improve the accuracy of model training and generation, two auxiliary tasks are added to help the model better recognize and learn external knowledge. The two auxiliary tasks are: the token type labeling task of natural language query statements and the identification task of the target statement node type by the constructor. Then, based on the conversion system and auxiliary tasks, a neural encoder-decoder network with enhanced recurrent connections is used to parameterize the parser. The parser is used to calculate the probability that different tokens should use different constructors, and the constructor with the highest probability is selected to construct the abstract syntax tree, so that the abstract syntax tree is as standard as possible and conforms to the grammatical rules. Both the encoder and decoder are implemented using LSTM networks. Finally, after the generation of the abstract syntax tree AST is completed, the target statement generation module in the conversion system is applied, and the corresponding statement generation function is constructed based on the specific syntax of the commit query language. Through these functions, the generated abstract syntax tree AST is converted into the target commit query statement to complete the automatic generation of the commit query language. In response to the above problems, the work and contributions of the present invention are as follows: 1. Based on the commit query language syntax file CommitQuery.g4 in the source code of the code repository, construct the corresponding abstract syntax description language ASDL for it, which is used as the syntax guide in the subsequent conversion system. Under the guidance of the abstract syntax description language ASDL, the input natural language is converted into the corresponding abstract syntax tree AST through a series of tree constructors. After the abstract syntax tree AST is generated, another part of the transition conversion system is applied to construct the corresponding syntax conversion function according to the syntax of the commit query language, and convert the abstract syntax tree AST into the commit query language according to the conversion function to complete the automatic generation of the commit query language.
[0007] 2. When programmers use the code repository for programming development, they search for the commits they need. If they want to obtain commit records with a high degree of matching, they need to input the matching commit query language based on the syntax of the commit query language. However, the syntax of the commit query language is relatively complex, and corresponding learning is required to better apply the query language in this special field, which has a great impact on the application efficiency of the code repository for programmers, resulting in unnecessary waste of time and energy. The present invention can realize the automatic generation of the commit query language, saving programmers the time and energy of learning the commit query language syntax and detailed usage methods when using the code repository query function, thereby improving the search, management and use efficiency of the code repository.
[0008] 3. By adding auxiliary tasks, the token type labeling task of natural language query statements and the recognition task of the target statement node type by the constructor, the model is further optimized, the model training performance and generation accuracy are improved. The addition of two auxiliary tasks helps the model to better recognize and learn external knowledge, and the accuracy and precision of the automatic generation of commit query statements are significantly improved.
[0009] 4. The present invention mainly uses the abstract syntax tree AST as the intermediate representation and auxiliary tasks to perform model optimization, completes the conversion and generation of natural language to the domain-specific language commit query language, and aims at the query function in the code repository. It saves programmers' time and energy in learning the syntax and usage of the commit query language, effectively helps programmers complete search query operations and better complete development tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION
[0011] The present invention specifically comprises the following steps: 1) First, we need to build a corresponding abstract syntax description language ASDL based on the syntax of the domain-specific language commit query language, which will be used as a syntax guide for converting natural language into abstract syntax tree AST in the subsequent conversion system.
[0012] 2) According to the syntax of the commit query language, construct the required corresponding data set in the data text format of text pairs, take the natural language question and the answer of the commit query language as a pair of data content, and construct a data set containing 2,000 data for the training of the conversion system and model.
[0013] 3) Guided by the abstract syntax description language ASDL that matches the commit query language, a transition conversion system suitable for the commit query language is constructed. Different tokens in the natural language become nodes in the abstract syntax tree after passing through the tree constructor, so as to achieve the purpose of converting the input natural language into the corresponding abstract syntax tree AST.
[0014] 4) In order to further optimize the model and improve the model training performance and generation accuracy, two auxiliary tasks are added to help the model better recognize and learn external knowledge. The two auxiliary tasks are: the token type labeling task of natural language query sentences and the constructor’s recognition task of the target sentence node type.
[0015] 5) Based on the conversion system and auxiliary tasks, a neural encoder-decoder network with enhanced recurrent connections is used to parameterize the parser. The parser is used to calculate the probability that different tokens should adopt different constructors, and the constructor with the highest probability is selected to construct the abstract syntax tree, so that the abstract syntax tree is as standard as possible and conforms to the grammatical rules. The encoder and decoder are both implemented using LSTM networks.
[0016] 6) After the abstract syntax tree AST is generated, the target statement generation module in the application conversion system is used to build the corresponding statement generation function based on the specific syntax of the commit query language. Through these functions, the generated abstract syntax tree AST is converted into the target commit query statement to complete the automatic generation of the commit query language.
[0017] 7) Train the model using the data set constructed in step 2), compare the answers output by the model with the commit query language answers in the data set, and obtain the corresponding commit query language performance evaluation results.
[0018] In step 1), it is necessary to build a matching abstract syntax description language ASDL based on the description of the syntax in the commit query language syntax definition file CommitQuery.g4 in the source code of the code repository. There are two basic components in ASDL: types and constructors. A composite type can be defined by a set of constructors under the type. The constructor uses its fields to specify a language construct of a specific type. The Conditions constructor under the composite type cond_expr represents a query statement expression and has two fields: op and value. An AST consists of multiple constructors, and each node on the tree corresponds to a typed field in the constructors (except the root node, which represents the root constructor). Depending on the cardinality of the field, a node can save one or more constructors as its value.
[0019] In step 2), we need to use text pairs as the data storage format, natural language as the question, and commit query language as the answer to construct the data set required for training. For example, search for my commits since last week (question), after (last week) committed-by-me (commit query). A total of nearly 2,000 pieces of data are generated for training the conversion system and model.
[0020] In step 3), the abstract syntax description language ASDL matching the commit query language should be used as a guide, and the transition conversion system suitable for the commit query language should be applied. Through a series of tree construction operations, starting from an initial derivation with a single root node, the corresponding abstract syntax tree AST is traversed from top to bottom and from left to right. Each time step may trigger a new extended derivation to continuously improve the current AST. The derivation actions are divided into three: APPLYCONSTR[c], REDUCE and GENTOKEN[v]. When no new frontier field is derived from the derivation, it means that the input natural language has been converted into the corresponding abstract syntax tree AST and saved.
[0021] Step 4) In order to further optimize the model and improve the model training performance and generation accuracy, two auxiliary tasks are added to help the model better recognize and learn external knowledge. The two auxiliary tasks are: 1. The token type labeling task of natural language query statements. During the data preprocessing process, we process the natural language query statement data by defining a new token object, which contains the value of the token and its specific type. Common examples of such fields include name, date, and path. The name field is mainly used to query the submitter or author, the date field is used to query submissions that meet specific time conditions, and the path field is used to query submissions within a specific path. In order to identify the token corresponding to the key field in the natural language query statement, we match the token with the key field and mark the token that appears in the key field set as the corresponding query condition field type. We mark the remaining ordinary tokens as "NONE". After processing the dataset, we add the new token object to the model training in order to improve the model performance and prediction accuracy. 2. The constructor identifies the target statement node type. In the submitted query statement, the specific node format of these query conditions is relatively fixed. For example, the first letter of the name is capitalized, the format of the time node is "xx xx xx", and the path node starts with " / ". Therefore, it becomes relatively easy to identify these nodes within the conversion system using string matching techniques. Once the identification is completed in the conversion system, we optimize the corresponding Abstract Syntax Description Language (ASDL) by refining the constructor of the var type into a specific constructor for each unique type. This enhancement enables the model to generate an abstract syntax tree more accurately based on the submitted query statement during training.
[0022] In step 5), based on the conversion system and auxiliary tasks, a neural encoder-decoder network with enhanced recurrent connections is used to parameterize the parser. The parser is used to calculate the probability that different tokens should adopt different constructors, and the constructor with the highest probability is selected to construct the abstract syntax tree, so that the abstract syntax tree is as standard as possible and conforms to the grammatical rules. The encoder and decoder are both implemented using LSTM networks. The encoder encodes the input utterance x, x[1..n] of n tokens into a vector representation h[1..n].
[0023] Step 6) First, obtain the generated abstract syntax tree AST, apply the transition conversion system applicable to the commit query language, and according to the conversion function applicable to the commit query language syntax defined in the conversion system, where the basic syntax of the commit query language is ' '* criteria (' '+ criteria)* ' '* EOF, criteria is the query condition, and its actual field values include after, before, committer, author, path, message, etc., convert the abstract syntax tree AST into the commit query language to complete the automatic generation of the commit query language.
[0024] Step 7) Train the model with the dataset constructed in step 2), compare the answers output by the model with the commit query language answers in the dataset, and obtain the corresponding commit query language performance evaluation results based on acc-1, acc-5, recall rate, execution accuracy, etc. When auxiliary tasks are added, the accuracy of the commit query statement automatic generation task reaches 92.3%.
Claims
1. A method for automatically generating a code repository commit query language based on auxiliary task enhancement, characterized by: The study analyzes how to apply the abstract syntax tree as an intermediate representation, adds auxiliary tasks based on the grammatical characteristics of the commit query language, realizes the transformation from natural language to the domain-specific language commit query language through model training, and realizes the automatic generation of the commit query language. First, it is necessary to construct the corresponding abstract syntax description language ASDL for the grammatical structure of the commit query language for the subsequent conversion system. Then, according to the grammar of the commit query language, the required corresponding data set is constructed, and the questions in the form of natural language and the answers to the commit query language are used as a pair of data content in the data text format of the text pair, and a data set containing two thousand data is constructed for the training of the conversion system and model. Then, the transition conversion system in the present invention is that under the guidance of the abstract syntax description language ASDL, different tokens in the natural language become a node in the abstract syntax tree after passing through the tree constructor, so as to achieve the purpose of converting the input natural language into the corresponding abstract syntax tree AST. Then, in order to further optimize the model and improve the accuracy of model training and generation, two auxiliary tasks are added to help the model better identify and learn external knowledge, wherein the two auxiliary tasks are: the token type labeling task of the natural language query statement and the recognition task of the target statement node type by the constructor. Then, based on the conversion system and auxiliary tasks, a neural encoder-decoder network with enhanced recurrent connections is used to parameterize the parser. The parser is used to calculate the probability that different tokens should use different constructors, and the constructor with the highest probability is selected to construct the abstract syntax tree, so that the abstract syntax tree is as standard as possible and conforms to the grammatical rules. The encoder and decoder are both implemented using LSTM networks. Finally, after the abstract syntax tree AST is generated, the target statement generation module in the conversion system is applied. Based on the specific syntax of the commit query language, the corresponding statement generation function is constructed. Through these functions, the generated abstract syntax tree AST is converted into the target commit query statement, completing the automatic generation of the commit query language.
2. According to the method for automatically generating code repository commit query language based on auxiliary task enhancement described in claim 1, Its characteristics include the following steps: 1) First, we need to build a corresponding abstract syntax description language ASDL based on the syntax of the domain-specific language commit query language, which will be used as a syntax guide for converting natural language into abstract syntax tree AST in the subsequent conversion system; 2) According to the syntax of the commit query language, the required corresponding data set is constructed. In the data text format of text pairs, the natural language question and the answer of the commit query language are used as a pair of data content to construct a data set containing 2,000 data for the training of the conversion system and model; 3) Guided by the abstract syntax description language ASDL that matches the commit query language, a transition conversion system suitable for the commit query language is constructed. Different tokens in the natural language become nodes in the abstract syntax tree after passing through the tree constructor, so as to achieve the purpose of converting the input natural language into the corresponding abstract syntax tree AST; 4) In order to further optimize the model and improve the model training performance and generation accuracy, two auxiliary tasks are added to help the model better recognize and learn external knowledge. The two auxiliary tasks are: the token type labeling task of natural language query sentences and the constructor’s recognition task of the target sentence node type; 5) Based on the conversion system and auxiliary tasks, a neural encoder-decoder network with enhanced recurrent connections is used to parameterize the parser. The parser is used to calculate the probability that different tokens should use different constructors, and the constructor with the highest probability is selected to construct the abstract syntax tree, so that the abstract syntax tree is as standard as possible and conforms to the grammatical rules. The encoder and decoder are both implemented using LSTM networks; 6) After the abstract syntax tree AST is generated, the target statement generation module in the application conversion system is used to build the corresponding statement generation function based on the specific syntax of the commit query language. Through these functions, the generated abstract syntax tree AST is converted into the target commit query statement, completing the automatic generation of the commit query language; 7) The model is trained using the data set constructed in step 2), and the answers output by the model are compared with the commit query language answers in the data set to obtain the corresponding commit query language performance evaluation results.
3. According to the method of automatic generation of code repository commit query language based on auxiliary task enhancement according to claim 2, it is characterized by: In step 1), it is necessary to build a matching abstract syntax description language ASDL based on the description of its syntax in the commit query language syntax definition file CommitQuery.g4 in the source code of the code repository. ASDL has two basic components: types and constructors. A composite type can be defined by a set of constructors under the type. The constructor uses its fields to specify a language construct of a specific type. The Conditions constructor under the composite type cond_expr represents a query statement expression and has two fields: op and value. An AST consists of multiple constructors, and each node on the tree corresponds to a typed field in the constructors (except the root node, which represents the root constructor). Depending on the cardinality of the field, a node can save one or more constructors as its value.
4. According to the method of automatic generation of code repository commit query language based on auxiliary task enhancement according to claim 2, it is characterized by In step 2), we need to use text pairs as the data storage format, natural language as the question, and commit query language as the answer to construct the data set required for training. For example, search for my commits since last week (question), after (last week) committed-by-me (commit query). A total of nearly 2,000 pieces of data are generated for training the conversion system and model.
5. According to the method of automatic generation of code repository commit query language based on auxiliary task enhancement according to claim 2, it is characterized by: In step 3), the abstract syntax description language ASDL that matches the commit query language is used as a guide, and the transition conversion system suitable for the commit query language is applied. Through a series of tree construction operations, starting from an initial derivation with a single root node, the corresponding abstract syntax tree AST is traversed from top to bottom and from left to right. Each time step may trigger a new extended derivation to continuously improve the current AST. The derivation actions are divided into three: APPLYCONSTR[c], REDUCE and GENTOKEN[v]. When no new frontier field is derived from the derivation, it means that the input natural language has been converted into the corresponding abstract syntax tree AST and saved.
6. The method for automatically generating a code repository commit query language based on auxiliary task enhancement according to claim 2 is characterized by: In step 4), in order to further optimize the model and improve the model training performance and generation accuracy, two auxiliary tasks are added to help the model better recognize and learn external knowledge. The two auxiliary tasks are:
1. The token type labeling task of natural language query statements. During data preprocessing, we process natural language query statement data by defining a new token object, which contains the value of the token and its specific type. Common examples of such fields include name, date, and path. The name field is mainly used to query the submitter or author, the date field is used to query submissions that meet specific time conditions, and the path field is used to query submissions within a specific path. In order to identify the token corresponding to the key field in the natural language query statement, we match the token with the key field and mark the token that appears in the key field set as the corresponding query condition field type. We mark the remaining ordinary tokens as "NONE". After processing the dataset, we add the new token object to the model training in order to improve the model performance and prediction accuracy.
2. The constructor identifies the node type of the target statement. In the submitted query statement, the specific node format of these query conditions is relatively fixed. For example, the first letter of the name is capitalized, the format of the time node is "xx xx xx", and the path node starts with " / ". Therefore, it becomes relatively easy to identify these nodes within the conversion system using string matching techniques. Once the identification is completed in the conversion system, we optimize the corresponding abstract syntax description language ASDL by refining the constructor of the var type into a specific constructor for each unique type. This enhancement enables the model to generate an abstract syntax tree more accurately based on the submitted query statement during training.
7. The method for automatically generating code repository commit query language based on auxiliary task enhancement according to claim 2 is characterized by: In step 5), based on the conversion system and auxiliary tasks, a neural encoder-decoder network with enhanced recurrent connections is used to parameterize the parser. The parser is used to calculate the probability that different tokens should adopt different constructors, and the constructor with the highest probability is selected to construct the abstract syntax tree, so that the abstract syntax tree is as standard as possible and conforms to the grammatical rules. The encoder and decoder are both implemented using LSTM networks. The encoder encodes the input utterance x, x[1..n] of n tokens into a vector representation h[1..n].
8. The method for automatically generating a code repository commit query language based on auxiliary task enhancement according to claim 2 is characterized by: In step 6), first obtain the generated abstract syntax tree AST, apply the transition conversion system applicable to the commit query language, and according to the conversion function applicable to the commit query language syntax defined in the conversion system, where the basic syntax of the commit query language is ' '* criteria (' '+ criteria)* ' '* EOF, criteria is the query condition, and its actual field value includes after, before, committer, author, path, message, etc., convert the abstract syntax tree AST into the commit query language to complete the automatic generation of the commit query language.
9. The method for automatically generating code repository commit query language based on auxiliary task enhancement according to claim 2 is characterized by: In step 7), the model is trained with the dataset constructed in step 2), and the answers output by the model are compared with the commit query language answers in the dataset. The corresponding commit query language performance evaluation results are obtained based on the evaluation criteria such as acc-1, acc-5, recall rate, and execution accuracy. When auxiliary tasks are added, the accuracy of the commit query statement automatic generation task reaches more than 92.3%.
Citation Information
Cited By
Dynamic code generation method and system based on interface document
CN118860356A
Natural language intelligent analysis and data query instruction generation method based on large model
CN121188079A
