Code review method and device, electronic equipment and storage medium

By selecting and clustering a subset of training samples, a high-quality and highly diverse training dataset is constructed, which solves the problem of insufficient training data quality and diversity in code review models and improves the accuracy and diversity of code review.

CN121935124APending Publication Date: 2026-04-28TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TENCENT TECHNOLOGY (SHENZHEN) CO LTD
Filing Date
2024-10-28
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

In existing technologies, the training data quality and diversity screening efficiency of code review models are low, resulting in poor model training results and affecting the accuracy of code review.

Method used

By constructing a test sample set that meets the expected quality, and after initial training on the training sample set, the test impact of each training sample subset is evaluated. High-quality target training sample subsets are selected, and clustering and sampling are performed to form a high-quality and highly diverse training dataset, which is then used to retrain the code review model.

Benefits of technology

It improves the accuracy of the code review model, generates more accurate review information, and ensures the quality and diversity of review results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121935124A_ABST
    Figure CN121935124A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, in particular to a code review method and device, electronic equipment and a storage medium, which are used for efficiently screening out high-quality and high-diversity training data so as to improve the accuracy of code review. The method comprises the following steps: acquiring a training sample set and a test sample set, and dividing the training sample set into a plurality of training sample subsets; the test sample set comprises test samples reaching expected quality; after a to-be-trained code review model is preliminarily trained based on the training sample set, the test influence degree of each training sample subset on the code review model on the test sample set is determined; for at least one target training sample subset of which the test influence degree meets a preset influence condition in the plurality of training sample subsets, performing clustering according to a sample gradient to obtain a plurality of clusters; and sampling is carried out in each cluster, and the code review model after preliminary training is trained again according to the obtained sampling sample set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more particularly to a code review method, apparatus, electronic device, and storage medium. Background Technology

[0002] Code review (CR) is an important process in software development, aiming to find and correct errors that were missed in the early stages of software development by peer review, thereby improving code quality and the overall quality of the project. Code review goes beyond simply checking for syntax errors; it also includes evaluating aspects such as readability, maintainability, performance, security, and consistency.

[0003] In related technologies, code review models can be used for automated code review. These models are primarily based on the idea of ​​model inference, where language instructions and the code to be reviewed are input, and the model infers and outputs review information. However, traditional model inference result selection schemes suffer from inconsistent training sample quality, with a large number of low-quality training samples. These low-quality samples often contain syntax errors, logical errors, inconsistent styles, redundant code, security vulnerabilities, and performance issues, leading to poor model training results.

[0004] Since the effect of a model fine-tuned on a higher quality and more diverse dataset is better than that fine-tuned on a larger dataset, current related technologies mainly rely on other evaluation models to judge the quality and diversity of the dataset. These evaluation models also need to be trained separately, resulting in low screening efficiency.

[0005] In summary, how to efficiently select high-quality and diverse training data to improve the accuracy of code review is an urgent problem to be solved. Summary of the Invention

[0006] This application provides a code review method, apparatus, electronic device, and storage medium to efficiently filter out high-quality and highly diverse training data, thereby improving the accuracy of code review.

[0007] This application provides a code review method, including:

[0008] Obtain a training sample set and a test sample set, and divide the training sample set into multiple training sample subsets; the test sample set contains test samples that achieve the expected quality;

[0009] After initial training of the code review model to be trained based on the training sample set, the test impact of each training sample subset on the code review model is determined; the test impact reflects the influence of the training sample subset on the performance change of the code review model on the test sample set.

[0010] For the multiple training sample subsets, at least one target training sample subset whose test influence meets the preset influence conditions is clustered according to the sample gradient to obtain multiple clusters;

[0011] Sampling is performed in each cluster, and the code review model that has been initially trained is retrained based on the obtained sample set to obtain the trained target code review model; wherein, the target code review model is used to generate review information for the code to be reviewed.

[0012] This application provides a code review apparatus, comprising:

[0013] The data acquisition unit is used to acquire a training sample set and a test sample set, and to divide the training sample set into multiple training sample subsets; the test sample set contains test samples that achieve the expected quality.

[0014] The first processing unit is used to perform preliminary training on the code review model to be trained based on the training sample set, and then determine the test impact of each training sample subset on the code review model; the test impact reflects the influence of the training sample subset on the performance change of the code review model on the test sample set.

[0015] The filtering unit is used to cluster at least one target training sample subset whose influence meets the preset influence conditions from the plurality of training sample subsets, according to the sample gradient, to obtain multiple clusters.

[0016] The second processing unit is used to sample in each cluster and retrain the code review model that has been initially trained based on the obtained sample set to obtain the trained target code review model; wherein, the target code review model is used to generate review information for the code to be reviewed.

[0017] Optionally, the first processing unit is specifically used for:

[0018] Determine the Hessian matrix of the loss function of the code review model, the first gradient vector corresponding to each training sample subset, and the second gradient vector corresponding to the test sample set; wherein the first gradient vector and the second gradient vector are determined based on the gradient vector of each sample in the corresponding set.

[0019] For each training sample subset, the test influence of the training sample subset on the code review model is determined based on the first gradient vector corresponding to the training sample subset, the Hessian matrix, and the second gradient vector.

[0020] Optionally, the first gradient vector and the second gradient vector are d-dimensional column vectors, and the Hessian matrix is ​​a d×d matrix; the first processing unit is specifically used for:

[0021] The transpose of the second gradient vector is multiplied by the inverse of the Hessian matrix to obtain the intermediate vector.

[0022] Perform an inner product operation between the intermediate vector and the first gradient vector to obtain an intermediate scalar;

[0023] The negative of the intermediate scalar is used as the test influence of the training sample subset on the code review model.

[0024] Optionally, the gradient vector for each sample is determined based on the intermediate layer results of the code review model.

[0025] Optionally, the filtering unit is further configured to filter out a subset of target training samples by at least one of the following methods:

[0026] The N training sample subsets with the largest values ​​among the determined test influence values ​​are used as the target training sample subset, where N is a positive integer greater than or equal to 1.

[0027] The subset of training samples that reaches the preset influence threshold is used as the target training sample subset.

[0028] Optionally, the filtering unit is specifically used for:

[0029] For each target training sample in the at least one subset of target training samples, determine the third gradient vector of the target training sample;

[0030] Based on the distances between the determined third gradient vectors, each target training sample is clustered to obtain multiple clusters.

[0031] Optionally, the filtering unit is further configured to perform the following operation before clustering according to sample gradients to obtain multiple clusters:

[0032] Dimensionality reduction is performed on each target training sample; or

[0033] The third gradient vector of each target training sample is dimensionality reduced.

[0034] Optionally, the device further includes:

[0035] The review unit is used to input language instructions and code to be reviewed into the target code review model, obtain review information of the code to be reviewed and review probability corresponding to the review information based on the target code review model, and the review probability includes the probability of each word in the review information.

[0036] A verification unit is used to input the language instruction and the review information into at least one verification model to obtain the verification probability output by each verification model; each verification probability includes the probability of each word in the text sequence output by the corresponding verification model.

[0037] The determining unit is configured to determine a mutual information parameter for the review information based on the review probability and each of the verification probabilities, respectively; wherein each verification probability corresponds to a mutual information parameter;

[0038] The analysis unit is used to determine whether to present the review information to the object based on the obtained mutual information parameters.

[0039] Optionally, the determining unit is specifically used for:

[0040] For each verification probability, the logarithm of the product of the review probability and the corresponding verification probability is used as the mutual information parameter corresponding to the verification probability.

[0041] Optionally, the determining unit is specifically used for:

[0042] For each of the verification probabilities, a first ratio corresponding to the logarithm of the review probability and the length of the review information is determined, as well as a second ratio corresponding to the logarithm of the verification probability and the length of the text sequence.

[0043] The sum of the first ratio and the second ratio is used as the mutual information parameter corresponding to the verification probability.

[0044] Optionally, the analysis unit is specifically used for:

[0045] If the statistical parameters obtained based on the various mutual information parameters exceed the preset parameter threshold, the review information will be presented to the object.

[0046] Optionally, the target code review model is a large language model; the analysis unit is specifically used for:

[0047] If the statistical parameters obtained based on the mutual information parameters do not exceed the preset parameter threshold, then new review information and review probabilities are regenerated based on the target code review model, and the process of inputting the language instructions and the review information into at least one verification model to obtain the verification probability output by each verification model is returned.

[0048] Optionally, the review probability is a review probability sequence in sequence form, which contains the probability of each word in the review information; the verification probability is a verification probability sequence in sequence form; each verification probability sequence contains the probability of each word in the text sequence output by the corresponding verification model.

[0049] An electronic device provided in this application includes a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the steps of any of the above-described code review methods.

[0050] This application provides a computer-readable storage medium including a computer program. When the computer program is run on an electronic device, the computer program is used to cause the electronic device to perform the steps of any of the above-described code review methods.

[0051] This application provides a computer program product, which includes a computer program stored in a computer-readable storage medium. When a processor of an electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, causing the electronic device to perform the steps of any of the above-described code review methods.

[0052] The beneficial effects of this application are as follows:

[0053] This application provides a code review method, apparatus, electronic device, and storage medium. This application uses gradient values ​​to perform quality screening and diversity detection on training data, and trains a code review model with the resulting high-quality, highly diverse samples to improve the accuracy of the code review information generated by the model.

[0054] Specifically, this application first constructs a test sample set that meets the expected quality. After initial training of the code review model to be trained based on the training sample set, the influence of each training sample subset on the performance change of the model on the test sample set can be evaluated according to the multiple training sample subsets obtained by dividing the training sample set. This influence is denoted as the test impact degree. Generally speaking, high-quality data has a positive impact on high-quality test samples. Therefore, based on the test impact degree corresponding to each training sample subset, at least one high-quality target training sample subset can be selected from multiple training sample subsets.

[0055] Based on this, for a high-quality subset of target training samples, the target training samples contained therein are clustered and sampled according to the sample gradient to ensure that the samples in the obtained sample set have diversity.

[0056] In summary, unlike the dataset quality judgment methods in related technologies, the code review method in this application does not require separate training of the evaluation model. Instead, it is achieved through two parts: high-quality data selection based on influence and diverse data selection based on gradient clustering. This ensures that the final sample set is high-quality and highly diverse training data. Therefore, the code review model trained again based on this training data can perform code reviews more accurately and generate more accurate review information.

[0057] Other features and advantages of this application will be set forth in the following description and will be apparent in part from the description or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description

[0058] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments of this application and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0059] Figure 1 This is a schematic diagram of an application scenario in an embodiment of this application;

[0060] Figure 2 A flowchart illustrating the implementation of a code review method provided in this application embodiment;

[0061] Figure 3 This is a schematic diagram illustrating the calculation logic of the influence of a training sample subset on a test sample set in an embodiment of this application.

[0062] Figure 4 This is a schematic diagram illustrating the construction logic of a sampling sample set in one embodiment of this application;

[0063] Figure 5 This is a schematic diagram of a filtering logic for high-quality, highly diverse data in an embodiment of this application;

[0064] Figure 6 A flowchart illustrating the implementation of yet another code review method provided in this application embodiment;

[0065] Figure 7A This is a schematic diagram of a target code review model in an embodiment of this application;

[0066] Figure 7B This is a schematic diagram of a verification model in an embodiment of this application;

[0067] Figure 8 This is a schematic diagram of the processing logic of a code review system in an embodiment of this application;

[0068] Figure 9A This is a schematic diagram of a Prompt model in one embodiment of this application;

[0069] Figure 9B This is a schematic diagram of another model, Prompt, in the embodiments of this application;

[0070] Figure 10 This is a logical diagram illustrating a review information filtering method in an embodiment of this application.

[0071] Figure 11 This is a flowchart illustrating a specific implementation of a code review method in this application.

[0072] Figure 12 This is a schematic diagram illustrating the interaction logic between a terminal device and a server in one embodiment of this application;

[0073] Figure 13 This is a schematic diagram of the composition structure of a code review device according to an embodiment of this application;

[0074] Figure 14 This is a schematic diagram of the hardware structure of an electronic device using an embodiment of this application;

[0075] Figure 15 This is a schematic diagram of the hardware structure of another electronic device using an embodiment of this application. Detailed Implementation

[0076] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings of the embodiments of this application. Obviously, the described embodiments are only some embodiments of the technical solutions of this application, and not all embodiments. Based on the embodiments recorded in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the technical solutions of this application.

[0077] The following describes some of the concepts involved in the embodiments of this application.

[0078] 1. Language instructions and code:

[0079] Language instructions refer to a series of specific guidelines or commands given by coders or programmers to complete a particular task. They provide coders with clear tasks and goals, ensuring the code is written in the right direction. These instructions can be verbal, written, or communicated through some form of documentation, and typically include, but are not limited to, the following: Task description: the function to be implemented or the problem to be solved; Technical requirements: the programming language, framework, library, etc. to be used; Quality standards: code style, performance requirements, security requirements, etc.; Time constraints: the deadline for completing the task, thereby guiding coders to write code that meets project requirements.

[0080] Code refers to a specific program or script written according to the instructions in the aforementioned language. Code is a set of instructions that a computer can execute, usually written in a programming language. Code implements the functions described in the instructions or solves the problems raised in the instructions.

[0081] In this embodiment, the relationship between language instructions and code is one of guidance and implementation. Language instructions provide coders with clear tasks and goals, while code is the concrete implementation of these tasks and goals. Through language instructions, coders can ensure that their work meets the requirements and standards of the project, while through code, the project's requirements are specified and implemented.

[0082] 2. Code review and review information:

[0083] Code review is a process of improving code quality by reviewing existing code, typically implemented in a team's development process. CR requires team members to consciously and systematically check each other's code to verify requirements, identify errors, and point out non-compliant "low-quality" code, thereby improving the team's overall code quality.

