Method, device and equipment for code parameter verification and storage medium
Through the code parameter verification method based on machine learning model, code fragments are extracted and verification statements are generated, which solves the problem that the existing technology cannot identify and fix the missing code verification, and realizes automatic verification and completion in complex business scenarios. Improved code security.
Patent Information
- Application Number
- CN202310584013.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-22
- Publication Date
- 2024-11-22
AI Technical Summary
Existing automatic program repair technology cannot effectively identify and fix the problem of missing verification in the code, resulting in the occurrence of security vulnerabilities, especially in complex business scenarios that cannot adapt to various types of missing verification.
Using a machine learning model-based method, a trained model extracts code snippets matching the predetermined statement type from the target code, generates a check statement to verify the legality of parameters, combines language models and pre-training strategies to adapt to different business scenarios. code language semantics.
It realizes automatic identification and repair of missing verification problems in the code, timely discovers and completes verification statements, avoids the occurrence of security vulnerabilities, and improves the security and robustness of the code.
Smart Images

Figure CN119002919A_ABST
Abstract
Description
Technical Field
[0001] Example embodiments of the present disclosure generally relate to the field of computers, and more particularly to a method, apparatus, device, and computer-readable storage medium for checking code parameters. Background Art
[0002] Code verification is a check to avoid possible errors and omissions in code design and input. It can be done by program, verification tool or even manual. Code verification can find problems that do not meet the specifications in advance and improve the robustness of the developed software. Summary of the invention
[0003] In a first aspect of the present disclosure, a method for code parameter verification is provided. The method includes: detecting a parameter verification request for a target code; in response to detecting the parameter verification request, extracting at least one code snippet matching at least one of a plurality of predetermined statement types from the target code; and using a trained machine learning model to generate a verification statement for at least one parameter of the target code based on the at least one code snippet, the verification statement being configured to verify the legality of the at least one parameter, wherein the machine learning model is trained based on a sample code set and a sample verification statement for a parameter of the sample code in the sample code set.
[0004] In a second aspect of the present disclosure, a device for code parameter verification is provided. The device includes: a request detection module configured to detect a parameter verification request for a target code; an extraction module configured to extract at least one code snippet matching at least one of a plurality of predetermined statement types from the target code; and a generation module configured to generate a verification statement for at least one parameter of the target code based on at least one code snippet using a trained machine learning model, wherein the verification statement is configured to verify the legitimacy of at least one parameter, wherein the machine learning model is based on a sample code set and a sample P23041928901CN.
[0005] The sample verification statements of the parameters of the sample codes in the code set are trained.
[0006] In a third aspect of the present disclosure, an electronic device is provided. The device includes at least one processing unit; and at least one memory, the at least one memory is coupled to the at least one processing unit and stores instructions for execution by the at least one processing unit. When the instructions are executed by the at least one processing unit, the device executes the method of the first aspect.
[0007] In a fourth aspect of the present disclosure, a computer-readable storage medium is provided, wherein a computer program is stored on the computer-readable storage medium, and the computer program can be executed by a processor to implement the method of the first aspect.
[0008] It should be understood that the contents described in this content section are not intended to limit the key features or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:
[0010] Figure 1 A schematic diagram showing an example environment in which embodiments of the present disclosure can be implemented;
[0011] Figure 2 A flowchart of a method for code parameter checking according to some embodiments of the present disclosure is shown;
[0012] Figure 3 A schematic diagram showing the reasoning process of a machine learning model according to some embodiments of the present disclosure is shown;
[0013] Figure 4 A schematic diagram showing the reasoning and training process of a machine learning model according to some embodiments of the present disclosure is shown;
[0014] Figure 5A and Figure 5B A schematic diagram showing example codes for completing a verification statement according to some embodiments of the present disclosure is shown;
[0015] Figure 6 A block diagram showing an apparatus for code parameter checking according to some embodiments of the present disclosure; and
[0016] Figure 7 A block diagram of a device capable of implementing various embodiments of the present disclosure is shown.
[0017] P23041928901CN DETAILED DESCRIPTION
[0018] It is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and relevant provisions.
[0019] The term "in response to" as used herein refers to a state in which a corresponding event occurs or a condition is satisfied. It will be understood that the timing of executing a subsequent action executed in response to the event or condition is not necessarily strongly related to the time when the event occurs or the condition is satisfied. For example, in some cases, the subsequent action may be executed immediately when the event occurs or the condition is satisfied; while in other cases, the subsequent action may be executed some time after the event occurs or the condition is satisfied.
[0020] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0021] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The term "some embodiments" should be understood as "at least some embodiments". Other explicit and implicit definitions may be included below. The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may be included below.
[0022] As used herein, the term "model" can learn the association between the corresponding input and output from the training data, so that after the training is completed, the corresponding output can be generated for a given input. The generation of the model can be based on machine learning technology. Deep learning is a machine learning algorithm that processes inputs and provides corresponding outputs by using multiple layers of processing units. In this article, "model" may also be referred to as "machine learning model", "machine learning network" or "network", which are used interchangeably in this article. A model may also include different types of processing units or networks.
[0023] P23041928901CN
[0024] As used herein, a "unit", "operating unit" or "subunit" may consist of a machine learning model or network of any suitable structure. As used herein, a group of elements or similar expressions may include one or more such elements. For example, a "group of convolutional units" may include one or more convolutional units.
[0025] As briefly mentioned above, although you can write code according to specifications to reduce development and debugging time, code verification is still very important in programming. Missing verification is one of the common causes of security vulnerabilities. It means that due to the lack of security checks on the legitimacy of key parameters, illegal request data is not correctly intercepted, which leads to unexpected results, such as serious damage to corporate assets and data security issues.
[0026] Lack of verification causes many hazards and is prevalent in many business scenarios. For example, in some cases, there is a problem of permission bypass. Since the user has not been verified to have the access rights of the subject corresponding to the request parameter, the attacker can obtain other people's information beyond his / her authority. For example, in the e-commerce business scenario, failure to verify the order owner can cause the attacker to obtain other people's orders beyond his / her authority and cause information leakage. In other cases, due to failure to verify the uploaded file type, the attacker can upload harmful files such as viruses and Trojans to implement their purposes of controlling the victim's host and illegally collecting specific data. In some cases, due to failure to verify the legitimacy of the Structured Query Language (SQL) statement, the attacker can construct abnormal SQL statements to deceive the server, thereby achieving unauthorized illegal queries and causing data leakage. The above problems are widely distributed and are extremely common risk types in the enterprise software development life cycle (SDLC).
[0027] The current automatic program repair technology (Automated Program Repair, APR) mainly targets program errors (bugs) and realizes automatic location and automatic repair of program errors without human intervention. However, such technology usually has the following problems, which makes it unsuitable for repairing "missing verification" problems. Automatic program repair technology does not have the ability to automatically repair security issues such as missing verification that are tightly coupled with business logic. For example, "Null Pointer Dereference" is a common program error, which means that when a pointer points to an invalid memory area, it is still referenced, resulting in memory errors and software system crashes. Compared with such common program errors, "missing verification" is often caused by industry P23041928901CN
[0028] The expected business logic definition may meet the code running requirements and therefore cannot be discovered by APR technology. For example, in an e-commerce business scenario, the expected business logic is that ordinary users have no right to access other users' order information. Therefore, if the verification statement of user permissions is missing in the code, it will cause unauthorized damage. In this scenario, APR technology cannot effectively understand and identify the business scenarios that need to be verified, and thus cannot achieve automatic repair of defects.
[0029] Some automatic program repair technologies can be mainly divided into template-based, heuristic algorithm-based, constraint-based and deep learning-based methods. The most advanced methods are currently based on deep learning. These methods mainly rely on traditional neural network models such as Long Short-Term Memory (LSTM) to learn rules from existing program errors and repair data and automatically generate error patches. However, due to the number of parameters, data completeness and other reasons, such technologies cannot be effectively adapted to various types of complex business scenarios. For example, such methods cannot accurately generate patches in a single prediction. They usually need to generate multiple candidate patches at the same time and repair errors by verifying them one by one. In actual engineering practice, there is room for improvement in the practicality of such methods.
[0030] To this end, an embodiment of the present disclosure proposes an improved scheme for code parameter verification, which uses a machine learning model to help automatically complete verification statements. According to various embodiments of the present disclosure, in response to a parameter verification request for a target code, at least one code snippet that matches at least one of a plurality of predetermined statement types is extracted from the target code. Using a trained machine learning model, a verification statement for at least one parameter of the target code is generated based on at least one code snippet. The verification statement is configured to verify the legality of at least one parameter. The machine learning model used is trained based on a sample code set and sample verification statements for parameters of sample codes in the sample code set. Thus, automatic identification and repair of missing verification problems in the code can be achieved. In this way, the lack of parameter verification in the code can be discovered in a timely manner, and the verification statements can be completed in a timely manner to avoid security vulnerabilities.
[0031] Furthermore, some embodiments of the present disclosure also attempt to apply language models and pre-training strategies to code intelligence tasks, by selecting appropriate training data sets, designing appropriate architectures and training schemes, and combining the structural information of the code itself, using machine learning models to achieve code completion tasks. In this way, the machine learning model can learn various scenarios.
[0032] The semantics of the code language under the hood and how to perform verification tasks. Machine learning models with this knowledge are used to identify business scenarios that need verification and automatically complete verification statements.
[0033] Example embodiments of the present disclosure are described below with reference to the accompanying drawings.
[0034] Figure 1 A schematic diagram of an example environment 100 in which embodiments of the present disclosure can be implemented is shown. In the environment 100, the terminal device 110 can be used to provide code editing, debugging, verification, access, etc. to the user 140. The terminal device 110 provides a user interface 150. The user interface 150 includes, for example, a code editing page to support the user 140 to develop, debug, verify, etc. the code on the user interface 150 directly or via an attached device connected to the terminal device 110. The user interface 150 may also include any interface for accessing code, code files, etc.
[0035] In an embodiment of the present disclosure, code parameter verification is performed with the aid of a machine learning model 120. Figure 1 In the example of , the machine learning model 120 used can be deployed on the remote device 130. The terminal device 110 can communicate with the remote device 130 (for example, via network communication) to perform model reasoning tasks using the machine learning model 120 stored thereon. In other embodiments, the machine learning model 120 can also be partially or completely deployed locally on the terminal device 110. The embodiments of the present disclosure are not specifically limited to this.
[0036] The terminal device 110 can be any type of mobile terminal, fixed terminal or portable terminal, including a mobile phone, a desktop computer, a laptop computer, a notebook computer, a netbook computer, a tablet computer, a media computer, a multimedia tablet, a personal communication system (PCS) device, a personal navigation device, a personal digital assistant (PDA), an audio / video player, a digital camera / camcorder, a positioning device, a television receiver, a radio broadcast receiver, an e-book device, a gaming device, or any combination of the foregoing, including accessories and peripherals of these devices or any combination thereof. The remote device 130 may, for example, include a computing system / server, such as a mainframe, an edge computing node, a computing device in a cloud environment, a virtual machine, and the like. Although a single device is shown, the remote device 130 may include multiple physical devices. In addition, although only a single terminal device is shown, the remote device 130 or the machine learning model deployed therein can be accessed by multiple terminal devices to provide reasoning capabilities of the machine learning model 120.
[0037] It should be understood that the structure and functionality of environment 100 are described for exemplary purposes only and that
[0038] No limitation to the scope of the disclosure is implied.
[0039] Figure 2 1 is a flowchart of a method 200 for code parameter verification according to some embodiments of the present disclosure. The method 200 may be implemented in the example environment 100, for example, implemented at the terminal device 110. Figure 1 Method 200 is described.
[0040] In box 210, the terminal device 110 detects a parameter verification request for the target code. As described in detail below, in an embodiment of the present disclosure, a solution for automatic detection and completion of code verification missing is provided to determine whether the legality of the parameters in the code needs to be checked, and to generate corresponding verification statements. In some embodiments, the verification missing detection and completion proposed in the present disclosure can support the verification of the code being edited. In some embodiments, the verification missing detection and completion proposed in the present disclosure can also support the verification missing detection and completion of the underlying code of the code that has been edited and the packaged application / software.
[0041] In some embodiments, the terminal device 110 can detect parameter verification requests in the code editing page of the target code. For example, code developers can be allowed to initiate parameter verification requests during the code development process, such as when editing the code. In this way, it is convenient to confirm whether there are any missing checks at any time during code editing. In some embodiments, the terminal device 110 can receive parameter verification requests initiated for the code file of the target code. For example, the code file can be generated after the code editing is completed. In this way, it is possible to check whether there are any missing checks in the existing code, application, or software, and to complete them in a timely manner.
[0042] The parameter verification request can be triggered in various appropriate ways. The parameter verification request can be triggered manually by the user, or it can also be triggered automatically. For example, it can be triggered periodically during code editing or based on certain predetermined conditions (for example, a new parameter is detected to be defined). In some embodiments, the verification missing detection and completion scheme proposed in the present disclosure can be encapsulated as a specific function in the code development, editing, and verification process, for example, it can be encapsulated as an integrated development environment (IDE) plug-in. By triggering the IDE plug-in, a parameter verification request can be initiated. In addition, it can also support methods such as voice command triggering, clicking on preset controls, etc. to trigger parameter verification requests.
[0043] In response to detecting the parameter verification request, the terminal device 110 extracts at least one code segment from the target code at block 220. Each code segment matches one or more of the plurality of predetermined statement types. Each code segment may also be referred to as a "statement block".
[0044] Can consist of one or more lines of code.
[0045] The predetermined statement type selected in this way can be a code statement in the target code that is considered to potentially help the machine learning model 120 understand the semantics related to the parameter and help generate a verification statement for the legality of the parameter. In some embodiments, the predetermined statement types considered in parameter verification may include, but are not limited to: parameter statements, function headers and / or remote procedure call statements. Parameter statements refer to statements used to obtain the value of a parameter. For example, the value of a parameter can be obtained through #{key} and precompiled into an SQL statement; the value of a parameter can also be obtained through ${key} and spliced into an SQL statement. Parameter statements can include statements for obtaining parameters from request URL parameters, request bodies, and request headers. For example, in the go language, a statement for obtaining a request Session through the Gin framework Context class. A function usually includes a function header and a function body. The function header includes components such as the function name, function type, function attributes, function parameters, and parameter types of the function. Remote Procedure Call (RPC) is also called a method call or a subroutine call. A remote procedure call statement is a statement that calls a downstream service method based on the RPC protocol.
[0046] In some embodiments, the terminal device 110 may extract code snippets matching one or more of the plurality of predetermined statement types from the target code at a function granularity. Specifically, the terminal device 110 may identify one or more functions defined in the target code, and for each function, determine whether the function includes code snippets matching one or more of the plurality of predetermined statement types.
[0047] In block 230, the terminal device 110 generates a verification statement for at least one parameter of the target code based on at least one code snippet using the trained machine learning model 120. The verification statement is configured to verify the legality of the at least one parameter.
[0048] The terminal device 110 can use the machine learning model 120 to generate parameter verification statements. For example, in the code editing interface, the terminal device 110 continuously listens to the predetermined statement in the function currently edited by the user 140. The terminal device 110 extracts the code snippet that matches the predetermined statement type and provides it to the machine learning model 120. The machine learning model 120 can complete the corresponding verification statement, thereby generating a verification statement under the contextual semantics of the target code. For another example, after the code editing is completed, the terminal device 110 can respond to the trigger operation of the user 140 (such as clicking on the IDE plug-in or through voice commands, etc.) and use the machine learning model 120 to pin P23041928901CN
[0049] Generate parameter verification statements for code or code files.
[0050] The machine learning model 120 can be trained based on the sample code set and the sample verification statements for the parameters of the sample code in the sample code set. The training process of the machine learning model 120 will be referred to below. Figure 4 Describe in detail.
[0051] In the scenario of verification and completion, the verification statement is used to verify whether the value and use of the parameters in the code are legal. For example, in the code involving e-commerce business, the parameter to be checked may be "order user ID" to check whether the order user has access rights. In the code involving file upload, the parameter to be checked may be "uploaded file type" to check whether the file is a malicious file. In the code involving SQL injection, the parameter may be "SQL statement" to check whether the SQL statement is legal.
[0052] In some embodiments, after determining the verification statement, the terminal device 110 can present an insertion prompt control for the verification statement. If a preset operation for the insertion prompt control is detected, the terminal device 110 can insert the verification statement into the target code. The insertion prompt control is used to prompt the user that the verification statement can be inserted into the target code. In some embodiments, the insertion prompt control can include a reminder about the insertable verification statement, and / or can display the parameters or specific verification statements to be verified by the verification statement. In this way, the user can understand and confirm the insertion of the verification statement as needed. In some embodiments, the insertion prompt control can include a confirmation insertion option, a rejection insertion option, an editing option, etc. for the verification statement, for further selection by the user. The insertion prompt control can be presented in any appropriate form, such as a pop-up window form, presented in a specific area of the code editing page, etc.
[0053] In some embodiments, after the verification statement generated by the machine learning model 120 is returned to the terminal device 110 by the remote device 130, the terminal device 110 can automatically insert the verification statement into the target code without user confirmation. Of course, the undo operation can also be retained so that the user can undo the inserted verification statement as needed.
[0054] When determining the check statements to be inserted, the terminal device 110 may determine the target position in the target code where the check statements are to be inserted. Such a target position may include, for example, the position of an input cursor (also referred to as a "cursor position") or a user-specified position. The terminal device 110 may insert the check statements into the target position determined in the target code. For example, after obtaining the check statements, the terminal device 110 may automatically insert the check statements into the cursor position, for example, in the code P23041928901CN
[0055] In some embodiments, the position to be inserted can be specifically specified by the user before or after the verification statement is generated. For example, after the verification statement is presented to the user, the position to be inserted is selected by the user.
[0056] According to an embodiment of the present disclosure, automatic and convenient identification and verification completion of missing verification problems can be achieved. In some embodiments, based on the machine learning model 120, it can be determined that multiple parameters in the target code need to be verified, or multiple verification statements can be generated. The terminal device 110 can also insert these verification statements into the target code in a similar manner. In some embodiments, if the machine learning model 120 determines that no additional verification statements are required for the current target code, an indication that the parameter verification is not missing can also be returned.
[0057] In some embodiments, when generating a verification statement, in addition to the code snippets that match one or more of the multiple predetermined statement types, the terminal device 110 can also determine the target position in the target code where the verification statement is to be inserted, and extract another code snippet in a predetermined neighborhood of the target position of the target code. In some cases, in addition to considering the code snippets that match the predetermined statement types, it is also necessary to additionally consider some code snippets near the target position where the verification statement is to be inserted. These code snippets may also indicate useful information for generating verification statements. For example, in an e-commerce business scenario, in order to verify whether a user is the order owner to prevent him from unauthorizedly obtaining other people's orders, code snippets in a predetermined neighborhood are usually more helpful in generating verification statements for business scenarios or business logic.
[0058] As mentioned above, the target position in the target code where the verification statement is to be inserted may include the position of the cursor or the position specified by the user. The predetermined neighborhood of the target position may include a predetermined number of lines of code near the target position. For example, in the process of code editing by user 140, the predetermined neighborhood may be a number of consecutive lines before the cursor position (for example, 10 consecutive lines). Statements that match the code snippets in such a predetermined neighborhood are also referred to as "cursor preamble statements". For another example, after the code is written, the verification statement is inserted at a certain position in the code in accordance with the user 140's designation, or other tools or methods are used to automatically determine that a verification statement needs to be inserted at a certain position. In such a scenario, the predetermined neighborhood may include several consecutive lines before and after the specified position (for example, the first 5 lines to the last 5 lines). Statements that match the code snippets in such a predetermined neighborhood are also referred to as "statements before and after the specified position". Further, the terminal device 110 uses the machine learning model 120, based on P23041928901CN
[0059] A verification statement is generated by using a previously extracted code snippet matching a predetermined statement type and another code snippet currently extracted in a predetermined neighborhood.
[0060] In some embodiments, when using the machine learning model 120 to generate the terminal device 110, the prompt word input can be obtained by combining the extracted code snippets and the task prompt word, and the prompt word input is provided to the machine learning model 120 to obtain the verification statement. The task prompt word is used to indicate the verification statement generation task. For example, the terminal device 110 inserts "[complete validation]" as the task prompt word before or after the extracted code snippet. Of course, this is only an example, and any predetermined character or string can be configured as the task prompt word for the verification statement generation task. The structure of the prompt word input can be, for example, "[complete validation] <x>" format, where <x>The code snippet to be provided to the machine learning model 120. The task prompt word can be used to clearly indicate to the machine learning model 120 the task to be completed using the code snippet, that is, to determine the generation of a verification statement. In this way, the machine learning model 120 can more accurately return the correct verification statement in a single prediction scenario, and can effectively shift the missing verification problem to the left.
[0061] In some scenarios, if the number of code snippets extracted from the target code that match the predetermined statement type is small, and the prompt word input provided to the machine learning model 120 is of a fixed size, the terminal device 110 may use the extracted code snippets and a predetermined symbol (e.g., "0") to construct the prompt word input. <x>.
[0062] In some embodiments, during prompt word input, the terminal device 110 can splice multiple code snippets according to the order of the multiple code snippets in the target code, and combine the spliced multiple code snippets and the task prompt word. The order of the code snippets in the target code is, for example, the natural order of writing the code, also known as the front-to-back order. Because the statements associated with the code have a front-to-back dependency, retaining such a front-to-back order helps the machine learning model 120 better understand the code semantics. For example, the terminal device 110 continuously monitors the predetermined statements in the function currently edited by the user 140, and extracts multiple code snippets that match the predetermined statement type from the target code, and splices them according to the natural order of these code snippets in the target code. Furthermore, the terminal device 110 inserts "[completevalidation]" as the task prompt word before the spliced multiple code snippets to construct "[complete validation]" <x>" format.
[0063] P23041928901CN
[0064] The reasoning process (also referred to as the application process) of the machine learning model 120 is described above through multiple embodiments and in combination with method 200. Generally, machine learning can roughly include three stages, namely the training stage (also referred to as the training process), the testing stage (also referred to as the testing process) and the reasoning stage (also referred to as the reasoning process). In the training stage, a given model can be trained using a large amount of training data, and iterated continuously until the model can obtain consistent reasoning that meets the expected goals from the training data. Through training, the model can be considered to be able to learn the association between input and output (also referred to as the mapping of input to output) from the training data. In the testing stage, the test input is applied to the trained model to test whether the model can provide the correct output, thereby determining the performance of the model. In the reasoning stage, the model can be used to process the actual input based on the parameter values obtained through training to determine the corresponding output. The following references Figures 3 to 5B The training process and inference process of the machine learning model 120 are described in more detail.
[0065] Figure 3 A schematic diagram of the reasoning process 300 of the machine learning model 120 according to some embodiments of the present disclosure is shown. Example 300 is, for example, a scenario in which a user 140 is developing a target code 310. The terminal device 110 automatically triggers the IDE plug-in to continuously monitor the "parameter statement", "function header", "RPC call statement" and "cursor preamble statement" in the target code 310. When the terminal device 110 monitors these statements, it can extract code snippets 320 matching the above statements from the target code 310 in real time or periodically. The code snippet 320 may include one or more code snippets. The terminal device 110 splices the extracted code snippets 320 into a text format according to the natural order of the code, and inserts a task prompt word (such as "[complete validation]") in the first line (or other appropriate position) thereof to obtain a prompt word input 330. For example, the code snippet 320 and the task prompt word 330 can be in the order of "[complete validation] <x>" format to obtain the prompt word input 330. The prompt word input 330 is sent to the remote device 130. The remote device 130 inputs the prompt word input 330330 to the machine learning model 120. The machine learning model 120 receives such content and performs reasoning to generate a verification statement 340 to be completed for the target code 310. The remote device 130 returns such a verification statement 340 to the terminal device 110 of the user 140, so as to complete the verification statement in real time at the appropriate location of the target code 310.
[0066] In the inference process 300, it is assumed that the machine learning model 120 has been trained.
[0067] The device 110 can detect and repair the missing verification of the completed code by using the trained machine learning model 120. The machine learning model 120 can be trained based on the sample code set and the sample verification statement. The sample code set can include various types of codes, such as internal business codes and open source codes. The sample verification statement is a code identified from the sample code and used to verify the legality of one or more parameters in the sample code, such as a continuous code block consisting of an if statement and its branch statements.
[0068] In some embodiments, the training of the machine learning model 120 includes a pre-training process and a fine-tuning process. As described above, in the training phase, the model can learn the association between input and output from the training data. In implementations involving pre-training, the training phase can include a pre-training phase and a fine-tuning phase. In the pre-training phase, the parameters of at least part of the model are updated, and in the fine-tuning phase, the parameters of the overall model are further fine-tuned through the output layer required for the specific task.
[0069] In view of the strong generalization ability of the pre-trained model, it is expected that such a pre-trained model can also be provided in the task of code parameter verification. In the pre-training process, the machine learning model 120 can be pre-trained based on a sample code set. The sample code set of this process can include endogenous business code and open source code. In this way, the model can learn strong generalization ability through a large amount of sample code. The model obtained by pre-training can continue the fine-tuning process to fine-tune it for the task of code parameter verification.
[0070] During the fine-tuning process, according to the task requirements, the sample code set can continue to be selected to fine-tune the pre-trained model to obtain the desired machine learning model 120. The corresponding model training algorithm can also be used to update and adjust the parameters of the overall model during fine-tuning. According to an embodiment of the present disclosure, the machine learning model 120 is fine-tuned using sample code snippets in the sample code from the sample code set and sample verification statements for the parameters in the sample code. The sample code set of this process, for example, only includes endogenous business code. That is, some sample code snippets and verification statements are extracted from the endogenous business code for fine-tuning the machine learning model 120. In this way, the code parameter verification can be tightly coupled with the business logic, that is, the sample code set is constructed in combination with the code of the verification scenario in the actual business logic, so that the trained machine learning model 120 can identify the business scenarios that need to be verified in complex business scenarios and complete the corresponding verification statements.
[0071] P23041928901CN
[0072] In some embodiments, the sample code set used in the pre-training process and the sample code set used in the fine-tuning process may be partially the same or completely different. Since the model has learned a lot of knowledge from the sample code set in the pre-training stage, a relatively small amount of sample code can be used in the fine-tuning stage to obtain a machine learning model 120 that meets the expectations. For example, the sample code set is divided into two subsets, one for the pre-training process and the other for the fine-tuning process.
[0073] In some embodiments, the sample code set used in the pre-training process includes the complete code. The sample code set used in the fine-tuning phase may include code snippets and verification statements extracted from the complete code. In this way, supervised learning is performed on the machine learning model 120.
[0074] In some embodiments, the sample code snippet includes a code snippet in the sample code that matches at least one of a plurality of predetermined statement types. The predetermined statement type is a statement type that needs to be applied during the reasoning process of the machine learning model 120. As described above, the predetermined statement type includes, for example, a parameter statement, a function header, or a remote procedure call statement.
[0075] In some embodiments, the sample code snippet also includes a code snippet in a predetermined neighborhood of the sample code and the sample verification statement. The predetermined neighborhood corresponds to the code range of the target position where the verification statement is to be inserted during the reasoning process of the machine learning model 120. In the training phase, the code snippet in the predetermined neighborhood can be referred to as a "verification preamble statement" or "statements before and after the verification statement". In the reasoning phase, it can be referred to as a "cursor preamble statement" or "statements before and after the specified position".
[0076] For example, if the "verify preamble statement" is used in the training process of the machine learning model 120, a code snippet matching the "cursor preamble statement" can be extracted in its inference stage, that is, the "verify preamble statement" corresponds to the "cursor preamble statement". If the "verify statements before and after the statement" is used in the training process, a code snippet matching the "statements before and after the specified position" can be extracted in the inference process, that is, the "statements before and after the verify statement" corresponds to the "statements before and after the specified position".
[0077] Figure 4 A schematic diagram of an example 400 of training and applying a machine learning model 120 according to some embodiments of the present disclosure is shown. Example 400 includes a training process and an inference process of the machine learning model 120. The machine learning model 120 is deployed on a remote device 130 after training. The training of the machine learning model 120 can be performed on the remote device 130, on the terminal device 110, or on any other appropriate device (e.g., a cloud device).
[0078] The embodiments of the present disclosure do not limit this. In the reasoning process, the trained machine learning model 120 can be used to process the input of the code snippet in the business scenario and provide the output of the corresponding verification statement. The specific embodiments can refer to the above description.
[0079] As described above, the training of the machine learning model 120 includes a pre-training process and a fine-tuning process. In the pre-training process, the model 420 can be trained using the sample code set 410. An important factor affecting the performance of the model is the construction of the training data set. A large number of high-quality training data is the basis of pre-training. In an embodiment of the present disclosure, it is expected that the sample code set 410 includes as many sample codes as possible. In some embodiments, the sample code set 410 can be a corpus including large-scale open source code and endogenous business code. For example, open source code data can be collected from an open source code platform, and endogenous code data can be collected from a data source corresponding to a specific business scenario. In some embodiments, these code data can be pre-processed, for example, by comparing hash values to remove duplicate codes in these data. For another example, remove noise data in these data. In one example, data that meets the following three rules is defined as noise data: 1) The length of a single file exceeds 1M; 2) The average length of words per line exceeds 100; 3) The number of characters in the file accounts for less than 0.35. For another example, remove blank lines in the code in these data, remove codes containing specific information, such as hard-coded keys, and so on.
[0080] The preprocessed sample code set 410 is provided to the model 420. The model 420 is, for example, a language model constructed based on the codec of the Transformer. Of course, according to the actual application needs, other model structures, especially model structures suitable for pre-training, can be selected to construct the model 420. The number of parameters of the model 420 is huge (for example, more than one billion), so that it has basic code syntax and semantics knowledge as well as code knowledge in business scenarios.
[0081] In some embodiments, the machine learning model 120 is pre-trained by at least one of the masked language model (MLM) task and the causal language model (CLM) task during the pre-training process. For example, the model 420 is iteratively trained on the masked language model task and the causal language model task using the pre-processed sample code set 410 to obtain the pre-trained model 430. Then, the pre-trained model 430 is fine-tuned during the fine-tuning process to obtain the machine learning model 120. These model tasks enable the model to learn high-quality contextual token embeddings, P23041928901CN
[0082] It significantly improves downstream performance. Compared with traditional static verification tools, it greatly saves the workload of developing verification tools that support different business scenarios and adapt to new programming languages.
[0083] The masked language model can mask a portion of the input sequence (e.g., a certain percentage of words) to train the model 420 to predict the masked words or characters based on the context. For example, the masked language model masks 80% of the words in the input sequence with <mask>The masked language model task is also called a "Token masking task". For another example, the masked language model replaces 80% of the words in the code comments in the input sequence with <mask>Replace or randomly replace with other words, and train the model 420 to restore the replaced words. Such a masked language model task is also called an "API mask task".
[0084] The causal language model can predict masked tokens in the input sequence. During the prediction process, each token mask can only see the token information before it, but not the token information after it. The training goal of model 420 is to predict the token information of the next position based on the token information before it. For example, the probability of occurrence of a combination of words is calculated based on the probability distribution. Thus, the causal language model can predict the token information of the current moment based on all the previous token information. As an example, the causal language model can replace each word in the input sequence with <mask>, and calculate the probability of occurrence of the word based on the words that appeared in the previous text, and then train the model 420 to recover the current word.
[0085] During the pre-training process, the reason for using the masked language model for iterative training is that there is bidirectional dependency information in the programming language. For example, a statement depends on the variable assigned by the previous statement, and the variable returned by the statement affects the subsequent statement. Therefore, it is necessary to use a masked language model to enable model 420 to learn the bidirectional grammatical and semantic information contained in the code. In addition, since model 420 needs to ultimately face the code generation task, the causal language model task is used to train the model. Finally, the model 420 is alternately trained with these two tasks to obtain a pre-trained model 430.
[0086] During the fine-tuning process, the pre-trained model 430 is fine-tuned on the constructed verification missing scenario data so that it has the ability to complete the verification statement. For example, verification scenario screening 450 is performed in the internal source business code, that is, the code with "verification logic" is screened. In some embodiments, the verification logic includes judging whether the request parameters are in compliance with P23041928901CN through an if branch statement.
[0087] Whether the statement block is composed of consecutive lines of code.
[0088] Furthermore, the screened codes with "verification logic" are divided into independent samples based on function granularity, and the "parameter statements", "function headers", "RPC call statements", "verification preamble statements" and "statements before and after verification statements" in the function are extracted. Such statements will be matched with code snippets as predetermined statement types during the reasoning process, so the definition during the training process corresponds to the definition during the reasoning process. After obtaining the above statements, they can be spliced in the natural order of the code, and "[complete validation]" can be inserted in the first line as the task prompt word 470 through the prompt project 460. Finally, the sample data format is "[complete validation] <x> <z>",in <x>The text related to the sample code, for example, the sample code associated with the above-mentioned statement type is structured according to the natural order of the code. <z>It is the output related to the inspection target, that is, the sample inspection statement.
[0089] It is worth noting that in Figure 4 In the example of , the sample data format containing task prompt word 470 in the fine-tuning process is different from the sample data format containing task prompt word 330 in the reasoning process. <z>A sample verification statement in the format of FIG. 1 is provided to instruct the machine learning model 120 to learn and generate a verification statement. <z>It can include positive sample verification statements and / or negative sample verification statements. Positive sample verification statements are verification statements that are correctly generated. Negative sample verification statements are verification statements that are incorrectly generated. In addition, the former contains <x>Positive samples and / or negative samples may also be included. The code snippets in the positive samples may indicate useful content for code verification, while at least one code snippet in the negative samples is useless. Accordingly, it is necessary to identify whether each sample code and sample verification statement is a positive sample or a negative sample in the prompting project 460.
[0090] In some embodiments, the sample data format is preprocessed to remove irrelevant code logic, such as removing duplicate codes, removing noise data, removing blank lines in the code, removing codes containing specific information, and so on.
[0091] In some embodiments, the pre-trained model 430 is fine-tuned through the causal language model task to obtain the machine learning model 120. Since the model 420 has mastered the underlying grammatical information of the programming language during the pre-training process, only the causal language model task can be used for training during the fine-tuning process.
[0092] Figure 5A and Figure 5B A schematic diagram of an example code 500 for completing a verification statement P23041928901CN according to some embodiments of the present disclosure is shown. The example code 500 relates to an e-commerce business scenario and is used to obtain order information and order owner information. Figure 5A As shown, in the code editing page, the code 500 is being edited. The terminal device 110 can monitor the typing content in the code editing page, and when a code snippet matching a predetermined statement type is monitored, it can be provided to the machine learning model 120 together with the code snippet in a predetermined neighborhood before the cursor position to generate a verification statement.
[0093] exist Figure 5A In the example, example code 500 includes code snippets 510 to 530. Code snippet 510 includes a function header, such as the function name "GetOrder" and the input parameters required by the function. Code snippet 520 includes an RPC call statement, such as "orderInfo, err:=order.GetOrder(req.OrderId)" (used to remotely call order information). Blank line 540 corresponds to the current cursor position. Therefore, there may be a code snippet associated with a cursor preceding statement within a predetermined neighborhood of the current cursor position, such as a code snippet useful for verifying the owner of an order. For example, code snippet 530 includes a parameter statement + a cursor preceding statement "userId:=ctx.UserId" (used to obtain the current user identity), and a cursor preceding statement "orderUserId:=orderInfo.GetAccount().Id" (used to obtain the owner of an order).
[0094] exist Figure 5A In the example, the terminal device 110 continuously monitors the user's current editing function. When the user types to the cursor position of the blank line 540, the terminal device 110 monitors the "parameter statement", "RPC call statement" and "cursor preceding statement". The terminal device 110 extracts the matching code snippet 510, code snippet 520 and code snippet 530, and provides these code snippets to the machine learning model 120 after splicing them in code order. The verification statement (i.e., code snippet 550) generated by the machine learning model 120 can verify whether the current user is the order owner. The terminal device 110 receives such a verification statement (i.e., code snippet 550) and inserts the code snippet to the current cursor position, such as Figure 5B By inserting a verification statement, it is possible to prevent information leakage caused by unauthorized access to other people's orders.
[0095] In some embodiments, the terminal device 110 may present an insertion prompt control in the user interface 150, for example, by using an animation to remind the user 140 to confirm whether to insert the verification statement. Additionally or alternatively, the terminal device 110 may also display the verification statement in the user interface 150, and insert it into the corresponding position after receiving a confirmation operation from the user 140, or no longer display the verification statement after receiving a cancellation operation.
[0096] P23041928901CN
[0097] In summary, according to various embodiments of the present disclosure, a trained machine learning model 120 is used to generate verification statements for code parameters to identify and repair missing verification problems in the target code. Furthermore, the machine learning model 120 is a Transformer-based model that is pre-trained using open source code and endogenous business code, so that the trained machine learning model 120 can identify business scenarios that need to be verified in complex business scenarios and complete the corresponding verification statements. Furthermore, sample data for missing verification based on task prompts is constructed, and fine-tuning is performed on the business code that is tightly coupled to the business. In this way, the correct verification statement can be returned more accurately in a single prediction scenario.
[0098] Example devices and equipment
[0099] Figure 6 A schematic structural block diagram of an apparatus 600 for code parameter verification according to some embodiments of the present disclosure is shown. The apparatus 600 may be implemented as or included in a terminal device 110. Each module / component in the apparatus 600 may be implemented by hardware, software, firmware, or any combination thereof.
[0100] As shown in the figure, the device 600 includes a request detection module 610, which is configured to detect a parameter verification request for the target code. The device 600 also includes an extraction module 620, which is configured to extract at least one code snippet matching at least one of a plurality of predetermined statement types from the target code. The device 600 also includes a generation module 630, which is configured to generate a verification statement for at least one parameter of the target code based on at least one code snippet using a trained machine learning model, wherein the verification statement is configured to verify the legality of at least one parameter, wherein the machine learning model is trained based on a sample code set and a sample verification statement for a parameter of a sample code in the sample code set.
[0101] In some embodiments, the detection module 610 includes: an editing detection module configured to detect a parameter verification request in a code editing page of the target code; or a file detection module configured to receive a parameter verification request initiated for a code file of the target code.
[0102] In some embodiments, the apparatus 600 further includes: a control presentation module configured to present an insertion prompt control for a verification statement; and a statement insertion module configured to insert the verification statement into the target code if a preset operation for the insertion prompt control is detected.
[0103] In some embodiments, the statement insertion module includes: a position determination module configured as P23041928901CN
[0104] Determine the target position of the target code where the verification statement is to be inserted, the position includes the position of the input cursor or the position specified by the user; and insert the verification statement by position module, which is configured to insert the verification statement into the target code at the determined target position.
[0105] In some embodiments, the plurality of predetermined statement types include at least one of the following: a parameter statement, a function header, and a remote procedure call statement.
[0106] In some embodiments, the generation module 630 is further configured to determine a target position in the target code where a verification statement is to be inserted; extract another code snippet in a predetermined neighborhood of the target position of the target code; and generate a verification statement based on at least one code snippet and another code snippet using a machine learning model.
[0107] In some embodiments, the generation module 630 is further configured to combine at least one code snippet and a task prompt word to obtain a prompt word input, where the task prompt word indicates a verification statement generation task; and provide the prompt word input to a machine learning model to obtain a verification statement.
[0108] In some embodiments, at least one code snippet includes multiple code snippets, and the generation module 630 is further configured to splice the multiple code snippets in the order of the multiple code snippets in the target code; and combine the spliced multiple code snippets with the task prompt word.
[0109] In some embodiments, the training of the machine learning model includes a pre-training process and a fine-tuning process, wherein in the pre-training process, a sample code set is used to pre-train the machine learning model, and wherein in the fine-tuning process, at least one sample code snippet in the sample code from the sample code set and a sample verification statement for a parameter in the sample code are used to fine-tune the machine learning model, and the at least one sample code snippet includes a code snippet in the sample code that matches at least one predetermined statement type among a plurality of predetermined statement types.
[0110] In some embodiments, the at least one sample code snippet further comprises a code snippet in the sample code in a predetermined neighborhood of the sample verification statement.
[0111] In some embodiments, during the pre-training process, the machine learning model is pre-trained by at least one of a masked language model (MLM) task and a causal language model (CLM) task.
[0112] Figure 7 A block diagram of an electronic device 700 is shown in which one or more embodiments of the present disclosure may be implemented. It should be understood that Figure 7 The electronic device 700 shown is only a schematic diagram.
[0113] The present invention is merely exemplary and should not be construed as limiting the functionality and scope of the embodiments described herein. Figure 7 The electronic device 700 shown can be used to implement Figure 1 terminal device 110.
[0114] like Figure 7 As shown, the electronic device 700 is in the form of a general electronic device. The components of the electronic device 700 may include, but are not limited to, one or more processors or processing units 710, a memory 720, a storage device 730, one or more communication units 740, one or more input devices 750, and one or more output devices 760. The processing unit 710 may be an actual or virtual processor and is capable of performing various processes according to a program stored in the memory 720. In a multi-processor system, multiple processing units execute computer executable instructions in parallel to improve the parallel processing capability of the electronic device 700.
[0115] The electronic device 700 typically includes a plurality of computer storage media. Such media may be any accessible media that is accessible to the electronic device 700, including but not limited to volatile and non-volatile media, removable and non-removable media. The memory 720 may be a volatile memory (e.g., a register, a cache, a random access memory (RAM)), a non-volatile memory (e.g., a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), flash memory), or some combination thereof. The storage device 730 may be a removable or non-removable medium, and may include a machine-readable medium, such as a flash drive, a disk, or any other medium, which may be capable of being used to store information and / or data (e.g., training data for training) and may be accessed within the electronic device 700.
[0116] The electronic device 700 may further include additional removable / non-removable, volatile / non-volatile storage media. Figure 7 As shown in , a disk drive for reading or writing from a removable, non-volatile disk (e.g., a "floppy disk") and an optical drive for reading or writing from a removable, non-volatile optical disk may be provided. In these cases, each drive may be connected to the bus (not shown) by one or more data media interfaces. The memory 720 may include a computer program product 725 having one or more program modules that are configured to perform various methods or actions of various embodiments of the present disclosure.
[0117] The communication unit 740 enables communication with other electronic devices via a communication medium. Additionally, the functions of the components of the electronic device 700 can be implemented in a single computing cluster or multiple computing machines that can communicate via a communication connection.
[0118] 700 may operate in a networked environment using logical connections to one or more other servers, a network personal computer (PC), or another network node.
[0119] The input device 750 may be one or more input devices, such as a mouse, a keyboard, a tracking ball, etc. The output device 760 may be one or more output devices, such as a display, a speaker, a printer, etc. The electronic device 700 may also communicate with one or more external devices (not shown) through the communication unit 740 as needed, such as a storage device, a display device, etc., communicate with one or more devices that allow a user to interact with the electronic device 700, or communicate with any device that allows the electronic device 700 to communicate with one or more other electronic devices (e.g., a network card, a modem, etc.). Such communication may be performed via an input / output (I / O) interface (not shown).
[0120] According to an exemplary implementation of the present disclosure, a computer-readable storage medium is provided, on which computer-executable instructions are stored, wherein the computer-executable instructions are executed by a processor to implement the method described above. According to an exemplary implementation of the present disclosure, a computer program product is also provided, which is tangibly stored on a non-transitory computer-readable medium and includes computer-executable instructions, and the computer-executable instructions are executed by a processor to implement the method described above.
[0121] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices, equipment, and computer program products implemented according to the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0122] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0123] P23041928901CN
[0124] Computer-readable program instructions can be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, so that the instructions executed on the computer, other programmable data processing apparatus, or other device implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0125] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple implementations of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of a module, program segment or instruction includes one or more executable instructions for realizing the logical function of the specification. In some implementations as replacements, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a special hardware-based system that performs the function or action of the specification, or can be realized by a combination of special hardware and computer instructions.
[0126] The above descriptions of various implementations of the present disclosure are exemplary, non-exhaustive, and not limited to the disclosed implementations. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described implementations. The selection of terms used herein is intended to best explain the principles of the implementations, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the various implementations disclosed herein.< / x> < / z> < / z> < / z> < / x> < / z> < / x> < / mask> < / mask> < / mask> < / x> < / x> < / x> < / x> < / x>
Claims
1. A method for code parameter verification, comprising: Detect parameter verification requests for target code; In response to detecting the parameter checking request, extracting at least one code segment matching at least one of a plurality of predetermined statement types from the target code; as well as generating, using the trained machine learning model, a verification statement for at least one parameter of the code based on the at least one code snippet, wherein the verification statement is configured to verify the legality of the at least one parameter, The machine learning model is trained based on a sample code set and sample verification statements for parameters of the sample codes in the sample code set.
2. The method according to claim 1, wherein detecting the parameter verification request comprises: Detecting the parameter verification request in a code editing page of the target code; or The parameter verification request initiated for the code file of the target code is received.
3. The method according to claim 1, further comprising: Presenting an insertion prompt control for the verification statement; as well as If a preset operation for the insertion prompt control is detected, the verification statement is inserted into the target code.
4. The method according to claim 3, wherein inserting the verification statement into the target code comprises: Determine a target position in the target code where the verification statement is to be inserted, wherein the target position includes a position of an input cursor or a position specified by a user; as well as Insert the verification statement into the target location.
5. The method according to claim 1, wherein the plurality of predetermined statement types comprises at least one of the following: Parameter statement, The function header, and Remote procedure call statement.
6. The method according to claim 1, wherein generating the verification statement further comprises: Determining a target position in the target code where a verification statement is to be inserted; extracting another code segment in a predetermined neighborhood of the target location of the target code; as well as The verification statement is generated based on the at least one code snippet and the another code snippet using the machine learning model.
7. The method according to claim 1, wherein generating the verification statement comprises: combining the at least one code snippet and a task prompt word to obtain a prompt word input, wherein the task prompt word indicates a verification statement generation task; as well as The prompt word input is provided to the machine learning model to obtain the verification sentence.
8. The method of claim 7, wherein the at least one code snippet comprises a plurality of code snippets, and wherein combining the at least one code snippet and a task prompt word comprises: splicing the multiple code snippets according to the order of the multiple code snippets in the target code; as well as The concatenated multiple code snippets are combined with the task prompt word.
9. The method according to claim 1, wherein the training of the machine learning model includes a pre-training process and a fine-tuning process, wherein the sample code set is used to pre-train the machine learning model during the pre-training process, and During the fine-tuning process, at least one sample code snippet in the sample code from the sample code set and a sample verification statement for a parameter in the sample code are used to fine-tune the machine learning model, and the at least one sample code snippet includes a code snippet in the sample code that matches at least one predetermined statement type among the multiple predetermined statement types.
10. The method according to claim 9, wherein the at least one sample code snippet further comprises a code snippet in the sample code in a predetermined neighborhood of the sample verification statement.
11. A device for code parameter verification, comprising: A request detection module, configured to detect a parameter verification request for a target code; a fragment extraction module configured to extract, in response to detecting the parameter checking request, at least one code fragment matching at least one predetermined statement type among a plurality of predetermined statement types from the target code; as well as a verification generation module, configured to generate a verification statement for at least one parameter of the code based on the at least one code snippet using a trained machine learning model, wherein the verification statement is configured to verify the legality of the at least one parameter; The machine learning model is trained based on a sample code set and sample verification statements for parameters of the sample codes in the sample code set.
12. An electronic device comprising: at least one processing unit; as well as At least one memory, the at least one memory being coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions causing the electronic device to perform the method according to any one of claims 1 to 10 when executed by the at least one processing unit.
13. A computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the method according to any one of claims 1 to 10 when executed by a processor.
Citation Information
Patent Citations
Code generation method based on machine learning, code editing system and storage medium
CN113805861A
Chip function verification method and device, computer readable medium and electronic equipment
CN115017863A
Code completion method and device, electronic equipment and computer readable storage medium
CN115291941A
Code generation method and device, processor and electronic equipment
CN115686471A
Method and system of processing kernel patch forprevention of kernel vulnerability
KR1020070008782A
