Method for training large model in comment positioning scene of code review

By training a large model in a code review scenario and using positive and negative sample data for supervised fine-tuning and direct preference optimization, the problems of inaccurate localization and slow response of large models are solved, and more efficient code snippet localization is achieved.

CN121705145APending Publication Date: 2026-03-20ALIBABA (CHINA) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511725975.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-21
Publication Date
2026-03-20

AI Technical Summary

Technical Problem

In existing technologies, large models have a low success rate in locating code snippets during code reviews, slow response speed, and are easily tampered with, leading to inaccurate location.

Method used

By acquiring multiple positive sample data, generating positive and negative sample pairs, and performing supervised fine-tuning and direct preference optimization, a large target model is trained to improve the localization success rate and response speed.

Benefits of technology

It improves the success rate and response speed of large models in code review, and reduces inference cost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121705145A_ABST
    Figure CN121705145A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a method for training a large model in a comment positioning scene of code review. In the embodiment of the invention, multiple pieces of positive sample data are obtained, and each piece of positive sample data comprises code snippets which are successfully positioned; multiple positive and negative sample pair data are generated according to each piece of positive sample data, and the positive and negative sample pair data comprise code snippets which are successfully positioned and code snippets which are tampered based on the code snippets which are successfully positioned; performing supervised fine tuning (SFT) on the initial large model according to the plurality of positive sample data to generate an intermediate large model; and performing direct preference optimization (DPO) on the intermediate large model according to the plurality of positive and negative sample pair data to generate a target large model. According to the method, the positive sample data and the positive and negative sample pair data are adopted to carry out supervision fine tuning and direct preference optimization on the initial large model, the success rate of comment positioning of the target large model can be improved, and the response speed of comment positioning is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and more specifically, to a method for training large models in the context of code review comment location. Background Technology

[0002] In the field of Artificial Intelligence (AI) code review, the Unified Diff text is first input into a large model, and then code review results are generated. These results include review comments on the problems found in the Unified Diff text, which can also be called comments. The comments need to be precisely located to the corresponding code segments.

[0003] In existing technologies, manually locating the code segment containing the problem in code review results requires significant human resources and is susceptible to human error. To reduce human resource consumption, a method of calculating line numbers using large models has been proposed to locate the code segment corresponding to the problem. However, large models have limited computational power, and the line numbers output by the large models may be offset, making it impossible to accurately locate the code segment. Subsequently, a method of restoring code segments using large models has been proposed. However, this method relies on large-size models, has a slow response speed, and the code is easily tampered with using these large-size models, resulting in the tampered code segment not being able to accurately match the original code, leading to a low success rate in locating the problem.

[0004] In conclusion, improving the success rate of large-scale models in locating comments and increasing response speed are problems that need to be solved. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a method for training a large model in the context of comment location in code review, which can improve the success rate of large model in comment location and improve the response speed of comment location.

[0006] In a first aspect, embodiments of the present invention provide a method for training a large model in a code review comment location scenario. The method includes: acquiring multiple positive sample data, wherein each positive sample data includes a code segment that has been successfully located; generating multiple positive and negative sample pairs based on each positive sample data, wherein the positive and negative sample pairs include code segments that have been successfully located and code segments that have been modified based on the code segments that have been successfully located; performing supervised fine-tuning (SFT) on an initial large model based on the multiple positive sample data to generate an intermediate large model; and performing direct preference optimization (DPO) on the intermediate large model based on the multiple positive and negative sample pairs to generate a target large model.

[0007] Optionally, the method further includes: acquiring multiple negative sample data, wherein each negative sample data includes a code segment that failed to locate; and determining the tampering type ratio of the code segment that failed to locate based on the multiple negative sample data.

[0008] Optionally, generating multiple positive and negative sample pairs based on each positive sample data specifically includes: generating multiple positive and negative sample pairs based on the proportion of the tampering type for each positive sample data.

[0009] Optionally, obtaining multiple positive sample data further includes: obtaining a correct dataset and a failed modification dataset, wherein the correct dataset and the failed modification dataset each include multiple positive sample data; and extracting multiple positive sample data from the correct dataset and the failed modification dataset according to a set ratio.

[0010] Optionally, obtaining the correct dataset specifically includes: obtaining multiple candidate positive sample data; filtering the multiple candidate positive sample data to determine that the multiple positive sample data constitute the correct dataset.