[0084] Review information, also known as review comments, refers to the specific feedback and suggestions provided by reviewers to the reviewed code during the code review process. This feedback is used to ensure the quality and compliance of the code. This information typically includes evaluations of the code's logic, structure, style, performance, etc., as well as pointing out existing problems and providing suggestions for improvement. The aim is to help developers improve code quality and ensure that the code conforms to project specifications and requirements.

[0085] 3. Large Language Model (LLM): A deep learning algorithm capable of performing various Natural Language Processing (NLP) tasks. Large language models typically use multiple transformer models and are trained on massive datasets, resulting in a very large scale. This is the powerful foundation for their ability to recognize, translate, predict, or generate text or other content. The code review and validation models in this application can be considered large language models.

[0086] 4. Sample gradient: This refers to the gradient vector of the loss function with respect to the model parameters on a specific sample. Specifically, for a single sample z... i Loss function L(z) i ;θ) is the gradient vector of the model parameter θ This represents the direction and rate of change of the function value at that sample point. Specifically, the gradient of a function at a point is a vector with both direction and magnitude. Its direction points to the direction in which the function value increases the most, i.e., the direction of the maximum directional derivative. Its magnitude represents the maximum rate of change in that direction; that is, the magnitude of the gradient is the value of the maximum directional derivative. The sample gradient is used to guide parameter updates during optimization to minimize the loss function.

[0087] 5. Intermediate Layer Activation Values: These refer to the output values ​​obtained after the activation functions of neurons in each intermediate layer (hidden layer) of a neural network. This is a type of intermediate layer result described in this application. During the forward propagation of a neural network, the input data undergoes a series of linear transformations and non-linear activation functions to ultimately obtain the output result. The activation values ​​of the intermediate layer network can be seen as the representation of the input data in the neural network, containing the feature information of the input data after network learning and processing. These activation values ​​can be used for subsequent tasks such as feature extraction, classification, and regression.

[0088] 6. Logits are the raw scores of the model's output layer before they have been processed by activation functions such as softmax or sigmoid. These scores represent the model's raw confidence in each category and have not yet been normalized to probability values. Logits preserve the model's raw output information.

[0089] 7. Maximum Mutual Information (MMI): In natural language processing, this is an optimization criterion that aims to explore the correlation between two random variables by maximizing the mutual information between them. Mutual information I(X;Y) measures the amount of information shared between two random variables (X) and (Y), i.e., the degree to which knowing the value of one variable reduces the uncertainty about the other. MMI enhances the model's ability to capture correlations by optimizing the objective function maxI(X;Y), thereby improving the model's performance and robustness. It focuses on maximizing the dependency between input and output.

[0090] 8. Maximum Likelihood Estimation (MLE): This is a statistical method used to estimate model parameters that maximize the probability of observed data occurring. Specifically, given a set of observed data, MLE finds the optimal parameters by maximizing the likelihood function, focusing on maximizing the likelihood of the observed data.

[0091] The design concept of the embodiments of this application will be briefly described below:

[0092] When fine-tuning instructions, the quality and diversity of the dataset have a significant impact on the final performance of the model. Traditional data selection methods often rely on additional models or external evaluation metrics, which may diminish the model's potential. Therefore, how to efficiently select high-quality and highly diverse training data has become an important research topic.

[0093] Furthermore, traditional model inference result selection schemes typically involve fully training the model on a training set, then, given an input, obtaining multiple results through sampling methods, such as random sampling or temperature-adjusted sampling. The output results are then sorted according to their probability values, and the output with the highest probability value is selected as the final result. While this approach is widely used, it also has some problems, as follows:

[0094] (1) It has certain limitations:

[0095] The probability values ​​of a model's output are not always proportional to the quality of the output. A high-probability output may simply reflect a common pattern that the model tends to generate, rather than necessarily the best result. Furthermore, relying on probability ranking can lead to a lack of diversity in the generated code snippets, limiting the potential for innovation and optimization.

[0096] (2) Degradation scheme:

[0097] Reordering model outputs based on probability values ​​can cause the model to tend to choose degenerate solutions. For example, inference results obtained using greedy decoding or beam search methods often favor high-probability but low-quality outputs, which may result in a lack of diversity and originality in the model's generated results.

[0098] Specifically, when using greedy decoding, choosing the next word with the highest probability each time can easily lead to local optima, resulting in a lack of diversity in the generated text. While beam search is more flexible than greedy decoding, it may still be biased towards patterns that the model has already seen, leading to overly conservative generated text.

[0099] In view of this, embodiments of this application propose a code review method, apparatus, electronic device, and storage medium. This application performs quality screening and diversity detection on training data based on gradient values, and trains the code review model using the resulting high-quality, highly diverse samples to improve the accuracy of the model's generated code review information.

[0100] Specifically, this application first constructs a test sample set that meets the expected quality. After initial training of the code review model to be trained based on the training sample set, the influence of each training sample subset on the performance change of the model on the test sample set can be evaluated according to the multiple training sample subsets obtained by dividing the training sample set. This influence is denoted as the test impact degree. Generally speaking, high-quality data has a positive impact on high-quality test samples. Therefore, based on the test impact degree corresponding to each training sample subset, at least one high-quality target training sample subset can be selected from multiple training sample subsets.

[0101] Based on this, for a high-quality subset of target training samples, the target training samples contained therein are clustered and sampled according to the sample gradient to ensure that the samples in the obtained sample set have diversity.

[0102] In summary, by using the influence-based screening and gradient-based clustering and sampling methods described above, we ensure that the final sample set is high-quality and highly diverse training data. Therefore, the code review model trained again based on this training data can perform code reviews more accurately and generate more accurate review information.

[0103] Furthermore, this application proposes a code review technology applicable to online environments. The target code review model in this paper can be deployed online. After deployment, the object can use the review information automatically generated by the target code review model. However, at this time, the result is not directly presented to the object. Instead, one or more verification models are used to further verify the review information output by the trained code review model to ensure that the verification is passed before presenting the review information to the object. This verification process utilizes the idea of ​​maximum mutual information to fully guarantee the accuracy of the review information and improve the object's experience.

[0104] The preferred embodiments of this application are described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit this application. Furthermore, the embodiments and features in the embodiments of this application can be combined with each other without conflict.

[0105] like Figure 1 The diagram shown illustrates an application scenario in an embodiment of this application. The application scenario diagram includes a terminal device 110 and a server 120.

[0106] In this embodiment, the terminal device 110 includes, but is not limited to, mobile phones, tablets, laptops, desktop computers, e-book readers, smart voice interaction devices, smart home appliances, and in-vehicle terminals. The terminal device may have a client installed related to code review. This client can be software (e.g., a browser, code review software), a webpage, or a mini-program. The server 120 is the backend server corresponding to the software, webpage, or mini-program, or a server specifically used for code review; this application does not impose specific limitations. The server 120 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0107] It should be noted that the code review method in each embodiment of this application can be executed by an electronic device, which can be a terminal device 110 or a server 120. That is, the method can be executed by the terminal device 110 or the server 120 alone, or by the terminal device 110 and the server 120 together.

[0108] In one alternative implementation, the terminal device 110 and the server 120 can communicate via a communication network.

[0109] In one alternative implementation, the communication network is a wired network or a wireless network.

[0110] It should be noted that, Figure 1 The examples shown are merely illustrative; in reality, the number of terminal devices and servers is unlimited and is not specifically limited in the embodiments of this application.

[0111] In this embodiment of the application, when there are multiple servers, the multiple servers can form a blockchain, and the servers are nodes on the blockchain; as disclosed in the code review method of this embodiment, the relevant data involved can be stored on the blockchain, such as various samples, model parameters, code, review information, etc.

[0112] Furthermore, the embodiments of this application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, and assisted driving. Specifically, they involve some scenarios in the software development process under these scenarios, some of which are briefly listed below:

[0113] (I) New Feature Development:

[0114] Once a team member has completed coding for a new feature, other team members will review the code to check if it conforms to the project's technical specifications, if the logic is correct, and if there is room for optimization. This helps ensure a high-quality implementation of the new feature and reduces subsequent maintenance costs.

[0115] (II) Bug Fixes:

[0116] Once a bug or defect is discovered in the software, developers write a fix. Code review verifies the effectiveness and safety of the fix, while also checking for the risk of introducing new problems. This process helps improve the stability and security of the software.

[0117] (III) Code Refactoring:

[0118] To improve existing code structure, enhance performance, or adapt to new technology standards, teams may refactor parts of their code. In such cases, code reviews can help identify any issues that might have been missed during the refactoring process, ensuring that the refactored code is more robust, easier to understand, and easier to maintain.

[0119] (iv) Technology Debt Management:

[0120] Long-term accumulated technical debt (such as inefficient code resulting from rapid development, outdated technology stacks, etc.) can affect the sustainable development of a project. Regular code reviews can help identify and address this technical debt in a timely manner, preventing larger problems from arising in the future.

[0121] (V) Newcomer Training and Integration:

[0122] For new members who have just joined the team, participating in code reviews can not only help them quickly understand the project's technical architecture and coding standards, but also promote communication and cooperation with other members, accelerating their integration into the team.

[0123] Code review is an important part of software development to ensure code quality, promote team collaboration and knowledge sharing. The application scenarios listed above are just simple examples. Other code review scenarios are also applicable to the embodiments of this application, and will not be elaborated on here.

[0124] The code review method provided by the exemplary embodiments of this application will be described below with reference to the accompanying drawings and the application scenarios described above. It should be noted that the application scenarios described above are only shown to facilitate understanding of the spirit and principles of this application, and the embodiments of this application are not limited in any way in this respect.

[0125] See Figure 2 The diagram shown is an implementation flowchart of a code review method provided in this application embodiment. Taking the server as the execution subject as an example, the specific implementation flow of the method is as follows: S21 to S24:

[0126] S21: Obtain the training sample set and the test sample set, and divide the training sample set into multiple training sample subsets; the test sample set contains test samples that achieve the expected quality.

[0127] For a code review model, the input is code and language instructions, and the output is review information. The model's samples include sample code, sample language instructions, and may also include real review information as sample labels. Specifically, this refers to the real review information specific to the sample code, which can also be called real labels in this paper.

[0128] In this embodiment of the application, the samples of the training sample set can be derived from historical review records in the actual software development process, including specific programming task descriptions (which can be recorded as sample language instructions), corresponding code implementations (which can be recorded as sample code), and review comments given by experienced reviewers (which can be recorded as labeled real review information).

[0129] Specifically, these samples can be obtained through manual annotation, such as by experienced developers manually reviewing the code and providing detailed review comments to form high-quality sample code, language instructions, and review information; or by using existing code review records in the project to extract code snippets, review instructions, and review results as samples; in addition, more samples can be generated by combining a small number of manually annotated high-quality samples with a large amount of unannotated code data through semi-supervised learning methods, etc. This paper does not make specific limitations on this.

[0130] In this application embodiment, a test sample that achieves the expected quality specifically refers to a test sample that can be rated as high quality. For code review tasks, if a sample makes the code review model more likely to output high-quality review opinions, then the sample can be considered high quality. Such samples can be selected by manual evaluation or by automatic scoring based on some evaluation rules, and then selected based on the scores.

[0131] Specifically, sample quality can be assessed from the following aspects:

[0132] Evaluation Focus 1: Code. Specifically, this includes considering the code's logic, syntax correctness, redundancy, style consistency, readability, and performance. For example, assessing whether the code logic is clear and reasonable, whether there are logical errors or unreasonable designs, whether it conforms to the language's syntax rules (no syntax errors), whether it is concise, without unnecessary repetition or redundancy, whether it follows the project's coding standards and style guidelines, and whether it is easy to understand.

[0133] Evaluation Direction Two: Review Information. Specifically, consider the diversity and depth of the review information. For example, determine whether the review information is comprehensive, covering all aspects of the code, including but not limited to logical correctness, performance optimization, security vulnerabilities, coding style, and maintainability. Also consider whether specific improvement suggestions are provided to ensure the review results have both breadth and depth.

[0134] Evaluation Direction 3: Language Instructions. Specifically, consider the clarity, explicitness, completeness, professionalism, guidance, and adaptability of language instructions. For example, assess whether the language instructions are clearly expressed, have a clear intent, avoid ambiguity, provide sufficient contextual information for model understanding and processing, use correct terminology and industry standards reflecting an understanding of specific domain knowledge, include specific requirements for the model's output (e.g., what feedback is desired, whether improvement suggestions are needed), and whether they can adapt to changing needs in different scenarios.

[0135] In this embodiment, high-quality samples should possess characteristics such as clear logic, correct syntax, conciseness without redundancy, and comprehensive, specific, and constructive review information, providing multifaceted improvement suggestions. Such samples can effectively improve the accuracy and generalization ability of the model.

[0136] In practical applications, based on the above rules, a portion of high-quality code CR seeds can be manually compiled to form a seed set (i.e., the test sample set in this article) as a standard for evaluating high-quality training data. In addition, based on the above rules, automatic evaluation can also be performed. When performing automatic evaluation, the samples can be scored according to the above-mentioned directions. Taking a 5-point system as an example, for the diversity of review information, the scoring criteria can be: 1 point indicates that the review information is singular and lacks diversity; 3 points indicate that the review information covers some aspects and has a certain degree of diversity; 5 points indicate that the review information is comprehensive and covers multiple aspects such as logic, performance, and security. Similarly, a similar scoring mechanism is used for other directions to obtain individual scores for each aspect.

[0137] These individual scores ultimately yield a total score for a sample. A score of 4 points or higher is considered high-quality; alternatively, a sample is considered high-quality if all individual scores are at least 3 points and at least one score is 5 points. This multi-dimensional scoring system allows for a more comprehensive evaluation of sample quality, ensuring that high-quality samples are used to train the code review model, thereby improving the model's accuracy and generalization ability.

