Task testing method, code annotation method, task testing platform, equipment
By generating target annotation text and testing the generated code, the problem of accuracy and fairness of code annotation testing in the existing technology is solved, and code annotation verification and fair evaluation at the semantic level are achieved.
Patent Information
- Application Number
- CN202410742557.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-11
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2044-06-11
AI Technical Summary
The testing method of code annotations in the prior art relies on text comparison, ignores the function and logic of the annotations, and is biased due to manual scoring, resulting in insufficient testing accuracy and fairness.
By obtaining the test code, generating the target annotation text and executing the code generation task, the target code is tested based on the instance of the test code, and the test results of the code annotation task are determined. The unit test results are used as the evaluation criteria to avoid bias and improve test accuracy and impartiality.
It improves the testing accuracy of code comments, provides quantifiable and objective feedback, simplifies the readability of test results, ensures the accuracy of code comments at the semantic level, and avoids bias caused by individual differences in large models.
Smart Images

Figure CN118312212B
Abstract
Description
Technical Field
[0001] The embodiments of the present specification relate to the field of computer technology, and in particular to a task testing method, a code annotation method, a task testing platform, and a device. Background Art
[0002] In the development process, automatically generating code comments based on the code is a key function. Good code comments can improve the readability, maintainability and understandability of the code, which is crucial for collaboration and code maintenance. Therefore, it is important to test the accuracy and intuitiveness of code comments.
[0003] In related technologies, the code annotation test method compares the generated code annotation with the reference annotation. However, relying solely on text comparison ignores the real purpose of the annotation - conveying the function and logic of the code. Even if the code annotation and the reference annotation have large text differences, the code annotation may express the same code function and logic as the reference annotation, and the test accuracy needs to be improved. In addition, some other solutions use models or manual subjective scoring of the code, which will be affected by the bias caused by individual differences in scoring, making the test evaluation system lack fairness and consistency.
[0004] Therefore, there is an urgent need for an accurate task testing method for code annotation tasks. Summary of the invention
[0005] In view of this, an embodiment of this specification provides a task testing method. One or more embodiments of this specification also relate to a code annotation method, a task testing platform, a task testing device, a code annotation device, a computing device, a computer-readable storage medium and a computer program product to solve the technical defects existing in the prior art.
[0006] According to the first aspect of the embodiments of this specification, a task testing method is provided, including: obtaining test code; executing a code annotation task based on the test code to generate a target annotation text for the test code; executing a code generation task based on the target annotation text to generate a target code; testing the target code based on a test instance corresponding to the test code to determine a test result of the code annotation task.
[0007] An embodiment of the present specification realizes obtaining test code, executing code annotation task based on test code, generating target annotation text of test code, executing code generation task based on target annotation text, generating target code, testing target code based on test instance corresponding to test code, and determining test result of code annotation task. On one hand, by testing target code, the better the test result, the higher the quality of target annotation text of input code generation task, and further indicates that the code annotation generation capability of code annotation task is better, and it can verify whether the generated code annotation accurately reflects the function and behavior of code at semantic level, rather than just the similarity with reference annotation at text level, thus improving test accuracy; on the other hand, the unit test result of target code is used as evaluation standard of code annotation, which provides quantifiable and objective feedback for quality test of code annotation, and avoids the influence of bias caused by individual differences of large model compared with subjective scoring by large model, thus making test evaluation system more fair and consistent; on the other hand, the test result of code annotation task is determined by using concise and clear test result of target code, which replaces the text form test result containing more redundant information, thus improving readability of test result. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] Figure 1 An architecture diagram of a task testing system provided by an embodiment of this specification is shown;
[0009] Figure 2 An architecture diagram of another task testing system provided by an embodiment of this specification is shown;
[0010] Figure 3 A flowchart of a task testing method provided by an embodiment of this specification is shown;
[0011] Figure 4 A flowchart of a code annotation method provided by an embodiment of this specification is shown;
[0012] Figure 5 A process flow chart of a task testing method applied to a code annotation task provided by one embodiment of the present specification is shown;
[0013] Figure 6 A schematic diagram of the structure of a task testing device provided by an embodiment of this specification is shown;
[0014] Figure 7 A schematic diagram of the structure of a code annotation device provided by an embodiment of this specification is shown;
[0015] Figure 8 A structural block diagram of a computing device provided by an embodiment of the present specification is shown. DETAILED DESCRIPTION
[0016] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.
[0017] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0018] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0019] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0020] In one or more embodiments of this specification, a large model refers to a deep learning model with large-scale model parameters, which usually contains hundreds of millions, tens of billions, hundreds of billions, trillions, or even more than 10 trillion model parameters. A large model can also be called a foundation model / foundation model. The large model is pre-trained with large-scale unlabeled corpus to produce a pre-trained model with more than 100 million parameters. This model can adapt to a wide range of downstream tasks, and the model has good generalization ability, such as a large-scale language model (LLM, Large Language Model), a multi-modal pre-training model, etc.
[0021] When the big model is used in practice, only a small number of samples are needed to fine-tune the pre-trained model and it can be applied to different tasks. The big model can be widely used in natural language processing (NLP), computer vision and other fields. Specifically, it can be applied to computer vision tasks such as visual question answering (VQA), image description (IC, Image Caption), image generation, as well as natural language processing tasks such as text-based sentiment classification, text summary generation, and machine translation. The main application scenarios of the big model include digital assistants, intelligent robots, search, online education, office software, e-commerce, intelligent design, etc.
[0022] First, the terms involved in one or more embodiments of this specification are explained.
[0023] Code Comments: Provide concise, fluent descriptions of source code so that developers can understand, conceptualize, and document the code effectively.
[0024] pass@1: A unit test evaluation metric used to characterize the probability that the code passes the unit test once.
[0025] In-context learning: contextual learning is a method that allows a language model to learn related tasks given only one or more examples.
[0026] BLEU: Bilingual Evaluation Understudy, a bilingual translation quality evaluation index, is an indicator used to evaluate machine translation results. It evaluates translation quality by comparing the vocabulary overlap between machine-generated translation texts and manual reference translations. Specifically, the BLEU indicator takes into account the exact match of n-gram (a language model) and the ratio between the length of the translation text and the length of the reference text, resulting in a score between 0 and 1. The higher the score, the better the translation quality.
[0027] ROUGE-L: Recall-Oriented Understudy for Gisting Evaluation, a recall-oriented method for summary evaluation, is mainly used to evaluate the overlap between automatically generated abstracts or translations and reference texts. ROUGE-L takes into account the longest common subsequence (LCS), that is, the length of the longest continuous subsequence in the generated abstract or translation that is the same as the reference text. The calculation method of ROUGE-L makes it more inclined to capture the semantic similarity between texts.
[0028] HumanEval dataset: is a dataset used to evaluate the ability of code generation models. The dataset contains 164 programming problems with function signatures, comments, specific implementations, and multiple unit tests.
[0029] In the development process of code generation big model, code comment generation is an important function. In order to improve the maintainability and readability of the code generated by the code generation big model, it is also crucial to evaluate the ability of the code generation big model to generate code comments.
[0030] In this specification, a task testing method is provided. This specification also involves a code annotation method, a task testing platform, a task testing device, a code annotation device, a computing device, a computer-readable storage medium and a computer program product, which are described in detail one by one in the following embodiments.
[0031] See also Figure 1 , Figure 1An architecture diagram of a task testing system provided by an embodiment of the present specification is shown, and the task testing system may include a client 100 and a server 200; the client 100 is used to send test code to the server 200; the server 200 is used to obtain the test code, perform a code annotation task based on the test code, generate a target annotation text for the test code, perform a code generation task based on the target annotation text, generate a target code, test the target code based on a test instance corresponding to the test code, and determine the test result of the code annotation task based on the unit test result; send the test result to the client 100; the client 100 is also used to receive the test result sent by the server 200.
[0032] Through this task testing system, on the one hand, by testing the target code, the better the test result, the higher the quality of the target annotation text of the input code generation task, which further shows that the code annotation generation ability of the code annotation task is better, and it can test whether the generated code annotation accurately reflects the function and behavior of the code at the semantic level, rather than just the similarity with the reference annotation at the text level, thereby improving the test accuracy; on the other hand, the unit test results of the target code are used as the evaluation criteria for the code annotation, which provides quantifiable and objective feedback for the quality test of the code annotation. Compared with relying on subjective scoring of large models, it avoids the influence of bias caused by individual differences of large models, making the test evaluation system more fair and consistent; on the other hand, the test results of the code annotation task are determined by the concise and clear unit test results of the target code, replacing the text test results containing more redundant information, thereby improving the readability of the test results.
[0033] See also Figure 2 , Figure 2 The architecture diagram of another task test system provided by an embodiment of the present specification is shown. The task test system may include multiple clients 100 and a server 200, wherein the client 100 may include a terminal-side device and the server 200 may include a cloud-side device. A communication connection may be established between multiple clients 100 through the server 200. In the task test scenario, the server 200 is used to provide task test services between multiple clients 100. Multiple clients 100 may serve as a sender or a receiver, respectively, and realize communication through the server 200.
[0034] The user can interact with the server 200 through the client 100 to receive data sent by other clients 100, or send data to other clients 100, etc. In the task testing scenario, the user can send a test code to the server 200 through the client 100, and the server 200 tests the code annotation task according to the test code and pushes the test results to other clients that have established communication.
[0035] See also Figure 3 , Figure 3 A flowchart of a task testing method provided by an embodiment of the present specification is shown, which specifically includes the following steps.
[0036] Step 302: Get the test code.
[0037] The test code refers to the code samples that are considered correct and serve as evaluation criteria. These codes are usually used as benchmarks to evaluate the results generated by natural language processing systems. The purpose of this test code is to provide a standard to evaluate whether the generated target code meets expectations and is correct, and then evaluate the performance and quality of the code annotation task. For example, the test code can be the code in the HumanEval dataset.
[0038] Specifically, select an appropriate test dataset that can contain multiple code examples covering various programming languages and application scenarios. Preprocess the selected test dataset, which may include operations such as removing noise, standardizing formats, and processing special characters to ensure data consistency and usability. Determine the specific definition of the code annotation task, including the content of the annotation, the style and format of the annotation, etc., so as to subsequently generate the target annotation text.
[0039] Step 304: Execute the code annotation task based on the test code to generate target annotation text of the test code.
[0040] Among them, the code annotation task refers to the process of adding descriptive information or explanatory text to the program code. These comments are intended to enhance the readability, maintainability and comprehensibility of the code, and help other developers or themselves understand the function, structure and design ideas of the code. Code annotation tasks usually include adding comments to variables, functions, classes, modules, algorithms, logical structures, etc. in the code, as well as explaining the design decisions, implementation details, algorithm principles, etc. of the code. The target comment text refers to the comment text generated after completing the code annotation task. It corresponds to the original code and provides a descriptive description for each part of the code. These comment texts are intended to help readers understand the function, purpose, implementation method, etc. of the code, so as to better read, understand and use the code. The target comment text usually includes a description of the function, input and output, implementation principle, precautions, etc. of each part of the code.
[0041] Specifically, before annotating the test code, the test code needs to be parsed and converted into a data structure that can be understood by the computer, such as an abstract syntax tree (AST) or a code representation vector. The purpose of this step is to convert the test code into a form that can be further processed. For each code snippet, such as each line of code, a corresponding comment text needs to be generated. The process of generating the comment text can be implemented in at least the following two ways: ① Rule-based method: Generate comments based on predefined rules and patterns. For example, rules can be written to identify variables, functions, control flow structures, etc., and generate corresponding comments for them. ② Machine learning-based method: Use machine learning models, such as deep learning models, to learn the mapping relationship between code and comments from a large amount of training data, and generate comments based on the learned patterns. For example, a sequence-to-sequence model or a pre-trained language model (such as BERT, etc.) can be used to generate comments. The advantage of this method is that it can capture more complex semantics and grammatical structures, but it requires a lot of training data and computing resources. After the code comments are generated, the code comments are extracted from the test code containing the code comments to obtain the target test text.
[0042] In actual applications, a model is selected and trained using the collected sample code and sample annotation datasets. During the training process, the model will learn the mapping relationship between code and annotation. Using the trained large language model, input a sorting algorithm function code and let the large language model generate the corresponding annotation text. Finally, the generated annotation text is extracted from the test code containing the generated annotation to form the target annotation text.
[0043] Furthermore, a code annotation task is performed based on the test code to generate a target annotation text of the test code, including: performing the code annotation task based on the test code to obtain a task code, wherein the task code includes the test code and the target annotation text of the test code; and extracting the target annotation text from the task code.
[0044] Specifically, the task testing system performs a code annotation task and generates a task code including a test code and a target annotation text of the test code for the test code. The task testing system extracts the target annotation text of the test code from the task code. These annotation texts may include information such as explanations of code statements. Extracting target annotation texts in different languages can be done by detecting preset comment identifiers such as "#", " / / ", " / *", etc., or can be extracted after semantic analysis through a machine learning model. This specification does not specifically limit the method of extracting the target annotation text.
[0045] In practical applications, the preset comment mark is detected, taking the task code in Python language as an example:
[0046] "def two_sum_to_zero(l):
[0047] # Iterate over each element of the list
[0048] for i in range(len(l)):
[0049] # Traverse each element after the current element
[0050] for j in range(i + 1, len(l)):
[0051] if l[i] + l[j] == 0: # Check if the sum of the two current elements in the list is zero
[0052] # If we find two elements whose sum is zero, return True
[0053] return True
[0054] # If no two elements in the list have a sum of zero, return False
[0055] return False
[0056] For this task code, extract the target comment text according to the comment mark "#", as follows:
[0057] # Iterate over each element of the list
[0058] # Traverse each element after the current element
[0059] # Check if the sum of the two current elements in the list is zero
[0060] # If we find two elements whose sum is zero, return True
[0061] # If no two elements in the entire list sum to zero, return False".
[0062] Based on this, the code annotation task is performed based on the test code to generate the target annotation text, which provides the test subject for the subsequent testing process.
[0063] Further, executing a code annotation task based on the test code to obtain the task code includes: based on the test code, calling a code annotation model to execute the code annotation task to obtain the task code.
[0064] Specifically, obtain a pre-trained code annotation model, which can be a machine learning model or a large language model for question answering, input the test code into the code annotation model, and prompt the code annotation model to generate corresponding comments for each line of code. The code annotation model will generate comments for each line of code.
[0065] Furthermore, based on the test code, the code annotation model is called to perform the code annotation task to obtain the task code, including: based on the preset code, constructing the first indication information for the code annotation task, wherein the preset code includes the preset annotation text; based on the first indication information and the test code, constructing the first prompt information; calling the code annotation model, performing the code annotation task based on the first prompt information, and obtaining the task code, wherein the code annotation model is a question-and-answer model for performing the code annotation task.
[0066] The preset code is a code predetermined by a tester. Preferably, in order to ensure the fairness of the test, the preset code is usually fixed.
[0067] Specifically, at any stage before executing the code annotation task, the task testing system first constructs the first indication information for the code annotation task based on the preset code predetermined by the tester, or the first indication information is directly input by the tester. The first indication information includes the code part of the preset code and the preset annotation text. The first indication information is used to characterize the input and output format of the code annotation model. The first indication information and the test code are combined to construct the first prompt information. A specific code annotation model is called, and the code annotation model can be a question-and-answer model for performing the code annotation task. This model can understand the first prompt information and generate annotations based on its internal learning or rules. Finally, the annotated task code is obtained from the model.
[0068] In actual application, taking the preset code as including a section of Python source code and corresponding sample annotation text as an example, wherein the preset annotation text includes the variable name, function name and description of the key algorithm of the Python source code, the first indication information can be constructed as follows:
[0069] "Problem: Generate comments for the following code:
[0070] def two_sum_to_zero(l):
[0071] for i in range(len(l)):
[0072] for j in range(i + 1, len(l)):
[0073] if l[i] + l[j] == 0:
[0074] return True
[0075] return False
[0076] reply:
[0077] deftwo_sum_to_zero(l):
[0078] # Iterate over each element of the list
[0079] for i in range(len(l)):
[0080] # Traverse each element after the current element
[0081] for j in range(i + 1, len(l)):
[0082] if l[i] + l[j] == 0: # Check if the sum of the two current elements in the list is zero
[0083] # If we find two elements whose sum is zero, return True
[0084] return True
[0085] # If no two elements in the list have a sum of zero, return False
[0086] return False".
[0087] According to the above first instruction information and test code, the first prompt information for the code annotation task can be constructed, for example:
[0088] "Problem: Generate comments for the following code:
[0089] deftwo_sum_to_zero(l):
[0090] for i in range(len(l)):
[0091] for j in range(i + 1, len(l)):
[0092] if l[i] + l[j] == 0:
[0093] return True
[0094] return False
[0095] reply:
[0096] def two_sum_to_zero(l):
[0097] # Iterate over each element of the list
[0098] for i in range(len(l)):
[0099] # Traverse each element after the current element
[0100] for j in range(i + 1, len(l)):
[0101] if l[i] + l[j] == 0: # Check if the sum of the two current elements in the list is zero
[0102] # If we find two elements whose sum is zero, return True
[0103] return True
[0104] # If no two elements in the list have a sum of zero, return False
[0105] return False
[0106] Following the question-answer format above, generate the following test code comments:
[0107] from typing import List
[0108] defhas_close_elements(numbers: List[float], threshold: float) ->bool:
[0109] for idx, elem1 in enumerate(numbers):
[0110] for idx2, elem2 in enumerate(numbers):
[0111] if idx != idx2:
[0112] distance = abs(elem1 - elem2)
[0113] if distance <threshold:
[0114] return Truereturn False
[0115] reply:".
[0116] Next, a question-answering model is called to generate comments based on the first prompt information. The question-answering model will understand the first prompt information and the test code, and then generate task-like code.
[0117] Based on this, by utilizing the model's automation capabilities, comments can be quickly generated for the code, which improves the efficiency of comments and reduces the time cost of manual comments.
[0118] Furthermore, extracting target annotation text from the task code includes: based on the task code, calling an annotation extraction model to perform an annotation extraction task to obtain the target annotation text.
[0119] Specifically, obtain the comment extraction model used to perform the comment extraction task. This model can be a trained machine learning model or a rule-based system. This model will be used to automatically extract the target comment text. Next, call the obtained model to perform the comment extraction task. Enter the task code into the model and request the model to extract the comment text for each line of code. The model will extract the comment text based on its internal training or rules. Finally, obtain the extracted target comment text. The model will extract the corresponding comment text for each line of code and return it to the user. In this way, you get a task code that contains the target comment text, making the code easier to understand and maintain.
[0120] Based on this, an automated annotation extraction process can improve the efficiency of annotation extraction.
[0121] Furthermore, based on the task code, the annotation extraction model is called to perform the annotation extraction task to obtain the target annotation text, including: based on the preset code and the preset annotation text, constructing second indication information for the annotation extraction task; based on the second indication information and the task code, constructing second prompt information; calling the annotation extraction model to perform the annotation extraction task based on the second prompt information, and extracting the target annotation text from the task code, wherein the annotation extraction model is a question-and-answer model that performs the annotation extraction task.
[0122] The preset code is a code predetermined by a tester. Preferably, in order to ensure the fairness of the test, the preset code is usually fixed.
[0123] Specifically, at any stage before executing the annotation extraction task, the task testing system first constructs the second indication information for the annotation extraction task based on the preset code and preset annotation text predetermined by the tester, or the tester directly inputs the first indication information, and the second indication information is used to characterize the input and output format of the annotation extraction model. The second indication information and the task code are combined to construct the second prompt information. Preferably, in order to ensure the fairness of the test, the preset code for constructing the second indication information is the same code as the preset code for constructing the first indication information in the previous text. A specific annotation extraction model is called, and the annotation extraction model can be a question-and-answer model for performing the annotation extraction task. This model can understand the second prompt information and extract annotations based on its internal learning or rules. Finally, the annotated target annotation text is obtained from the model.
[0124] In practical applications, following the above example, according to the preset code and the preset annotation text, the second instruction information for the annotation extraction task can be constructed, for example:
[0125] "Question: Extract the comments for the following code:
[0126] def two_sum_to_zero(l):
[0127] # Iterate over each element of the list
[0128] for i in range(len(l)):
[0129] # Traverse each element after the current element
[0130] for j in range(i + 1, len(l)):
[0131] if l[i] + l[j] == 0: # Check if the sum of the two current elements in the list is zero
[0132] # If we find two elements whose sum is zero, return True
[0133] return True
[0134] # If no two elements in the list have a sum of zero, return False
[0135] return False
[0136] reply:
[0137] # Iterate over each element of the list
[0138] # Traverse each element after the current element
[0139] # Check if the sum of the two current elements in the list is zero
[0140] # If we find two elements whose sum is zero, return True
[0141] # If no two elements in the entire list sum to zero, return False".
[0142] Based on the second instruction information and the task code, construct the second prompt information, for example:
[0143] "Question: Extract the comments for the following code:
[0144] deftwo_sum_to_zero(l):
[0145] # Iterate over each element of the list
[0146] for i in range(len(l)):
[0147] # Traverse each element after the current element
[0148] for j in range(i + 1, len(l)):
[0149] if l[i] + l[j] == 0: # Check if the sum of the two current elements in the list is zero
[0150] # If we find two elements whose sum is zero, return True
[0151] return True
[0152] # If no two elements in the list have a sum of zero, return False
[0153] return False
[0154] reply:
[0155] # Iterate over each element of the list
[0156] # Traverse each element after the current element
[0157] # Check if the sum of the two current elements in the list is zero
[0158] # If we find two elements whose sum is zero, return True
[0159] # If no two elements in the list have a sum of zero, return False
[0160] Following the question-answer format above, extract the following task code comments:
[0161] def has_close_elements(numbers: List[float], threshold: float) ->bool:
[0162] # Traverse all elements in the numbers list and carry the index idx
[0163] for idx, elem1 in enumerate(numbers):
[0164] # Iterate over all elements in the numbers list again, and carry the index idx2
[0165] for idx2, elem2 in enumerate(numbers):
[0166] # Make sure you are not comparing the same elements (different indexes)
[0167] if idx != idx2:
[0168] # Calculate the absolute value of the distance between two elements
[0169] distance = abs(elem1 - elem2)
[0170] # If this distance is less than the preset threshold, there are close elements
[0171] if distance <threshold:
[0172] # Once such a pair of elements is found, return True
[0173] return True
[0174] # If no distance less than the threshold is found after traversing all element pairs, False is returned
[0175] return False
[0176] reply:".
[0177] It is understandable that in the specific embodiments of this specification, in addition to extracting code comments through the comment extraction model, code comments can also be extracted through rule extraction. For example, when a preset comment identifier such as "#", " / / ", " / *", etc. is detected, code comments can be extracted in the task code according to the comment identifier to obtain the target comment text. For another example, Chinese text in the code can also be directly detected and the Chinese text can be extracted as the target comment text. This specification does not specifically limit the method of extracting the target comment text.
[0178] Step 306: Execute the code generation task based on the target annotation text to generate the target code.
[0179] Among them, the code generation task usually refers to the process of automatically generating corresponding code implementation based on a given target annotation text.
[0180] In the related art, directly testing the target annotation text will be affected by preference. For example, for the interface, plug-in or model that generates the target annotation text, if the target annotation text is tested directly, these interfaces, plug-ins or models will tend to give a higher score to the target annotation text generated by themselves. Therefore, in order to avoid the test of preference in the embodiments of this specification, the target annotation text is not tested directly, but the target code generated based on the target annotation text is tested. Specifically, the target annotation text needs to be parsed first and converted into a structure or representation that can be understood by the computer. Next, the corresponding target code is generated according to the information provided in the target annotation text. This process can be achieved in the following ways: ① Rule-based method: Use predefined rules and patterns to automatically generate target code according to the information provided in the target annotation text. ② Use machine learning models, such as generative adversarial networks or encoding-decoding models, to learn the patterns and laws of code generation from the target annotation text and generate the corresponding target code.
[0181] In practical applications, taking the generation of target code through the encoding-decoding model as an example, the target annotation text is first converted into a latent vector representation through the encoder, and then the corresponding target code, that is, the implementation code of the addition function, is generated through the decoder. The training process of the encoding-decoding model usually includes two stages: encoding and decoding. In the encoding stage, the model encodes the target annotation text into a vector representation of a fixed length. In the decoding stage, the model decodes this vector representation into the target code. By learning from a large amount of training data, the model can learn the mapping relationship between the target annotation text and the target code, thereby generating a target code that meets the requirements.
[0182] Further, executing a code generation task based on the target annotation text to generate the target code includes: based on the target annotation text, calling a code generation model to execute the code generation task to obtain the target code.
[0183] Specifically, the pre-trained code generation model is obtained, which can be a machine learning model or a large language model for question and answer. The target annotation is input into the code generation model, prompting the code generation model to generate the corresponding target code according to the target annotation text.
[0184] Furthermore, based on the target comment text, the code generation model is called to perform the code generation task to obtain the target code, including: based on the preset comment text and the preset code, constructing third indication information for the code generation task; based on the third indication information and the target comment text, constructing third prompt information; calling the code generation model, performing the code generation task based on the third prompt information, and generating the target code, wherein the code generation model is a question-and-answer model for performing the code generation task.
[0185] The preset code is a code predetermined by a tester. Preferably, in order to ensure the fairness of the test, the preset code is usually fixed.
[0186] Specifically, at any stage before executing the code generation task, the task testing system first constructs the third indication information for the code generation task based on the preset comment text and preset code predetermined by the tester, or the third indication information is directly input by the tester, and the third indication information is used to characterize the input and output format of the code generation model. The third indication information and the target comment text are combined to construct the third prompt information. A specific code generation model is called, and the code generation model can be a question-and-answer model for performing the code generation task. This model can understand the third prompt information and generate the target code according to its internal learning or rules.
[0187] It is understandable that the above-mentioned code annotation model, annotation extraction model and code generation model can be different models or the same model. The above-mentioned code annotation model, annotation extraction model and code generation model can be machine learning models, neural network models or open source large language models and other models. It is worth noting that when the model involved in this specification is an open source large language model, training can be omitted. This specification does not specifically limit the type, principle and parameter scale of the model involved.
[0188] In practical applications, following the above example, according to the preset comment text and the preset code, the third instruction information for the code generation task can be constructed, for example:
[0189] "question:
[0190] According to the following comment:
[0191] # Iterate over each element of the list
[0192] # Traverse each element after the current element
[0193] # Check if the sum of the two current elements in the list is zero
[0194] # If we find two elements whose sum is zero, return True
[0195] # If no two elements in the list have a sum of zero, return False
[0196] Complete the following code:
[0197] deftwo_sum_to_zero(l):
[0198] # Iterate over each element of the list
[0199] for i in range(len(l)):
[0200] # Traverse each element after the current element
[0201] for j in range(i + 1, len(l)):
[0202] # Check if the sum of the two current elements in the list is zero
[0203] if l[i] + l[j] == 0:
[0204] # If we find two elements whose sum is zero, return True
[0205] return True
[0206] # If no two elements in the list have a sum of zero, return False
[0207] return False".
[0208] Based on the third indication information and the target annotation text, the third prompt information is constructed, for example:
[0209] "question:
[0210] According to the following comment:
[0211] # Iterate over each element of the list
[0212] # Traverse each element after the current element
[0213] # Check if the sum of the two current elements in the list is zero
[0214] # If we find two elements whose sum is zero, return True
[0215] # If no two elements in the list have a sum of zero, return False
[0216] Complete the following code:
[0217] def two_sum_to_zero(l):
[0218] reply:
[0219] def two_sum_to_zero(l):
[0220] # Iterate over each element of the list
[0221] for i in range(len(l)):
[0222] # Traverse each element after the current element
[0223] for j in range(i + 1, len(l)):
[0224] if l[i] + l[j] == 0: # Check if the sum of the two current elements in the list is zero
[0225] # If we find two elements whose sum is zero, return True
[0226] return True
[0227] # If no two elements in the list have a sum of zero, return False
[0228] return False
[0229] Following the question-response format above, annotate the text according to the following goals:
[0230] # Traverse all elements in the numbers list and carry the index idx
[0231] # Iterate over all elements in the numbers list again, and carry the index idx2
[0232] # Make sure you are not comparing the same elements (different indexes)
[0233] # Calculate the absolute value of the distance between two elements
[0234] # If this distance is less than the preset threshold, there are close elements
[0235] # Once such a pair of elements is found, return True
[0236] # If no distance less than the threshold is found after traversing all element pairs, False is returned
[0237] Complete the following target code:
[0238] defhas_close_elements(numbers: List[float], threshold: float) ->bool:
[0239] reply:".
[0240] Step 308: Based on the test instance corresponding to the test code, the target code is tested to determine the test result of the code annotation task.
[0241] Among them, testing the target code is to perform functional and logical testing on the target code based on the test instance corresponding to the test code to determine whether their functions and logics are the same. The test instance can usually be obtained at the same time as the test code, such as the HumanEval data set. The test method can be unit testing. Unit testing usually involves inputting the preset input of the test instance into the test unit of the target code. The test unit can be a function or a class. The test unit obtains the output result based on the preset input, and obtains the unit test result of the test unit according to the output result and the preset output of the test instance. According to the unit test results of all test units, the indicator of the target code passing the unit test once is determined: pass@1, which is used as the test result of the final code annotation task.
[0242] In the related art, during the test of code comments, the large language model may prefer the comments generated by itself, because these answers are more consistent with the patterns and preferences in its training data. This bias may cause the model to tend to give answers similar to its training data, rather than the most appropriate or accurate answers. In addition, different large language models have different preferences and may give different test results for the same code comment. Therefore, directly testing the target comment text will be affected by preference. For example, for the interface, plug-in or model that generates the target comment text, if the target comment text is tested directly, these interfaces, plug-ins or models will tend to give a higher score to the target comment text generated by itself. Therefore, in order to avoid the test of preference in the embodiment of this specification, the target comment text is not tested directly, but the target code generated based on the target comment text is unit tested. Through the unit test results, the difference or error between the target code and the test code can be determined. Then, according to the test results, it can be judged whether the test results of the code annotation task meet the expectations, that is, whether the target code generated based on the target comment text can correctly implement the functions described in the test code.
[0243] In a specific embodiment of the present specification, the process of testing the target code may also include code comparison. The specific methods of performing code comparison include but are not limited to: using a code static analysis tool to perform static analysis on the target code and the test code, and comparing the differences in their structure, syntax, logic, etc.; the developer manually compares the target code and the test code line by line to determine whether their functional implementations are consistent; automated testing tools: using automated testing tools to perform automated testing on the target code to verify whether its functional implementation conforms to the description in the test code; natural language processing technology: using natural language processing technology to perform semantic analysis on the code comment text, match it with the target code, and determine the consistency between the code and the comment; calculating the text similarity between the target code and the test code, etc.
[0244] Furthermore, based on the test instance corresponding to the test code, the target code is tested to determine the test result of the code annotation task, including: based on the test instance corresponding to the test code, unit testing is performed on each unit to be tested in the target code; based on the unit test result of each unit to be tested, the unit test pass index of the target code is determined; and the unit test pass index is determined as the test result of the code annotation task.
[0245] Specifically, based on the test instances corresponding to the test code, unit tests are performed on each unit to be tested (function, class, etc.) in the target code. These test instances include input data and expected output results, which are used to verify whether the function and logic of the target code are correct. According to the unit test results of each unit to be tested, the unit test pass index pass@1 of the target code is determined. For any execution subject (such as model, interface, plug-in, etc.) that executes the code annotation task, taking the data set containing 100 test codes and corresponding test instances as an example, after the execution subject completes the code annotation test task for all the test codes in the data set, if 70 target codes pass the unit test, the unit test pass index pass@1 is 70 / 100=0.7. The unit test pass index pass@1=0.7 is used as the test result of the final code annotation task.
[0246] Based on this, by unit testing the target code, the better the unit test results are, the higher the quality of the target annotation text of the input code generation task is, which further indicates that the code annotation task has better code annotation generation capabilities, avoiding the problem of inaccurate testing caused by directly testing the code annotation generated by the code annotation task itself. At the same time, the test results of the code annotation task are determined by the test results of the target code, replacing the lengthy text test results, which improves the readability of the test results.
[0247] Furthermore, after testing the target code based on the test instance corresponding to the test code and determining the test result of the code annotation task, it also includes: if the test result does not meet the preset indicator, adjusting the task parameters of the code annotation task, and returning to the step of executing the code annotation task based on the test code.
[0248] Among them, the task parameters of the code annotation task are some parameters or rules that need to be set and adjusted when performing code annotation evaluation, such as the parameters of the code annotation model.
[0249] Specifically, if the test results do not meet the preset indicators, the task parameters of the code annotation task need to be adjusted. The task parameters can include settings for the format of the annotation, the content of the annotation, the specification of the annotation, etc., and can be adjusted accordingly based on the deficiencies in the test results. After adjusting the task parameters of the code annotation task, it is necessary to return to the steps of executing the code annotation task based on the test code. Re-acquire the test code and perform steps such as testing to verify whether the adjusted code annotation task meets the preset indicators.
[0250] In practical applications, take the code annotation task performed by the code annotation model as an example. When it is determined that the logic of part of the target code is different from the test code, the parameters of the code annotation model are adjusted and the task test method is re-performed.
[0251] Based on this, through the above steps, when the test results do not meet the preset indicators, the quality and correctness of the code annotation can be improved by adjusting the task parameters of the code annotation task.
[0252] Furthermore, a code annotation task is executed based on the test code to generate a target annotation text for the test code, including: based on the test code, respectively executing different types of code annotation tasks to generate multiple target annotation texts for the test code; based on the target annotation text, a code generation task is executed to generate a target code, including: based on each target annotation text, respectively executing the same type of code generation tasks to generate a target code corresponding to each target annotation text; based on a test instance corresponding to the test code, the target code is tested to determine a test result of the code annotation task, including: based on the test instance corresponding to the test code, each target code is tested to determine a test result of each code annotation task; after the target code is tested based on the test instance corresponding to the test code to determine the test result of the code annotation task, it also includes: based on the test result of each code annotation task, screening the target code annotation task.
[0253] Among them, different types of code annotation tasks refer to using different execution subjects to execute code annotation tasks based on the same test code. The same type of code generation tasks refer to using the same execution subject to execute code generation tasks based on different target annotation texts.
[0254] Specifically, based on the test code, different execution entities are used to perform code annotation tasks based on the same test code to obtain target annotation texts. Based on each target annotation text, the same type of code generation tasks are performed to generate target codes corresponding to each target annotation text. The purpose of this task is to generate a code structure that conforms to the annotation description based on the annotation text. Based on the test instance corresponding to the test code, each target code is tested. Based on the test results of each target code, the test results of each code annotation task are determined. This includes evaluating the accuracy, completeness and standardization of the annotations. If the target code is consistent with the test code and the annotations are clear, the annotation task passes the test. According to the test results of the code annotation task, the target code annotation tasks that pass the test and meet expectations are screened out.
[0255] In practical applications, different types of code annotation tasks are taken as examples of using different code annotation models (model A1, model A2, model A3, model A4) to perform code annotation tasks based on the same test code. The same type of code generation task refers to using the same code generation model (model B) to perform code generation tasks based on different target annotation texts. Based on the test code, models A1, A2, A3, and A4 are used to perform code annotation tasks based on the same test code, respectively, to obtain the first target annotation text, the second target annotation text, the third target annotation text, and the fourth target annotation text. Based on each target annotation text, model B is used to perform code generation tasks to generate the first target code, the second target code, the third target code, and the fourth target code corresponding to each target annotation text. Based on the same test instance, unit tests are performed on the first target code, the second target code, the third target code, and the fourth target code, respectively, to obtain the pass@1 indicators of model A1: 0.408, A2: 0.585, A3: 0.573, A4: 0.658. It can be seen that the code annotation capabilities of Model A1, Model A2, Model A3, and Model A4 are ranked as Model A4>Model A3>Model A2>Model A1.
[0256] Based on this, by evaluating the test results of the code annotation tasks, we can screen out the target code annotation tasks that have passed the test and meet the expectations, thereby gradually improving the accuracy, completeness and standardization of the annotations, and further improving the quality of the annotations.
[0257] An embodiment of the present specification realizes obtaining test code, executing code annotation task based on test code, generating target annotation text of test code, executing code generation task based on target annotation text, generating target code, testing target code based on test instance corresponding to test code, and determining test result of code annotation task. On one hand, by unit testing target code, the better the unit test result, the higher the quality of target annotation text of input code generation task, and further indicates that the code annotation generation capability of code annotation task is better, and it can verify whether the generated code annotation accurately reflects the function and behavior of code at semantic level, rather than just the similarity with reference annotation at text level, thus improving test accuracy; on the other hand, using unit test result of target code as evaluation standard of code annotation provides quantifiable and objective feedback for quality test of code annotation, and avoids the influence of bias caused by individual differences of large model compared with subjective scoring relying on large model, thus making test evaluation system more fair and consistent; on the other hand, using concise and clear unit test result of target code to determine test result of code annotation task replaces text test result containing more redundant information, thus improving readability of test result.
[0258] See also Figure 4 , Figure 4 A flowchart of a code annotation method provided by an embodiment of the present specification is shown, which specifically includes the following steps.
[0259] Step 402: Obtain an initial code, wherein the initial code is a code input by a front-end user and to be annotated.
[0260] Step 404: Execute a code annotation task based on the initial code to generate a target code, wherein the code annotation task is determined after testing using a task testing method.
[0261] Specifically, based on the initial code input by the user, the initial code is parsed and semantically analyzed to extract key information in the code, such as functions, variables, parameters, etc. This information will be used as the content of the comment. Based on the extracted information, the code comment task determined by the task testing method based on steps 302-308 is used to generate the target code containing the code comment.
[0262] Furthermore, after executing the code annotation task based on the initial code and generating the target code, it also includes: receiving feedback information for the target code sent by the front end, wherein the feedback information represents the feedback of the front end on the annotation text in the target code; based on the feedback information, adjusting the task parameters of the code annotation task, and using the task testing method to test the adjusted code annotation task to determine the code annotation task whose test results meet the preset indicators.
[0263] Specifically, the front end sends feedback information for the target code, and the feedback information represents the front end's feedback on the comment text in the target code. The feedback information may include evaluations on the accuracy, completeness, and possible suggestions for improvement of the comments. Based on the feedback information received, the task parameters of the code annotation task are adjusted. According to the adjusted code annotation task, the new code annotation task is tested using the task testing method of task steps 302-308. Based on the task testing method, determine whether the adjusted code annotation task has reached the preset indicators. If the test results meet expectations, it means that the adjusted annotation task has passed the test.
[0264] Based on this, we can timely understand the needs and expectations of users for code comment text, and then adjust the parameters of the code comment task in a targeted manner. Through continuous iteration of this process, the team can gradually improve the quality of code comments, ensure that the comment text is consistent with user needs, and meet the preset indicator requirements.
[0265] An embodiment of the present invention realizes obtaining initial code, executing code annotation tasks based on the initial code, and generating target code, wherein the code annotation tasks are determined after testing using a task testing method. By using the code annotation tasks determined by the task testing method provided in the embodiment of this specification, the generated target code will contain more accurate code annotations, ensuring the readability, maintainability and comprehensibility of the code.
[0266] The following combination Figure 5 , taking the application of the task testing method provided in this specification in the code annotation task as an example, the task testing method is further explained. Figure 5 A process flow chart of a task testing method applied to a code annotation task provided by an embodiment of the present specification is shown, which specifically includes the following steps.
[0267] Step 502: Generate annotations based on the evaluation code and the first indication information. Specifically, the HumanEval dataset, a code evaluation benchmark, is used. The HumanEval dataset contains 164 programming problems with function signatures, annotations, specific implementations, and multiple unit tests. This dataset is used to test the ability of large models to generate code. Based on the In-context learning approach, the code annotation model is used to generate corresponding code annotations for the complete code of each implementation in the HumanEval dataset to obtain the evaluation code containing annotations. For example, the input of the code annotation model (the first indication information and the evaluation code) can be as described in the first prompt information above, and will not be repeated here.
[0268] Step 504: Extract the comments in the evaluation code according to the second indication information. Specifically, the code annotation model is a large language model, and the ability of the large language model is relied upon to automatically extract the complete annotation text. For example, the content of the code input model in step 504 (the second indication information and the evaluation code) can be as described in the second prompt information above, and will not be repeated here.
[0269] Step 506: Generate code according to the annotation text and the third indication information. Specifically, generate code using a code generation model according to the generated annotation text, wherein the code generation model and the code annotation model may be the same model or different models. For example, the input of the code generation module (the third indication information and the annotation text) may be as described in the third prompt information, which will not be described here.
[0270] Step 508: Unit test the target code. Specifically, unit test the generated code. To ensure that the evaluation is in the same dimension, when testing different code annotation models, the code generation model should be fixed to the same large model. The pass@1 index is obtained through unit testing. The higher the pass@1 index, the higher the accuracy of the generated code, which also indicates that the quality of the code annotation is higher.
[0271] Corresponding to the above method embodiment, this specification also provides a task testing device embodiment, Figure 6 FIG. 1 is a schematic diagram showing the structure of a task testing device provided by an embodiment of the present specification. Figure 6 As shown, the device includes: a first acquisition module 602, configured to acquire test code; a code annotation module 604, configured to perform a code annotation task based on the test code, and generate a target annotation text for the test code; a code generation module 606, configured to perform a code generation task based on the target annotation text, and generate a target code; a test module 608, configured to test the target code based on a test instance corresponding to the test code, and determine a test result of the code annotation task.
[0272] Optionally, the code annotation module 604 is further configured to perform a code annotation task based on the test code to obtain a task code, wherein the task code includes the test code and a target annotation text of the test code; and extract the target annotation text from the task code.
[0273] Optionally, the code annotation module 604 is further configured to call the code annotation model to perform the code annotation task based on the test code to obtain the task code.
[0274] Optionally, the code annotation module 604 is further configured to construct first indication information for a code annotation task based on a preset code, wherein the preset code includes preset annotation text; construct first prompt information based on the first indication information and the test code; call the code annotation model, execute the code annotation task based on the first prompt information, and obtain the task code, wherein the code annotation model is a question-and-answer model for executing the code annotation task.
[0275] Optionally, the code annotation module 604 is further configured to call the annotation extraction model to perform the annotation extraction task based on the task code to obtain the target annotation text.
[0276] Optionally, the code annotation module 604 is further configured to construct second indication information for the annotation extraction task based on preset code and preset annotation text; construct second prompt information based on the second indication information and the task code; call the annotation extraction model, perform the annotation extraction task based on the second prompt information, and extract the target annotation text from the task code, wherein the annotation extraction model is a question-and-answer model for performing the annotation extraction task.
[0277] Optionally, the code generation module 606 is further configured to call the code generation model to perform the code generation task based on the target annotation text to obtain the target code.
[0278] Optionally, the code generation module 606 is further configured to construct third indication information for the code generation task based on preset comment text and preset code; construct third prompt information based on the third indication information and target comment text; call the code generation model, execute the code generation task based on the third prompt information, and generate target code, wherein the code generation model is a question-and-answer model for executing the code generation task.
[0279] Optionally, the test module 608 is further configured to perform unit testing on each unit to be tested in the target code based on the test instance corresponding to the test code; determine the unit test pass index of the target code based on the unit test results of each unit to be tested; and determine the unit test pass index as the test result of the code annotation task.
[0280] Optionally, the task testing device further includes an adjustment module configured to adjust task parameters of the code annotation task and return to the step of executing the code annotation task based on the test code when the test result does not meet preset indicators.
[0281] Optionally, the code annotation module 604 is further configured to perform different types of code annotation tasks based on the test code, and generate multiple target annotation texts for the test code; the code generation module 606 is further configured to perform the same type of code generation tasks based on each target annotation text, and generate target code corresponding to each target annotation text; the testing module 608 is further configured to test each target code based on the test instance corresponding to the test code, and determine the test results of each code annotation task; the task testing device also includes a screening module, which is configured to screen the target code annotation tasks based on the test results of each code annotation task.
[0282] Through this task testing device, on the one hand, by testing the target code, the better the test result, the higher the quality of the target annotation text of the input code generation task, which further shows that the code annotation generation ability of the code annotation task is better, and it can verify whether the generated code annotation accurately reflects the function and behavior of the code at the semantic level, rather than just the similarity with the reference annotation at the text level, thereby improving the test accuracy; on the other hand, the unit test results of the target code are used as the evaluation criteria for the code annotation, which provides quantifiable and objective feedback for the quality test of the code annotation. Compared with relying on subjective scoring of large models, it avoids the influence of bias caused by individual differences of large models, making the test evaluation system more fair and consistent; on the other hand, the test results of the code annotation task are determined by using concise and clear unit test results of the target code, replacing the textual test results containing more redundant information, thereby improving the readability of the test results.
[0283] The above is a schematic scheme of a task testing device of this embodiment. It should be noted that the technical scheme of the task testing device and the technical scheme of the above-mentioned task testing method belong to the same concept, and the details not described in detail in the technical scheme of the task testing device can be referred to the description of the technical scheme of the above-mentioned task testing method.
[0284] Corresponding to the above method embodiment, this specification also provides a task testing device embodiment, Figure 7 FIG. 1 shows a schematic diagram of a code annotation device provided by an embodiment of the present specification. Figure 7 As shown, the device comprises:
[0285] The second acquisition module 702 is configured to acquire an initial code.
[0286] The execution module 704 is configured to execute the code annotation task based on the initial code to generate the target code, wherein the code annotation task adopts the following method: Figure 6 The task of the test device is determined after testing.
[0287] Optionally, the code annotation device further includes an adjustment module, which is configured to receive feedback information sent by the front end for the target code, wherein the feedback information represents the feedback of the front end on the annotation text in the target code; based on the feedback information, adjust the task parameters of the code annotation task, and adopt the following method: Figure 6 The task testing device tests the adjusted code annotation task to determine the code annotation task whose test result reaches the preset index.
[0288] The code annotation device can obtain the initial code, perform the code annotation task based on the initial code, and generate the target code, wherein the code annotation task is determined after testing using the task testing method. Figure 6 The code annotation tasks determined by the task testing device will generate target code containing more accurate code annotations, ensuring the readability, maintainability and comprehensibility of the code.
[0289] The above is a schematic scheme of a code annotation device of this embodiment. It should be noted that the technical scheme of the code annotation device and the technical scheme of the above code annotation method belong to the same concept, and the details of the technical scheme of the code annotation device that are not described in detail can all be referred to the description of the technical scheme of the above code annotation method.
[0290] Figure 8 The structure block diagram of a computing device provided by an embodiment of the present specification is shown. The components of the computing device 800 include but are not limited to a memory 810 and a processor 820. The processor 820 is connected to the memory 810 via a bus 830, and the database 850 is used to store data.
[0291] The computing device 800 also includes an access device 840 that enables the computing device 800 to communicate via one or more networks 860. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 840 may include one or more of any type of network interface (e.g., a network interface card (NIC)) of wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a world-wide interoperability for microwave access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, and a near field communication (NFC).
[0292] In one embodiment of the present specification, the above components of the computing device 800 and Figure 8 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 8The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0293] The computing device 800 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 800 may also be a mobile or stationary server.
[0294] The memory 810 is used to store computer programs / instructions, and the processor 820 is used to execute the computer programs / instructions stored in the memory 810. When the computer programs / instructions are executed by the processor, the steps of the above-mentioned task testing method or code annotation method are implemented.
[0295] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the task testing method or code annotation method described above belong to the same concept, and the details not described in detail in the technical scheme of the computing device can be referred to the description of the technical scheme of the task testing method or code annotation method described above.
[0296] An embodiment of the present specification further provides a computer-readable storage medium storing a computer program / instruction, which implements the steps of the above-mentioned task testing method or code annotation method when executed by a processor.
[0297] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the task testing method or code annotation method described above belong to the same concept, and the details not described in detail in the technical scheme of the storage medium can be referred to the description of the technical scheme of the task testing method or code annotation method described above.
[0298] An embodiment of the present specification also provides a computer program product, including a computer program / instruction, which implements the steps of the above-mentioned task testing method or code annotation method when executed by a processor.
[0299] The above is a schematic scheme of a computer program product of this embodiment. It should be noted that the technical scheme of the computer program product and the technical scheme of the task testing method or code annotation method described above belong to the same concept, and the details not described in detail in the technical scheme of the computer program product can be referred to the description of the technical scheme of the task testing method or code annotation method described above.
[0300] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0301] Computer programs / instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. Computer readable media may include: any entity or device capable of carrying computer program codes, recording media, USB flash drives, mobile hard disks, magnetic disks, optical disks, computer memories, read-only memories (ROM), random access memories (RAM), electric carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the contents of computer readable media may be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, computer readable media do not include electric carrier signals and telecommunication signals.
[0302] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.
[0303] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0304] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to specific implementation methods. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that those skilled in the art can understand and use this specification well. This specification is limited only by the claims and their full scope and equivalents.
Claims
1. A task testing method, comprising: Get the test code; Execute a code annotation task based on the test code to generate a target annotation text for the test code; Execute a code generation task based on the target annotation text to generate target code; Based on the test instance corresponding to the test code, the target code is tested to determine the test result of the code annotation task; The testing of the target code based on the test instance corresponding to the test code to determine the test result of the code annotation task includes: Based on the test instance corresponding to the test code, perform unit testing on each unit to be tested in the target code; Determining a unit test pass index of the target code based on the unit test results of each unit to be tested; The unit test passing indicator is determined as the test result of the code annotation task.
2. The method according to claim 1, wherein the performing a code annotation task based on the test code to generate a target annotation text for the test code comprises: Execute a code annotation task based on the test code to obtain a task code, wherein the task code includes the test code and a target annotation text of the test code; The target annotation text is extracted from the task code.
3. The method according to claim 2, wherein the performing of the code annotation task based on the test code to obtain the task code comprises: Based on the test code, a code annotation model is called to perform a code annotation task to obtain a task code.
4. The method according to claim 3, wherein based on the test code, calling the code annotation model to perform the code annotation task and obtaining the task code comprises: Based on a preset code, construct first indication information for a code annotation task, wherein the preset code includes a preset annotation text; Constructing first prompt information based on the first indication information and the test code; The code annotation model is called, and the code annotation task is executed based on the first prompt information to obtain the task code.
5. The method according to claim 2, wherein extracting the target annotation text from the task code comprises: Based on the task code, the annotation extraction model is called to execute the annotation extraction task to obtain the target annotation text.
6. The method according to claim 5, wherein the step of calling the annotation extraction model to perform the annotation extraction task based on the task code to obtain the target annotation text comprises: Based on the preset code and the preset, construct second instruction information for the annotation extraction task; Constructing second prompt information based on the second indication information and the task code; The annotation extraction model is called to execute the annotation extraction task based on the second prompt information, and the target annotation text is extracted from the task code.
7. The method according to claim 1, wherein the performing of the code generation task based on the target annotation text to generate the target code comprises: Based on the target annotation text, a code generation model is called to perform a code generation task to obtain a target code.
8. The method according to claim 7, wherein the step of calling a code generation model to perform a code generation task based on the target annotation text to obtain the target code comprises: Based on the preset annotation text and the preset code, construct third instruction information for the code generation task; Constructing third prompt information based on the third indication information and the target annotation text; The code generation model is called, and the code generation task is executed based on the third prompt information to generate target code.
9. The method according to any one of claims 1 to 8, after testing the target code based on the test instance corresponding to the test code and determining the test result of the code annotation task, further comprising: When the test result does not reach the preset index, the task parameters of the code annotation task are adjusted, and the step of executing the code annotation task based on the test code is returned to be executed.
10. The method according to any one of claims 1 to 8, wherein the step of performing a code annotation task based on the test code to generate a target annotation text for the test code comprises: Based on the test code, performing different types of code annotation tasks respectively to generate multiple target annotation texts of the test code; The performing of the code generation task based on the target annotation text to generate the target code comprises: Based on each of the target annotation texts, respectively execute the same type of code generation tasks to generate target codes corresponding to each of the target annotation texts; The testing of the target code based on the test instance corresponding to the test code to determine the test result of the code annotation task includes: Based on the test instances corresponding to the test codes, each of the target codes is tested to determine the test results of each of the code annotation tasks; After testing the target code based on the test instance corresponding to the test code and determining the test result of the code annotation task, the method further includes: Based on the test results of each of the code annotation tasks, a target code annotation task is screened.
11. A code annotation method, comprising: Get the initial code; A code annotation task is performed based on the initial code to generate a target code, wherein the code annotation task is determined after testing using the task testing method according to any one of claims 1 to 10.
12. The method according to claim 11, after performing the code annotation task based on the initial code to generate the target code, further comprises: Receiving feedback information sent by the front end for the target code, wherein the feedback information represents the feedback of the front end on the annotation text in the target code; Based on the feedback information, the task parameters of the code annotation task are adjusted, and the adjusted code annotation task is tested using the task testing method to determine the code annotation task whose test result reaches a preset indicator.
13. A task testing platform, comprising a request interface and a test terminal; The request interface is used to receive a task test request sent by a terminal device, wherein: The task test request includes task parameter information of the code annotation task; The test end is used to execute the task testing method according to any one of claims 1 to 10 based on the task parameter information of the code annotation task to obtain the test result of the code annotation task; The request interface is also used to send the test result to the terminal device.
14. A computing device comprising: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions. When the computer programs / instructions are executed by the processor, the steps of the task testing method according to any one of claims 1 to 10 or the code annotation method according to any one of claims 11 to 12 are implemented.
15. A computer-readable storage medium storing a computer program / instruction, wherein the computer program / instruction, when executed by a processor, implements the steps of the task testing method according to any one of claims 1 to 10 or the code annotation method according to any one of claims 11 to 12.
16. A computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the task testing method according to any one of claims 1 to 10 or the code annotation method according to any one of claims 11 to 12.