[0011] Optionally, obtaining the failed modification dataset specifically includes: obtaining multiple negative sample data, wherein the negative sample data includes review comments; using multiple large models to relocate the review comments in each of the negative sample data; calculating the location consistency of the multiple large models to determine the location repair standard data; and combining the multiple location repair standard data to form the failed modification dataset.

[0012] Optionally, the method further includes: acquiring new positive sample data and new negative sample data; inputting the new positive sample data and the new negative sample data into the intermediate large model to determine multiple positioning failure sample data, wherein the positioning failure sample data includes code segments that have been modified based on code segments that have been successfully positioned; repositioning each of the positioning failure sample data through multiple large models to determine data that has been corrected for positioning failure, wherein the data that has been corrected for positioning failure includes code segments that have been successfully positioned; saving the code segments that have been modified based on code segments that have been successfully positioned and the code segments that have been successfully positioned to generate the positive and negative sample pairs.

[0013] Secondly, embodiments of the present invention provide an apparatus for training a large model in a code review comment location scenario. The apparatus includes: an acquisition unit for acquiring multiple positive sample data, wherein each positive sample data includes a code segment that has been successfully located; a generation unit for generating multiple positive and negative sample pairs based on each positive sample data, wherein the positive and negative sample pairs include code segments that have been successfully located and code segments that have been modified based on the code segments that have been successfully located; a supervised fine-tuning unit for performing supervised fine-tuning (SFT) on an initial large model based on the multiple positive sample data to generate an intermediate large model; and an optimization unit for performing direct preference optimization (DPO) on the intermediate large model based on the multiple positive and negative sample pairs to generate a target large model.

[0014] Optionally, the acquisition unit is further configured to: acquire multiple negative sample data, wherein each negative sample data includes a code segment that failed to locate; the device further includes: a determination unit, configured to determine the tampering type ratio of the code segment that failed to locate based on the multiple negative sample data.

[0015] Optionally, the generation unit is specifically used to: generate multiple pairs of positive and negative sample data for each positive sample data according to the proportion of the tampering type.

[0016] Optionally, the acquisition unit is further configured to: acquire a correct dataset and a failed modification dataset, wherein the correct dataset and the failed modification dataset each include multiple positive sample data; and extract multiple positive sample data from the correct dataset and the failed modification dataset according to a set ratio.

[0017] Optionally, the acquisition unit is specifically used to: acquire multiple candidate positive sample data; filter the multiple candidate positive sample data to determine that the multiple positive sample data constitute the correct dataset.

[0018] Optionally, the acquisition unit is further configured to: acquire multiple negative sample data, wherein the negative sample data includes review comments; relocate the review comments in each negative sample data using multiple large models; calculate the location consistency of the multiple large models to determine the location repair standard data; and combine the multiple location repair standard data into the failed modification dataset.

[0019] Optionally, the acquisition unit is further configured to: acquire new positive sample data and new negative sample data; input the new positive sample data and the new negative sample data into the intermediate large model to determine multiple positioning failure sample data, wherein the positioning failure sample data includes code segments that have been modified based on code segments that have been successfully positioned; reposition each of the positioning failure sample data through multiple large models to determine data that has been corrected for positioning failure, wherein the data that has been corrected for positioning failure includes code segments that have been successfully positioned; save the code segments that have been modified based on code segments that have been successfully positioned and the code segments that have been successfully positioned to generate the positive and negative sample pairs.

[0020] Thirdly, embodiments of the present invention provide an electronic device, including a memory and a processor, wherein the memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method as described in the first aspect or any one of the possible methods of the first aspect.

[0021] Fourthly, embodiments of the present invention provide a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, implement the method as described in the first aspect or any one of the possibilities of the first aspect.

[0022] In this embodiment of the invention, multiple positive sample data are acquired, each including a code snippet indicating successful localization; multiple positive and negative sample pairs are generated based on each positive sample data, including code snippets indicating successful localization and code snippets modified from the code snippets indicating successful localization; supervised fine-tuning of the initial large model using the multiple positive sample data is performed to generate an intermediate large model; and direct preference optimization (DPO) is performed on the intermediate large model using the multiple positive and negative sample pairs to generate the target large model. By using positive sample data and positive and negative sample pairs to perform supervised fine-tuning and direct preference optimization on the initial large model, the success rate of the target large model in locating comments can be improved, and the response speed of comment localization can be increased. Attached Figure Description