[0138] Considering that high-quality data generally has a positive impact on high-quality test samples, a small portion of high-quality test samples can be constructed as seed data using the above method. The quality of the training samples is then evaluated based on the model's performance on the seed set, and high-quality training samples that have a positive impact on the seed data are selected. In actual dataset selection, generally only 256 samples are used to form the test sample set to achieve the desired effect. When dividing the training sample subset, this data can be referenced, and the subset can be divided according to a certain sample ratio. For example, considering that non-high-quality data generally accounts for a large proportion, this application can set the sample ratio between the training sample subset and the test sample set to 10:1 or more to ensure that the selection results are accurate enough.

[0139] Based on the above, the specific sample selection method is as follows:

[0140] S22: After the code review model to be trained is initially trained based on the training sample set, the test impact of each training sample subset on the code review model is determined. The test impact reflects the influence of the training sample subset on the performance change of the code review model on the test sample set.

[0141] In constructing the code review model, a natural language model can be chosen as the foundation. This natural language model can include an initial network model, which can be pre-trained using large-scale text data to obtain the code review model to be trained in this application. Based on this, fine-tuning can be performed using dedicated samples to obtain the pre-trained code review model. The initial network model can include, but is not limited to, the following types: Recurrent Neural Network (RNN) model, Long Short-Term Memory (LSTM) model, Transformer model, etc. The specific model chosen depends on actual needs and resource availability; this paper does not impose specific limitations.

[0142] In practical implementation, a large number of unlabeled samples, such as web pages, books, and articles, can be used to perform unsupervised learning on the initial network model. The goal of pre-training is usually an Autoregressive Language Model (ARLM), which predicts the probability distribution of the (N+1)th word given the first N words of a text sequence. Through this unsupervised learning, the model can master the underlying knowledge of natural language, such as vocabulary, grammar, and sentence structure. Furthermore, in the fine-tuning training phase, samples specific to software engineering disciplines and software methodologies can be obtained. These samples include the sample language instructions, sample code, and their annotated real review information listed above. By performing supervised training on these samples, the model can acquire the ability to review software code and ultimately output the corresponding review information.

[0143] Specifically, in this embodiment, for the code review model, the model parameters can be denoted as θ, and the model parameters after initial training can be denoted as θ*. θ* represents the optimal parameters of the code review model after initial training and fine-tuning on the training sample set, which can be obtained by minimizing the loss function of the code review model, as shown in Formula 1 below:

[0144]

