Code repair method and device, storage medium and electronic device
Through the combination of the fault code identification model and the code prediction model, the code repair process is automated, and the problem of low code repair efficiency in the existing technology is solved, and an efficient and general code repair method is realized.
Patent Information
- Application Number
- CN202210265115.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-17
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2042-03-17
AI Technical Summary
In the existing technology, code repair efficiency is low, it relies on manual experience, consumes material and labor, and affects the development efficiency of application.
The fault code is obtained through the fault code identification model, divided it into common subword units, and converted it into common subword feature vectors, and input the code prediction model to generate predictive repair codes, and determine the repair code based on the correct probability.
It avoids dependence on manual experience, improves the universality and efficiency of code repair, reduces labor and material costs, quickly finds and repairs faulty codes in applications, and improves development efficiency.
Smart Images

Figure CN114625405B_ABST
Abstract
Description
Background Art
[0002] With the rapid development of computer science and technology, various applications have become an inseparable part of people's daily lives. Whether the code in the application runs correctly or not is related to the operation of the entire application. After the code runs incorrectly, it is necessary to troubleshoot the error as soon as possible to repair the code.
[0003] In the prior art, developers usually rely on their experience to find and fix error codes. However, in actual situations, there are many reasons for code errors, and the manual repair method in the prior art consumes material and human resources, thereby affecting the development efficiency of the application.
[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0005] The purpose of the present disclosure is to provide a code repair method and a code repair device, a computer-readable storage medium and an electronic device, which can solve the problem of low code repair efficiency.
[0006] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.
[0007] According to a first aspect of the present disclosure, a code repair method is provided, including: acquiring a fault code through a fault code recognition model, dividing the fault code into multiple common sub-word units; converting the common sub-word units into common sub-word feature vectors, and inputting the common sub-word feature vectors into a code prediction model; generating a predicted repair code according to the code prediction model, and determining a correct probability of the predicted repair code according to the predicted repair code; and determining the predicted repair code as a repair code corresponding to the fault code according to the correct probability of the predicted repair code.
[0008] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, before obtaining the fault code through the fault code recognition model, the method also includes: obtaining a sample fault code and a sample repair code corresponding to the sample fault code; parsing the sample fault code into a fault code syntax sequence, and parsing the sample repair code corresponding to the sample fault code into a repair code syntax sequence; training the fault code recognition model according to the fault code syntax sequence and the repair code syntax sequence.
[0009] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, a fault code recognition model is trained according to a fault code syntax sequence and a repair code syntax sequence, including: generating a fault code feature vector corresponding to the fault code syntax sequence according to the fault code syntax sequence; generating a repair code feature vector corresponding to the repair code syntax sequence according to the repair code syntax sequence; inputting the fault code feature vector into the fault code recognition model to obtain a prediction result, and determining a recognition loss function of the fault code recognition model according to the prediction result and the repair code feature vector; and iteratively updating the neural network parameters in the fault code recognition model through the recognition loss function to train the fault code recognition model.
[0010] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, before training the fault code recognition model according to the fault code syntax sequence and the repair code syntax sequence, the method also includes: obtaining the code fault type corresponding to the fault code syntax sequence, and obtaining the number of faults corresponding to the fault code syntax sequence; wherein the code fault type includes syntax fault; and discarding the fault code syntax sequence whose fault type is syntax fault and the fault code syntax sequence whose fault number is less than the preset fault number.
[0011] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the common sub-word feature vector is input into a code prediction model, including: determining the common sub-word feature word vector, the common sub-word feature text vector and the common sub-word feature position vector corresponding to the common sub-word feature vector according to the common sub-word feature vector; and inputting the common sub-word feature word vector, the common sub-word feature text vector and the common sub-word feature position vector into the code prediction model.
[0012] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the correct probability of the predicted repair code is determined according to the predicted repair code, including: obtaining multiple code words in the predicted repair code, determining a repair sub-probability according to every two adjacent code words in the multiple code words; determining the correct probability of the repair code according to the multiple repair sub-probabilities.
[0013] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the correct probability of the predicted repair code is determined according to the predicted repair code, including: converting the predicted repair code into a predicted code feature vector, generating a predicted code semantic graph according to the predicted code feature vector; and determining the correct probability of the repair code according to relevant information of the predicted code semantic graph and prior knowledge of code repair.
[0014] According to a second aspect of the present disclosure, a code repair device is provided, including: a fault code recognition module, used to obtain a fault code through a fault code recognition model, and divide the fault code into multiple common sub-word units; a common sub-word division module, used to convert the common sub-word units into common sub-word feature vectors, and input the common sub-word feature vectors into a code prediction model; a repair code generation module, used to generate a predicted repair code according to the code prediction model, and determine the correct probability of the predicted repair code according to the predicted repair code; a repair code determination module, used to determine the predicted repair code as the repair code corresponding to the fault code according to the correct probability of the predicted repair code.
[0015] According to a third aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the code repair method of the first aspect of the above embodiment is implemented.
[0016] According to a fourth aspect of the present disclosure, there is provided an electronic device, including:
[0017] one or more processors; and
[0018] A storage device is used to store one or more programs. When the one or more programs are executed by one or more processors, the one or more processors implement the code repair method of the first aspect of the above embodiment.
[0019] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0020] In a code repair method provided by an embodiment of the present disclosure, a fault code can be obtained through a fault model, and the fault code can be converted into a common subword feature vector, a predicted repair code can be generated through a code prediction model, and then the predicted repair code can be confirmed.
[0021] On the one hand, it can avoid the dependence on manual experience when repairing the code, and improve the versatility of code repair; on the other hand, there is no need to find the fault code and repair it through manual troubleshooting, the efficiency of code repair is higher, and the cost of manpower and material resources can be reduced, so that the fault code in the application can be quickly found and repaired, thereby improving the development efficiency of the application.
[0022] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present disclosure, and together with the specification, are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0024] Figure 1 A schematic diagram schematically shows an exemplary system architecture to which a code repair method according to an embodiment of the present disclosure can be applied;
[0025] Figure 2 A flowchart schematically illustrates a code repair method in an exemplary embodiment of the present disclosure;
[0026] Figure 3 A flowchart schematically illustrates a method of training a fault code recognition model according to a fault code grammar sequence and a repair code grammar sequence in an exemplary embodiment of the present disclosure;
[0027] Figure 4 A flowchart schematically illustrates a method of iteratively updating the neural network parameters in the fault code recognition model by identifying the loss function in an exemplary embodiment of the present disclosure to train the fault code recognition model;
[0028] Figure 5 A flowchart schematically illustrates discarding a fault code grammar sequence whose fault type is a grammar fault and a fault code grammar sequence whose fault number is less than a preset fault number in an exemplary embodiment of the present disclosure;
[0029] Figure 6 Schematically showing a flow chart of inputting a common subword feature character vector, a common subword feature text vector and a common subword feature position vector into a code prediction model in an exemplary embodiment of the present disclosure;
[0030] Figure 7 A flowchart schematically illustrates determining the correct probability of a repair code according to a plurality of repair sub-probabilities in an exemplary embodiment of the present disclosure;
[0031] Figure 8 A flowchart schematically illustrates the correct probability of repairing a code according to the relevant information of the predicted code semantic graph and the prior knowledge of code repair in an exemplary embodiment of the present disclosure;
[0032] Fig. 9 A schematic diagram schematically illustrates a method of generating a predicted code semantic graph according to a predicted code feature vector in an exemplary embodiment of the present disclosure;
[0033] Fig.10 A flowchart schematically illustrates a code repair process based on BERT in an exemplary embodiment of the present disclosure;
[0034] Fig.11 A schematic diagram schematically shows the composition of a code repair device in an exemplary embodiment of the present disclosure;
[0035] Fig.12 The structure diagram of a computer system suitable for implementing the electronic device of the exemplary embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0036] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concept of the example embodiments will be fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In addition, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known structures, methods, devices, implementations, materials, or operations are not shown or described in detail to avoid blurring various aspects of the present disclosure.
[0037] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or these functional entities or parts of functional entities may be implemented in one or more software hardened modules, or these functional entities may be implemented in different networks and / or processor devices and / or microcontroller devices.
[0038] Figure 1 A schematic diagram showing an exemplary system architecture to which the code repair method according to an embodiment of the present disclosure can be applied is shown.
[0039] like Figure 1 As shown, the system architecture 1000 may include one or more of terminal devices 1001, 1002, 1003, a network 1004, and a server 1005. The network 1004 is used to provide a medium for communication links between the terminal devices 1001, 1002, 1003 and the server 1005. The network 1004 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0040] It should be understood that Figure 1The number of terminal devices, networks and servers in the embodiment is only for illustration. According to the implementation requirements, there may be any number of terminal devices, networks and servers. For example, the server 1005 may be a server cluster composed of multiple servers.
[0041] Users can use terminal devices 1001, 1002, 1003 to interact with server 1005 through network 1004 to receive or send messages, etc. Terminal devices 1001, 1002, 1003 can be various electronic devices with display screens, including but not limited to smart phones, tablet computers, portable computers, desktop computers, etc. In addition, server 1005 can be a server that provides various services.
[0042] In one embodiment, the execution subject of the code repair method of the present disclosure can be an embodiment of the server 1005, the server 1005 can obtain the code sent by the terminal devices 1001, 1002, 1003, and identify the fault code according to the code repair method of the present disclosure, and then divide the fault code into multiple common sub-word units, convert the common sub-word units into common sub-word feature vectors, input the common sub-word feature vectors into the code prediction model, generate the predicted repair code according to the code prediction model, determine the correct probability of the predicted repair code according to the predicted repair code, determine the predicted repair code as the repair code corresponding to the fault code according to the correct probability of the predicted repair code, and then return the repair code corresponding to the fault code obtained after processing to the terminal devices 1001, 1002, 1003. In addition, the code repair method of the present disclosure can also be executed by the terminal devices 1001, 1002, 1003, etc., so as to realize the process of obtaining the fault node according to the structural topology information and the user perception information of the alarm node.
[0043] In addition, the implementation process of the code repair method disclosed in the present invention can also be implemented jointly by the terminal devices 1001, 1002, 1003 and the server 1005. For example, the terminal devices 1001, 1002, 1003 can obtain the code, and obtain the fault code through the fault code recognition model, divide the fault code into multiple common sub-word units, and then send the obtained multiple common sub-word units to the server 1005, so that the server 1005 can convert the common sub-word units into common sub-word feature vectors, input the common sub-word feature vectors into the code prediction model, generate a predicted repair code according to the code prediction model, determine the correct probability of the predicted repair code according to the predicted repair code, and determine the predicted repair code as the repair code corresponding to the fault code according to the correct probability of the predicted repair code.
[0044] The code repair scheme in the present disclosure can be applied to scenarios involving program code repair. For example, it can be applied to scenarios of developing applications or systems. It should be noted that the present disclosure does not specifically limit the application scenarios.
[0045] According to the code repair method provided in this exemplary embodiment, when a fault code is obtained through a fault code recognition model, the fault code is divided into multiple common sub-word units, the common sub-word units are converted into common sub-word feature vectors, the common sub-word feature vectors are input into a code prediction model, a predicted repair code is generated according to the code prediction model, the correct probability of the predicted repair code is determined according to the predicted repair code, and the predicted repair code is determined as the repair code corresponding to the fault code according to the correct probability of the predicted repair code.
[0046] like Figure 2 As shown, the code repair method may include the following steps:
[0047] Step S210, obtaining a fault code through a fault code recognition model, and dividing the fault code into a plurality of common sub-word units;
[0048] Step S220, converting the common sub-word units into common sub-word feature vectors, and inputting the common sub-word feature vectors into the code prediction model;
[0049] Step S230, generating a predicted repair code according to the code prediction model, and determining a correct probability of the predicted repair code according to the predicted repair code;
[0050] Step S240: determining the predicted repair code as the repair code corresponding to the fault code according to the correct probability of the predicted repair code.
[0051] In a code repair method provided by an embodiment of the present disclosure, a fault code can be obtained through a fault model, and the fault code can be converted into a common subword feature vector, and a predicted repair code can be generated through a code prediction model, and then the predicted repair code can be confirmed. On the one hand, it can avoid the dependence on manual experience during code repair, and improve the versatility of code repair; on the other hand, it is not necessary to find and repair the fault code through manual troubleshooting, and the efficiency of code repair is high, and the cost of manpower and material resources can be reduced, so that the fault code in the application can be quickly found and repaired, thereby improving the development efficiency of the application.
[0052] Next, steps S210 to S240 of the code repair method in this exemplary embodiment will be described in more detail with reference to the accompanying drawings and embodiments.
[0053] Step S210, obtaining a fault code through a fault code recognition model, and dividing the fault code into a plurality of common sub-word units;
[0054] In an exemplary embodiment of the present disclosure, a fault code can be obtained through a fault code recognition model. Specifically, the fault code recognition model can be used to recognize a fault code, that is, after the code is input into the fault code recognition model, the fault code recognition model can recognize the fault code from multiple code segments, that is, the code that needs to be repaired.
[0055] Among them, the fault code recognition model can be a model based on a variety of network models. For example, the fault code recognition model may include a model based on an RNN (Recurrent Neural Network) network; or, the fault code recognition model may include a model based on an LSTM (Long Short-Term Memory) network; or, the fault code recognition model may include a model based on an LSTM (Generative Adversarial Networks) network. It should be noted that the present disclosure does not specifically limit the specific type of the fault code recognition model.
[0056] Specifically, the fault code obtained by the fault code recognition model may include a section of code related to the fault. For example, the code is "[cls] public vaid savePerson", where "vaid" fails, and at this time, "[cls] public vaid savePerson" is the fault code.
[0057] It should be noted that the present disclosure does not specifically limit the specific form of the fault code obtained by the fault code recognition model.
[0058] In an exemplary embodiment of the present disclosure, after the fault code is obtained through the above steps, the fault code can be divided into multiple common sub-word units. Specifically, the common sub-word unit refers to the smallest unit word that can be divided in the fault code. For example, the fault code is "[cls] public void savePerson", at this time, the fault code can be divided into "cls", "public", "void", and "savePerson".
[0059] It should be noted that the present disclosure does not specifically limit the form of the common sub-word unit and the manner of dividing the fault code into multiple common sub-word units.
[0060] Step S220, converting the common sub-word units into common sub-word feature vectors, and inputting the common sub-word feature vectors into the code prediction model;
[0061] In an exemplary embodiment of the present disclosure, after the fault code is divided into multiple common sub-word units through the above steps, the multiple common sub-word units can be converted into common sub-word feature vectors. Specifically, the common sub-word feature vector can be used to indicate the semantic information of the common sub-word unit, such as the meaning of the common sub-word unit, the position of the common sub-word unit in the fault code, and other information. It should be noted that the present disclosure does not specifically limit the specific content indicated by the common sub-word feature vector.
[0062] Furthermore, the common sub-word units can be converted into one-dimensional common sub-word feature vectors as input of the code prediction model.
[0063] It should be noted that the present disclosure does not specifically limit the specific method of converting the common sub-word units into the common sub-word feature vectors.
[0064] In an exemplary embodiment of the present disclosure, after the common sub-word units are converted into common sub-word feature vectors through the above steps, the common sub-word feature vectors can be input into the code prediction model. Specifically, the code prediction model can be used to provide corresponding predicted repair codes for fault codes. Among them, the code prediction model can be a model based on a variety of network models. For example, the code prediction model may include a model based on an RNN (Recurrent Neural Network) network; or, the code prediction model may include a model based on an LSTM (Long Short-Term Memory) network; or, the code prediction model may include a model based on an LSTM (Generative Adversarial Networks) network. It should be noted that the present disclosure does not specifically limit the specific type of the code prediction model.
[0065] Step S230, generating a predicted repair code according to the code prediction model, and determining a correct probability of the predicted repair code according to the predicted repair code;
[0066] In an exemplary embodiment of the present disclosure, after the common subword feature vector is input into the code prediction model through the above steps, a predicted repair code can be generated according to the code prediction model. Specifically, the predicted repair code may include a code for repairing the faulty code, or the predicted repair code may include a code for replacing the faulty code for repair.
[0067] For example, the fault code is "
cls
cls
[0068] In an example embodiment of the present disclosure, after the predicted repair code is obtained through the code prediction model, the correct probability of the predicted repair code can be determined based on the predicted repair code. Specifically, the predicted code obtained through the code prediction model may not be able to repair the fault code, and in this case, the correct probability of the predicted repair code needs to be determined. Among them, the correct probability of the predicted repair code can be used to indicate the repair possibility of the predicted repair code for the fault code corresponding to the predicted repair code. The higher the correct probability of the predicted repair code, the greater the repair possibility for the fault code corresponding to the predicted repair code.
[0069] Specifically, when determining the correct probability of the predicted repair code according to the predicted repair code, the predicted repair code can be compared with the repair log in the repair database to obtain the correct probability of the predicted repair code. The repair database refers to a database for storing repair logs, each of which records the fault code and the repair code corresponding to the fault code, as well as the repair solution for the fault code and other information.
[0070] It should be noted that the present disclosure does not specifically limit the specific content and form of the repair log.
[0071] For example, the fault code is "
cls
cls
[0072] It should be noted that the present disclosure does not specifically limit the specific method of determining the correct probability of the predicted repair code based on the predicted repair code.
[0073] In an example embodiment of the present disclosure, the code prediction model may be a model based on BERT (Bidirectional Encoder Representation from Transformers, a pre-trained language representation model). The BERT model may be trained using large-scale unlabeled corpus to obtain text containing rich semantic information.
[0074] Step S240: determining the predicted repair code as the repair code corresponding to the fault code according to the correct probability of the predicted repair code.
[0075] In an exemplary embodiment of the present disclosure, after the correct probability of the predicted repair code is obtained through the above steps, the predicted repair code can be determined as the repair code corresponding to the fault code according to the correct probability of the predicted repair code. Specifically, a correct threshold can be set, and when the correct probability of the predicted repair code is greater than the correct threshold, it can be indicated that the predicted repair code is likely to repair the fault code, and the predicted repair code can be determined as the repair code corresponding to the fault code.
[0076] It should be noted that the present disclosure does not specifically limit the specific manner of determining the predicted repair code as the repair code corresponding to the fault code according to the correct probability of the predicted repair code.
[0077] In an exemplary embodiment of the present disclosure, a sample fault code and a sample repair code corresponding to the sample fault code may be obtained, the sample fault code may be parsed into a fault code grammar sequence, the sample repair code corresponding to the sample fault code may be parsed into a repair code grammar sequence, and a fault code recognition model may be trained based on the fault code grammar sequence and the repair code grammar sequence. Figure 3 As shown, training the fault code recognition model according to the fault code grammar sequence and the repair code grammar sequence may include the following steps S310-S330:
[0078] Step S310, obtaining a sample fault code and a sample repair code corresponding to the sample fault code;
[0079] In an example embodiment of the present disclosure, before obtaining a fault code through a fault code recognition model, the fault code recognition model needs to be trained, and sample fault codes and sample repair codes corresponding to the sample fault codes may be obtained to train the fault code recognition model.
[0080] Specifically, the sample fault code and the sample repair code corresponding to the sample fault code, wherein the sample repair code corresponding to the sample fault code refers to the repair code for repairing the fault code after the fault code is found. The sample fault code and the sample repair code corresponding to the sample fault code can be stored in a sample database, and the sample fault code and the sample repair code corresponding to the sample fault code can be obtained in the sample database, or the sample fault code and the sample repair code corresponding to the sample fault code can be obtained in some platforms (such as Github) that maintain the sample fault code and the sample repair code corresponding to the sample fault code.
[0081] It should be noted that the present disclosure does not specifically limit the specific method of obtaining the sample fault code and the sample repair code corresponding to the sample fault code.
[0082] Step S320, parsing the sample fault code into a fault code grammar sequence, and parsing the sample repair code corresponding to the sample fault code into a repair code grammar sequence;
[0083] In an exemplary embodiment of the present disclosure, after the sample fault code and the sample repair code corresponding to the sample fault code are obtained through the above steps, the sample fault code can be parsed into a fault code grammatical sequence, and the sample repair code corresponding to the sample fault code can be parsed into a repair code grammatical sequence. Specifically, the fault code grammatical sequence and the repair code grammatical sequence can represent a sequence of grammatical structures of the fault code and a sequence representing the grammatical structure of the repair code.
[0084] In an exemplary embodiment of the present disclosure, a sample fault code can be parsed into a fault code syntax sequence through an abstract syntax tree (AST), and a sample repair code corresponding to the sample fault code can be parsed into a repair code syntax sequence through the abstract syntax tree. The abstract syntax tree is a tree representation of the abstract syntax of a code, which does not represent the details of the real syntax and does not rely on the syntax structure of the source code.
[0085] It should be noted that the present disclosure does not specifically limit the specific manner of parsing the sample fault code into a fault code syntax sequence and the specific form of the repair code syntax sequence.
[0086] Step S330: training a fault code recognition model according to the fault code grammar sequence and the repair code grammar sequence.
[0087] In an exemplary embodiment of the present disclosure, after the sample fault code is parsed into a fault code grammar sequence and the sample repair code corresponding to the sample fault code is parsed into a repair code grammar sequence through the above steps, a fault code recognition model can be trained according to the fault code grammar sequence and the repair code grammar sequence. Specifically, the fault code grammar sequence and the repair code grammar sequence can be input into the fault code recognition model, and the fault code recognition model can use the repair code grammar sequence to determine whether an error occurs in the fault code grammar sequence, and the fault code recognition model can be trained in this way, so that the fault code recognition model can more accurately recognize the fault code.
[0088] It should be noted that the present disclosure does not specifically limit the specific method of training the fault code recognition model according to the fault code grammar sequence and the repair code grammar sequence.
[0089] Through the above steps S310 to S330, sample fault codes and sample repair codes corresponding to the sample fault codes can be obtained, the sample fault codes can be parsed into fault code grammatical sequences, the sample repair codes corresponding to the sample fault codes can be parsed into repair code grammatical sequences, and a fault code recognition model can be trained based on the fault code grammatical sequences and the repair code grammatical sequences.
[0090] In an exemplary embodiment of the present disclosure, a fault code feature vector corresponding to a fault code grammar sequence can be generated according to a fault code grammar sequence, a repair code feature vector corresponding to a repair code grammar sequence can be generated according to a repair code grammar sequence, the fault code feature vector can be input into a fault code recognition model to obtain a prediction result, a recognition loss function of the fault code recognition model can be determined according to the prediction result and the repair code feature vector, and the neural network parameters in the fault code recognition model can be iteratively updated by the recognition loss function to train the fault code recognition model. Figure 4 As shown, iteratively updating the neural network parameters in the fault code recognition model by identifying the loss function to train the fault code recognition model may include the following steps S410 to S440:
[0091] Step S410, generating a fault code feature vector corresponding to the fault code grammar sequence according to the fault code grammar sequence;
[0092] Step S420, generating a repair code feature vector corresponding to the repair code grammar sequence according to the repair code grammar sequence;
[0093] In an exemplary embodiment of the present disclosure, after obtaining the fault code grammar sequence and the fault code grammar sequence through the above steps, a fault code feature vector corresponding to the fault code grammar sequence can be generated according to the fault code grammar sequence. Specifically, the fault code grammar sequence can be converted into a fault code feature vector, and the repair code grammar sequence can be converted into a repair code feature vector. Among them, the fault code feature vector can be used to indicate the semantic information of the fault code grammar sequence, such as the meaning of the fault code grammar sequence, the position of each item in the fault code grammar sequence, and other information; the repair code feature vector can be used to indicate the semantic information of the repair code grammar sequence, such as the meaning of the repair code grammar sequence, the position of each item in the repair code grammar sequence, and other information.
[0094] Furthermore, a one-dimensional fault code feature vector corresponding to the fault code syntax sequence may be generated according to the fault code syntax sequence, and a one-dimensional repair code feature vector corresponding to the repair code syntax sequence may be generated according to the repair code syntax sequence.
[0095] It should be noted that the present disclosure does not specifically limit the specific method of generating a fault code feature vector corresponding to a fault code syntax sequence according to a fault code syntax sequence and the specific method of generating a repair code feature vector corresponding to a repair code syntax sequence according to a repair code syntax sequence.
[0096] Step S430, inputting the fault code feature vector into the fault code recognition model to obtain a prediction result, and determining the recognition loss function of the fault code recognition model according to the prediction result and the repair code feature vector;
[0097] In an exemplary embodiment of the present disclosure, after obtaining the fault code feature vector corresponding to the fault code grammar sequence and the repair code feature vector corresponding to the repair code grammar sequence through the above steps, the fault code feature vector can be input into the fault code recognition model to obtain a prediction result. Specifically, the prediction result obtained by the fault code recognition model refers to whether the code input into the fault code recognition model is a fault code, and the prediction result may include whether it is a fault code or not a fault code.
[0098] In an exemplary embodiment of the present disclosure, after the prediction result is obtained through the above steps, the recognition loss function of the fault code recognition model can be determined according to the prediction result and the repair code feature vector. Specifically, the prediction result and the repair code feature vector can be analyzed to obtain the recognition loss function of the fault code recognition model.
[0099] For example, the code input into the fault code recognition model is a fault code. In the fault code recognition model, after comparing the input fault code feature vector with the repair code feature vector, the result output by the fault code recognition model is not a fault code, that is, the output result (prediction result) of the fault code recognition model is wrong, and there is a difference between the prediction result and the actual result. The recognition loss function of the fault code recognition model can be determined based on the difference.
[0100] Among them, the identification loss function can be used to indicate the difference between the predicted results and the actual results. The identification loss function is a function that maps the values of a random event or its related random variables to non-negative real numbers to represent the "loss" of the random event. It is used to evaluate the degree to which the predicted results of the model are different from the actual results (i.e., whether the input fault code feature vector is a fault code). The lower the loss function, the better the performance of the model is generally.
[0101] Furthermore, the recognition loss function may include an absolute value loss function, a logarithmic loss function, a mean square error loss function, an exponential loss function, a Hinge loss function, a perceptual loss function, a cross entropy loss function, etc. It should be noted that the present disclosure does not specifically limit the specific form of the recognition loss function.
[0102] Step S440, iteratively updating the neural network parameters in the fault code recognition model by identifying the loss function to train the fault code recognition model.
[0103] In an exemplary embodiment of the present disclosure, after obtaining the recognition loss function through the above steps, the neural network parameters in the fault code recognition model can be iteratively updated through the recognition loss function to train the fault code recognition model. Specifically, the neural network parameters of the convolutional neural network of the fault code recognition model can be initialized first, and the output value can be obtained through multiple layers in the convolutional neural network (such as convolutional layer, deconvolutional layer, fully connected layer, etc.), and the neural network parameters are adjusted according to the recognition loss function, and the neural network parameters are iteratively updated. When the recognition loss function converges, the training ends. Furthermore, the convolutional layer and the deconvolutional layer can correspond to each other one by one and be interconnected to facilitate signal transmission between the convolutional layer and the deconvolutional layer. When training the model to be trained, the signal can be transmitted from the convolutional layer to the deconvolutional layer, or the signal can be transmitted from the deconvolutional layer to the convolutional layer, which can speed up the training process of the fault code recognition model.
[0104] It should be noted that the present disclosure does not specifically limit the specific method of iteratively updating the neural network parameters in the fault code recognition model by identifying the loss function to train the fault code recognition model.
[0105] Through the above steps S410 to S440, a fault code feature vector corresponding to the fault code syntax sequence can be generated according to the fault code syntax sequence, a repair code feature vector corresponding to the repair code syntax sequence can be generated according to the repair code syntax sequence, the fault code feature vector can be input into the fault code recognition model to obtain a prediction result, the recognition loss function of the fault code recognition model can be determined according to the prediction result and the repair code feature vector, and the neural network parameters in the fault code recognition model can be iteratively updated through the recognition loss function to train the fault code recognition model.
[0106] In an exemplary embodiment of the present disclosure, the code fault type corresponding to the fault code syntax sequence can be obtained, the fault number corresponding to the fault code syntax sequence can be obtained, and the fault code syntax sequence whose fault type is a syntax fault and whose fault number is less than a preset fault number can be discarded. Figure 5 As shown, discarding the fault code grammar sequence whose fault type is grammar fault and the fault code grammar sequence whose fault number is less than the preset fault number may include the following steps S510-S520:
[0107] Step S510, obtaining the code fault type corresponding to the fault code syntax sequence, and obtaining the fault quantity corresponding to the fault code syntax sequence; wherein the code fault type includes syntax fault;
[0108] In an exemplary embodiment of the present disclosure, after the sample fault code is parsed into a fault code syntax sequence through the above steps, and the sample repair code corresponding to the sample fault code is parsed into a repair code syntax sequence, the code fault type corresponding to the fault code syntax sequence can be obtained. Specifically, the fault type corresponding to the fault code syntax sequence may include errors such as syntax errors, variable errors, and illegal parameters.
[0109] It should be noted that the present disclosure does not make any special limitation on the specific type of code fault and does not make any special limitation on the specific method of obtaining the code fault type corresponding to the fault code syntax sequence.
[0110] In an exemplary embodiment of the present disclosure, the number of faults corresponding to a fault code syntax sequence may be obtained. Specifically, the number of faults corresponding to a fault code syntax sequence refers to the number of times the same fault code appears in a historical fault record. When obtaining the number of faults corresponding to a fault code syntax sequence, all fault records in the historical fault record may be traversed, and the number of occurrences of the fault code corresponding to the fault code syntax sequence may be counted.
[0111] It should be noted that the present disclosure does not specifically limit the specific method for obtaining the number of faults corresponding to the fault code syntax sequence.
[0112] Step S520, discarding the fault code grammar sequence whose fault type is grammar fault and the fault code grammar sequence whose fault number is less than the preset fault number.
[0113] In an exemplary embodiment of the present disclosure, after obtaining the code fault type corresponding to the fault code syntax sequence and the fault number corresponding to the fault code syntax sequence through the above steps, the fault code syntax sequence whose code fault type is a syntax fault can be discarded, that is, when training the fault code recognition model, the fault code syntax sequence whose code fault type is a syntax fault is not used to train the fault code recognition model, and the fault code syntax sequence whose fault number is less than the preset fault number is discarded, that is, when training the fault code recognition model, the fault code syntax sequence whose fault number is less than the preset fault number is not used to train the fault code recognition model.
[0114] It should be noted that the present disclosure does not specifically limit the specific number of the preset fault number.
[0115] Through the above steps S510 to S520, the code fault type corresponding to the fault code syntax sequence can be obtained, the fault number corresponding to the fault code syntax sequence can be obtained, and the fault code syntax sequence whose fault type is a syntax fault and the fault code syntax sequence whose fault number is less than the preset fault number can be discarded.
[0116] In an exemplary embodiment of the present disclosure, a common subword feature vector, a common subword feature text vector, and a common subword feature position vector corresponding to the common subword feature vector can be determined based on the common subword feature vector, and the common subword feature word vector, the common subword feature text vector, and the common subword feature position vector are input into the code prediction model. Figure 6 As shown, inputting the common subword feature character vector, the common subword feature text vector and the common subword feature position vector into the code prediction model may include the following steps S610-S620:
[0117] Step S610, determining the common sub-word feature character vector, the common sub-word feature text vector and the common sub-word feature position vector corresponding to the common sub-word feature vector according to the common sub-word feature vector;
[0118] Step S620, inputting the common subword feature character vector, the common subword feature text vector and the common subword feature position vector into the code prediction model.
[0119] In an exemplary embodiment of the present disclosure, after the common subword vector is obtained through the above steps, the common subword feature vector, the common subword feature text vector and the common subword feature position vector corresponding to the common subword feature vector can be determined according to the common subword feature vector. Specifically, the common subword feature word vector can be used to indicate the common subword itself, the common subword feature text vector can be used to indicate the semantic information of the common subword, and the common subword feature position vector can be used to indicate the position information of the common subword in the fault code.
[0120] It should be noted that the present disclosure does not specifically limit the specific method of determining the common subword feature character vector, the common subword feature text vector and the common subword feature position vector corresponding to the common subword feature vector.
[0121] In an exemplary embodiment of the present disclosure, after obtaining the common sub-word feature character vector, the common sub-word feature text vector and the common sub-word feature position vector corresponding to the common sub-word feature vector through the above steps, the common sub-word feature character vector, the common sub-word feature text vector and the common sub-word feature position vector can be input into a code prediction model to generate a predicted repair code according to the code prediction model.
[0122] Through the above steps S610 to S620, the common sub-word feature word vector, common sub-word feature text vector and common sub-word feature position vector corresponding to the common sub-word feature vector can be determined according to the common sub-word feature vector, and the common sub-word feature word vector, common sub-word feature text vector and common sub-word feature position vector can be input into the code prediction model.
[0123] In an exemplary embodiment of the present disclosure, multiple code words in the predicted repair code may be obtained, a repair sub-probability may be determined based on every two adjacent code words in the multiple code words, and a correct probability of the repair code may be determined based on the multiple repair sub-probabilities. Figure 7 As shown, determining the correct probability of repairing the code according to multiple repair sub-probabilities may include the following steps S710-S720:
[0124] Step S710, obtaining multiple code words in the predicted repair code, and determining a repair sub-probability according to every two adjacent code words in the multiple code words;
[0125] Step S720: determining the correct probability of the repair code according to the multiple repair sub-probabilities.
[0126] In an exemplary embodiment of the present disclosure, after obtaining the predicted repair code through the above steps, multiple code words in the predicted repair code can be obtained, and the repair sub-probability can be determined according to every two adjacent code words in the multiple code words. Specifically, the predicted repair code can be divided into multiple code words, and the repair sub-probability can be calculated according to every two code words, and then the correct probability of the repair code can be determined according to the multiple repair sub-probabilities. Among them, the repair sub-probability of every two adjacent code words can be used to indicate the probability of whether the two code words are correct or not. The larger the repair sub-probability of every two adjacent code words, the greater the possibility that the two code words are correct, and the smaller the repair sub-probability of every two adjacent code words, the smaller the possibility that the two code words are correct.
[0127] Specifically, multiple code words in the predicted repair code are obtained, the repair sub-probability is determined according to every two adjacent code words in the multiple code words, and the expression for determining the correct probability of the repair code according to the multiple repair sub-probabilities is as follows, where s is the repair code, p(s) is the correct probability of the repair code, w1, w2, w3...wn are adjacent code words, p(w2 / w1), p(w3 / w2)... are the repair sub-probabilities of every two adjacent code words:
[0128] p(s)=p(w1|)*p(w2|w1)*p(w3|w2)*...*p(|wn)
[0129] Through the above steps S710 to S720, multiple code words in the predicted repair code can be obtained, a repair sub-probability is determined according to every two adjacent code words in the multiple code words, and the correct probability of the repair code is determined according to the multiple repair sub-probabilities.
[0130] In an exemplary embodiment of the present disclosure, the predicted repair code can be converted into a predicted code feature vector, a predicted code semantic graph is generated according to the predicted code feature vector, and the correct probability of the repair code is determined according to the relevant information of the predicted code semantic graph and the prior knowledge of code repair. Figure 8 As shown, determining the correct probability of repairing the code according to the relevant information of the predicted code semantic graph and the prior knowledge of code repair may include the following steps S810 to S820:
[0131] Step S810, converting the predicted repair code into a predicted code feature vector, and generating a predicted code semantic graph according to the predicted code feature vector;
[0132] In an exemplary embodiment of the present disclosure, after the predicted repair code is obtained through the above steps, the predicted repair code can be converted into a predicted code feature vector, and a predicted code semantic map can be generated according to the predicted code feature vector. The predicted code semantic map can be used to indicate the semantic structure of the predicted repair code.
[0133] It should be noted that the present disclosure does not specifically limit the specific method of converting the predicted repair code into the predicted code feature vector and generating the predicted code semantic graph according to the predicted code feature vector.
[0134] For example, Fig. 9 As shown, it is a schematic diagram of generating a predicted code semantic graph based on a predicted code feature vector.
[0135] Step S820, determining the correct probability of repairing the code based on the relevant information of the predicted code semantic graph and the prior knowledge of code repair.
[0136] In an exemplary embodiment of the present disclosure, after obtaining the predicted code semantic graph corresponding to the predicted code feature vector through the above steps, the correct probability of the repair code can be determined based on the relevant information of the predicted code semantic graph and the code repair prior knowledge. Specifically, the relevant information of the predicted code semantic graph may include each code word in the predicted repair code, the number of vertices, the number of edges contained in the vertices, etc. The code repair prior knowledge can be used to indicate the repair data in the code repair database, and the repair data includes the fault code and the repair code corresponding to the fault code. The correct probability of the currently obtained predicted repair code can be calculated based on the code repair prior knowledge.
[0137] It should be noted that the present disclosure does not specifically limit the specific types of relevant information for predicting code semantic graphs.
[0138] In an exemplary embodiment of the present disclosure, each code word in the predicted code semantic graph can be first converted into a corresponding feature vector, and then the number of vertices in the predicted code semantic graph and the number of edges contained in each vertex can be obtained, and the correct probability of repairing the code can be calculated based on the above information and the prior knowledge of code repair. The expression for determining the correct probability of repairing the code based on the relevant information of the predicted code semantic graph and the prior knowledge of code repair is as follows, where F is the correct probability of repairing the code, CiCj is the feature vector corresponding to each code word in the predicted code semantic graph, Aij is the predicted code semantic graph, KiKj is the number of edges contained in each vertex, L is the number of vertices, and Pi is the prior knowledge of code repair:
[0139]
[0140] Through the above steps S810 to S820, the predicted repair code can be converted into a predicted code feature vector, a predicted code semantic graph can be generated based on the predicted code feature vector, and the correct probability of the repair code can be determined based on the relevant information of the predicted code semantic graph and prior knowledge of code repair.
[0141] In an exemplary embodiment of the present disclosure, after obtaining the repair code through the above steps, the current fault code can be repaired by the repair code, and the repair result can be monitored. If the repaired fault code can run normally, the repaired fault code is directly used. If an error occurs, the code prediction model is retrained.
[0142] In an example embodiment of the present disclosure, sample fault codes and sample repair codes corresponding to the sample fault codes can be obtained from a sample database, and the sample fault codes and sample repair codes corresponding to the sample fault codes can be parsed into fault code grammatical sequences and repair code grammatical sequences through a syntax abstract tree, and the fault code grammatical sequences whose fault types are grammatical faults and the fault code grammatical sequences whose fault numbers are less than a preset fault number are discarded, and then the fault code grammatical sequences and the repair code grammatical sequences are converted into fault code feature vectors and repair code feature vectors according to a JAVA parser, and then a fault code recognition model is trained according to the fault code feature vectors and the repair code feature vectors, the fault code is recognized through the fault code recognition model, and a predicted repair code is generated through a BERT-based code prediction model, the correct probability of the predicted repair code is calculated, and the quality of the repair code is judged. If the repaired fault code can run normally, the repaired fault code is directly used to repair the fault code. Fig.10 As shown, the BERT-based code repair process may include the following steps S1001 to S1010:
[0143] Step S1001, obtain sample fault codes and sample repair codes corresponding to the sample fault codes in a sample database; step S1002, parse the sample fault codes and the sample repair codes corresponding to the sample fault codes into fault code grammatical sequences and repair code grammatical sequences through a syntax abstract tree; step S1003, discard the fault code grammatical sequences whose fault types are grammatical faults and the fault code grammatical sequences whose fault numbers are less than a preset fault number; step S1004, convert the fault code grammatical sequences and the repair code grammatical sequences into fault code feature vectors and repair code feature vectors according to the JAVA parser; step S1005, train a fault code recognition model according to the fault code feature vectors and the repair code feature vectors; step S1006, identify the fault code through the fault code recognition model; step S1007, generate a predicted repair code through a BERT-based code prediction model; step S1008, calculate the correct probability of the predicted repair code; step S1009, make a quality judgment on the repair code; step S1010, repair the fault code.
[0144] According to the code repair method provided in this exemplary embodiment, when a fault code is obtained through a fault code recognition model, the fault code is divided into multiple common sub-word units, the common sub-word units are converted into common sub-word feature vectors, the common sub-word feature vectors are input into a code prediction model, a predicted repair code is generated according to the code prediction model, the correct probability of the predicted repair code is determined according to the predicted repair code, and the predicted repair code is determined as the repair code corresponding to the fault code according to the correct probability of the predicted repair code.
[0145] In a code repair method provided by an embodiment of the present disclosure, a fault code can be obtained through a fault model, and the fault code can be converted into a common subword feature vector, and a predicted repair code can be generated through a code prediction model, and then the predicted repair code can be confirmed. On the one hand, it can avoid the dependence on manual experience during code repair, and improve the versatility of code repair; on the other hand, it is not necessary to find and repair the fault code through manual troubleshooting, and the efficiency of code repair is high, and the cost of manpower and material resources can be reduced, so that the fault code in the application can be quickly found and repaired, thereby improving the development efficiency of the application.
[0146] It should be noted that the above figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0147] In addition, in an exemplary embodiment of the present disclosure, a code repair device is also provided. Fig.11 As shown, a code repair device 1100 includes: a fault code identification module 1110, a common subword division module 1120, a repair code generation module 1130, and a repair code determination module 1140.
[0148] Among them, the fault code recognition module is used to obtain the fault code through the fault code recognition model and divide the fault code into multiple common sub-word units; the common sub-word division module is used to convert the common sub-word unit into a common sub-word feature vector and input the common sub-word feature vector into the code prediction model; the repair code generation module is used to generate a predicted repair code according to the code prediction model and determine the correct probability of the predicted repair code according to the predicted repair code; the repair code determination module is used to determine the predicted repair code as the repair code corresponding to the fault code according to the correct probability of the predicted repair code.
[0149] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, before acquiring the fault code through the fault code recognition model, the device also includes: a sample code acquisition unit, used to acquire a sample fault code and a sample repair code corresponding to the sample fault code; a grammar sequence parsing unit, used to parse the sample fault code into a fault code grammar sequence, and parse the sample repair code corresponding to the sample fault code into a repair code grammar sequence; a grammar sequence input unit, used to train the fault code recognition model according to the fault code grammar sequence and the repair code grammar sequence.
[0150] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, a fault code recognition model is trained according to a fault code syntax sequence and a repair code syntax sequence, and the device also includes: a fault feature vector generation unit, which is used to generate a fault code feature vector corresponding to the fault code syntax sequence according to the fault code syntax sequence; a repair feature vector generation unit, which is used to generate a repair code feature vector corresponding to the repair code syntax sequence according to the repair code syntax sequence; an identification loss function acquisition unit, which is used to input the fault code feature vector into the fault code recognition model to obtain a prediction result, and determine the identification loss function of the fault code recognition model according to the prediction result and the repair code feature vector; a fault code recognition model training unit, which is used to iteratively update the neural network parameters in the fault code recognition model through the identification loss function to train the fault code recognition model.
[0151] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, before training the fault code recognition model according to the fault code syntax sequence and the repair code syntax sequence, the device also includes: a code fault information acquisition unit, used to obtain the code fault type corresponding to the fault code syntax sequence, and obtain the number of faults corresponding to the fault code syntax sequence; wherein the code fault type includes syntax fault; a syntax sequence discarding unit, used to discard the fault code syntax sequence whose fault type is syntax fault and the fault code syntax sequence whose fault number is less than the preset fault number.
[0152] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the common sub-word feature vector is input into the code prediction model, and the device also includes: a sub-feature vector acquisition unit, which is used to determine the common sub-word feature word vector, the common sub-word feature text vector and the common sub-word feature position vector corresponding to the common sub-word feature vector according to the common sub-word feature vector; and a sub-feature vector input unit, which is used to input the common sub-word feature word vector, the common sub-word feature text vector and the common sub-word feature position vector into the code prediction model.
[0153] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the correct probability of the predicted repair code is determined according to the predicted repair code, and the device also includes: a repair sub-probability determination unit, which is used to obtain multiple code words in the predicted repair code, and determine the repair sub-probability according to every two adjacent code words in the multiple code words; a first correct probability determination unit, which is used to determine the correct probability of the repair code according to the multiple repair sub-probabilities.
[0154] In an exemplary embodiment of the present disclosure, based on the aforementioned scheme, the correct probability of the predicted repair code is determined according to the predicted repair code, and the device also includes: a predicted code semantic graph generation unit, which is used to convert the predicted repair code into a predicted code feature vector, and generate a predicted code semantic graph according to the predicted code feature vector; a second correct probability determination unit, which is used to determine the correct probability of the repair code according to relevant information of the predicted code semantic graph and prior knowledge of code repair.
[0155] Since the functional modules of the code repair device in the example embodiment of the present disclosure correspond to the steps of the example embodiment of the above-mentioned code repair method, for details not disclosed in the embodiment of the device of the present disclosure, please refer to the embodiment of the above-mentioned code repair method of the present disclosure.
[0156] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0157] In addition, in an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above code repair method is also provided.
[0158] Those skilled in the art will appreciate that various aspects of the present disclosure may be implemented as systems, methods or program products. Therefore, various aspects of the present disclosure may be specifically implemented in the following forms, namely: complete hardware embodiments, complete software embodiments (including firmware, microcode, etc.), or embodiments combining hardware and software aspects, which may be collectively referred to herein as "circuits", "modules" or "systems".
[0159] Refer to the following Fig.12 1200 according to this embodiment of the present disclosure is described. Fig.12 The electronic device 1200 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0160] like Fig.12 As shown, the electronic device 1200 is in the form of a general computing device. The components of the electronic device 1200 may include, but are not limited to: the at least one processing unit 1210, the at least one storage unit 1220, a bus 1230 connecting different system components (including the storage unit 1220 and the processing unit 1210), and a display unit 1240.
[0161] The storage unit stores program codes, which can be executed by the processing unit 1210, so that the processing unit 1210 performs the steps according to various exemplary embodiments of the present disclosure described in the above “Exemplary Method” section of this specification. For example, the processing unit 1210 can perform the following steps: Figure 2 In step S210 shown in the figure, the fault code is obtained through the fault code recognition model, and the fault code is divided into multiple common sub-word units; in step S220, the common sub-word units are converted into common sub-word feature vectors, and the common sub-word feature vectors are input into the code prediction model; in step S230, a predicted repair code is generated according to the code prediction model, and the correct probability of the predicted repair code is determined according to the predicted repair code; in step S240, the predicted repair code is determined as the repair code corresponding to the fault code according to the correct probability of the predicted repair code.
[0162] For example, electronic devices can achieve Figure 2 The steps shown.
[0163] The storage unit 1220 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 1221 and / or a cache memory unit 1222 , and may further include a read-only memory unit (ROM) 1223 .
[0164] The storage unit 1220 may also include a program / utility 1224 having a set (at least one) of program modules 1225, such program modules 1225 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0165] Bus 1230 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0166] The electronic device 1200 may also communicate with one or more external devices 1270 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1200, and / or communicate with any device that enables the electronic device 1200 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 1250. In addition, the electronic device 1200 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 1260. As shown, the network adapter 1260 communicates with other modules of the electronic device 1200 via a bus 1230. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1200, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0167] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiment of the present disclosure.
[0168] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible embodiments, various aspects of the present disclosure can also be implemented in the form of a program product, which includes a program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary embodiments of the present disclosure described in the above "Exemplary Method" section of the present specification.
[0169] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0170] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0171] Program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0172] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0173] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.
Claims
1. A code repair method, characterized in that: The method comprises: Acquire a fault code through a fault code recognition model, and divide the fault code into a plurality of common sub-word units; Converting the common sub-word units into common sub-word feature vectors, and inputting the common sub-word feature vectors into a code prediction model; generating a predicted repair code according to the code prediction model, and determining a correct probability of the predicted repair code according to the predicted repair code; Determining the predicted repair code as a repair code corresponding to the fault code according to the correct probability of the predicted repair code; Wherein, determining the correct probability of the predicted repair code according to the predicted repair code includes: Acquire multiple code words in the predicted repair code, and determine a repair sub-probability according to every two adjacent code words in the multiple code words; determine a correct probability of the repair code according to the multiple repair sub-probabilities; or, The predicted repair code is converted into a predicted code feature vector, and a predicted code semantic map is generated according to the predicted code feature vector; the correct probability of the repair code is determined according to relevant information of the predicted code semantic map and prior knowledge of code repair.
2. The method according to claim 1, characterized in that: Before acquiring the fault code through the fault code recognition model, the method further includes: Obtaining a sample fault code and a sample repair code corresponding to the sample fault code; Parsing the sample fault code into a fault code syntax sequence, and parsing the sample repair code corresponding to the sample fault code into a repair code syntax sequence; The fault code recognition model is trained according to the fault code grammar sequence and the repair code grammar sequence.
3. The method according to claim 2, characterized in that The step of training the fault code recognition model according to the fault code grammar sequence and the repair code grammar sequence comprises: Generate a fault code feature vector corresponding to the fault code grammar sequence according to the fault code grammar sequence; Generating a repair code feature vector corresponding to the repair code grammar sequence according to the repair code grammar sequence; Inputting the fault code feature vector into the fault code recognition model to obtain a prediction result, and determining a recognition loss function of the fault code recognition model according to the prediction result and the repair code feature vector; The neural network parameters in the fault code recognition model are iteratively updated through the recognition loss function to train the fault code recognition model.
4. The method according to claim 2, characterized in that: Before training the fault code recognition model according to the fault code grammar sequence and the repair code grammar sequence, the method further includes: Obtaining a code fault type corresponding to the fault code syntax sequence, and obtaining a fault quantity corresponding to the fault code syntax sequence; wherein the code fault type includes a syntax fault; The fault code grammar sequence whose fault type is a grammar fault and the fault code grammar sequence whose fault number is less than a preset fault number are discarded.
5. The method according to claim 1, characterized in that The step of inputting the common subword feature vector into a code prediction model comprises: Determine, according to the common subword feature vector, a common subword feature character vector, a common subword feature text vector, and a common subword feature position vector corresponding to the common subword feature vector; The common sub-word feature character vector, the common sub-word feature text vector and the common sub-word feature position vector are input into the code prediction model.
6. A code repair device, characterized in that: The device comprises: A fault code recognition module, used for obtaining a fault code through a fault code recognition model, and dividing the fault code into a plurality of common sub-word units; A common subword division module, used for converting the common subword units into common subword feature vectors, and inputting the common subword feature vectors into a code prediction model; A repair code generation module, used to generate a predicted repair code according to the code prediction model, and determine the correct probability of the predicted repair code according to the predicted repair code; a repair code determination module, configured to determine the predicted repair code as a repair code corresponding to the fault code according to a correct probability of the predicted repair code; Wherein, the repair code generation module is specifically used for: Acquire multiple code words in the predicted repair code, and determine a repair sub-probability according to every two adjacent code words in the multiple code words; determine a correct probability of the repair code according to the multiple repair sub-probabilities; or, The predicted repair code is converted into a predicted code feature vector, and a predicted code semantic map is generated according to the predicted code feature vector; the correct probability of the repair code is determined according to relevant information of the predicted code semantic map and prior knowledge of code repair.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
8. An electronic device, characterized in that: include: one or more processors; as well as The memory is used to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Method hierarchical defect positioning method based on Bert model
CN111427775A
Method for acquiring data of Githhub open source platform and source code defect repairing system
CN113127339A