[0023] The above and other objects, features and advantages of the present invention will become clearer from the following description of embodiments of the invention with reference to the accompanying drawings, in which: Figure 1 This is a flowchart of a method for training a large model in a code review comment location scenario according to an embodiment of the present invention; Figure 2 This is a flowchart of another method for training a large model in the context of code review comment location in an embodiment of the present invention; Figure 3This is a flowchart of another method for training a large model in the context of code review comment location in an embodiment of the present invention; Figure 4 This is a flowchart of another method for training a large model in the context of code review comment location in this embodiment of the invention; Figure 5 This is a schematic diagram of an apparatus for training a large model in a code review comment location scenario according to an embodiment of the present invention; Figure 6 This is a schematic diagram of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0024] The present application is described below based on embodiments, but it is not limited to these embodiments. In the detailed description of the present application below, certain specific details are described in detail. Those skilled in the art can fully understand the present application without these details. To avoid obscuring the substance of the present application, well-known methods, processes, flows, elements, and circuits are not described in detail.

[0025] Furthermore, those skilled in the art should understand that the accompanying drawings provided herein are for illustrative purposes only and are not necessarily drawn to scale.

[0026] Unless the context explicitly requires it, words such as "including" or "contains" throughout the application should be interpreted as including rather than exclusive or exhaustive; that is, meaning "including but not limited to".

[0027] In the description of this application, it should be understood that the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0028] In existing technologies, code review processes typically involve manually searching, using large-scale model-calculated line numbers, or having a large-scale model return line numbers to locate the code segments corresponding to issues in the Unified Diff (Unified Diff) text. This involves locating the review comments (also known as remarks) corresponding to the issues within the code segments of the Unified Diff text. This code review can also be called code inspection, which refers to the systematic review of computer source code, often conducted through peer review. Its purpose is to identify and correct errors missed in the early stages of software development, thereby improving software quality and the developer's technical skills. Large-scale model-based code review, or AI code review, is a method that uses artificial intelligence to assist or automate the software code review process. It combines machine learning, natural language processing, and static code analysis, among other AI technologies, to analyze, evaluate, and improve code quality. During the review process, the AI-identified code issues are located using localization techniques, simulating human commentary on the code segments. Specifically, manually locating the problematic code segment in the code review results requires significant manpower and is susceptible to human error. The large model calculates line numbers by providing examples (e.g., few-shots) to illustrate the calculation rules for the Diff head. The Diff head refers to lines in the Unified Diff that begin and end with @@. For example, @@ -1,7 +1,6@@ indicates that the old code counts 7 lines from line 1, and the new code counts 6 lines from line 1. The old code is the code before modification, and the new code is the code after modification. The Unified Diff text is determined based on the old and new code. The large model calculates the line number of the problematic code segment based on the Diff head calculation rules, but its computational capabilities are limited, resulting in inaccurate line number calculations and an inability to accurately locate the code segment. The large model returns the line number specifically through the Diff... The `head` function calculates the line number of the code segment and appends a line number identifier to the beginning of the line. The Diff head with the line number identifier is then input into the large model, which returns the line number of the problematic code segment. Some tools convert the Unified Diff code into old and new code before adding the line number identifier and then add the line number to each. The large model is not sensitive to numbers, and in actual use, positional offsets may occur, meaning that the code segment cannot be accurately located.

[0029] During code review, a method of restoring code snippets using a large model was proposed. This method uses prompts to guide the large model to output the original code snippet corresponding to the code problem. However, this method relies on a large model, resulting in slow response times, especially in synchronous tasks within an Integrated Development Environment (IDE), impacting user experience. Furthermore, the large model is susceptible to code tampering, leading to altered code snippets that cannot accurately match the original, resulting in a low success rate for localization. Additionally, the large model incurs high inference costs and resource consumption. Therefore, improving the success rate of large models in locating comments and increasing response speed are current challenges that need to be addressed.

[0030] In this embodiment of the invention, the large model can also be called an Artificial Intelligence (AI) model or a Large Language Model (LLM). The large language model is a deep learning model based on a transformer architecture that can process and generate natural language text. It is usually trained on a large amount of text data and has the ability to understand and generate language. It is widely used in dialogue systems, text generation and other natural language processing tasks.

[0031] In this embodiment of the invention, to address the aforementioned problems, a method for training a large model in the context of code review comment localization is proposed, specifically as follows: Figure 1 As shown, the method includes: Step S101: Obtain multiple positive sample data.