[0145] Where θ represents the model parameters, θ * This represents the optimal parameters after initial training and fine-tuning, z. i =(x i ,y i Let represent the i-th sample pair in the training sample set, where xi represents the input of the code review model, yi represents the output of the code review model, and n represents the total number of samples in the training sample set.

[0146] Optionally, the loss of the code review model can be calculated only for the response portion, and the loss function is calculated as shown in Formula 2 below:

[0147]

[0148] Among them, y j Let y represent the j-th token in y. <j This refers to all the tokens preceding the j-th token in y. When y represents review information, in the code review model, the review information is usually output as text token by token, and each token can be a word, punctuation mark, or special character.

[0149] For example, review message y is "The logic of this code is clear, but the variable names could be more descriptive.", which contains a total of 15 tokens (2 punctuation marks and 13 words), and the specific division method is as follows:

[0150] ["this", "segment", "code", "of", "logic", "clear", ", "but", "variable", "naming", "can", "more", "have", "descriptive", "."]

[0151] Referring to Formula 2, the loss function of the code review model will calculate the loss for each token separately. Starting with the first token, the loss for each token will be calculated sequentially. For example, the loss for the first token "this" will be calculated, followed by the loss for the second token "segment", and so on, until the loss for the last token ".". In actual calculations, if supervised training is used, when calculating the loss for each token in Formula 2, it is necessary to calculate the difference between the review information generated by the model and the corresponding token in the actual review information (not directly shown in Formula 2).

[0152] This token-by-token loss calculation method helps the model gradually generate complete review information while ensuring that the generated content has good syntactic structure and semantic coherence. By continuously adjusting and optimizing the generation of each token, the model can gradually improve the overall quality and usability of the review information, thereby better serving the purpose of code review.

[0153] In this embodiment, for the code review model, the response refers to the review information generated by the model. The loss is calculated only for the response, indicating that the model's training focuses on optimizing the quality of the generated review comments, ensuring they are accurate, relevant, and useful, rather than focusing too much on the direct optimization of the input encoding or other internal states. Specifically, during calculation, only the difference between the model-generated review information and the actual review information needs to be considered. This ensures that the model continuously optimizes its generated review information during training to get as close to the actual labels as possible, enabling the model to learn to generate accurate review information and directly improve its review capabilities.

[0154] In the embodiments of this application, the loss function of the code review model can be the cross-entropy loss function or the mean squared error loss function. Using these loss functions can effectively guide the model to learn how to generate accurate review information. Of course, other loss functions can also be used, and this article does not make specific limitations on them.

[0155] After initial training of the code review model, high-quality training samples can be selected based on high-quality test samples. Specifically, when selecting high-quality training samples based on high-quality test samples, it is necessary to consider which training samples have a positive impact on the high-quality test samples. This application uses the idea of ​​an influence equation to analyze the degree of influence of training samples on high-quality test samples, thereby selecting training samples with a positive impact.

[0156] The influence function (IF), also known as the influence equation, is a statistical tool used to evaluate the impact of a single data point on model parameters and prediction results. Samples with high IF values ​​typically have a greater positive impact on model performance. Specifically, the IF describes how the model parameter estimates change when a new observation is added to the dataset. Mathematically, the IF is defined as the rate of change of the model estimates over a dataset containing the new data point.

[0157] This application, referencing this idea, proposes a method for calculating the impact of a subset of training samples on the performance changes of a code review model on a test sample set.

[0158] Specifically, the influence of the training sample set on the test sample set is quantified by referring to the Influence Function. The main method is to divide the training sample set into multiple training sample subsets, calculate the influence of each training sample subset on the test sample set (i.e., the test influence in this paper), and then select high-quality target training sample subsets from multiple training sample subsets based on this parameter.

[0159] See Figure 3 The diagram illustrates the calculation logic of the influence of a training sample subset on the test sample set in an embodiment of this application. Specifically, in this calculation process, the training sample set is first divided into subsets, such as... Figure 3 The training sample subsets 1, 2, 3, and 4 shown are used to initially train the code review model to be trained.

[0160] In actual dataset screening, to improve computational efficiency, the code review model can be replicated multiple times, with each model corresponding to a subset of training samples. Based on this, the influence of each training sample subset on the test sample set (i.e., the test influence in this paper) can be calculated in parallel, which helps improve the efficiency of sample screening. Of course, a similar approach can be used when initially training the code review model based on the training sample set, which will not be repeated here.

[0161] Then, the influence of each training sample subset on the test sample set can be calculated separately. This influence provides a quantitative assessment of the impact on the samples, increases the interpretability of the model, and high-quality sample selection is carried out based on this result.

[0162] The following is a detailed explanation of the process of selecting high-quality samples based on impact:

[0163] In this embodiment of the application, an optional method for calculating the influence of training samples on test samples is as follows:

[0164] First, determine the Hessian matrix of the loss function of the code review model, the first gradient vector corresponding to each training sample subset, and the second gradient vector corresponding to the test sample set.

[0165] In this embodiment, the first gradient vector refers to the gradient vector of the loss function of the code review model with respect to the model parameters for a subset of training samples, and the second gradient vector refers to the gradient vector of the loss function of the code review model with respect to the model parameters for a set of test samples. The first and second gradient vectors are determined by combining the gradient vectors of each sample (training or testing sample) in the corresponding set. The gradient vector of each sample refers to the gradient vector of the loss function of the code review model with respect to the model parameters for that sample, reflecting the degree of influence of that sample's data point on the update of the model parameters.

[0166] Given the loss function, the Hessian matrix is ​​a matrix composed of the second-order partial derivatives of the loss function with respect to the model parameters, used to describe the curvature of the loss function. In this paper, the Hessian matrix is ​​the loss function with respect to the model parameters θ.* The matrix can be denoted as Where θ * It refers to the model parameters obtained after the code review model (with model parameters θ) is initially trained.

[0167] The specific steps for calculating the Hessian matrix are as follows:

[0168] First, calculate the first-order partial derivatives of the loss function with respect to each model parameter. Then, differentiate each first-order partial derivative again to obtain the second-order partial derivatives. Finally, combine all the second-order partial derivatives into a matrix, which is the Hessian matrix. The Hessian matrix is ​​used in second-order optimization methods, such as Newton's method, to provide information about the curvature of the loss function, which helps to achieve faster convergence.

[0169] For the training sample subset and the test sample set, the gradient vector of the sample set is determined by combining the gradient vectors of all samples in the set. Specifically, it can be the sum of the gradient vectors of these samples, or the mean of the gradient vectors of these samples, etc. This paper does not make any specific restrictions on this.

[0170] The gradient vector for each sample refers to the gradient vector of the loss function with respect to the model parameters on that sample. The specific calculation steps are as follows:

[0171] First, the sample is input into the code review model and forward propagation is performed to obtain the model's output. Then, based on the model's output and the true label, the loss function is calculated; the specific calculation method will not be repeated here. Next, the gradient of the loss function with respect to the model parameters is calculated using the backpropagation algorithm, yielding the gradient vector corresponding to the sample.

[0172] Based on the above data, for each training sample subset, the test influence corresponding to that training sample subset can be determined according to the first gradient vector, Hessian matrix, and second gradient vector.

[0173] Specifically, the first gradient vector reflects the trend of the loss function on the training sample subset, and is the gradient calculated on the training sample subset, i.e., the first derivative of the loss function with respect to the model parameters on the training sample subset; the second gradient vector reflects the trend of the loss function on the test sample set, and is calculated on the test sample set, i.e., the first derivative of the loss function with respect to the model parameters on the test sample set; while the Hessian matrix describes the curvature information of the loss function, i.e., the second partial derivatives between the parameters. Through these data, the influence of the training sample subset on the performance changes of the code review model on the test sample set can be evaluated.

[0174] In the above implementation, by analyzing these mathematical features, the importance of each training sample subset can be quantified. This process helps to identify key samples that contribute significantly to model training or affect model performance, thereby optimizing the training set and improving the model's generalization ability and stability.

[0175] Optionally, both the first and second gradient vectors are d-dimensional column vectors, and the Hessian matrix is ​​a d×d matrix. Based on this, when determining the test influence of a training sample subset on the test sample set using the first gradient vector, Hessian matrix, and second gradient vector corresponding to that subset, the negative of the product of the transpose of the second gradient vector, the inverse of the Hessian matrix, and the first gradient vector corresponding to that training sample subset can be used as the influence of that training sample subset on the code review model's performance on the test sample set, i.e., the test influence. The specific calculation method is as follows:

[0176] The transpose of the second gradient vector corresponding to the test sample set is multiplied by the inverse of the Hessian matrix to obtain an intermediate vector. This intermediate vector is then multiplied by the inner product of the first gradient vector corresponding to the training sample subset to obtain an intermediate scalar. Finally, the negative of this intermediate scalar is used as the test influence of the training sample subset.

[0177] The above calculation method can be expressed by the following formula 3. After the model is trained on the training sample set, the model parameters are updated from θ to θ * Given a subset of training samples z m In the test sample set z t The evaluation process is as follows: Formula 3:

[0178]

[0179] Where, θ * This represents the optimal parameters of the code review model after initial training and fine-tuning using the training sample set. That is, the test sample set z t The corresponding second gradient vector, where T represents the transpose; This represents the inverse of the aforementioned Hessian matrix; That is, the intermediate vector in this article is a d-dimensional row vector; That is, the training sample subset z m The corresponding first gradient vector is a d-dimensional column vector; This refers to the intermediate scalar in this paper; L(z) m , z t That is, the training sample subset z m For the test sample set z t The impact of the test.

[0180] The above implementation method, by utilizing the inverse of the Hessian matrix and the gradient information of the samples, can accurately capture how small changes in the training samples affect the prediction of the test samples. This helps to identify key training samples, optimize model performance, and improve the robustness and generalization ability of the model.

[0181] When processing large-scale datasets, directly calculating the gradient for each sample is inefficient. To improve efficiency and reduce computational costs, this application proposes a gradient approximation method to calculate the gradient vector. In other words, one possible implementation is as follows:

[0182] The sample gradient is calculated based on the intermediate layer results output by the model. Specifically, when calculating the first gradient vector, the second gradient vector, etc., the gradient vector of each sample is determined based on the intermediate layer results of the code review model.

[0183] The intermediate layers refer to all layers located between the model's input and output layers. They are responsible for progressively transforming the input data and extracting features. These layers typically have lower dimensionality, making gradient computation less costly.

[0184] Taking the code review model as an example of a large language model, a large language model generally includes an embedding layer, an encoder layer, a decoder layer, an output layer, a normalization layer, etc. In this approach, certain intermediate layers in the code review model are selected to calculate gradients, such as the encoder layer or the decoder layer, etc., without making specific limitations here.

[0185] For example, in calculating the first gradient vector in Equation 3 above At this time, it is necessary to first calculate the training sample subset z. m The gradient vector of each training sample is obtained by averaging the gradient vectors of these training samples. For each training sample, during this calculation process, the gradient vector of the training sample can be calculated based on the decoder layer activation value output by the code review model after the training sample is input into the code review model.

[0186] Similarly, in calculating the second gradient vector in Equation 3 above... At this time, it is necessary to first calculate the test sample set z. t The gradient vector of each test sample is obtained by averaging the gradient vectors of these test samples. For each test sample, during this calculation process, the gradient vector of the test sample can be calculated based on the decoder layer activation value output by the code review model after the test sample is input into the code review model.

[0187] In addition, considering that the code review model in this application adopts a token-by-token output method when predicting review information, when calculating the gradient vector of a training sample or test sample, forward and backward propagation can be performed on the selected intermediate layer output to calculate the gradient of each token or feature of the intermediate layer output for that sample. The calculated gradients are then aggregated, for example, by taking the average, maximum, or weighted average, to finally obtain the gradient vector of that sample.

[0188] In this way, gradient vectors for each sample can be generated. These vectors not only reflect the impact of the sample on the model's loss function, but also take into account the contribution of each token in the sample, thus more comprehensively representing the characteristics of the sample.

[0189] In the above implementation, the gradient is calculated by selecting the results of the middle layers of the model. The dimensionality of the middle layers is usually lower, and the cost of calculating the gradient is lower. Compared with calculating the gradient based on the results of the output layer, it can accelerate the data processing speed. In addition, by using gradient approximation, the diversity of training data can be increased, thereby improving the generalization ability of the model.

[0190] Based on this, high-quality training samples can be selected according to the test impact, and the diversity of training samples can be further improved by gradient clustering and sampling. The specific implementation method is as follows:

[0191] S23: For at least one target training sample subset in multiple training sample subsets, the test influence degree meets the preset influence condition, and cluster them according to the sample gradient to obtain multiple clusters.

[0192] In step S23, the first step is to select a subset of target training samples that meet the preset influence conditions. The preset influence conditions refer to the specific criteria used to select the subset of training samples. These criteria can be a size condition related to the numerical value of the test influence, such as the test influence falling within a specific range, exceeding a certain threshold, ranking high, having small fluctuations, or meeting the requirements after weighting.

[0193] Based on step S22, the test influence of each training sample subset on the test sample set can be calculated. Then, the target training sample subset can be selected from multiple training sample subsets using at least one of the following methods:

[0194] Screening Method 1: Select the N training sample subsets with the largest values ​​among the determined test influence values ​​as the target training sample subset, where N is a positive integer greater than or equal to 1.

[0195] If N=1, it means that the training sample subset corresponding to the largest test influence among all test influences will be used as the target training sample subset, that is, only one subset will be selected.

[0196] If N=2, it means that the training sample subsets corresponding to the two largest test influence values ​​among all test influence values ​​will be used as the target training sample subsets, that is, two subsets will be selected.

[0197] If N=3, it means that the training sample subsets corresponding to the three largest test influence values ​​among all test influence values ​​will be used as the target training sample subsets, that is, three subsets will be selected.

[0198] Of course, N can take other values, and so on. In the embodiments of this application, the value of N can be flexibly set according to actual needs, computing resources, etc., which will not be elaborated here.

[0199] Screening Method 2: Select the subset of training samples that reach the preset influence threshold as the target training sample subset.

[0200] In this embodiment, the preset influence threshold can also be flexibly set according to actual needs, computing resources, etc., which will not be elaborated here.

[0201] Suppose we have a training sample set containing 1000 training samples, which are divided into 5 training sample subsets, each containing 200 training samples. In addition, there is a separate test sample set containing 20 test samples (this is just a simple example; the actual sample data volume may be larger).

[0202] First, a code review model can be trained using each training sample subset. Based on this, the test impact corresponding to each training sample subset is calculated. Let's assume that the test impact corresponding to these 5 training sample subsets are denoted as L1, L2, L3, L4, and L5, respectively.

[0203] Assuming the selection is done according to method one, N=2, and the order of influence of these tests is: L4>L2>L5>L1>L3, then the target training sample subsets are subset 4 and subset 2.

[0204] Assuming the selection is carried out according to the second selection method, the preset influence threshold is Lth, and L4 > Lth > L2 > L5 > L1 > L3, then the target training sample subset is subset 4.

[0205] Of course, the two screening methods mentioned above can also be used in combination, that is, the top N corresponding training sample subsets with the largest values ​​among the determined test influence values, all of which reach the preset influence value threshold, are used as the target training sample subset.

[0206] Suppose there are 10 training sample subsets, and their corresponding test influence values ​​are denoted as L1, L2, L3, L4, L5, L6, L7, L8, L9, and L10, respectively, N=3, and the order of these test influence values ​​is: L4>L7>L2>L10>L5>L6>L1=L10>L8>L9>L3. Then the target training sample subsets are subset 4, subset 7, and subset 2.

[0207] In addition to the screening criteria mentioned above, preset influence conditions can also include various other conditions to more flexibly select the target training sample subset. For example, selecting a training sample subset whose test influence is higher than a certain percentage (e.g., the top 10%) of the test influence of all training sample subsets; selecting a training sample subset whose weighted test influence value meets specific conditions (e.g., selecting a training sample subset whose weighted test influence value is greater than a certain threshold); selecting a training sample subset whose test influence is both within a specific range and higher than a certain threshold (e.g., selecting a training sample subset whose test influence is between 0.3 and 0.7 and higher than 0.5); selecting a training sample subset that performs well on multiple targets (e.g., test influence, sample diversity, training time); or a combination of multiple conditions (e.g., selecting a training sample subset whose test influence is higher than a certain threshold and whose sample diversity is higher than another threshold), etc. This paper does not make specific limitations on these.

[0208] Furthermore, if the above methods fail to select a suitable subset of target training samples, or if the selection method does not yield a sufficient subset of target training samples, the training sample subset can be re-divided, and the above process can be repeated until a suitable subset of target training samples is selected.

[0209] By using the above screening methods and these diverse preset influence conditions, we can more flexibly select the target training sample subset and effectively screen out the target training sample subset that has a significant positive impact on the test sample set from multiple training sample subsets. This method can not only improve the performance and generalization ability of the model, but also save computing resources, optimize the training process, reduce the risk of overfitting, and improve the interpretability and interpretability of the model. These beneficial effects work together to make the model more reliable and effective in practical applications.

[0210] In this embodiment of the application, the target training sample subset selected by the above method belongs to high-quality training data. On this basis, in order to ensure the richness of the review comments, gradient approximation can also be used to evaluate the diversity of the data. It is believed that the data that have an approximate impact on the model can be divided into one category, that is, gradient clustering. Then, sampling is performed from the clustering results, and finally a high-quality and highly diverse sample set is constructed.

[0211] In this application embodiment, an optional clustering method is as follows:

[0212] First, for each target training sample in at least one subset of target training samples, determine the third gradient vector for each target training sample. The third gradient vector for each target training sample refers to the gradient vector of the loss function of the code review model with respect to the model parameters for that target training sample. This gradient vector can also be determined using the intermediate layer results of the code review model. The specific calculation steps are as follows:

[0213] First, the target training sample is input into the code review model for forward propagation to obtain the model's output. Then, based on the model's output and the true labels, the loss function is calculated; the specific calculation method will not be repeated here. Next, the gradient of the loss function with respect to the model parameters is calculated using the backpropagation algorithm, yielding the gradient vector corresponding to the target training sample, denoted as the third gradient vector.

[0214] Optionally, when calculating the third gradient vector, the model output can also be an intermediate layer result (such as the activation value of an intermediate layer), as detailed in the above embodiments, which will not be repeated here.

[0215] It should be noted that in the process of calculating the test influence, it is also necessary to calculate the gradient vector of the sample. The target training sample in this step is a part of the above sample. Therefore, in this step, the relevant results calculated in the above process can be directly used as the third gradient vector of the corresponding target training sample, without repeating the calculation, so as to improve the calculation efficiency.

[0216] After determining the third gradient vector of each target training sample, these target training samples can be clustered according to the distance between the determined third gradient vectors to obtain multiple clusters.

[0217] Specifically, a distance metric (such as Euclidean distance, cosine similarity, etc.) can be used to calculate the distance between each third gradient vector, statistically analyze the differences in distribution between the data, and then, based on the calculated distance, clustering algorithms, such as K-means or density-based spatial clustering of applications with noise (DBSCAN), can be used to cluster the target training samples to obtain multiple clusters.

[0218] Taking the K-means algorithm for clustering as an example, the K-means algorithm is used to cluster data with similar importance. In this application, the gradient values ​​of the model on the dataset are used as the representation of the dataset. The goal is to divide the data points into k clusters, minimizing the distance between data points within each cluster and maximizing the distance between different clusters. During this process, the centroid of each cluster is continuously updated until convergence.

[0219] Assuming k = 1024, meaning we want to obtain 1024 clusters, the specific clustering process is as follows:

[0220] First, 1024 gradient vectors are randomly selected from the set of gradient vectors of the target training samples (composed of each third gradient vector) as initial cluster centers. Then, the distance from the gradient vector of each target training sample to these 1024 initial cluster centers is calculated (using Euclidean distance or cosine similarity), and each sample is assigned to the cluster of the nearest cluster center. Next, the average of the gradient vectors of all samples in each cluster is calculated, and this average is used as the new cluster center. Using the updated cluster centers, the distance from each sample to the new cluster center is recalculated, and the sample is reassigned to the cluster of the nearest cluster center. This process is repeated iteratively until the cluster centers no longer change or a predetermined number of iterations is reached. When the cluster centers are stable or convergence conditions are met, the clustering process ends, resulting in 1024 clusters, where the target training samples within each cluster have similar third gradient vectors.

[0221] This method allows for clustering of target training samples based on the similarity of gradient vectors, leading to a better understanding of the impact of different samples on the model. Ultimately, multiple clusters are obtained, with samples within each cluster sharing similar gradient vectors. This facilitates the analysis and optimization of the model's training process. Furthermore, sampling from different clusters effectively enriches the diversity of the sample data.

[0222] In this embodiment of the application, in order to accelerate the process of data diversification, dimensionality reduction techniques can be used to reduce the dimensionality of the data, thereby reducing the amount of computation. One optional implementation method is as follows:

[0223] Before clustering according to the sample gradient to obtain multiple clusters, perform any of the following operations:

[0224] Dimensionality reduction is performed on each target training sample;

[0225] Alternatively, the third gradient vector of each target training sample can be reduced in dimensionality.

[0226] Of the two operations mentioned above, the first operation is to reduce the dimensionality of the sample, specifically by reducing the dimensionality of the sample features, and the second operation is to reduce the dimensionality of the gradient vector of the sample.

[0227] The specific method of dimensionality reduction is not limited in this paper. For example, random projection or data compression can be used to reduce the dimensionality of the data and reduce the amount of computation. When using random projection for dimensionality reduction, a random matrix can be used to project high-dimensional data into a low-dimensional space. This method is simple and computationally efficient.

[0228] In addition, dimensionality reduction can be achieved through Principal Component Analysis (PCA), which projects the data onto the direction of maximum variance through linear transformation, preserving the main information of the data. Dimensionality reduction can also be performed using methods such as t-Distributed Stochastic Neighbor Embedding (t-SNE), Uniform Manifold Approximation and Projection (UMAP), Locally Linear Embedding (LLE), and Autoencoders. This paper does not limit the specific dimensionality reduction method used; any dimensionality reduction method for samples or gradient vectors is applicable to the embodiments of this application.

[0229] In the above implementation, dimensionality reduction of the target training samples or their third gradient vector can significantly accelerate the data diversification process. Dimensionality reduction techniques such as random projection or PCA can effectively reduce the dimensionality of data, lower computational complexity, and thus speed up the clustering algorithm. This not only improves the efficiency of clustering but also makes it possible to process large-scale datasets. Furthermore, dimensionality reduction can remove redundant information, retain key features, and enhance the stability and accuracy of clustering results. In this way, the impact of different samples on the model can be identified and analyzed more efficiently, optimizing the model training process and improving the model's performance and generalization ability.

[0230] Based on this, sampling can be performed from the clustering results of each cluster to ensure the diversity of training samples. The specific process is as follows:

[0231] S24: Sample each cluster and retrain the pre-trained code review model based on the obtained sample set to obtain the trained target code review model; the target code review model is used to generate review information for the code to be reviewed.

[0232] In the embodiments of this application, these clusters are obtained by gradient clustering of high-quality training samples. Each cluster has similarity and stability. Specifically, samples within the same cluster have similar gradient vectors, and these samples influence the model in similar ways during training, and their performance is relatively consistent across multiple training iterations, which helps to evaluate the stability and robustness of the model. Furthermore, different clusters exhibit diversity; specifically, samples between different clusters show significant gradient differences, reflecting the different impacts of different types of samples on the model.

[0233] Therefore, by sampling these clusters, this application obtains a high-quality and highly diverse training sample set. Furthermore, when sampling within each cluster, uniform sampling can be performed, meaning that the same number of samples are selected from each cluster to form the sampling sample set.

[0234] See Figure 4 As shown, this is a schematic diagram illustrating the construction logic of a sampling sample set in an embodiment of this application. Assuming that in... Figure 3 Based on the above, two target training sample subsets are obtained, denoted as target training sample subset 1 and target training sample subset 2, respectively. Each subset contains a certain number of high-quality training samples. Assuming that these two subsets contain a total of 400 training samples, these 400 training samples can be clustered according to the sample gradient to obtain the following... Figure 4 The three clusters shown are denoted as cluster 1, cluster 2, and cluster 3, respectively. The number of training samples in these clusters may not be the same, which is not a limitation in this paper. The training samples in each cluster are represented by different graphs, indicating that the training samples in the same cluster have a similar impact on the model performance, while the training samples in different clusters have different impacts on the model performance.

[0235] Based on this, after uniformly sampling these clusters to form a sample set, high-quality and highly diverse training data can be obtained. The code review model can be retrained based on this sample set, resulting in better target code review performance.

[0236] Of course, in order to ensure the data diversity of the sample set, in addition to uniform sampling, the following sampling strategies can also be adopted:

[0237] Strategy 1: Proportional sampling, which involves sampling proportionally to the size of each cluster. For example, if a cluster contains a large number of samples, more samples can be taken to ensure the representativeness of both large and small clusters.

[0238] Strategy 2: Importance sampling, which involves sampling based on the importance of each cluster, with more samples taken from clusters of higher importance. The importance of each cluster can be determined based on the magnitude of the central gradient vector of the cluster, the density of the cluster, or other indicators.

[0239] Strategy 3: Random sampling, which involves randomly sampling within each cluster to ensure that each sample has a certain probability of being selected, thereby increasing the randomness and diversity of the samples.

[0240] Strategy 4: Stratified sampling, which combines uniform sampling and proportional sampling. First, determine the basic number of samples for each cluster according to the proportion, and then perform uniform sampling within each cluster to ensure that each cluster has representative samples.

[0241] Strategy 5: Adaptive sampling, which dynamically adjusts the number of samples based on the model's performance across different clusters. For example, if samples from a certain cluster perform poorly during training, the number of samples from that cluster can be increased to improve model performance.

[0242] In this embodiment of the application, after screening the training samples through the above process, the code review model that has been initially trained is finally trained again based on the sampled sample set obtained by screening. Since the samples in the sampled sample set are sampled from different clusters, clustering can help identify the types of samples that cause overfitting, and reduce the risk of overfitting through appropriate data augmentation or regularization. In addition, the samples of different clusters cover different feature spaces, which helps the model learn more diverse features and improve the model's generalization ability. Furthermore, by analyzing the samples of different clusters, the shortcomings of the model on certain types of samples can be found, which helps to diagnose and improve the model.

[0243] Through these features and effects, clustering not only helps to understand the impact of different samples on the model, but also guides the optimization and improvement of the model, improving overall performance. Combined with the diverse sampling strategies in this paper, it can more comprehensively cover different types of samples, improve the quality and diversity of the sample set, and thus improve the training effect and generalization ability of the model.

[0244] See Figure 5 As shown, this is a schematic diagram of a filtering logic for high-quality, highly diverse data in an embodiment of this application. Simply put, Figure 5 That is to Figure 3 and Figure 4 The integration of the two parts, after Figure 3 The process shown allows calculation of the influence of each training sample subset on the test sample set. Generally, high-quality data will have a positive impact on high-quality test samples. Based on this influence, a high-quality target training sample subset can be selected, such as... Figure 5In this process, high-quality training samples are selected as target training sample subset 1 (assuming it is training sample subset 1) and target training sample subset 2 (assuming it is training sample subset 3) according to their influence. For specific implementation methods, please refer to the above embodiments, which will not be repeated here.

[0245] Based on these two subsets of target training samples, high-quality training samples are further divided according to the sample gradient to obtain... Figure 5 The three clusters shown can be sampled uniformly to obtain high-quality and highly diverse training samples.

[0246] In the calculation of influence and the clustering of samples, the gradients of the samples are actually used. This application utilizes gradient information to quantify the impact of each sample on model performance. Specifically, by calculating the gradient value of each sample and its impact on the model's loss function, the importance and contribution of the sample can be evaluated. This method does not require additional models or complex evaluation metrics; instead, it directly utilizes the model's own training process for data selection. Furthermore, the computational process is relatively efficient and suitable for large-scale datasets. This method not only improves model performance but also enhances its interpretability and efficiency. Through this method, better results can be obtained in tasks such as instruction fine-tuning.

[0247] By selecting high-quality and diverse training data, overfitting of the model can be effectively reduced, its generalization ability can be improved, and the model can generate more accurate review information that better meets actual needs.

[0248] It should be noted that the above methods improve the accuracy of code review models from the perspective of samples (i.e., training). Of course, the accuracy of code review models can also be improved from the perspective of application.

[0249] This application addresses the issue that traditional model inference employs maximum likelihood estimation, which can lead to generic or degenerate review comments. Therefore, this application introduces a novel model, denoted as the validation model, which cross-validates the review information output by the code review model using several validation models, thereby filtering out low-quality review comments.

[0250] From the perspective of online application of the model, the following solution aims to further improve the accuracy of code review by filtering code review comments:

[0251] See Figure 6 The diagram shown is an implementation flowchart of another code review method provided in this application embodiment. Taking the server as the execution subject as an example, the specific implementation flow of this method is as follows: S61 to S64:

[0252] S61: Input the language instructions and the code to be reviewed into the target code review model, obtain the review information of the code to be reviewed and the review probability corresponding to the review information based on the target code review model, and the review probability includes the probability of each word in the review information.

[0253] In the embodiments of this application, the target code review model is a pre-trained code review model. Specifically, it can be trained in the manner listed above (i.e., firstly, preliminary training is performed based on the training sample set, and then retraining is performed based on the sampled sample set), or it can be trained in any other manner, such as not screening the training sample set and directly training based on the original training sample set, or it can be based on a pre-trained code review model from some related technologies, etc. This article does not make specific limitations on this.

[0254] The target code review model takes language instructions and code as input and outputs review information, which is a text sequence. That is, when the target code review model outputs review information, it adopts a token-by-token output method. Each token in the review information corresponds to a probability, and these probabilities together constitute the review probability.

[0255] See Figure 7A As shown, it is a schematic diagram of a target code review model in an embodiment of this application. Figure 7A In this model, the code to be reviewed is a piece of code used for data analysis, denoted as Code 1. After inputting the code to be reviewed and the language instructions into the target code review model, the review information is output to describe the problems in the code and provide suggestions.

[0256] Optionally, the review probability is a sequence of review probabilities in the form of a sequence, which contains the probability of each word in the review information.

[0257] S62: Input the language instructions and review information into at least one verification model respectively, and obtain the verification probability output by each verification model; each verification probability includes the probability of each word in the text sequence output by the corresponding verification model.

[0258] In this embodiment, the input to the verification model is language instructions and review information. The language instructions are those input into the target code review model, and the review information is the review information output from the target code review model. Therefore, the output of the verification model can be code, or other information, and can be flexibly set according to actual needs. Specifically, the output of the verification model is also in the form of a text sequence. Similar to the target code review model, the verification model outputs the text sequence token by token. Each token in the output text sequence corresponds to a probability, and these probabilities together constitute the verification probability.

[0259] The optional verification probabilities are sequences in the form of a sequence; each sequence of verification probabilities contains the probability of each word in the text sequence (such as code) output by the corresponding verification model.

[0260] See Figure 7B As shown, this is a schematic diagram of a verification model in an embodiment of this application. Figure 7B In Chinese, the language instructions are: Figure 7A The language instruction shown in code 1 has the following review information: Figure 7A The coder model outputs the review information for code 1. After inputting this review information and language instructions into the validation model, the validation model outputs a piece of code for data analysis, denoted as code 2. The validation probability is the probability of each word in code 2.

[0261] The following is a brief explanation of the process of constructing the validation model:

[0262] In a code review scenario, a user inputs a piece of code, and the large model produces different outputs based on different decoding strategies. Simulating a multi-developer development scenario, after a coder submits a piece of code, multiple code reviewers cross-validate its effectiveness.

[0263] Following this approach, this application proposes a new model for verifying the review comments output by the target code review model, called the verification model. Therefore, the target code review model in this application can also be referred to as the Coder model, or simply Coder, and the verification model can also be called the Reviewer model, or simply Reviewer. This verification model is used to evaluate the effectiveness based on the language instructions input and the review information output in the Coder.

[0264] In this embodiment, the Reviewer and Coder can use the same model or different models, but the prompt words are different.

[0265] See Figure 8 The diagram shown illustrates the processing logic of a code review system according to an embodiment of this application. The code review system based on a large model proposed in this application mainly comprises three important modules: a dataset construction module.

[0266] The application includes a large-scale model selection and fine-tuning module, as well as a review comment filtering module. Dataset construction emphasizes high quality and diversity; therefore, the dataset construction model in this application is used to collect, clean, and preprocess data, constructing training sample sets and high-quality test sample sets (such as...). Figure 8The dataset contains z0, z1, z2, ..., zn. It combines large-scale model selection with fine-tuning of the model, and filters data from the training dataset with reference to the test dataset. This constructs a sampling dataset containing high-quality and highly diverse samples, ensuring data diversity and representativeness, and providing a reliable foundation for model training. The main idea of ​​this module is the quality and diversity detection of training data based on gradient values ​​mentioned above. Simply put, it first uses an influence equation to assess the quality of the training samples, then uses gradients to perform K-means clustering to assess the diversity of the training samples, and finally performs uniform sampling on the clusters to obtain high-quality, highly diverse training samples. For specific implementation details, please refer to the above embodiments, which will not be repeated here.

[0267] The large model selection and fine-tuning module is used to select a suitable initial network model and fine-tune it according to the requirements of the code review task in this application. By adjusting the model parameters and architecture, the model performance is optimized. On this basis, the model is fine-tuned again using the sample set constructed by the dataset construction module to obtain the target code review model, so that it achieves the best performance in the code review task.

[0268] The trained target code review model described above can be deployed online. The review comment filtering module in this application is used to evaluate the output of the online target code review model, filtering out irrelevant or low-quality review comments and retaining valuable ones to present to the user, thereby improving the overall system performance and user experience. The main idea of ​​this module is review comment filtering based on maximum mutual information; simply put, it involves calculating the code review model (e.g., ...) Figure 8 The output and validation model of the Coder (e.g.) Figure 8 The mutual information between the outputs of the Reviewer in the model, i.e. the mutual information parameter in this paper, can be used to reorder the outputs, which can avoid the degradation or generic answers that the model is prone to produce.

[0269] The Reviewer's Prompt can be obtained by rearranging and assembling parts of the Coder's Prompt (such as language instructions and code).

[0270] Specifically, a Prompt for Reviewer can take the following forms:

[0271] Taking the target code review model and the verification model as the same language model as an example, theoretically, after the code is generated, the order in which the language instructions and the code appear in the input context can be reversed and input into the language model again to obtain their p(x|y).

[0272] like Figure 9A As shown, this is a schematic diagram of a Prompt model in an embodiment of this application. Wherein, Figure 9A The left side shows the Coder's Prompt, and the right side shows the Reviewer's Prompt. The Reviewer's output is code, and its task is to complete the dataset for Python functions. Therefore... Figure 9A This example demonstrates a task-specific prompt designed for a Python function completion dataset, referencing the coder's prompt on the left. In this reviewer's prompt, the function header from the coder's prompt on the left is copied, and the generated code is placed before the instruction docstring (i.e., language instructions). Additionally, a natural language task description is inserted into the reviewer's prompt on the right: "Write a docstring for the above function (i.e.,..." Figure 9A By typing "write a docstring for the above function", you can obtain the Reviewer's Prompt shown on the right, which allows you to further specify the task of the pre-trained language model.

[0273] Specifically, in practical applications, when copying function headers, the function name can remain unchanged or be changed. For example, in the Coder's Prompt shown on the left, there is a Python function named `get_decimal`, which extracts the decimal part from the input number. In the Reviewer's Prompt shown on the right, the Python function is named `f`.

[0274] In the process described above, when rearranging the positions of parts of the Coder's Prompt (such as language instructions and code), in order to improve the efficiency of the rearrangement, you can use tags, such as HTML tags (html-tag), to wrap the instructions and code. In this way, when generating the Reviewer's Prompt, you can refer to this tag to quickly rearrange the order of instructions and code.

[0275] like Figure 9B As shown, this is a schematic diagram of another model, Prompt, in an embodiment of this application. Wherein, Figure 9B The text provides an example of using tags to wrap instructions and code; for instance, these tags can be used to wrap instructions and code. <text> and< / text> The instruction is enclosed within it. <text> It is the start tag of a language instruction, located before the first token of an instruction.< / text> It is the closing tag of a language instruction, located after the last token of an instruction. An instruction is wrapped in this way, such as... Figure 9B middle," <text> Print information of "bash"< / text> "and"<text> Change the owner of "dir" to "nginx"< / text> ".

[0276] Similarly, through tags <code> and< / code> Package code, in which, <code> It is the start tag of the code, located before the first token of a code.< / code> It's the code's closing tag, located after the last token of a code block. It's used to wrap a piece of code, like this: Figure 9B middle," <code> echo s(ls-1 / bin / bash)< / code> "and <code> chown nginx:nginx dir< / code> .

[0277] It should be noted that, Figure 9B The labels listed are just simple examples. Other labels are also applicable to the embodiments of this application, and will not be described in detail here.

[0278] The above steps provide a brief explanation of the inputs and outputs of the Coder and Reviewer, as well as the Prompt. For the outputs of these two models, the accuracy of the review information output by the target code review model can be verified by calculating the maximum mutual information. The specific implementation method is as follows:

[0279] S63: Determine the mutual information parameters for the review information based on the review probability and each verification probability, respectively; where each verification probability corresponds to one mutual information parameter.

[0280] In simple terms, the Coder in this application is used to output review comments, and the Reviewer is used to analyze whether the review comments output by the Coder are accurate. The review probability is part of the output of the Coder in the target code review model, and the verification probability is part of the output of the Reviewer in the verification model. Let the language instruction be denoted as c, the code as x, and the review information as y. The probability output by the Coder can be denoted as p(y|c,x), and the probability output by the Reviewer can be denoted as p(x|c,y). When the language instruction c input into the Coder is randomly adjusted, c1, c2, ..., cn can be obtained. Correspondingly, the Coder will also output y1, y2, ..., yn. Therefore, the probability output by the Reviewer, p(x|c,y), can also be denoted as p(x|c,y,c1,y1,...,cn,yn).

[0281] Considering that the inputs of both the Coder and Reviewer in this embodiment contain language instructions c, for ease of description later, the input of the Coder is denoted as x, and the output of the Coder is denoted as y. p(y|x) represents the probability of generating the output y given the input x, which is a conditional probability and is essentially a sequence, i.e., the review probability in this paper. The input of the Reviewer is denoted as y, and the output of the Reviewer is denoted as x. Then p(x|y) represents the probability of generating the output x given the input y, which is a conditional probability and is also essentially a sequence, i.e., the verification probability in this paper.

[0282] Each verification model outputs a verification probability. Therefore, each verification model will obtain a mutual information parameter for the review information. Even if these mutual information parameters correspond to different verification probabilities, that is, different verification models, they all correspond to the same target code review model and are for the same review information. By comparing these mutual information parameters, the accuracy of the review information can be verified.

[0283] The derivation process of the calculation formula for the mutual information parameter in the embodiments of this application will be briefly explained below:

[0284] Mutual information is the difference between the information entropy of the joint distribution of two variables and their respective marginal distributions. It measures the amount of information shared by two random variables (X) and (Y), that is, the degree to which knowing the value of one variable reduces the uncertainty about the other variable.

[0285] Taking the output y of the Coder and the output x of the Reviewer in this embodiment as examples, the mutual information parameter in this application is used to measure the interdependence between x and y. For x and y in this paper, the formula for mutual information is as follows:

[0286]

[0287] The physical meaning of Formula 4 above is: given an input x, choose an output y such that the logarithm of the ratio of the joint probability p(y,x) of y and x to the marginal probabilities p(x) and p(y) of x and y is maximized.

[0288] Here, argmax is a mathematical operator. y This indicates finding the function that makes the above function The independent variable y reaches its maximum value.

[0289] The joint probability p(y,x) represents the probability that input x and output y occur simultaneously. In the code review task of this application embodiment, it can be understood as the probability of generating output review information given an input code fragment.

[0290] The marginal probability p(x) represents the probability of input x occurring. In the code review task of this application embodiment, it can be understood as the frequency or probability of the input code segment appearing.

[0291] The marginal probability p(y) represents the probability of output y occurring. In the code review task of this application embodiment, it can be understood as the frequency or probability of output review information appearing.

[0292] α is a weighting parameter used to adjust the influence of p(y).

[0293] Formula 4 above aims to balance the correlation between y and x, that is, to select the high-quality output y that is most relevant to the input x by using p(y,x) and the marginal probability p(y) of y.

[0294] Formulas 5 and 6 are both variations of Formula 4:

[0295] For Equation 4, by expressing the joint probability p(y,x) in terms of conditional probability, p(y,x)=p(y|x)·p(x)=p(x|y)·p(y), and by expanding and simplifying it using the properties of logarithms, ignoring the constant term, we can obtain Equation 5. The specific derivation process is as follows:

[0296]

[0297] Ignoring the constant term logp(x), we can obtain Formula 4 = Formula 5.

[0298] As for Equation 5, by expressing the conditional probability in terms of joint probability and marginal probability, and further expanding and simplifying it while ignoring the constant term, we can obtain Equation 6. The specific derivation process is as follows:

[0299]

[0300] Ignoring the constant term logp(x), we get Formula 4 = argmax. y (1-α)logp(y|x)+αlogp(y|x)-αlogp(y)-αlogp(x)=Formula 6.

[0301] In this embodiment, by adjusting the value of α, a trade-off can be made between p(y|x) and p(x|y) to select a more suitable output y. Specifically:

[0302] When α = 1, Formula 4 degenerates into maximum likelihood estimation, which only considers the probability p(x|y) of generating input x given output y. This may cause the output to generalize or degenerate.

[0303] When α = 0.5, this is actually a weighted version of maximizing mutual information. In this case, Equation 5 = argmax y 0.5logp(y|x)+0.5logp(x|y)=argmax y 0.5logp(y|x)p(x|y).

[0304] In the above process, by setting α = 0.5, a balance point is found. By maximizing mutual information, it can be ensured that the selected output y has a stronger correlation with the input x, and the review information with higher mutual information with the language instructions is selected, thereby improving the accuracy and consistency of the model.

[0305] The above formulas together constitute the Code-Reviewer Reranking proposed in this application. Code-Reviewer Reranking is a special case of maximizing mutual information and is also the basic rule for calculating the mutual information parameter in this application. Of course, it can also be understood as a reranking rule. Based on this rule, it is beneficial to select review information with higher mutual information to the instruction and filter out low-quality rejection schemes that cannot well interpret the instruction. The specific process is as follows:

[0306] Based on the above ideas, the calculation method of the mutual information parameter in the embodiments of this application will be described in detail below:

[0307] One optional method for calculating mutual information parameters is as follows:

[0308] For each verification probability, the logarithm of the product of the review probability and the corresponding verification probability is used as the mutual information parameter for the review information corresponding to that verification probability.

[0309] Specifically, with the Coder and Reviewer, the results of the Coder and Reviewer are multiplied and represented in logarithmic form, which facilitates calculation and optimization.

[0310] Optionally, the calculation formula for a mutual information parameter in one embodiment of this application is as follows:

[0311] Mutual information parameter = logp(x|y)p(y|x) = logp(x|y) + logp(y|x) (Formula 7)

[0312] Equation 7 represents the logarithmic form of the joint probability p(x|y)p(y|x). In Equation 7, p(x|y) is the verification probability output by the Reviewer, and p(y|x) is the review probability output by the Coder. In Equation 7, these two probabilities are directly multiplied; in actual calculation, the two probability sequences are multiplied. Of course, according to the logarithmic algorithm, the logarithm of the product of the joint probabilities can also be expressed as the sum of the logarithms of the joint probabilities, as shown on the right side of the equal sign in Equation 7.

[0313] Each verification model and the target code review model can have a mutual information parameter calculated based on Formula 7.

[0314] It should be noted that Formula 7 in the embodiments of this application represents a special instance of Formula 5 (i.e. Formula 4) when α = 0.5, which is a special instance of maximizing mutual information.

[0315] In the above implementation, using the logarithm of the product of the review probability and the corresponding verification probability as the mutual information parameter can effectively quantify the correlation between review information and verification results, enhance the model's sensitivity to low-probability events, improve discrimination ability and review accuracy, thereby building a more intelligent and efficient review system.

[0316] Based on this, considering that the output length generated by the model may vary greatly, and these length differences will affect the final evaluation results, in order to prevent the influence of excessively long or short outputs on the results and ensure that the model performs consistently across outputs of different lengths, this application also proposes a mutual information parameter calculation method based on length regularization.

[0317] That is, another optional method for calculating mutual information parameters is:

[0318] For each verification probability, determine the first ratio of the logarithm of the review probability to the length of the review information, and the second ratio of the logarithm of the corresponding verification probability to the length of the text sequence; the sum of this first ratio and the second ratio is used as the mutual information parameter for the review information corresponding to that verification probability.

[0319] In other words, by combining the outputs of the coder and reviewer, and performing appropriate regularization and optimization, high-quality review information can be selected.

[0320] In actual calculations, these two probabilities are a probability sequence, so when performing length regularization, each probability in the probability sequence can be regularized.

[0321] Optionally, another formula for calculating the mutual information parameter in this application embodiment is as follows:

[0322]

[0323] Specifically, Formula 8 represents length regularization of the result of Formula 7. Here, |x| represents the length of the Reviewer output x (a text sequence, such as a code snippet), and the second ratio is... |y| represents the length of the coder's output y (i.e., the review information), and the first ratio is...

[0324] Outputs of different lengths may not be directly comparable in terms of their original probability scores. For example, a longer output may receive a higher probability score because it has more opportunities to match the input, even if its overall quality is not high. In the embodiments of this application, for example, the outputs of the coder and the reviewer cannot be directly compared, nor can the outputs of different reviewers be directly compared.

[0325] Each verification model and the target code review model can have a mutual information parameter calculated based on Formula 8.

[0326] In the above implementation, by dividing the probability score by the length through length regularization to adjust the probability score of the model output, it is possible to ensure that outputs of different lengths are comparable during evaluation, achieve the effect of fair comparison, ensure that the mutual information parameters optimized in this way are more comparable, more effectively quantify the correlation between review information and verification results, and ensure that the results are more accurate.

[0327] Optionally, when calculating the mutual information parameters, the probability values ​​in the review probability (sequence) and verification probability (sequence) mentioned above can also be the values ​​of the corresponding model output layer output without activation function processing (i.e., without normalization processing), denoted as Logits.

[0328] For target code review or validation models, the probability values ​​output by the model's output layer are typically normalized using activation functions (such as softmax or sigmoid). These activation functions can lead to numerical stability issues, especially when dealing with a wide range of input values. For example, the softmax function may cause overflow or underflow when the input values ​​are very large or very small. Logits generally offer better numerical stability than normalized probability values ​​because they are linear and unaffected by exponential operations. Furthermore, logits preserve the model's original confidence scores for each class, information that might be lost after softmax or sigmoid processing. For instance, softmax normalizes all scores to probability values, potentially compressing or smoothing out subtle differences.

[0329] In this embodiment, using Logits to calculate mutual information parameters directly reflects the model's original judgment strength for different categories or features, avoiding information distortion that may be introduced during normalization. This allows for a more accurate capture of dependencies between variables, improving the effectiveness of mutual information parameters as a feature selection or model interpretation tool. Furthermore, in some cases, directly using Logits can simplify the calculation process, especially when dealing with high-dimensional data. In summary, using Logits for mutual information calculation avoids numerical stability issues, retains more information, and provides greater flexibility.

[0330] Based on the above method, the correlation between each Reviewer's output and the Coder's output can be calculated, which is the mutual information parameter in this paper. Since the Code-Reviewer Reranking scheme combines the two models through a product, a low probability of either one will affect the result. Therefore, it is necessary to find a result that is agreed upon by both the Coder and the Reviewer. Seeking consensus will filter out some low-quality results.

[0331] Therefore, by sorting, comparing, or analyzing these mutual information parameters, it can be determined whether the review information output by the Coder is accurate enough and whether it can be presented to the object. The specific process is as follows:

[0332] S64: Based on the obtained mutual information parameters, determine whether to present the review information to the object.

[0333] Specifically, each mutual information parameter is determined by combining the output of the target code review model and the output of a validation model, reflecting the correlation between the outputs of the two models. Based on these mutual information parameters, it is determined whether to present the review information output by the current target code review model to the object. This ensures that the information received by the object is both relevant and important, which helps to improve the quality and efficiency of code review. This method can effectively filter out irrelevant or low-value review information, allowing developers to focus on the issues that need the most attention, thereby speeding up the development process and improving code quality.

[0334] Optionally, each validation model corresponds to a mutual information parameter. By sorting these mutual information parameters, the ranking result can be used to determine whether to present the review information for which the maximum mutual information calculation was performed to the object. One possible implementation is as follows:

[0335] If the statistical parameters obtained from each mutual information parameter exceed the preset parameter threshold, the review information will be presented to the object.

[0336] Among them, the statistical parameters are obtained by mathematically calculating the various mutual information parameters, and include, but are not limited to, at least one of the following:

[0337] (1) Maximum mutual information parameter: the maximum value among all mutual information parameters; (2) Minimum mutual information parameter: the minimum value among all mutual information parameters; (3) Mean: the average value among all mutual information parameters; (4) Standard deviation: the standard deviation among all mutual information parameters; (5) Median: the median among all mutual information parameters.

[0338] Specifically, the preset threshold values ​​for multiple statistical parameters can be the same or different. Let's assume that the preset threshold values ​​for multiple statistical parameters are different, with each statistical parameter having one preset threshold value. For example, when the statistical parameter is the maximum mutual information parameter, the corresponding preset threshold value is C1; when the statistical parameter is the minimum mutual information parameter, the corresponding preset threshold value is C2; when the statistical parameter is the mean of all mutual information parameters, the corresponding preset threshold value is C3; and so on.

[0339] If there is only one mutual information parameter participating in the data statistics, then the statistical parameter is the mutual information parameter itself. That is, when the mutual information parameter exceeds the preset parameter threshold, it means that the verification is passed, and the review information can be presented to the object.

[0340] If there are multiple mutual information parameters involved in the data statistics, analysis can be performed based on a single statistical parameter or multiple statistical parameters.

[0341] If the analysis is based on a single statistical parameter, then when the statistical parameter exceeds the corresponding preset parameter threshold, the review information can be presented to the object.

[0342] If analysis is performed based on multiple statistical parameters, then when each statistical parameter exceeds the corresponding preset parameter threshold, the verification is considered successful and the review information is presented to the object; or, when a preset number (e.g., 1, or 2, etc.) of statistical parameters exceed the corresponding preset parameter threshold, the verification is considered successful and the review information is presented to the object, and so on.

[0343] Suppose that a certain review information is processed as above through 10 verification models, resulting in 10 mutual information parameters. These 10 mutual information parameters have three statistical parameters: the maximum mutual information parameter M1, the minimum mutual information parameter M2, and the mean mutual information parameter M3. Each parameter has a preset parameter threshold: C1, C2, and C3.

[0344] When analyzing based on a single statistical parameter, assuming the statistical parameter is the maximum mutual information parameter M1 and the preset threshold C1 = 0.8, then if M1 > C1, the review information can be presented to the object. Assuming the statistical parameter is the minimum mutual information parameter M2 and the preset threshold C2 = 0.5, then if M2 > C2, the review information can be presented to the object. Assuming the statistical parameter is the mean mutual information parameter M3 and the preset threshold C3 = 0.6, then if M3 > C3, the review information can be presented to the object.

[0345] When analyzing based on multiple statistical parameters, if the verification passes when all statistical parameters exceed the corresponding preset thresholds, then M1>C1, M2>C2, and M3>C3 are required, and the review information can then be presented to the object.

[0346] If the verification passes when at least one statistical parameter exceeds the corresponding preset threshold, then the review information can be presented to the object when M1>C1, M2>C2, or M3>C3.

[0347] If the verification passes when at least two statistical parameters exceed the corresponding preset thresholds, then the review information can be presented to the object if M1>C1 and M2>C2, or M1>C1 and M3>C3, or M2>C2 and M3>C3.

[0348] The above examples demonstrate how to determine whether to present review information to an object based on one or more statistical parameters and their preset thresholds. This flexible setting of conditions can help to more accurately filter and present valuable review information.

[0349] In the above implementation, mutual information is an indicator that measures the correlation between two variables. When the statistical parameter exceeds a preset threshold, it means that the output of the target code review model and the output of the verification model in this application have a high degree of correlation or importance. This application can selectively present important review information based on the statistical characteristics of the mutual information parameters, effectively improving the relevance and quality of information, thereby improving the efficiency and quality of code review. This not only helps users quickly obtain the most valuable feedback, improving decision-making efficiency and satisfaction, but also reduces the confusion caused by information overload, making it easier for users to focus on key points. Furthermore, this method can enhance the intelligence level of the system and improve the user experience.

[0350] In practical applications, if calculations and comparisons reveal that the statistical parameters obtained from each mutual information parameter do not exceed the preset parameter threshold, it indicates that the review information cannot be presented to the object. In this case, to improve the quality and relevance of the review information, it should be filtered out. Furthermore, this application supports regenerating new review information and repeating the above verification process based on the new review information. One possible implementation is as follows:

[0351] If the statistical parameters obtained based on each mutual information parameter do not exceed the preset parameter threshold, then new review information and review probabilities are regenerated based on the target code review model, and the process of inputting language instructions and review information into at least one verification model to obtain the verification probability output by each verification model is returned, which is step S62 above. Figure 8 The steps shown may be repeated until the statistical parameters corresponding to the latest generated review information exceed a preset parameter threshold, at which point it is determined that the latest generated review information can be presented to the object. Alternatively, the process may continue until the maximum number of repetitions of the above process is reached.

[0352] In the context of analysis based on multiple statistical parameters, the statement that the statistical parameters obtained based on each mutual information parameter do not exceed the preset parameter threshold means that each statistical parameter does not exceed the corresponding preset parameter threshold, or that a preset number of statistical parameters (such as 1 or 2) do not exceed the corresponding preset parameter threshold, and so on.

[0353] Specifically, when the target code review model is a large language model, considering that the large language model has powerful generation and contextual understanding capabilities, due to its internal randomness and generation mechanism, the model will use different random seeds and internal states each time it is generated, thus producing different outputs. This application utilizes this characteristic of the large language model to support the regeneration of new review information and repeat the process described in S62 to S64 above.

[0354] See Figure 10 The diagram shown is a logical schematic of a review information filtering method in an embodiment of this application. It takes the validation of review information output by the target code review model using a validation model as an example. Figure 10As shown, after inputting the code to be reviewed (denoted as code 1) and the language instruction into the target code review model, the review information and review probability are output. At this time, the review information is not directly presented to the object. Instead, the review information and the language instruction are input into the verification model. The verification model outputs code 2 and the verification probability. Based on the review probability p(y|x) and the verification probability p(x|y), the mutual information parameter is calculated with reference to the above formula 7 / formula 8. If the mutual information parameter exceeds the preset parameter threshold, the review information is directly presented to the object. If the mutual information parameter does not exceed the preset parameter threshold, new review information, review probability, etc. are regenerated, the mutual information parameter is recalculated, and the comparison and analysis are re-conducted until the calculated mutual information parameter exceeds the preset parameter threshold. Then, the latest generated review information is presented to the object. Alternatively, the latest generated review information can be presented to the object when the number of repetitions reaches the upper limit (e.g., 10 times). The optimal review information (i.e., the one with the largest mutual information parameter among these 10 times) can also be presented to the object. Error prompts can also be given to the object.

[0355] In addition, the object can provide feedback on the review information, such as scores and comments. Based on the object's feedback, the parameters of the target code review model can be further adjusted and the model optimized.

[0356] In the above implementation, by regenerating the review information and recalculating the mutual information parameters, the final review information presented is ensured to have higher relevance and quality, avoiding low-quality review information from misleading developers. At the same time, by repeatedly generating and verifying, the adaptability and robustness of the model can be enhanced, enabling it to generate high-quality review information in different scenarios.

[0357] Furthermore, the above methods can present high-quality review information to the target audience. High-quality review information can more accurately point out problems and areas for improvement in the code, helping developers to understand and fix problems more quickly, thereby improving the overall efficiency of code review.

[0358] In conclusion, this approach can significantly improve the quality and efficiency of code reviews, ensure the accuracy and reliability of review information, and thus promote the team's code quality and development efficiency.

[0359] See Figure 11 The diagram shown is a flowchart illustrating a specific implementation of a code review method according to an embodiment of this application. The specific implementation process of this method is as follows:

[0360] S1101: A test sample set composed of high-quality samples selected from the training data;

[0361] S1102: After the code review model to be trained is initially trained based on the training sample set, the test impact of each training sample subset on the test sample set is calculated.

[0362] S1103: Among the determined test influence values, the two training sample subsets with the largest test influence values ​​are taken as the target training sample subsets;

[0363] S1104: Cluster each target training sample in the target training sample subset according to the sample gradient to obtain 3 clusters;

[0364] S1105: Perform uniform sampling in each cluster and combine the sampling results into a sample set;

[0365] S1106: The code review model that was initially trained was retrained based on the sampled sample set to obtain the target code review model after training.

[0366] S1107: Deploy the target code review model online;

[0367] S1108: Input the language instructions and the code to be reviewed into the target code review model, and obtain the review information of the code to be reviewed and the review probability corresponding to the review information based on the target code review model;

[0368] S1109: Input the language instruction and the review information into the verification model to obtain the verification probability output by the verification model;

[0369] S1110: Determine the mutual information parameters for the review information based on the review probability and each of the verification probabilities;

[0370] S1111: Determine whether the mutual information parameter exceeds the preset parameter threshold. If yes, execute S1112; otherwise, execute S1113.

[0371] S1112: Present the latest review information to the recipients;

[0372] S1113: Regenerate new review information and review probabilities based on the target code review model, and return to S1109.

[0373] It should be noted that the above Figure 11 The implementation process listed is merely a simple example; other processes are equally applicable to the embodiments of this application and are not specifically limited here. Figure 11 For specific implementation methods of these processes, please refer to the above embodiments; repeated details will not be repeated here.

[0374] See Figure 12As shown, it is a schematic diagram of the interaction logic between a terminal device and a server in an embodiment of this application.

[0375] In this application, a code review client can be installed on the terminal device. The user can input language commands and the code to be reviewed through the client, and then send this data to the server. The server 120 pre-deploys a pre-trained target code review model, denoted as Coder, and a verification model, denoted as Reviewer. Here, a verification model is used as an example. The server then uses the code review method in this embodiment to predict review information based on the Coder and calculates mutual information parameters in conjunction with the Reviewer. When the mutual information parameters exceed a preset threshold, the review information output by the Coder can be returned to the terminal device for presentation to the user. The specific recognition process is detailed in the above embodiment; repeated details will not be elaborated further.

[0376] Based on the same inventive concept, embodiments of this application also provide a code review apparatus. For example... Figure 13 As shown, this is a structural diagram of the code review device 1300, which may include:

[0377] The data acquisition unit 1301 is used to acquire a training sample set and a test sample set, and to divide the training sample set into multiple training sample subsets; the test sample set contains test samples that achieve the expected quality.

[0378] The first processing unit 1302 is used to perform preliminary training on the code review model to be trained based on the training sample set, and then determine the test influence degree of each training sample subset on the code review model; the test influence degree reflects the influence of the training sample subset on the performance change of the code review model on the test sample set.

[0379] The screening unit 1303 is used to cluster at least one target training sample subset whose influence meets the preset influence conditions in the plurality of training sample subsets according to the sample gradient to obtain multiple clusters.

[0380] The second processing unit 1304 is used to sample in each cluster and retrain the code review model that has been initially trained based on the obtained sample set to obtain the trained target code review model; wherein, the target code review model is used to generate review information for the code to be reviewed.

[0381] Optionally, the first processing unit 1302 is specifically used for:

[0382] Determine the Hessian matrix of the loss function of the code review model, the first gradient vector corresponding to each training sample subset, and the second gradient vector corresponding to the test sample set; wherein the first gradient vector and the second gradient vector are determined based on the gradient vector of each sample in the corresponding set.

[0383] For each training sample subset, the test influence of the training sample subset on the code review model is determined based on the first gradient vector corresponding to the training sample subset, the Hessian matrix, and the second gradient vector.

[0384] Optionally, the first gradient vector and the second gradient vector are d-dimensional column vectors, and the Hessian matrix is ​​a d×d matrix; the first processing unit 1302 is specifically used for:

[0385] The transpose of the second gradient vector is multiplied by the inverse of the Hessian matrix to obtain the intermediate vector.

[0386] Perform an inner product operation between the intermediate vector and the first gradient vector to obtain an intermediate scalar;

[0387] The negative of the intermediate scalar is used as the test influence of the training sample subset on the code review model.

[0388] Optionally, the gradient vector for each sample is determined based on the intermediate layer results of the code review model.

[0389] Optionally, the filtering unit 1303 is further configured to filter a subset of target training samples by at least one of the following methods:

[0390] The N training sample subsets with the largest values ​​among the determined test influence values ​​are used as the target training sample subset, where N is a positive integer greater than or equal to 1.

[0391] The subset of training samples that reaches the preset influence threshold is used as the target training sample subset.

[0392] Optionally, the filtering unit 1303 is specifically used for:

[0393] For each target training sample in the at least one subset of target training samples, determine the third gradient vector of the target training sample;

[0394] Based on the distances between the determined third gradient vectors, each target training sample is clustered to obtain multiple clusters.

[0395] Optionally, the filtering unit 1303 is further configured to perform the following operation before clustering according to sample gradients to obtain multiple clusters:

[0396] Dimensionality reduction is performed on each target training sample; or

[0397] The third gradient vector of each target training sample is dimensionality reduced.

[0398] Optionally, the device further includes:

[0399] The review unit 1305 is used to input language instructions and code to be reviewed into the target code review model, and obtain review information of the code to be reviewed and review probability corresponding to the review information according to the target code review model. The review probability includes the probability of each word in the review information.

[0400] The verification unit 1306 is used to input the language instruction and the review information into at least one verification model respectively to obtain the verification probability output by each verification model; each verification probability includes the probability of each word in the text sequence output by the corresponding verification model.

[0401] The determining unit 1307 is used to determine a mutual information parameter for the review information based on the review probability and each of the verification probabilities, respectively; wherein each verification probability corresponds to a mutual information parameter;

[0402] The analysis unit 1308 is used to determine whether to present the review information to the object based on the obtained mutual information parameters.

[0403] Optionally, the determining unit 1307 is specifically used for:

[0404] For each verification probability, the logarithm of the product of the review probability and the corresponding verification probability is used as the mutual information parameter corresponding to the verification probability.

[0405] Optionally, the determining unit 1307 is specifically used for:

[0406] For each of the verification probabilities, a first ratio corresponding to the logarithm of the review probability and the length of the review information is determined, as well as a second ratio corresponding to the logarithm of the verification probability and the length of the text sequence.

[0407] The sum of the first ratio and the second ratio is used as the mutual information parameter corresponding to the verification probability.

[0408] Optionally, the analysis unit 1308 is specifically used for:

[0409] If the statistical parameters obtained based on the various mutual information parameters exceed the preset parameter threshold, the review information will be presented to the object.

[0410] Optionally, the target code review model is a large language model; the analysis unit 1308 is specifically used for:

[0411] If the statistical parameters obtained based on the mutual information parameters do not exceed the preset parameter threshold, then new review information and review probabilities are regenerated based on the target code review model, and the process of inputting the language instructions and the review information into at least one verification model to obtain the verification probability output by each verification model is returned.

[0412] Optionally, the review probability is a review probability sequence in sequence form, which contains the probability of each word in the review information; the verification probability is a verification probability sequence in sequence form; each verification probability sequence contains the probability of each word in the text sequence output by the corresponding verification model.

[0413] This application uses gradient values ​​to perform quality screening and diversity detection on the training data. The code review model is then trained using the resulting high-quality and highly diverse samples to improve the accuracy of the code review information generated by the model.

[0414] Specifically, this application first constructs a test sample set that meets the expected quality. After initial training of the code review model to be trained based on the training sample set, the influence of each training sample subset on the performance change of the model on the test sample set can be evaluated according to the multiple training sample subsets obtained by dividing the training sample set. This influence is denoted as the test impact degree. Generally speaking, high-quality data has a positive impact on high-quality test samples. Therefore, based on the test impact degree corresponding to each training sample subset, at least one high-quality target training sample subset can be selected from multiple training sample subsets.

[0415] Based on this, for a high-quality subset of target training samples, the target training samples contained therein are clustered and sampled according to the sample gradient to ensure that the samples in the obtained sample set have diversity.

[0416] In summary, by using the influence-based screening and gradient-based clustering and sampling methods described above, we ensure that the final sample set is a high-quality and highly diverse training sample. Therefore, the code review model trained again based on these training samples can perform code reviews more accurately and generate more accurate review information.

[0417] Furthermore, this application proposes a code review technology applicable to online environments. The target code review model in this paper can be deployed online. After deployment, the object can use the review information automatically generated by the target code review model. However, at this time, the result is not directly presented to the object. Instead, one or more verification models are used to further verify the review information output by the trained code review model to ensure that the verification is passed before presenting the review information to the object. This verification process utilizes the idea of ​​maximum mutual information to fully guarantee the accuracy of the review information and improve the object's experience.

[0418] For ease of description, the above sections are divided into modules (or units) according to their functions and described separately. Of course, in implementing this application, the functions of each module (or unit) can be implemented in one or more software or hardware components.

[0419] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.

[0420] Having introduced the code review method and apparatus according to exemplary embodiments of this application, we will now introduce an electronic device according to another exemplary embodiment of this application.

[0421] Those skilled in the art will understand that various aspects of this application can be implemented as a system, method, or program product. Therefore, various aspects of this application can be specifically implemented in the following forms: a completely hardware implementation, a completely software implementation (including firmware, microcode, etc.), or a combination of hardware and software implementations, collectively referred to herein as a "circuit," "module," or "system."

[0422] Based on the same inventive concept as the above-described method embodiments, this application also provides an electronic device. In one embodiment, the electronic device may be a server, such as... Figure 1 The server 120 is shown. In this embodiment, the structure of the electronic device can be as follows: Figure 14 As shown, it includes a memory 1401, a communication module 1403, and one or more processors 1402.

[0423] The memory 1401 is used to store computer programs executed by the processor 1402. The memory 1401 may mainly include a program storage area and a data storage area. The program storage area may store the operating system and programs required to run instant messaging functions, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.

[0424] Memory 1401 may be volatile memory, such as random-access memory (RAM); memory 1401 may also be non-volatile memory, such as read-only memory, flash memory, hard disk drive (HDD), or solid-state drive (SSD); or memory 1401 may be any other medium capable of carrying or storing a desired computer program having the form of instructions or data structures and accessible by a computer, but is not limited thereto. Memory 1401 may be a combination of the above-described memories.

[0425] Processor 1402 may include one or more central processing units (CPUs) or digital processing units, etc. Processor 1402 is used to implement the above-described code review method when calling computer programs stored in memory 1401.

[0426] The communication module 1403 is used to communicate with terminal devices and other servers.

[0427] This application embodiment does not limit the specific connection medium between the memory 1401, communication module 1403, and processor 1402. This application embodiment... Figure 14 The memory 1401 and the processor 1402 are connected via a bus 1404, and the bus 1404 is in Figure 14 The diagram uses thick lines to describe the connections between other components; these are for illustrative purposes only and should not be considered limiting. The 1404 bus can be divided into address bus, data bus, control bus, etc. For ease of description, Figure 14 It is described using only a thick line, but does not indicate that there is only one bus or one type of bus.

[0428] The memory 1401 stores a computer storage medium, which stores computer-executable instructions. These instructions are used to implement the code review method of this application embodiment. The processor 1402 is used to execute the above-described code review method, such as... Figure 2 or Figure 6 As shown.

[0429] In another embodiment, the electronic device may also be other electronic devices, such as... Figure 1 The terminal device 110 is shown. In this embodiment, the electronic device can be structured as follows: Figure 15 As shown, it includes components such as: communication component 1510, memory 1520, display unit 1530, camera 1540, sensor 1550, audio circuit 1560, Bluetooth module 1570, processor 1580, etc.

[0430] The communication component 1510 is used to communicate with the server. In some embodiments, it may include a Circuit-Based Wireless Fidelity (WiFi) module, which is a short-range wireless transmission technology. Electronic devices can use the WiFi module to help users send and receive information.

[0431] The memory 1520 can be used to store software programs and data. The processor 1580 executes various functions of the terminal device 110 and performs data processing by running the software programs or data stored in the memory 1520. The memory 1520 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. The memory 1520 stores an operating system that enables the terminal device 110 to run. In this application, the memory 1520 may store the operating system and various application programs, and may also store computer programs that execute the code review method of the embodiments of this application.

[0432] The display unit 1530 can also be used to display information input by the user or information provided to the user, as well as various menus of the terminal device 110, in a graphical user interface (GUI). Specifically, the display unit 1530 may include a display screen 1532 disposed on the front of the terminal device 110. The display screen 1532 may be configured as a liquid crystal display, a light-emitting diode, or the like. The display unit 1530 can be used to display code-related interfaces, code review-related interfaces, etc., as described in the embodiments of this application.

[0433] The display unit 1530 can also be used to receive input digital or character information and generate signal inputs related to user settings and function control of the terminal device 110. Specifically, the display unit 1530 may include a touch screen 1531 disposed on the front of the terminal device 110, which can collect touch operations of the user on or near it, such as clicking buttons, dragging scroll boxes, etc.

[0434] The touchscreen 1531 can be placed on top of the display screen 1532, or the touchscreen 1531 and the display screen 1532 can be integrated to realize the input and output functions of the terminal device 110. After integration, it can be referred to as a touch display screen. In this application, the display unit 1530 can display the application and the corresponding operation steps.

[0435] Camera 1540 can be used to capture still images, which users can then share via an application. There can be one or multiple cameras 1540. An object is projected onto a photosensitive element through a lens, generating an optical image. This photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then transmitted to the processor 1580 for conversion into a digital image signal.

[0436] The terminal device may also include at least one sensor 1550, such as an accelerometer 1551, a proximity sensor 1552, a fingerprint sensor 1553, and a temperature sensor 1554. The terminal device may also be equipped with other sensors such as a gyroscope, barometer, hygrometer, thermometer, infrared sensor, light sensor, and motion sensor.

[0437] Audio circuitry 1560, speaker 1561, and microphone 1562 provide an audio interface between the user and terminal device 110. Audio circuitry 1560 converts received audio data into electrical signals, which are then transmitted to speaker 1561, where they are converted into sound signals for output. Terminal device 110 may also be equipped with volume buttons for adjusting the volume of the sound signal. On the other hand, microphone 1562 converts collected sound signals into electrical signals, which are received by audio circuitry 1560, converted into audio data, and then output to communication component 1510 for transmission to, for example, another terminal device 110, or to memory 1520 for further processing.

[0438] The Bluetooth module 1570 is used to interact with other Bluetooth devices that also have a Bluetooth module via the Bluetooth protocol. For example, a terminal device can establish a Bluetooth connection with a wearable electronic device (such as a smartwatch) that also has a Bluetooth module through the Bluetooth module 1570, thereby exchanging data.

[0439] The processor 1580 is the control center of the terminal device, connecting various parts of the terminal through various interfaces and lines. It executes various functions and processes data by running or executing software programs stored in the memory 1520 and calling data stored in the memory 1520. In some embodiments, the processor 1580 may include one or more processing units; the processor 1580 may also integrate an application processor and a baseband processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the baseband processor mainly handles wireless communication. It is understood that the baseband processor may not be integrated into the processor 1580. In this application, the processor 1580 can run the operating system, applications, user interface display and touch response, as well as the code review method of the embodiments of this application. Furthermore, the processor 1580 is coupled to the display unit 1530.

[0440] In some possible implementations, various aspects of the code review method provided in this application can also be implemented in the form of a program product, which includes a computer program. When the program product is run on an electronic device, the computer program causes the electronic device to perform the steps of the code review method according to the various exemplary embodiments of this application described above. For example, the electronic device can perform actions such as... Figure 2 or Figure 6 The steps are shown in the figure.

[0441] The program product may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0442] The program product of the embodiments of this application may employ a portable compact disc read-only memory (CD-ROM) and include a computer program, and may run on an electronic device. However, the program product of this application is not limited thereto. In this document, the readable storage medium may be any tangible medium that contains or stores a program that may be used by or in conjunction with a command execution system, apparatus, or device.

[0443] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a readable computer program. This propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium, capable of sending, propagating, or transmitting a program for use by or in conjunction with a command execution system, apparatus, or device.

[0444] Computer programs contained on readable media may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.

[0445] Computer programs for performing the operations of this application can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java and C++, and conventional procedural programming languages ​​such as C or similar languages. The computer program can execute entirely on the user's electronic device, partially on the user's electronic device, as a standalone software package, partially on the user's electronic device and partially on a remote electronic device, or entirely on a remote electronic device or server. In cases involving remote electronic devices, the remote electronic device can be connected to the user's electronic device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external electronic device (e.g., via the Internet using an Internet service provider).

[0446] It should be noted that although several units or sub-units of the device have been mentioned in the detailed description above, this division is merely exemplary and not mandatory. In fact, according to embodiments of this application, the features and functions of two or more units described above can be embodied in one unit. Conversely, the features and functions of one unit described above can be further divided and embodied by multiple units.

[0447] Furthermore, although the operations of the method of this application are described in a specific order in the accompanying drawings, this does not require or imply that these operations must be performed in that specific order, or that all the operations shown must be performed to achieve the desired result. Additionally or alternatively, certain steps may be omitted, multiple steps may be combined into one step, and / or one step may be broken down into multiple steps.

[0448] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing a computer-usable computer program.

[0449] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, produce a machine for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0450] These computer program commands may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the commands stored in the computer-readable storage medium produce an article of manufacture including command means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0451] These computer program commands can also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing the commands executed on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0452] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.

