Code detection method and device based on fine-tuning large model
By building fine-tuning models and code generation models, automatic detection and repair of code, the problem of manual detection and repair of code efficiency and accuracy is solved, and efficient and accurate code detection and repair is achieved.
Patent Information
- Application Number
- CN202510006669.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-03
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2045-01-03
AI Technical Summary
In the prior art, manual detection and repair codes are accurate and efficient, and the correct code cannot be quickly obtained.
By constructing a fine-tuning model, including the correspondence between the detection code and the reference detection result, obtain the code to be detected and preprocessed, obtain the detection result based on the fine-tuning model, and use the code generation model to adjust the code to be detected to be generated code snippets.
It realizes automated code detection and repair, improves the accuracy and efficiency of code detection, and the generated code snippets can run normally, solving the problem of low efficiency and accuracy of manual detection and repair of code.
Smart Images

Figure CN119807003A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of deep machine learning algorithms, and in particular to a code detection method and device based on fine-tuning a large model. Background Art
[0002] In recent years, the rise of big models in the field of artificial intelligence has attracted widespread attention and discussion. With the continuous maturity of model training and fine-tuning technology, the continuous improvement of the base model's ability to code has enabled program developers to greatly improve development efficiency in the corresponding development work. Traditional code maintenance relies on manual review and testing, which are time-consuming and susceptible to human errors. As the scale and complexity of software systems increase, the accuracy and efficiency of manual code detection and repair are low, and it is impossible to quickly obtain the correct code. Summary of the invention
[0003] The present invention provides a code detection method and device based on fine-tuning a large model, which solves the problems of low accuracy and efficiency in manual code detection and code repair in the prior art.
[0004] According to one aspect of the present invention, a code detection method based on a fine-tuned large model is provided, comprising:
[0005] Constructing a fine-tuning model; wherein the fine-tuning model includes a correspondence between the detection code and the reference detection result;
[0006] Get the code to be tested;
[0007] Preprocessing the code to be detected to obtain the preprocessed code to be detected;
[0008] Acquire a detection result of the code to be detected according to the code to be detected and the fine-tuning model;
[0009] Based on the code generation model and according to the detection result, the code to be detected is adjusted and a code snippet is generated.
[0010] In one embodiment, the preprocessing of the code to be detected to obtain the preprocessed code to be detected includes:
[0011] According to the format requirements, verify the format of the code to be detected and generate a verification result;
[0012] If the verification result indicates that the format of the code to be detected is normal, then removing the characters matching the preset characters in the code to be detected to obtain a cleaned code to be detected;
[0013] Removing characters of the code to be detected that match the preset symbol to obtain the code to be detected after removal;
[0014] According to the screening rule, the key code is screened from the removed to-be-detected code.
[0015] In one embodiment, the filtering of the key code from the removed code to be detected according to the filtering rule includes:
[0016] Classifying the removed codes to be detected to obtain classified codes to be detected;
[0017] Running the classified code to be detected;
[0018] Select the classified code to be tested whose output result meets the functional requirements after running as the target code;
[0019] The object code having the same content as the object code is deleted to obtain the key code.
[0020] In one embodiment, constructing a fine-tuning model includes:
[0021] Acquire multiple abnormal detection codes and multiple normal detection codes; wherein the abnormal detection codes correspond to error types; wherein the reference detection results include the error types;
[0022] Based on the full parameter fine-tuning strategy, a fine-tuning model is generated according to the multiple abnormality detection codes, the multiple normal detection codes and the error type corresponding to each abnormality detection code.
[0023] In one embodiment, after obtaining the plurality of abnormal detection codes and the plurality of normal detection codes, the code detection method based on the fine-tuning large model further includes:
[0024] removing comments from the plurality of anomaly detection codes;
[0025] Remove comments from the plurality of normal detection codes;
[0026] The generating of the fine-tuning model based on the full parameter fine-tuning strategy according to the multiple abnormality detection codes, the multiple normal detection codes and the error type corresponding to each abnormality detection code comprises:
[0027] Based on the full parameter fine-tuning strategy, a fine-tuning model is generated according to the multiple removed abnormal detection codes, the multiple removed normal detection codes, and the error type corresponding to each removed abnormal detection code.
[0028] In one embodiment, the method for constructing the code generation model includes:
[0029] Acquire multiple abnormality detection codes and multiple normal detection codes; wherein the abnormality detection codes correspond to modified codes;
[0030] Based on the full parameter fine-tuning strategy, a code generation model is generated according to the multiple abnormality detection codes, the multiple normal detection codes and the modified code corresponding to each abnormality detection code.
[0031] In one embodiment, adjusting the code to be detected and generating a code snippet based on the code generation model and according to the detection result includes:
[0032] If the detection result indicates that the code to be detected is abnormal, the code to be detected is input into the code generation model to obtain a code fragment.
[0033] In one embodiment, before adjusting the code to be detected and generating code snippets based on the code generation model according to the detection result, the code detection method based on fine-tuning the large model further includes:
[0034] Get the number of runs;
[0035] Running the code to be detected and generating multiple running results according to the number of runs;
[0036] The step of adjusting the code to be detected and generating a code snippet based on the code generation model and the detection result includes:
[0037] If it is determined that the error type of each running result is the same as the initial error type corresponding to the code to be detected, based on the code generation model and according to the detection result, the code to be detected is adjusted and a code snippet is generated.
[0038] In one embodiment, adjusting the code to be detected and generating a code snippet based on the code generation model and according to the detection result includes:
[0039] If the detection result indicates that the code to be detected is abnormal, extracting the abnormal code of the code to be detected;
[0040] The exception code is input into the code generation model to generate a code snippet.
[0041] According to another aspect of the present invention, there is provided a code detection device based on a fine-tuned large model, comprising:
[0042] A construction module, used to construct a fine-tuning model; wherein the fine-tuning model includes a correspondence between the detection code and the reference detection result;
[0043] An acquisition module is used to obtain the code to be detected;
[0044] A preprocessing module, used for preprocessing the code to be detected to obtain the preprocessed code to be detected;
[0045] A detection module, used for obtaining a detection result of the code to be detected according to the code to be detected and the fine-tuning model;
[0046] A generation module is used to adjust the code to be detected and generate a code snippet based on a code generation model and according to the detection result.
[0047] The embodiment of the present invention provides a code detection method and device based on a fine-tuning large model, including: constructing a fine-tuning model, wherein the fine-tuning model includes a corresponding relationship between a detection code and a reference detection result, obtaining the code to be detected, preprocessing the code to be detected to obtain the preprocessed code to be detected, obtaining the detection result of the code to be detected according to the code to be detected and the fine-tuning model, and adjusting the code to be detected and generating a code snippet based on the detection result based on the code generation model. By constructing a fine-tuning model and inputting the code to be detected into the fine-tuning model, it can be determined whether the code to be detected is abnormal, and the abnormal code is input into the code generation model and the abnormal code is modified, so that the generated code snippet is a code that can run normally, thereby achieving the problem of low accuracy and efficiency of manual code detection and code repair in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 It is a flowchart of a code detection method based on a fine-tuned large model provided by an exemplary embodiment of the present invention.
[0049] Figure 2 It is a flowchart of a method for preprocessing a code to be detected provided by an exemplary embodiment of the present invention.
[0050] Figure 3 It is a structural diagram of a code detection device based on a fine-tuned large model provided by an exemplary embodiment of the present invention.
[0051] Figure 4 It is a structural diagram of a code detection device based on a fine-tuned large model provided by another exemplary embodiment of the present invention.
[0052] Figure 5 is a structural diagram of an electronic device provided by an exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0053] Figure 1 FIG. 1 is a flow chart of a code detection method based on a fine-tuned large model provided by an exemplary embodiment of the present invention. Figure 1 As shown in the figure, the code detection method based on fine-tuning the large model includes:
[0054] Step 110: construct a fine-tuning model, wherein the fine-tuning model includes a correspondence between the detection code and the reference detection result.
[0055] Step 120: Obtain the code to be detected.
[0056] In an embodiment of the present invention, the method of obtaining the code to be detected by the present invention may include: obtaining the code to be detected through online resources, public data sets, professional databases, and literature in specific fields obtained by web crawler technology. Among them, the present invention can develop customized crawler programs to adapt to different website structures and data formats to ensure the diversity and comprehensiveness of data. According to project requirements, the crawled data is preliminarily screened to exclude content that is not related to programming to ensure the relevance and accuracy of the data. In addition to web crawlers, data sources can also be enriched by purchasing professional data sets, obtaining data through cooperation, or using data synthesis technology.
[0057] Step 130: preprocess the code to be detected to obtain the preprocessed code to be detected.
[0058] In the embodiment of the present invention, preprocessing the code to be detected is an important step in software development, which helps to improve the readability and maintainability of the code. Preprocessing can include formatting code, eliminating unnecessary comments, optimizing variable naming and structural adjustments, etc. By cleaning and optimizing the code, developers can more easily identify potential errors and vulnerabilities. In addition, good preprocessing can also improve the operating efficiency of the code, reduce the time of subsequent debugging, and ensure the compatibility of the software in different environments.
[0059] Step 140: Obtain the detection result of the code to be detected according to the code to be detected and the fine-tuning model.
[0060] In an embodiment of the present invention, the process of obtaining the detection results based on the code to be detected and the fine-tuned model is crucial. First, the code to be detected needs to be preprocessed to ensure that its format and structure meet the model input requirements. Next, the code is input into the fine-tuned model, and the model will analyze it in combination with the existing training data to identify potential problems or vulnerabilities. Finally, the detection results can be fed back to the developer in the form of a report, pointing out errors, performance bottlenecks or security risks in the code. This process not only improves the quality of the code, but also accelerates the development cycle, ensuring that the software is in the best state before release.
[0061] Step 150: Based on the code generation model and according to the detection result, the code to be detected is adjusted and a code snippet is generated.
[0062] In an embodiment of the present invention, the process of adjusting the code to be detected and generating code snippets according to the detection results based on the code generation model is particularly important in software development. By analyzing the detection results, developers can identify defects and improvement points in the code, and then use the code generation model to automatically generate optimized code snippets. By learning a large number of high-quality code samples, the model can propose solutions that meet best practices. This not only improves development efficiency, but also reduces the possibility of human errors, making the final generated code more robust and maintainable. This process effectively shortens the iteration cycle and improves the overall quality of the software.
[0063] The embodiment of the present invention provides a code detection method based on a fine-tuning large model, including: constructing a fine-tuning model, wherein the fine-tuning model includes a corresponding relationship between a detection code and a reference detection result, obtaining the code to be detected, preprocessing the code to be detected to obtain the preprocessed code to be detected, obtaining the detection result of the code to be detected according to the code to be detected and the fine-tuning model, and adjusting the code to be detected and generating a code snippet based on the detection result based on the code generation model. By constructing a fine-tuning model and inputting the code to be detected into the fine-tuning model, it can be determined whether the code to be detected is abnormal, and the abnormal code is input into the code generation model and the abnormal code is modified, so that the generated code snippet is a code that can run normally, thereby achieving the problem of low accuracy and efficiency of manual code detection and code repair in the prior art.
[0064] Figure 2 FIG. 1 is a flow chart of a method for preprocessing a code to be detected provided by an exemplary embodiment of the present invention. Figure 2 As shown, step 130 may include:
[0065] Step 131: According to the format requirement, verify the format of the code to be detected and generate a verification result.
[0066] In the embodiment of the present invention, first, it is necessary to clarify the code format specifications, such as indentation, naming rules, comment style, etc. These specifications are intended to improve the readability and consistency of the code. Then, static code analysis tools are used to verify the format of the code to be detected. These tools automatically check whether the code meets the preset format standards.
[0067] During the verification process, the tool will identify parts that do not meet the specifications, such as extra spaces, incorrect indentation, non-standard variable naming, etc. Through this process, the communication costs caused by inconsistent formats are reduced, and the overall quality and maintainability of the software are ultimately improved.
[0068] Step 132: If the verification result indicates that the format of the code to be detected is normal, characters matching the preset characters in the code to be detected are removed to obtain a cleaned code to be detected.
[0069] In an embodiment of the present invention, if the verification result indicates that the format of the code to be tested is normal, the code can be further cleaned to improve its readability and conciseness. The first step of cleaning is to identify characters in the code that match preset characters. These characters may be redundant comments, debugging information, or unnecessary spaces, etc. When implementing the cleaning process, automated tools are usually used, which can effectively identify and delete unnecessary characters and information. The cleaned code to be tested will be neater, which not only improves the aesthetics of the code, but also reduces potential misunderstandings and maintenance difficulties. In addition, the cleaned code performs better in subsequent performance testing and defect detection because unnecessary interference information is removed, which facilitates problem location and performance optimization. Therefore, this process is crucial to ensuring code quality and improving development efficiency.
[0070] Step 133: remove characters matching the preset symbol from the code to be detected, so as to obtain the code to be detected after removal.
[0071] In an embodiment of the present invention, removing characters that match the code to be detected with preset symbols to obtain the removed code to be detected is an important step in code optimization and cleaning. Preset symbols usually include specific characters, comment symbols, spaces, line breaks or other redundant information, which may not be necessary in the core logic of the code and may even interfere with the readability and maintainability of the code. By identifying and removing these symbols, the code can be made more streamlined, which is convenient for subsequent analysis and debugging. The removed code to be detected will be clearer, which helps to quickly locate problems and expand functions. In addition, the optimized code usually also improves in performance because unnecessary characters or information will no longer occupy memory and processing resources. Ultimately, this process will significantly improve the overall quality and development efficiency of the code.
[0072] Step 134: According to the screening rules, the key code is screened from the removed to-be-detected codes.
[0073] In the embodiment of the present invention, data cleaning is a key step to ensure data quality, the purpose of which is to remove noise and inconsistency in the data and improve the usability of the data. Use automated scripts and algorithms to identify and remove irrelevant characters, special symbols, and format errors in the data. Standardize the data format, such as converting all codes into a unified programming language format to ensure data consistency. Especially for programming data, it is necessary to develop algorithms to identify and process comments, because although comments are helpful for understanding the code, they may introduce unnecessary information when training the model.
[0074] In one embodiment, step 134 can be specifically implemented as follows: classify the removed code to be detected to obtain the classified code to be detected; run the classified code to be detected; select the classified code to be detected whose output result after running meets the functional requirements as the target code; delete the target code with the same content as the target code to obtain the key code.
[0075] In an embodiment of the present invention, classifying the removed code to be detected to obtain the classified code to be detected is a key step in optimizing code management and improving software quality. During the classification process, automated tools can help identify the relevance of code fragments and group them to form an orderly code structure. After obtaining the classified code to be detected, the next step is to run the codes. By executing the code, it can be verified whether its function meets expectations and observe the performance of the codes of different classifications in actual operation. This process helps to discover potential errors or performance issues and provides a basis for subsequent optimization. The target code should not only achieve the expected function, but also be efficient and readable for subsequent maintenance. Finally, in order to ensure the simplicity and efficiency of the code, it is necessary to delete other target codes with the same content as the target code to obtain the key code. This step is intended to eliminate redundancy, retain the optimal implementation scheme, and ensure that the key code can meet the project requirements in terms of function and performance.
[0076] In one embodiment, step 110 can be specifically implemented as follows: obtaining multiple anomaly detection codes and multiple normal detection codes; wherein the anomaly detection codes correspond to error types; wherein the reference detection results include error types; based on a full-parameter fine-tuning strategy, generating a fine-tuning model according to multiple anomaly detection codes, multiple normal detection codes and the error type corresponding to each anomaly detection code.
[0077] In an embodiment of the present invention, obtaining multiple anomaly detection codes and multiple normal detection codes is the first step in building an efficient anomaly detection system. These anomaly detection codes contain different types of errors, such as syntax errors, logic errors, runtime errors, etc., while normal detection codes represent code implementations that meet the expected functions and logic. By analyzing these codes, we can gain an in-depth understanding of the characteristics of various errors and their manifestations. In this process, the error types corresponding to the anomaly detection codes will serve as important annotation information. These error types can help the fine-tuning model to more accurately understand which code patterns are associated with specific errors. At the same time, the reference detection results must also include these error types to provide a clear learning goal for the model. Full parameter fine-tuning is a machine learning technique that adjusts all parameters of the model to enable it to better adapt to new data sets. In this process, the model learns how to distinguish between anomaly detection codes and normal detection codes, and how to identify features associated with specific error types.
[0078] By comprehensively analyzing multiple anomaly and normal detection codes, the fine-tuned model can grasp more complex code patterns, thereby enhancing its application effect in the real world. Ultimately, the generated fine-tuned model can not only improve the accuracy of anomaly detection, but also play a key role in subsequent code review and automatic repair. This technical solution provides a solid foundation for achieving efficient code quality assurance and helps improve the overall efficiency and reliability of software development.
[0079] Then, design different training strategies based on the two functions of the model. For code problem detection, focus on training the model to identify and fix logical errors; for code generation, focus on training the model to understand user descriptions and generate accurate code. Choose appropriate loss functions to measure model performance, such as cross entropy loss, mean square error, etc., to ensure that the model can learn effectively. Define clear evaluation metrics, such as accuracy, recall, and F1 score, to quantify the performance of the model.
[0080] In one embodiment, step 110 can be specifically implemented as follows: removing comments from multiple exception detection codes; removing comments from multiple normal detection codes; wherein, based on the full-parameter fine-tuning strategy, generating a fine-tuning model according to the multiple exception detection codes, the multiple normal detection codes, and the error type corresponding to each exception detection code includes: based on the full-parameter fine-tuning strategy, generating a fine-tuning model according to the multiple exception detection codes after removal, the multiple normal detection codes after removal, and the error type corresponding to each exception detection code after removal.
[0081] In an embodiment of the present invention, removing comments from multiple anomaly detection codes and multiple normal detection codes is an important step in the code cleaning and optimization process. Comments are usually used in the code to explain logic, provide context or explain complex functions, but when performing data analysis and model training, redundant comment content may introduce noise and affect the learning effect of the model. Therefore, cleaning comments can help improve the accuracy and effectiveness of subsequent analysis. Specifically, it is first necessary to systematically analyze multiple anomaly detection codes and normal detection codes to identify all comment parts. These comments may include single-line comments, multi-line comments, and document strings. By using text processing tools or regular expressions, these comments can be quickly and effectively located and deleted to ensure that the core logic and structure of the code are retained. The process of removing comments also helps to reduce the complexity of the code, making the remaining code more concise and clear. In this way, in subsequent model training and anomaly detection tasks, the algorithm can focus more on the actual behavior of the code rather than the explanations added by humans, thereby improving the model's ability to recognize code patterns. In addition, the cleaned code can understand the code logic faster during code review, especially when facing a large amount of code, the simplified code structure can significantly improve the review efficiency. Ultimately, the operation of removing annotations not only provides a clearer data basis for generating fine-tuned models, but also lays the foundation for improving code quality and maintainability, and ensures the efficiency and stability of software development.
[0082] In one embodiment, the method for constructing a code generation model can be specifically implemented as follows: obtaining multiple exception detection codes and multiple normal detection codes; wherein the exception detection code corresponds to a modified code; based on a full parameter fine-tuning strategy, a code generation model is generated according to multiple exception detection codes, multiple normal detection codes and the modified code corresponding to each exception detection code.
[0083] In an embodiment of the present invention, obtaining multiple anomaly detection codes and multiple normal detection codes is an important step in building an intelligent code generation model. In this process, the anomaly detection code includes not only those codes with errors or problems, but also their corresponding modified codes. These modified codes represent fixed or optimized versions, showing how to transform the error code into a functioning code. This provides valuable learning data for the model, enabling it to understand the source of the error and how to fix it.
[0084] First, the collection of anomaly detection codes should cover multiple programming languages and error types to ensure the generalization ability of the model. During the collection process, the development team needs to carefully annotate the error type of each anomaly detection code and associate it with the corresponding modified code. This association will provide important contextual information for model training and help it understand the connection between errors and fixes.
[0085] Next, based on the full parameter fine-tuning strategy, the team will use the collected anomaly detection code, normal detection code and their corresponding modified code to generate a code generation model. Full parameter fine-tuning is a powerful technique that allows the model to learn deeply and adjust based on existing knowledge to adapt to new data. This process will enable the model to not only identify normal code and abnormal code, but also learn the specific steps and strategies for how to transform abnormal code into normal code.
[0086] During the model training phase, the algorithm will analyze a large number of code examples to identify common patterns that cause anomalies and learn corresponding solutions. For each anomaly detection code, the model will learn how to apply the logic in the modified code to generate equivalent, functional code. In this way, the model can continuously optimize its generation capabilities and eventually form an efficient code generation tool.
[0087] Ultimately, the code generation model can not only automatically generate code that meets functional requirements, but also provide repair suggestions for existing abnormal codes during the development process. This will greatly improve the efficiency of software development, reduce code defects caused by human errors, and improve the quality and maintainability of the code.
[0088] In one embodiment, step 150 may be specifically implemented as follows: if the detection result indicates that the code to be detected is abnormal, the code to be detected is input into a code generation model to obtain a code snippet.
[0089] In an embodiment of the present invention, when the detection result shows that the code to be detected is abnormal, the next step of processing is to input the code to be detected into a pre-trained code generation model to generate a repaired or optimized code snippet. This process can not only improve development efficiency, but also automate error repair and reduce the need for manual intervention. First, before code input, the code to be detected needs to be preprocessed. This may include removing irrelevant comments in the code, formatting the code structure, and ensuring that the code meets the input requirements. This step is to ensure that the code generation model can accurately understand the context and logical structure of the code to be detected. In addition, preprocessing can also help the model identify abnormal parts more effectively, so that when generating code, it can focus more on fixing related errors. Next, the code to be detected will be input into the code generation model. At this stage, the model will analyze the structure, syntax and logic of the code to be detected based on its previously learned knowledge, identify existing problems and generate corresponding code snippets.
[0090] In one embodiment, before step 150, the code detection method based on the fine-tuning large model can be specifically implemented as follows: obtaining the number of runs; based on the number of runs, running the code to be detected and generating multiple run results; the code detection method based on the fine-tuning large model can be specifically implemented as follows: if it is determined that the error type of each run result is the same as the initial error type corresponding to the code to be detected, then based on the code generation model, according to the detection result, adjusting the code to be detected and generating a code snippet.
[0091] In an embodiment of the present invention, the number of code runs and the results generated are crucial for detecting and repairing errors. By obtaining the number of code runs to be detected, we can systematically analyze its behavior, identify potential errors and generate corresponding repair suggestions. The system needs to record the number of code runs to be detected. This can be achieved by setting a counter, which increments each time the code is executed. The significance of obtaining the number of runs is that it can provide sufficient data basis for subsequent error analysis. The statistics of the number of runs can also help the development team understand the stability of the code, and frequently running code segments are more likely to expose potential problems. After counting a certain number of runs, the system will run the code to be detected according to these times. Each run will generate a run result, which will be stored for subsequent analysis. The reason for setting multiple runs is that some errors may be intermittent and only appear under certain conditions. Therefore, by running multiple times, we can obtain a more comprehensive data set to help identify error patterns. If it is determined that the error type of each run result is the same as the initial error type corresponding to the code to be detected, the system will execute the next step. The purpose of this consistency check is to ensure that the current error analysis and detection are effective. Only when the error type is consistent can subsequent code adjustments be safely performed.
[0092] In one embodiment, step 150 may be specifically implemented as follows: if the detection result indicates that the code to be detected is abnormal, then extracting abnormal code of the code to be detected; and inputting the abnormal code into a code generation model to generate a code snippet.
[0093] In an embodiment of the present invention, the system needs to receive the detection result from running the code to be detected. If the detection result shows that the code to be detected is abnormal, the system will trigger the subsequent exception handling process. The system will identify the specific type of exception through static and dynamic analysis tools, such as runtime errors, logical errors, out-of-bounds access, null pointer references, etc. Collect relevant information when the exception occurs, including exception stack trace, input parameters, operating environment, etc., for subsequent analysis. After confirming that the code to be detected is abnormal, the system will extract the code segment related to the exception. Analyze the exception stack information to determine the specific code line that caused the exception. Extract context information related to the exception code, including function call chain, variable status, execution path, etc., to generate more contextual repair suggestions. The extracted exception code will be input into a pre-trained code generation model. This model can be based on machine learning or deep learning technology, aiming to understand and generate code. Ensure that the input exception code meets the input format requirements of the model, including necessary comments, code style, etc., to improve the quality of the generated results. The extracted context information is passed to the model to help the model better understand the cause and background of the exception. The model adopts an appropriate repair strategy based on the input exception code and its context. Common repair strategies include refactoring code, adding exception handling logic, modifying conditional judgments, etc. The model may generate multiple different code snippets to deal with different repair methods for the same exception. Developers can choose the most appropriate repair solution based on specific needs. Unit test the generated code snippets to verify their performance under different input conditions to ensure that the repair is effective and does not introduce new errors.
[0094] In one embodiment, after step 150, the code detection method based on the fine-tuning large model can be specifically implemented as follows: real-time tracking of the running status of the code snippet, capturing the anomalies and errors of the code. When a code error is detected, the system automatically extracts the relevant code snippet and prepares for further analysis. The fine-tuning model receives the error code and uses the knowledge obtained from the previous training to perform logical and grammatical analysis. Based on the analysis results, the model proposes a repair plan or directly generates the corrected code. On the premise of ensuring that the repair code will not cause other problems, the system automatically replaces the original error code. After the replacement, an automated test is immediately performed to verify the repair effect and ensure the stability and performance of the new code. Through continuous monitoring and repair, the system achieves self-iteration and optimization. Reduce the manual intervention of operation and maintenance personnel, reduce maintenance costs, and improve system stability. The system automatically records all monitoring, analysis, and repair processes and results to facilitate problem tracking and historical analysis. Operation and maintenance personnel regularly check the logs, perform manual proofreading and review, and ensure that the automatic maintenance of the system does not introduce new problems.
[0095] Figure 3 FIG. 1 is a schematic diagram of a code detection device based on a fine-tuned large model provided by an exemplary embodiment of the present invention. Figure 3 As shown, the code detection device based on the fine-tuning large model includes: a construction module 201, which is used to construct a fine-tuning model; wherein the fine-tuning model includes a correspondence between a detection code and a reference detection result; an acquisition module 202, which is used to obtain a code to be detected; a preprocessing module 203, which is used to preprocess the code to be detected to obtain the preprocessed code to be detected; a detection module 204, which is used to obtain a detection result of the code to be detected based on the code to be detected and the fine-tuning model; a generation module 205, which is used to adjust the code to be detected and generate a code snippet based on the code generation model and the detection result.
[0096] The embodiment of the present invention provides a code detection device based on a fine-tuning large model, including: a construction module constructs a fine-tuning model, wherein the fine-tuning model includes a correspondence between a detection code and a reference detection result, obtains the code to be detected, a preprocessing module preprocesses the code to be detected to obtain the preprocessed code to be detected, a detection module obtains the detection result of the code to be detected based on the code to be detected and the fine-tuning model, and a generation module adjusts the code to be detected and generates a code snippet based on the code generation model according to the detection result. By constructing a fine-tuning model and inputting the code to be detected into the fine-tuning model, it can be determined whether the code to be detected is abnormal, and the abnormal code is input into the code generation model and the abnormal code is modified, so that the generated code snippet is a code that can run normally, thereby achieving the problem of low accuracy and efficiency of manual code detection and code repair in the prior art.
[0097] Figure 4 FIG. 1 is a schematic diagram of a code detection device based on a fine-tuned large model provided by another exemplary embodiment of the present invention. Figure 4 As shown, the preprocessing module 203 may include: a format unit 2031, used to verify the format of the code to be detected and generate a verification result according to the format requirements; a first removal unit 2032, used to remove the characters matching the preset characters in the code to be detected if the verification result indicates that the format of the code to be detected is normal, so as to obtain the cleaned code to be detected; a second removal unit 2033, used to remove the characters matching the preset symbols in the code to be detected, so as to obtain the removed code to be detected; a screening unit 2034, used to screen the key code from the removed code to be detected according to the screening rules.
[0098] In one embodiment, the screening unit 2034 can be specifically configured as follows: classify the removed code to be detected to obtain the classified code to be detected; run the classified code to be detected; select the classified code to be detected whose output result after running meets the functional requirements as the target code; delete the target code with the same content as the target code to obtain the key code.
[0099] In one embodiment, the construction module 201 can be specifically configured as follows: obtaining multiple anomaly detection codes and multiple normal detection codes; wherein the anomaly detection code corresponds to an error type; wherein the reference detection result includes the error type; based on the full parameter fine-tuning strategy, a fine-tuning model is generated according to multiple anomaly detection codes, multiple normal detection codes and the error type corresponding to each anomaly detection code.
[0100] In one embodiment, the construction module 201 can be specifically configured to: remove comments from multiple exception detection codes; remove comments from multiple normal detection codes; based on the full-parameter fine-tuning strategy, generate a fine-tuning model according to the multiple exception detection codes after removal, the multiple normal detection codes after removal, and the error type corresponding to each exception detection code after removal.
[0101] In one embodiment, a device for constructing a code generation model includes: obtaining multiple exception detection codes and multiple normal detection codes; wherein the exception detection code corresponds to a modified code; based on a full parameter fine-tuning strategy, a code generation model is generated according to the multiple exception detection codes, the multiple normal detection codes and the modified code corresponding to each exception detection code.
[0102] In one embodiment, the generation module 205 may be specifically configured as follows: if the detection result indicates that the code to be detected is abnormal, the code to be detected is input into the code generation model to obtain a code snippet.
[0103] In one embodiment, before generating module 205, the code detection device 20 based on the fine-tuning large model can be specifically configured as follows: obtaining the number of runs; based on the number of runs, running the code to be detected and generating multiple run results; wherein, the generation module 205 can be specifically configured as follows: if it is determined that the error type of each run result is the same as the initial error type corresponding to the code to be detected, then based on the code generation model and according to the detection result, adjusting the code to be detected and generating a code snippet.
[0104] In one embodiment, the generation module 205 may be specifically configured as follows: if the detection result indicates that the code to be detected is abnormal, then the abnormal code of the code to be detected is extracted; and the abnormal code is input into the code generation model to generate a code snippet.
[0105] Figure 5 A block diagram of an electronic device according to an embodiment of the present application is illustrated.
[0106] like Figure 5 As shown, the electronic device 10 includes one or more processors 11 and a memory 12 .
[0107] The processor 11 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 10 to perform desired functions.
[0108] The memory 12 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 11 may run the program instructions to implement the code detection method based on the fine-tuning large model of each embodiment of the present application described above and / or other desired functions. Various contents such as input signals, signal components, noise components, etc. may also be stored in the computer-readable storage medium.
[0109] In one example, the electronic device 10 may further include: an input device 13 and an output device 14, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).
[0110] When the electronic device 10 is a stand-alone device, the input device 13 may be a communication network connector for receiving collected input signals from the first device and the second device.
[0111] In addition, the input device 13 may also include, for example, a keyboard, a mouse, etc.
[0112] The output device 14 can output various information to the outside, including the determined distance information, direction information, etc. The output device 14 can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.
[0113] Of course, to simplify, Figure 5 Only some of the components related to the present application in the electronic device 10 are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device 10 may also include any other appropriate components.
[0114] The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0115] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0116] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A code detection method based on fine-tuning a large model, characterized in that: include: Constructing a fine-tuning model; wherein the fine-tuning model includes a correspondence between the detection code and the reference detection result; Get the code to be tested; Preprocessing the code to be detected to obtain the preprocessed code to be detected; Acquire a detection result of the code to be detected according to the code to be detected and the fine-tuning model; Based on the code generation model and according to the detection result, the code to be detected is adjusted and a code snippet is generated.
2. The code detection method based on fine-tuning large model according to claim 1 is characterized in that: The preprocessing of the code to be detected to obtain the preprocessed code to be detected includes: According to the format requirements, verify the format of the code to be detected and generate a verification result; If the verification result indicates that the format of the code to be detected is normal, then removing the characters matching the preset characters in the code to be detected to obtain a cleaned code to be detected; Removing characters of the code to be detected that match the preset symbol to obtain the code to be detected after removal; According to the screening rule, the key code is screened from the removed to-be-detected code.
3. The code detection method based on fine-tuning large model according to claim 2 is characterized in that: The key code obtained by screening from the removed code to be detected according to the screening rule includes: Classifying the removed codes to be detected to obtain classified codes to be detected; Running the classified code to be detected; Select the classified code to be tested whose output result meets the functional requirements after running as the target code; The object code having the same content as the object code is deleted to obtain the key code.
4. The code detection method based on fine-tuning large model according to claim 1 is characterized in that: The constructing of the fine-tuning model comprises: Acquire multiple abnormal detection codes and multiple normal detection codes; wherein the abnormal detection codes correspond to error types; wherein the reference detection results include the error types; Based on the full parameter fine-tuning strategy, a fine-tuning model is generated according to the multiple abnormality detection codes, the multiple normal detection codes and the error type corresponding to each abnormality detection code.
5. The code detection method based on fine-tuning large model according to claim 4 is characterized in that: After obtaining the plurality of abnormal detection codes and the plurality of normal detection codes, the method further includes: removing comments from the plurality of anomaly detection codes; Remove comments from the plurality of normal detection codes; The generating of the fine-tuning model based on the full parameter fine-tuning strategy according to the multiple abnormality detection codes, the multiple normal detection codes and the error type corresponding to each abnormality detection code comprises: Based on the full parameter fine-tuning strategy, a fine-tuning model is generated according to the multiple removed abnormal detection codes, the multiple removed normal detection codes, and the error type corresponding to each removed abnormal detection code.
6. The code detection method based on fine-tuning large model according to claim 1 is characterized in that: The method for constructing the code generation model includes: Acquire multiple abnormality detection codes and multiple normal detection codes; wherein the abnormality detection codes correspond to modified codes; Based on the full parameter fine-tuning strategy, a code generation model is generated according to the multiple abnormality detection codes, the multiple normal detection codes and the modified code corresponding to each abnormality detection code.
7. The code detection method based on fine-tuning large model according to claim 1 is characterized in that: The step of adjusting the code to be detected and generating a code snippet based on the code generation model and according to the detection result comprises: If the detection result indicates that the code to be detected is abnormal, the code to be detected is input into the code generation model to obtain a code fragment.
8. The code detection method based on fine-tuning large model according to claim 1 is characterized in that: Before adjusting the code to be detected and generating code snippets based on the code generation model and according to the detection result, the method further includes: Get the number of runs; Running the code to be detected and generating multiple running results according to the number of runs; The step of adjusting the code to be detected and generating a code snippet based on the code generation model and the detection result includes: If it is determined that the error type of each running result is the same as the initial error type corresponding to the code to be detected, based on the code generation model and according to the detection result, the code to be detected is adjusted and a code snippet is generated.
9. The code detection method based on fine-tuning large model according to claim 8 is characterized in that: The step of adjusting the code to be detected and generating a code snippet based on the code generation model and according to the detection result comprises: If the detection result indicates that the code to be detected is abnormal, extracting the abnormal code of the code to be detected; The exception code is input into the code generation model to generate a code snippet.
10. A code detection device based on fine-tuning a large model, characterized in that: include: A construction module, used to construct a fine-tuning model; wherein the fine-tuning model includes a correspondence between the detection code and the reference detection result; An acquisition module is used to obtain the code to be detected; A preprocessing module, used for preprocessing the code to be detected to obtain the preprocessed code to be detected; A detection module, used for obtaining a detection result of the code to be detected according to the code to be detected and the fine-tuning model; A generation module is used to adjust the code to be detected and generate a code snippet based on a code generation model and according to the detection result.
Citation Information
Patent Citations
AST-based source code anomaly detection method and device
CN115146282A
Code defect detection method and device based on large model and related equipment
CN117743164A
Cited By
Abnormal code detection method and device based on artificial intelligence
CN120011245A
An Abnormal Code Detection Method and Device Based on Artificial Intelligence
CN120011245B