[0032] Specifically, each of the positive sample data includes a code snippet indicating successful localization.

[0033] In one possible implementation, a unified output format (Unified Diff) text and AI review comments are input into the large model. The output is the code snippet that was successfully located according to the AI ​​review comments, also known as the AI-reconstructed code snippet, i.e., the code snippet reconstructed by the large model through the AI ​​review comments. If the code snippet reconstructed according to the AI ​​review comments is the original code snippet in the Unified Diff text, then the AI ​​review comments have successfully located the code. If the code snippet reconstructed according to the AI ​​review comments is a code snippet modified from the original code snippet, then the AI ​​review comments have failed to locate the code. The Unified Diff text can also be called code difference content. The Unified Diff is a variant of the context format, omitting redundant context lines, making the format more compact. When generating the Unified Diff, the parameter `lines` is set, indicating the number of context lines to be displayed for the modified code. It is generally set to three lines by default. Specifically, the Unified Diff format can be generated using GNUdiff, where GNU diff is a command-line tool widely used in UNIX and UNIX-like systems for comparing the differences between two files or directories.

[0034] In this embodiment of the invention, the format of the positive sample data is {"code_diff": "code difference content", "ai_comment": "AI review comments", "ai_code_snippet": "AI-recited code snippet"}, wherein the AI-recited code snippet is the code snippet that was successfully located.

[0035] In one possible implementation, in addition to the positive sample data of a successful localization, negative sample data can also be obtained. The negative sample data includes code fragments that failed to be localized. The negative sample data is reconstructed using a large-size model to reconstruct the target code fragments. The localization function is used to determine whether the localization of the reconstructed target code fragments is correct. The target code fragments that are correctly localized are selected. The negative sample data is then distilled to generate positive sample data.

[0036] In this embodiment of the invention, the positive sample data that was successfully located once from the plurality of positive sample data can be mixed with the positive sample data distilled from the negative sample data in a set ratio.

[0037] Step S102: Generate multiple positive and negative sample pairs based on each of the positive sample data.

[0038] Specifically, the positive and negative sample pairs include code snippets that were successfully located and code snippets that were modified based on the successfully located code snippets.

[0039] In one possible implementation, constructing corresponding negative sample data using the positive sample data can ensure semantic consistency between comments and code snippets while guaranteeing successful location. When generating a modified code snippet based on the successfully located code snippet, traditional formatting methods (such as spaces, line breaks, etc.), omitting some lines, or formatting using a large model, omitting some lines, or refactoring the code while maintaining the original semantics can be used.

[0040] For example, the format of the positive and negative sample data is as follows: {"code_diff": "code difference content", "ai_comment": "AI review comments", "ai_code_snippet_success": "code snippet that was successfully located", "ai_code_snippet_fail": "code snippet that was tampered with based on the code snippet that was successfully located"}.

[0041] Step S103: Perform supervised fine-tuning of the initial large model using multiple positive sample data to generate an intermediate large model.

[0042] In one possible implementation, the initial large model is subjected to supervised fine-tuning (SFT) through a supervised fine-tuning instruction design, wherein the initial large model is a small-sized large model.

[0043] For example, the design of the supervision and fine-tuning instruction is as follows: <|system|> ```system ### Role Definition You are a professional code comment location assistant, responsible for generating target code snippets corresponding to code comments to improve the location accuracy of the diff-based dynamic sliding window algorithm.

[0044] ### Algorithm Principles **Dynamic sliding window algorithm based on diff:** - **Input**: diff changes + target code snippet - **Execution**: Match line by line in the diff hunk, with the target code line number as the window size, and trim the content during matching. - **Output**: Coordinates of the window positions of successfully matched windows ### Common causes and solutions for location failure #### 1. Line break format mismatch The code is under change. ```diff the line code1 + the line + code2 + the line code3 the line code4 ``` The target code snippet for the error example: the line code2 the line code3 At this point, you should return to the target code snippet: the line code2 the line code3 #### 2. Inconsistent spaces between the target code and the modified code caused the matching to fail. The code is under change. ```diff the line code1 + the line code 2 the line code3 ``` The target code snippet for the error example: the line code2 At this point, you should return to the target code snippet: the line code 2 #### 3. The target code omits blank lines or other lines, disrupting continuity. The code is under change. ```diff the line code1 + the line code2 + + the line code4 the line code5 ``` The target code snippet for the error example: the line code2 the line code4 At this point, you should return to the target code snippet: the line code2 the line code4 ``` <|user|> ```user ### Code Changes {diff} ### Problem Description {suggestion_content} ### Task - Based on the problem description, search through the code changes to find the approximate location.

[0045] Please re-output the target code snippet so that it can use the comment location algorithm to pinpoint the correct location in the code change.

[0046] Please return directly to the modified target code snippet; do not use ``` code snippet inclusions, and do not return any other content.