[0453] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.

Claims

1. A code review method, characterized in that, The method includes: Obtain a training sample set and a test sample set, and divide the training sample set into multiple training sample subsets; the test sample set contains test samples that achieve the expected quality; After initial training of the code review model to be trained based on the training sample set, the test impact of each training sample subset on the code review model is determined; the test impact reflects the influence of the training sample subset on the performance change of the code review model on the test sample set. For the multiple training sample subsets, at least one target training sample subset whose test influence meets the preset influence conditions is clustered according to the sample gradient to obtain multiple clusters; Sampling is performed in each cluster, and the code review model that has been initially trained is retrained based on the obtained sample set to obtain the trained target code review model; wherein, the target code review model is used to generate review information for the code to be reviewed.

2. The method as described in claim 1, characterized in that, The step of determining the test impact of each training sample subset on the code review model includes: Determine the Hessian matrix of the loss function of the code review model, the first gradient vector corresponding to each training sample subset, and the second gradient vector corresponding to the test sample set; wherein the first gradient vector and the second gradient vector are determined based on the gradient vector of each sample in the corresponding set. For each training sample subset, the test impact of the training sample subset on the code review model is determined based on the first gradient vector corresponding to the training sample subset, the Hessian matrix, and the second gradient vector.

3. The method as described in claim 2, characterized in that, The first gradient vector and the second gradient vector are d-dimensional column vectors, and the Hessian matrix is ​​a d×d matrix; Based on the first gradient vector corresponding to the training sample subset, the Hessian matrix, and the second gradient vector, the test impact of the training sample subset on the code review model is determined, including: The transpose of the second gradient vector is multiplied by the inverse of the Hessian matrix to obtain the intermediate vector. Perform an inner product operation between the intermediate vector and the first gradient vector to obtain an intermediate scalar; The negative of the intermediate scalar is used as the test influence of the training sample subset on the code review model.