[0047] ``` Specifically, during the initial large model training process, the code change {diff} in <|user|> above will be replaced with code_diff: "code difference content" in the positive sample data; the problem description {suggestion_content} above will be replaced with "AI review comments" in the positive sample data.

[0048] In this embodiment of the invention, the above-described design of the supervisory fine-tuning instruction is merely an illustrative example, and the specific design should be based on actual circumstances.

[0049] Step S104: Perform Direct Preference Optimization (DPO) on the intermediate large model based on the multiple positive and negative sample pairs to generate the target large model.

[0050] Specifically, Direct Preference Optimization (DPO) is a simplified reinforcement learning method that directly utilizes preference data (e.g., "better answer - worse answer" pairs) to optimize the model, thereby aligning the model output with the preferences.

[0051] In one possible implementation, the intermediate large model is trained using DPO instructions in JSON format. For example, the DPO instruction design is as follows: json [ { "instruction": "<task_instruction> ", "chosen": "Good Case(Rewrite)", "rejected": "Bad Case(Original)" } ] ``` Specifically, the task_instruction is replaced with the same content in the supervised fine-tuning instruction design, except that the code change {diff} in <|user|> is replaced with code_diff: "code difference content" in the positive and negative sample pair data; the problem description {suggestion_content} is replaced with "AI review comments" in the positive and negative sample pair data; the Good Case is replaced with "code snippet that was successfully located" in the positive and negative sample pair data; and the Bad Case is replaced with "code snippet that was tampered with based on code snippet that was successfully located" in the positive and negative sample pair data.

[0052] In this embodiment of the invention, the above-described DPO instruction design is merely an example and should be designed according to actual circumstances.

[0053] In one possible implementation, after step S101, other steps are included, specifically as follows: Figure 2 As shown, it includes the following steps: Step S105: Obtain multiple negative sample data.

[0054] Specifically, each of the negative sample data includes a code snippet indicating a failed localization.

[0055] Step S106: Determine the tampering type ratio of the code segment that failed to locate based on multiple negative sample data.

[0056] In one possible implementation, the type of tampering includes formatting, omitting lines, and code refactoring, which are merely illustrative examples.

[0057] In one possible implementation, generating multiple positive and negative sample pairs based on each positive sample data specifically includes: generating multiple positive and negative sample pairs based on the proportion of the tampering type for each positive sample data.

[0058] In this embodiment of the invention, generating positive and negative sample pairs based on the proportion of tampering types can improve the balance of the target large model during subsequent DPO training.

[0059] In this embodiment of the invention, the generation of the above-mentioned positive sample data and positive-negative sample pairs is a method for obtaining training data before training the target large model. As the target large model is trained, new data will be continuously generated, and new positive sample data and positive-negative sample pairs will be determined based on the continuously generated new data.

[0060] In one possible implementation, the process for generating new positive sample data is as follows: Figure 3 As shown, it includes the following steps: Step S301: Obtain the correct dataset and the failed dataset and modify it.

[0061] Specifically, the correct dataset and the failed modification dataset each include multiple positive sample data.

[0062] In one possible implementation, obtaining the correct dataset and the failed modified dataset includes: obtaining multiple candidate positive sample data; filtering the multiple candidate positive sample data to determine that the multiple positive sample data constitute the correct dataset. The filtering method includes deleting candidate positive sample data with excessively large location ranges and deleting candidate positive sample data for which the user feedback indicates rejection.

[0063] In this embodiment of the invention, the positive sample data in the correct dataset can stabilize the localization ability of the intermediate large model itself during subsequent supervised fine-tuning training, and avoid catastrophic forgetting caused by the intermediate large model.

[0064] In one possible implementation, obtaining the failed modification dataset specifically includes: obtaining multiple negative sample data, wherein the negative sample data includes review comments; using multiple large models to relocate the review comments in each of the negative sample data; calculating the location consistency of the multiple large models to determine the location repair standard data; and combining the multiple location repair standard data to form the failed modification dataset.

[0065] Step S302: Extract multiple positive sample data from the correct dataset and the failed modified dataset according to a set ratio.

[0066] Specifically, multiple positive sample data will be extracted according to a set ratio to construct a supervised fine-tuning dataset. The initial large model will be supervised and fine-tuned using the supervised fine-tuning dataset to generate an intermediate large model.

[0067] In one possible implementation, the process of generating new positive and negative sample pairs is as follows: Figure 4 As shown, it includes the following steps: Step S401: Obtain new positive sample data and new negative sample data.

[0068] Step S402: Input the new positive sample data and the new negative sample data into the intermediate large model to determine multiple sample data of failed localization.

[0069] The sample data of failed positioning includes code segments that have been tampered with based on code segments that were successfully positioned.

[0070] Step S403: Relocate each of the failed positioning sample data through multiple large models to determine the data that failed to be positioned.

[0071] The data for fixing location failures includes the code snippets for successful location fixing.

[0072] Step S404: Save the code segment that was tampered with based on the code segment that was successfully located and the code segment that was successfully located, and generate the positive and negative sample pairs.

[0073] In this embodiment of the invention, multiple positive and negative samples are generated to perform DPO on the intermediate large model to generate the target large model.

[0074] In one possible implementation, when determining the positive and negative sample data for the initial large model training, a set proportion of sample data is retained as the evaluation dataset. The target large model is then used to continue calculating positive sample recall, negative sample recall, code comment relevance, average inference time, etc. The obtained calculation results are all improved compared with traditional localization methods.

[0075] Through the above embodiments, by supervising and fine-tuning the small-sized initial large model and using reinforcement learning, the localization accuracy of the small-sized large model is improved while the response speed is increased and the inference cost is reduced.

[0076] In this embodiment of the invention, an apparatus for training a large model in a code review comment location scenario is provided, such as... Figure 5 As shown, the system specifically includes: an acquisition unit 501, a generation unit 502, a supervised fine-tuning unit 503, and an optimization unit 504; wherein, the acquisition unit 501 is used to acquire multiple positive sample data, wherein each positive sample data includes a code fragment that has been successfully located; the generation unit 502 is used to generate multiple positive and negative sample pairs based on each positive sample data, wherein the positive and negative sample pairs include code fragments that have been successfully located and code fragments that have been modified based on the code fragments that have been successfully located; the supervised fine-tuning unit 503 is used to perform supervised fine-tuning of the initial large model using the multiple positive sample data to generate an intermediate large model; the optimization unit 504 is used to perform direct preference optimization (DPO) on the intermediate large model using the multiple positive and negative sample pairs to generate a target large model.

[0077] Furthermore, the acquisition unit is also configured to: acquire multiple negative sample data, wherein each negative sample data includes a code segment that failed to locate; the device further includes: a determination unit, configured to determine the tampering type ratio of the code segment that failed to locate based on the multiple negative sample data.

[0078] Furthermore, the generation unit is specifically used to generate multiple pairs of positive and negative sample data for each positive sample data according to the proportion of the tampering type.

[0079] Furthermore, the acquisition unit is also configured to: acquire a correct dataset and a failed modification dataset, wherein the correct dataset and the failed modification dataset each include multiple positive sample data; and extract multiple positive sample data from the correct dataset and the failed modification dataset according to a set ratio.

[0080] Furthermore, the acquisition unit is specifically used to: acquire multiple candidate positive sample data; filter the multiple candidate positive sample data to determine that the multiple positive sample data constitute the correct dataset.

[0081] Furthermore, the acquisition unit is specifically used to: acquire multiple negative sample data, wherein the negative sample data includes review comments; relocate the review comments in each negative sample data using multiple large models; calculate the location consistency of the multiple large models to determine the location repair standard data; and combine the multiple location repair standard data into the failed modification dataset.

[0082] Furthermore, the acquisition unit is also configured to: acquire new positive sample data and new negative sample data; input the new positive sample data and the new negative sample data into the intermediate large model to determine multiple positioning failure sample data, wherein the positioning failure sample data includes code segments that have been modified based on code segments that have been successfully positioned; reposition each of the positioning failure sample data through multiple large models to determine data that has been corrected for positioning failure, wherein the data that has been corrected for positioning failure includes code segments that have been successfully positioned; save the code segments that have been modified based on code segments that have been successfully positioned and the code segments that have been successfully positioned to generate the positive and negative sample pairs.