4. The method as described in claim 2, characterized in that, The gradient vector for each sample is determined based on the intermediate layer results of the code review model.

5. The method according to any one of claims 1 to 4, characterized in that, The target training sample subset is selected using at least one of the following methods: The N training sample subsets with the largest values ​​among the determined test influence values ​​are used as the target training sample subset, where N is a positive integer greater than or equal to 1. The subset of training samples that reaches the preset influence threshold is used as the target training sample subset.

6. The method according to any one of claims 1 to 4, characterized in that, For the plurality of training sample subsets, at least one target training sample subset whose test influence meets the preset influence conditions is clustered according to the sample gradient to obtain multiple clusters, including: For each target training sample in the at least one subset of target training samples, determine the third gradient vector of the target training sample; Based on the distances between the determined third gradient vectors, each target training sample is clustered to obtain multiple clusters.

7. The method according to any one of claims 1 to 4, characterized in that, Before clustering according to sample gradients to obtain multiple clusters, the method further includes: Dimensionality reduction is performed on each target training sample; or The third gradient vector of each target training sample is dimensionality reduced.

8. The method according to any one of claims 1 to 4, characterized in that, The method further includes: The language instructions and the code to be reviewed are input into the target code review model. The review information of the code to be reviewed and the review probability corresponding to the review information are obtained according to the target code review model. The review probability includes the probability of each word in the review information. The language instructions and the review information are respectively input into at least one verification model to obtain the verification probability output by each verification model; each verification probability includes the probability of each word in the text sequence output by the corresponding verification model. Based on the review probability and each of the verification probabilities, a mutual information parameter is determined for the review information; wherein, each verification probability corresponds to a mutual information parameter. Based on the obtained mutual information parameters, determine whether to present the review information to the object.