[0083] Figure 6 This is a schematic diagram of the structure of the electronic device described in an embodiment of the present invention. Figure 6As shown, it includes a general computer hardware architecture, which includes at least a processor 601 and a memory 602. The processor 601 and the memory 602 are connected via a bus 603. The memory 602 is adapted to store instructions or programs executable by the processor 601. The processor 601 can be a standalone microprocessor or a collection of one or more microprocessors. Thus, the processor 601 executes the instructions stored in the memory 602 to perform the method flow of the embodiments of the present invention as described above, thereby realizing data processing and control of other devices. The bus 603 connects the above-mentioned components together, and also connects the above-mentioned components to a display controller 604, a display device, and an input / output (I / O) device 605. The input / output (I / O) device 605 can be a mouse, keyboard, modem, network interface, touch input device, motion-sensing input device, printer, and other devices known in the art. Typically, the input / output device 605 is connected to the system via an input / output (I / O) controller 606.

[0084] The instructions stored in memory 602 are executed by at least one processor 601 to: acquire multiple positive sample data; generate multiple positive-negative sample pairs based on each of the positive sample data; perform supervised fine-tuning (SFT) on an initial large model based on the multiple positive sample data to generate an intermediate large model; and perform direct preference optimization (DPO) on the intermediate large model based on the multiple positive-negative sample pairs to generate a target large model.

[0085] Specifically, the electronic device includes: one or more processors 601 and a memory 602. Figure 6 Take a processor 601 as an example. The processor 601 and the memory 602 can be connected via a bus or other means. Figure 6 Taking a bus connection as an example, memory 602, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. Processor 601 executes various functional applications and data processing of the device by running the non-volatile software programs, instructions, and modules stored in memory 602, thereby implementing the aforementioned method for training a large model in the context of code review comment positioning.

[0086] Memory 602 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function; the data storage area may store an option list, etc. Furthermore, memory 602 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 non-volatile solid-state storage device. In some embodiments, memory 602 may optionally include memory remotely located relative to processor 601, and these remote memories may be connected to external devices via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0087] One or more modules are stored in memory 602, and when executed by one or more processors 601, they execute the method for training a large model in the comment location scenario of code review in any of the above method embodiments.

[0088] As those skilled in the art will recognize, various aspects of the embodiments of the present invention can be implemented as a system, method, or computer program product. Therefore, various aspects of the embodiments of the present invention can take the form of a completely hardware implementation, a completely software implementation (including firmware, resident software, microcode, etc.), or an implementation combining software and hardware aspects, which may generally be referred to herein as a "circuit," "module," or "system." Furthermore, various aspects of the embodiments of the present invention can take the form of a computer program product implemented in one or more computer-readable media having computer-readable program code implemented thereon.

[0089] Any combination of one or more computer-readable media can be used. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example, (but not limited to) an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination thereof. More specific examples (not an exhaustive list) of computer-readable storage media will include: an electrical connection having one or more wires, a portable computer floppy disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable optical disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the context of embodiments of the present invention, a computer-readable storage medium can be any tangible medium capable of containing or storing a program used by or in conjunction with an instruction execution system, device, or apparatus.

[0090] Computer-readable signal media may include propagated digital signals having computer-readable program code implemented therein, such as in baseband or as part of a carrier wave. Such propagated signals may take any of a variety of forms, including, but not limited to, electromagnetic, optical, or any suitable combination thereof. A computer-readable signal medium may be any computer-readable medium that is not a computer-readable storage medium and can communicate, propagate, or transmit a program used by or in conjunction with an instruction execution system, device, or apparatus.

[0091] Program code implemented on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, fiber optic cable, RF, or any suitable combination thereof.

[0092] Computer program code for performing operations relating to various aspects of embodiments of the present invention can be written in any combination of one or more programming languages, including: object-oriented programming languages ​​such as Java, Smalltalk, C++, etc.; and conventional procedural programming languages ​​such as the "C" programming language or similar programming languages. The program code can be executed as a standalone software package entirely on the user's computer, partially on the user's computer, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer can be connected to the user's computer 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 computer (e.g., via the Internet provided by an Internet service provider).