9. The method as described in claim 8, characterized in that, The step of determining the mutual information parameters for the review information based on the review probability and each of the verification probabilities includes: For each verification probability, the logarithm of the product of the review probability and the corresponding verification probability is used as the mutual information parameter corresponding to the verification probability.

10. The method as described in claim 9, characterized in that, The step of determining the mutual information parameters for the review information based on the review probability and each of the verification probabilities includes: For each of the verification probabilities, a first ratio corresponding to the logarithm of the review probability and the length of the review information is determined, as well as a second ratio corresponding to the logarithm of the verification probability and the length of the text sequence. The sum of the first ratio and the second ratio is used as the mutual information parameter corresponding to the verification probability.

11. The method as described in claim 8, characterized in that, The step of determining whether to present the review information to the object based on the obtained mutual information parameters includes: If the statistical parameters obtained based on the various mutual information parameters exceed the preset parameter threshold, the review information will be presented to the object.

12. The method as described in claim 11, characterized in that, The target code review model is a large language model; the step of determining whether to present the review information to the object based on the obtained mutual information parameters includes: If the statistical parameters obtained based on the mutual information parameters do not exceed the preset parameter threshold, then new review information and review probabilities are regenerated based on the target code review model, and the process of inputting the language instructions and the review information into at least one verification model to obtain the verification probability output by each verification model is returned.

13. The method as described in claim 8, characterized in that, The review probability is a sequence of review probabilities in the form of a sequence, which contains the probability of each word in the review information; the verification probability is a sequence of verification probability in the form of a sequence, and each of the verification probability sequences contains the probability of each word in the text sequence output by the corresponding verification model.

14. A code review device, characterized in that, include: A data acquisition unit is used to acquire a training sample set and a test sample set, and to divide the training sample set into multiple training sample subsets; The test sample set contains test samples that meet the expected quality. The first processing unit is used to perform preliminary training on the code review model to be trained based on the training sample set, and then determine the test impact of each training sample subset on the code review model. The test impact reflects the influence of a subset of training samples on the performance changes of the code review model on the test sample set; The filtering unit is used to cluster at least one target training sample subset whose influence meets the preset influence conditions from the plurality of training sample subsets, according to the sample gradient, to obtain multiple clusters. The second processing unit is used to sample in each cluster and retrain the code review model that has been initially trained based on the obtained sample set to obtain the trained target code review model; wherein, the target code review model is used to generate review information for the code to be reviewed.

15. An electronic device, characterized in that, It includes a processor and a memory, wherein the memory stores a computer program that, when executed by the processor, causes the processor to perform the steps of any of the methods described in claims 1 to 13.

16. A computer-readable storage medium, characterized in that, It includes a computer program that, when run on an electronic device, causes the electronic device to perform the steps of any of the methods described in claims 1 to 13.

17. A computer program product, characterized in that, The method includes a computer program stored in a computer-readable storage medium; when a processor of an electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, causing the electronic device to perform the steps of any one of claims 1 to 13.