[0093] The flowchart illustrations and / or block diagrams of the methods, apparatus (systems), and computer program products according to embodiments of the present invention describe various aspects of the embodiments of the present invention. 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, or other programmable data processing apparatus to produce a machine such that the instructions (executed via the processor of the computer or other programmable data processing apparatus) create means for implementing the functions / actions specified in the flowchart and / or block diagram blocks or blocks.

[0094] These computer program instructions may also be stored in a computer-readable medium that can direct a computer, other programmable data processing apparatus or other means to operate in a particular manner, such that the instructions stored in the computer-readable medium produce an article of writing that includes instructions that implement the functions / actions specified in flowchart and / or block diagram blocks or blocks.

[0095] Computer program instructions may also be loaded onto a computer, other programmable data processing apparatus or other device to cause a series of operable steps to be performed on the computer, other programmable apparatus or other device to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide for implementing the functions / actions specified in flowchart and / or block diagram blocks or blocks.

[0096] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

[0097] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, and displayed data) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use, and processing of such data must comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding access points are provided for users to choose to authorize or refuse processing. A user's refusal to process personal information beyond what is necessary for basic functions will not affect the user's use of basic functions.

Claims

1. A method for training a large model in a code review comment location scenario, characterized in that, The method includes: Acquire multiple positive sample data, wherein each positive sample data includes a code snippet indicating successful localization; Multiple positive and negative sample pairs are generated based on each positive sample data, wherein the positive and negative sample pairs include code fragments that were successfully located and code fragments that were modified based on the code fragments that were successfully located; The initial large model is subjected to supervised fine-tuning of the SFT based on multiple positive sample data to generate an intermediate large model; Based on multiple positive and negative sample pairs, the intermediate large model is directly optimized using the DPO (Direct Preference Optimization) method to generate the target large model.

2. The method according to claim 1, characterized in that, The method further includes: Acquire multiple negative sample data, wherein each negative sample data includes a code snippet indicating a failed localization; The proportion of tampering types of the code segments that failed to locate were determined based on multiple negative sample data.

3. The method according to claim 2, characterized in that, The step of generating multiple positive and negative sample pairs based on each positive sample data specifically includes: Each positive sample data point generates multiple positive and negative sample pairs based on the proportion of the tampering type.

4. The method according to claim 1, characterized in that, The acquisition of multiple positive sample data also includes: Obtain a correct dataset and a failed modification dataset, wherein the correct dataset and the failed modification dataset each include multiple positive sample data; Multiple positive sample data are extracted from the correct dataset and the failed modified dataset according to a set ratio.

5. The method according to claim 4, characterized in that, Obtaining the correct dataset specifically includes: Obtain multiple candidate positive sample data; The candidate positive sample data are filtered to determine the correct dataset.

6. The method according to claim 4, characterized in that, The process of retrieving the failed modified dataset specifically includes: Obtain multiple negative sample data, wherein the negative sample data includes review comments; Multiple large models are used to reposition the review comments in each of the negative sample data; Calculate the localization consistency of the multiple large models and determine the localization repair standard data; The failure modification dataset is composed of multiple sets of location repair standard data.

7. The method according to claim 1, characterized in that, The method further includes: Obtain new positive sample data and new negative sample data; The new positive sample data and the new negative sample data are input into the intermediate large model to determine multiple positioning failure sample data, wherein the positioning failure sample data includes code segments that have been tampered with based on code segments that have been successfully positioned. Each of the failed positioning sample data is repositioned using multiple large models to determine the data that was corrected for the failed positioning. The data that was corrected for the failed positioning includes the code fragments that were corrected for the successful positioning. Save the modified code segment based on the successfully located code segment and the successfully located code segment to generate the positive and negative sample pairs.

8. An apparatus for training a large model in a code review comment location scenario, characterized in that, The device includes: An acquisition unit is used to acquire multiple positive sample data, wherein each positive sample data includes a code fragment indicating successful localization; A generation unit is configured to generate multiple positive and negative sample pairs based on each positive sample data, wherein the positive and negative sample pairs include code segments that have been successfully located and code segments that have been modified based on the code segments that have been successfully located. The supervised fine-tuning unit is used to perform supervised fine-tuning of the SFT on the initial large model based on multiple positive sample data to generate an intermediate large model. The optimization unit is used to perform Direct Preference Optimization (DPO) on the intermediate large model based on multiple positive and negative sample pairs of data to generate the target large model.

9. An electronic device comprising a memory and a processor, characterized in that, The memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1-7.