A discrete reconfiguration coding fault location method based on code change set

Through the discrete reconstruction encoding method that uses the function library and BERT encoder for strongly supervised signal guidance in fault location, the problem of code semantics learning in the prior art and the problem of model overfitting is solved, and stronger generalization ability and more accurate fault location are achieved.

CN119201753BActive Publication Date: 2025-04-18NANJING UNIV OF POSTS & TELECOMM
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411697756.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2025-04-18
Estimated Expiration
2044-11-26

AI Technical Summary

Technical Problem

The prior art is difficult to learn code semantics effectively in fault location, and the lack of strong supervision signals leads to model overfitting, especially in tasks with poor localization results in tasks lacking historical repair records.

Method used

A discrete reconstruction encoding fault location method based on code change set is adopted, and a functional library is formed through the logic and control functions in natural language predefined programming, and the BERT encoder is used for initialization of encoding, and the code semantics is learned through strong supervision signal guidance model to quantify and reduce semantic losses in the encoding process.

Benefits of technology

The "many-to-one" special learning of the code is realized, which reduces semantic losses in the encoding process and improves the generalization ability of the model, especially in cross-projects or tasks that lack historical repair records.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201753B_ABST
    Figure CN119201753B_ABST
Patent Text Reader

Abstract

The present invention discloses a discrete reconstruction coding fault location method based on code change set, which belongs to the field of artificial intelligence and information retrieval. The fault location method uses a fault location model for location, and the fault location model includes a code semantic learning module, a fault report learning module and a fault report-code matching module. Compared with the traditional fault location method, the method performs strong supervision and guidance on the code according to the functions of different code sentences in the coding stage, and at the same time quantifies and reduces the semantic loss in the coding stage as much as possible, and the discrete coding form also enhances the model generalization ability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of artificial intelligence and information retrieval, and in particular is a discrete reconstruction coding fault locating method based on a code change set. Background Art

[0002] Fault localization is usually defined as an information retrieval (IR) task, in which there are usually a large number of fault-causing code change sets and unpaired fault reports, and each fault report usually describes a fault caused by multiple code change sets.

[0003] The goal of the fault localization task is to locate all the code change sets that caused the fault for the input fault report based on the semantic relevance between the two. The focus of this task is how to train the model to learn the semantic relevance between the fault report and the code change set paired with it. To achieve this goal, the model must learn the semantics of the fault report and the code change set respectively, and then map the two to the same vector space for comparison. Since the fault report is described in natural language, its semantics can be easily obtained through fine-tuning and training of the encoder of the BERT-based natural language processing model using the fault report. Therefore, the difficulty of model learning is usually how to fully learn the code semantics and match it with the learned fault report semantics.

[0004] Code language is different from ordinary natural language. Although it has various forms, many different code sentences often correspond to the same logic or control function. In the existing methods, during the code encoding stage, there is no supervisory signal designed to guide the model to learn the "many-to-one" particularity of the code. In addition, the existing methods mostly use continuous vectors to encode the code. If there is a lack of strong supervisory signals, the trained neural network is prone to overfitting on the training data. If the project to be located lacks historical repair records, the positioning results will be poor. In addition, the code encoding process will cause more or less semantic loss, and this part of the loss has not been quantified in the existing methods, so there is also a lack of supervisory signals to reduce the semantic loss in the encoding process. Summary of the invention

[0005] In order to solve the problems in the prior art, the present invention proposes a discrete reconstruction coding fault location method based on code change sets. Compared with the traditional fault location method, this method strongly supervises and guides the code according to the functions of different code sentences in the coding stage, and at the same time quantifies and reduces the semantic loss in the coding stage as much as possible. The discrete coding form also enhances the generalization ability of the model.

[0006] Technical solution: A discrete reconstruction coding fault location method based on code change set, characterized in that the fault location method uses a fault location model for location, the fault location model includes a code semantic learning module, a fault report learning module, and a fault report-code matching module; the fault location method includes the following steps:

[0007] S1. Prepare several fault reports and the code change sets that caused them to form several matching pairs, and divide the matching pairs into two parts according to the proportion, which are recorded as training set and test set;

[0008] S2. In the code semantics learning module, all logic and control functions that appear in programming are predefined in natural language to form a function library, and each function is initialized and encoded using the BERT encoder to obtain the function matrix B; the code change set in the training set is mapped into a word embedding matrix C, and the preliminary encoding matrix IC is obtained using BERT encoding. Each vector in IC is mapped to the vector in B that is closest to its semantics, and the final encoding matrix OC is obtained; the BERT encoder of the function matrix B is trained to reduce the mapping loss function , and correct the vectors in the function library to obtain the trained function matrix B;

[0009] S3, input the final encoding matrix OC obtained in S2 into the reconstructor in the code semantic learning module to obtain the reconstruction matrix RC, quantify the semantic loss as the difference between RC and the word embedding matrix C in S2, train the BERT encoder and reconstructor of IC obtained in the code semantic learning module, and obtain the semantic loss function ;

[0010] S4, input the code change set in the test set into the code semantics learning module trained in S3 to obtain the final encoding matrix OC representing its code semantics;

[0011] S5. In the fault report learning module, the BERT encoder is fine-tuned using the training set, and the fault reports in the test set are encoded using the fine-tuned BERT encoder to obtain a preliminary encoding matrix IR of the fault report;

[0012] S6. In the fault report-code matching module, each vector in the IR obtained in S5 is mapped to the vector in the function matrix B trained in S2 according to the semantic similarity, and the final encoding matrix OR of the report semantics is obtained; the fault report-code matching module is trained to learn the similarity between OR and all OCs matched with OR obtained in S4, and the matching loss is obtained. And the global loss function Loss;

[0013] S7. Input the fault report to be matched in the test set and all code change sets submitted before the fault report to be matched into the fault location model to obtain a matching probability vector P and generate a location result.

[0014] Compared with the traditional fault location method, the present invention has the following beneficial effects:

[0015] 1) This invention enables the model to learn the "many-to-one" specificity of the encoding code:

[0016] Compared with traditional methods, this method provides strong supervision guidance according to the different functions of code sentences in the encoding stage, mapping them to the vector that best describes their functions in the function matrix, so that the model can learn the "many-to-one" particularity of mapping different code sentences to the same function.

[0017] 2) This paper quantifies the semantic loss caused by the encoding and mapping stages:

[0018] During the training process, the present invention requires the model to reconstruct the code change set word embedding matrix using the final encoding matrix representing the semantics of the code change set as input, quantify the semantic loss as the difference between the two, and quantify and reduce the semantic loss in the encoding process as much as possible.

[0019] 3) The present invention has strong generalization ability:

[0020] Since discrete vectors are used in the process of encoding the code, all final encoding matrices representing the semantics of the code are composed only of vectors in the functional matrix, which can better avoid overfitting on the training dataset and has stronger potential in cross-project tasks or tasks with a lack of historical repair records. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 is a training flow chart of the fault location method of the present invention;

[0022] Figure 2 The process of locating and reasoning about the matching fault reports and all code change sets that may cause the matching fault reports. DETAILED DESCRIPTION

[0023] The technical solution of the present invention is described in detail below through embodiments, but the protection scope of the present invention is not limited to the embodiments.

[0024] The present invention discloses a discrete reconstruction coding fault location method based on code change set, wherein the fault location method uses a fault location model for location, and the fault location model includes a code semantic learning module, a fault report learning module, and a fault report-code matching module. The three modules are introduced as follows:

[0025] 1) Code semantics learning module: including BERT encoder, feature library matrix and reconstructor.

[0026] In the code semantics learning module, during the coding stage of the code, the functions that may appear in the programming are organized into a matrix to guide the coding. All the logic or control functions that may appear in the programming are predefined using natural language to form a function library. All functions in the function library are mapped into vectors that can best represent them to form an offline matrix to be queried. According to the different functions of each code sentence in the coding process, each code sentence is mapped into a vector in the function library, guiding the model to learn the "many-to-one" specialness of mapping different code sentences to the same function. Discrete coding also enhances the generalization ability of the model. In order to quantify the semantic loss in the coding process, the model reconstructs the code change set word embedding matrix with the final coding matrix representing the semantics of the code change set as input, quantifies the semantic loss as the difference between the two, and minimizes the semantic loss in the coding process.

[0027] In the training phase, the function library matrix and reconstructor in the code semantic learning module are trained to map different functions in the code into an offline matrix to be queried, and the reconstructor is trained to quantify and reduce semantic loss as much as possible. In the reasoning phase, according to the different functions of the input code sentences, they are mapped into vectors in the library, guiding the model to learn the "many-to-one" particularity of mapping different code sentences to the same function, and obtaining the discrete encoding matrix of the code.

[0028] 2) Fault report learning module: It is a BERT encoder fine-tuned by fault reports and is used to obtain the preliminary encoding matrix of fault reports.

[0029] 3) Fault reporting-code matching module:

[0030] The discrete coding matrix of the code and the preliminary coding matrix of the fault report are input into the fault report-code matching module. In the training phase, the training model learns to map the preliminary coding matrix of the fault report into the final coding matrix composed of vectors in the function library and the similarity of the matrix of all matching code change sets. In the inference phase, the cross entropy of the final coding matrix of the fault report and the discrete coding matrix of the code is calculated to obtain the matching rate between the two and generate the positioning result.

[0031] The present invention discloses a discrete reconstruction coding fault location method based on code change set, and its training flow chart is as follows: Figure 1 As shown in FIG. 1 , the process of locating and reasoning the matching fault report and all code change sets that may cause the matching fault report is as follows: Figure 2 As shown, the fault location method of the present invention includes the following steps:

[0032] S1. Prepare several fault reports and the code change sets that caused them to form several matching pairs, and divide the matching pairs into two parts according to the proportion, which are recorded as training set and test set;

[0033] S2. In the code semantics learning module, all logic and control functions that appear in programming are predefined in natural language to form a function library, and each function is initialized and encoded using the BERT encoder to obtain the function matrix B; the code change set in the training set is mapped into a word embedding matrix C, and the preliminary encoding matrix IC is obtained using BERT encoding. Each vector in IC is mapped to the vector in B that is closest to its semantics, and the final encoding matrix OC is obtained; the BERT encoder of the function matrix B is trained to reduce the mapping loss function , and correct the vectors in the function library to obtain the trained function matrix B.

[0034] In order to avoid the frequent appearance of vectors in the function library on the decision boundary, according to the mapping results, the vectors describing similar functions in B are made as close as possible, and the vectors of different functions are made as far away as possible. At the same time, the vectors in the function library are moved in the direction of the vector mapped to them to learn the particularity of the code description function.

[0035] The BERT encoder is a pre-trained language usage processing model that can encode natural language sequences based on context.

[0036] The specific steps of S2 are as follows:

[0037] S2-1. In the code semantics learning module, all common logic and control functions in programming are predefined in the form of phrases using natural language to form a function library. Each function is initialized and encoded using the pre-trained BERT encoder to obtain the initialization function matrix. , the matrix Behavior Vector , corresponding to the function library functions, is the vector dimension, The number of functions predefined in the function library.

[0038] In this embodiment, the predefined logic or control function is shown in the following sequence:

[0039]

[0040] S2-2. For the code change set in the training set, remove all spaces and line breaks, set each word as the smallest unit for processing, use the pre-trained global tokenizer to map each word into a vector, and obtain the word embedding matrix of the code change set. , the matrix Behavior Vector , from the source code The vectors of all the words in the sentence code are concatenated. is the vector dimension, is the number of code sentences in the code.

[0041] S2-3, the word embedding matrix obtained in S2-2 , use BERT to encode the code sentences in the source code and get the preliminary encoding matrix of the code change set , , the matrix Behavior Vector , corresponding to the source code A preliminary vector representation of the sentence code, is the vector dimension, is the number of code sentences in the code.

[0042] S2-4. Preliminary coding matrix based on code change set Mean vector and the function matrix in S2-1 Mean vector The Euclidean distance in the L-dimensional vector space is used to measure the semantic distance between the two. The vector is mapped to The vectors in the matrix form the final encoding matrix , is the vector dimension, is the number of code sentences in the code, The number of functions predefined in the function library;

[0043]

[0044]

[0045] in, is the second-order norm of the matrix, Yes The value of parameter t when the value is minimum, m is the number of functions predefined in the function library in S2-1, express Corresponding code statements and function libraries The semantic distance between the predefined functions corresponding to the vectors, Indicates that in the function library The vector with the smallest semantic distance of the corresponding code sentence.

[0046] In this embodiment, the functions corresponding to the sample code change set are shown in Table 1:

[0047] Table 1

[0048]

[0049] S2-5, in order to make vectors with large functional differences as far apart as possible, and vectors with similar functions as close as possible. For each vector in the functional matrix B in S2-1 , the code sentence vector mapped to it is used as a positive sample for learning semantic similarity, and the code sentence vector not mapped to it is used as a negative sample. The BERT encoder of the training function matrix B is reduced , this step does not train BERT encoder;

[0050]

[0051]

[0052] in, Between [-1, 1], it is used to measure the linear relationship between two vectors. yes The positive sample of yes Negative samples. is a vector The average value of all scalars in For the summation symbol, express The vector scalar, express The vector scalar, exp is an exponential function with the natural constant e as the base, is the number of positive samples, is the number of negative samples, is an artificially set temperature coefficient, refers to the mapping loss function, and M refers to the number of matching pairs in a training batch in the training set.

[0053] After each training, in order to better adapt to the particularity of the code description function, the vector in the function library should be corrected and fine-tuned towards the direction of the vector mapped to it to obtain the trained function matrix B. Back propagation is not used in this part.

[0054]

[0055]

[0056]

[0057] in, is the first vectors, In the current iteration t, IC maps to A collection of vectors, Representing a collection The number of elements in , Yes Parameters when the value is minimum The value of For the summation symbol, is an artificially set learning rate, is the vector dimension; Indicates that the first Vector To fine-tune the vector that maps to it, express The corresponding code sentence and the first The semantic distance between the predefined features corresponding to the vectors.

[0058] In this embodiment, the adjustment coefficient is set , the initialization vectors of the example functions are shown in Table 2:

[0059] Table 2

[0060]

[0061] S3, train the code semantic learning module to quantify and reduce the semantic loss, input the final encoding matrix OC obtained in S2 into the reconstructor in the code semantic learning module to obtain the reconstruction matrix RC, quantify the semantic loss as the difference between RC and the word embedding matrix C in S2, train the BERT encoder and reconstructor of IC obtained in the code semantic learning module, and obtain the semantic loss function , making RC as close to C as possible to reduce semantic loss.

[0062] The specific steps of S3 are:

[0063] S3-1, in order to train the model quantization and reduce the semantic loss in the mapping process, the S2 obtained Input the transformer-decoder based reconstructor Reconstruct to get the reconstructed matrix , , is the vector dimension, is the number of code sentences in the code, Represents the i-th vector of the reconstruction matrix.

[0064] S3-2. Quantify the semantic loss caused by the mapping process into a reconstruction matrix And the word embedding matrix in S2 The second-order norm of the matrix is ​​obtained by subtraction, and the BERT encoder and reconstructor of IC obtained in S2 are trained to minimize the semantic loss;

[0065]

[0066] in, is the second-order norm of the matrix, It is a transformer-decoder based neural network. During the back-propagation process, the gradient will be directly passed back to the IC, avoiding the influence of non-differentiable operations. It refers to the semantic loss function.

[0067] S4: Input the code change set in the test set into the code semantics learning module trained in S3 to obtain the final encoding matrix OC representing its code semantics.

[0068] The specific steps of S4 are as follows:

[0069] S4-1. Input the code change set in the test set into the code semantic learning module trained in S3. For each input code change set, obtain the corresponding word embedding matrix , use the BERT encoder trained by S3 to embed the word into the matrix C, encode it in units of code sentences in the source code, and obtain the preliminary encoding matrix of the code change set , the matrix Behavior Vector , corresponding to the source code A preliminary vector representation of the sentence code, is the vector dimension, is the number of code sentences in the code.

[0070] S4-2. Use the information obtained in S4-1 Mean vector And the function matrix trained in S2 Mean vector The Euclidean distance in the L-dimensional vector space is used to measure the semantic distance between the two. The vector in S2 is mapped to the trained function matrix The vectors in the middle form the final encoding matrix , is the vector dimension, is the number of code sentences in the code, The number of functions predefined in the function library:

[0071]

[0072]

[0073] in, is the second-order norm of the matrix, Yes The value of parameter t when the value is minimum, is the number of functions predefined in the function library, Represents the preliminary coding matrix of the code change set The i-th row vector With the function matrix The t-th row vector The semantic distance of Representation and vector The vector with the closest semantic distance .

[0074] In this embodiment, taking the code sentence "if (!access.equals("")" in S2 as an example, its similarity with the function library vector is shown in Table 3:

[0075] Table 3

[0076]

[0077] Among them, the function "if conditional judgment" with the highest similarity is used as the mapping of the corresponding function in the input code sentence "if (!access.equals("")".

[0078] S5. In the fault report learning module, the fault reports in the training set are used to fine-tune the BERT encoder, and the fine-tuned BERT encoder is used to encode the fault reports in the test set to obtain a preliminary encoding matrix IR of the fault reports.

[0079] The specific steps of S5 are as follows:

[0080] S5-1. Use the training set to perform mask pre-training on the BERT encoder and fine-tune the parameters of the BERT encoder.

[0081] S5-2. Use the BERT encoder fine-tuned in S5-1 to encode the fault reports in the test set in sentences to obtain the preliminary encoding matrix of the fault reports. , , the matrix Behavior Vector , corresponding to the report A preliminary vector representation of a natural language sentence, is the vector dimension, is the number of statements in the report.

[0082] In this embodiment, the vectors of sentence encoding of the example fault report using the method in S5 are shown in Table 4:

[0083] Table 4

[0084]

[0085] S6. In the fault report-code matching module, each vector in the IR obtained in S5 is mapped to the vector in the function matrix B trained in S2 according to the semantic similarity, and the final encoding matrix OR of the report semantics is obtained. The fault report-code matching module is trained to learn the similarity between OR and all OCs matching OR obtained by reasoning in S4.

[0086] S6-1. Preliminary coding matrix of fault report obtained according to S5 Mean vector and the trained feature matrix in S2 Mean vector The Euclidean distance in the L-dimensional vector space is used to measure the semantic distance between the two. The vector is mapped to The vectors in the matrix form the final encoding matrix , is the vector dimension, is the number of statements in the fault report, The number of functions predefined in the function library:

[0087]

[0088]

[0089] in, is the second-order norm of the matrix, Yes The value of parameter t when the value is minimum, The number of functions predefined in the function library.

[0090] S6-2, in order to make the fault report-code matching module learn the similarity between the fault report and all the code change sets matched with it, the similarity is calculated by cross entropy, and the fault report-code matching module is trained to reduce the matching loss ,During the back-propagation process, the gradient will be directly transferred back to IR,IC, and will not be affected by the non-differentiable operations during the mapping process;

[0091]

[0092]

[0093]

[0094]

[0095]

[0096]

[0097] in, Is caused The number of all code change sets corresponding to the bug report, is the summation symbol, log is the logarithmic function with base 2, is a matrix The normalized matrix of is a matrix No. Line Elements of the column, is with The corresponding fault report matches The coding matrix of the code change set, refers to the matching loss function, It refers to The similarity between the coding matrix corresponding to the code change set and the final coding matrix of the fault report.

[0098] S6-3. Define the global loss function Loss and train the fault report-code matching module to reduce the global loss function:

[0099]

[0100] in, is the mapping loss function proposed in S2-4 for vectors in the feature library to obtain their optimal representation, is the semantic loss function proposed in S3-2, is the matching loss function proposed in S6-2, It is a manually set hyperparameter used to guide the current learning focus of the model.

[0101] S7. Input the fault report to be matched in the test set and all code change sets submitted before the fault report to be matched into the fault location model to obtain a matching probability vector P and generate a location result.

[0102] The specific steps of S7 are as follows:

[0103] S7-1. Obtain a preliminary coding matrix IR of the fault report to be matched in the fault report learning module, and input all code change sets that may cause the fault report to be matched into the code semantics learning module to obtain a final coding matrix OC representing its code semantics.

[0104] S7-2, in the fault report-code matching module, map the IR matrix obtained in S7-1 into a matrix according to the method in S6 , is the vector dimension, is the number of statements in the fault report to be matched, The number of functions predefined in the function library;

[0105]

[0106]

[0107] in, is the second-order norm of the matrix, Yes Parameters when the value is minimum t The value of The number of functions predefined in the function library.

[0108] S7-3, input all code change sets that may cause the fault report to be matched into the code semantic learning module, and obtain the matrix sequence according to S4 , is the number of code change sets that may cause the matching fault report; Represents a matrix sequence Middle i A matrix.

[0109] S7-4. Calculate the OR obtained in S7-2 and the value obtained in S7-3 The cross entropy of each matrix in is used to obtain the similarity vector S;

[0110]

[0111]

[0112]

[0113]

[0114] in, It may cause The number of all code change sets corresponding to the bug report, is the summation symbol, is the method of calculating similarity in S6-2, is a matrix The normalized matrix , is a matrix No. Line The elements of the column, is with The corresponding fault report matches A code changeset.

[0115] S7-5. Use SoftMax to normalize S to obtain the pairing probability vector P, and output the vector with the highest pairing probability with the fault report. k code change sets as the fix for this report;

[0116]

[0117]

[0118] in, Yes When the value is maximum The corresponding code changeset, is the summation symbol, is a natural constant, is the number of all code change sets in the project, It is with The code changesets that match the crash reports. All possible causes Code changesets, is the j-th element of vector P.

[0119] In this embodiment, ,The 4 code change sets with the highest similarity to the fault report are used as example fault reports, and the repair results are shown in Table 5:

[0120] Table 5

[0121]

[0122] As described above, although the present invention has been shown and described with reference to specific preferred embodiments, it should not be construed as limiting the present invention itself. Various changes in form and details may be made without departing from the spirit and scope of the present invention.

Claims

1. A discrete reconstruction coding fault location method based on code change set, characterized in that: The fault location method uses a fault location model for location, and the fault location model includes a code semantic learning module, a fault report learning module and a fault report-code matching module; The fault location method comprises the following steps: S1. Prepare several fault reports and the code change sets that caused them to form several matching pairs, and divide the matching pairs into two parts according to the proportion, which are recorded as training set and test set; S2. In the code semantics learning module, all logic and control functions that appear in programming are predefined in natural language to form a function library, and each function is initialized and encoded using the BERT encoder to obtain the function matrix B; the code change set in the training set is mapped into a word embedding matrix C, and the preliminary encoding matrix IC is obtained using BERT encoding. Each vector in IC is mapped to the vector in B that is closest to its semantics, and the final encoding matrix OC is obtained; Train the BERT encoder of the function matrix B to reduce the mapping loss function , and correct the vectors in the function library to obtain the trained function matrix B; S3, input the final encoding matrix OC obtained in S2 into the reconstructor in the code semantic learning module to obtain the reconstruction matrix RC, quantify the semantic loss as the difference between RC and the word embedding matrix C in S2, train the BERT encoder and reconstructor of IC obtained in the code semantic learning module, and obtain the semantic loss function ; S4, input the code change set in the test set into the code semantics learning module trained in S3 to obtain the final encoding matrix OC representing its code semantics; S5. In the fault report learning module, the BERT encoder is fine-tuned using the training set, and the fault reports in the test set are encoded using the fine-tuned BERT encoder to obtain a preliminary encoding matrix IR of the fault report; S6, in the fault report-code matching module, each vector in the IR obtained in S5 is mapped to the vector in the function matrix B trained in S2 according to the semantic similarity, and the final encoding matrix OR of the report semantics is obtained; Train the fault report-code matching module to learn the similarity between OR and all OCs matched with OR obtained by S4, and obtain the matching loss And the global loss function Loss; S7. Input the fault report to be matched in the test set and all code change sets submitted before the fault report to be matched into the fault location model to obtain a matching probability vector P and generate a location result.

2. The method for locating a discrete reconstruction coding fault based on a code change set according to claim 1, characterized in that: The specific steps of S2 are: S2-1. Use natural language to predefine all logic and control functions that appear in programming in the form of phrases to form a function library; use the pre-trained BERT encoder to initialize and encode each function to obtain a function matrix , the matrix Behavior Vector , corresponding to the function library functions, is the vector dimension, The number of functions predefined in the function library; S2-2. For the code change set in the training set, remove all spaces and line breaks, set each word as the smallest unit for processing, use the pre-trained global tokenizer to map each word into a vector, and obtain the word embedding matrix of the code change set. , the matrix Behavior Vector , from the source code The vectors of all the words in the sentence code are concatenated. is the vector dimension, is the number of code sentences in the code; S2-3, the word embedding matrix obtained in S2-2 , use BERT to encode the code sentences in the source code and get the preliminary encoding matrix of the code change set , , the matrix Behavior Vector , corresponding to the source code A preliminary vector representation of the sentence code, is the vector dimension, is the number of code sentences in the code; S2-4. Preliminary coding matrix based on the code change set in S2-3 Mean vector and the function matrix in S2-1 Mean vector The Euclidean distance in the L-dimensional vector space is used to measure the semantic distance between the two. The vector is mapped to The vectors in the middle form the final encoding matrix , is the vector dimension, is the number of code sentences in the code, The number of functions predefined in the function library; ; ; in, is the second-order norm of the matrix, Yes Parameters when the value is minimum t The value of , m is the number of functions predefined in the function library in S1-3; express Corresponding code statements and function libraries The semantic distance between the predefined functions corresponding to the vectors, Indicates that in the function library The vector with the smallest semantic distance of the corresponding code sentence; S2-5, for each vector in the function matrix B in S2-1 , the code sentence vector mapped to it is used as a positive sample for learning semantic similarity, and the code sentence vector not mapped to it is used as a negative sample. The BERT encoder of the training function matrix B is reduced ; ; ; in, Between [-1, 1], it is used to measure the linear relationship between two vectors; yes The positive sample of yes Negative samples of is a vector The average value of all scalars in For the summation symbol, express The kth scalar of a vector, express The kth scalar of the vector, exp is the exponential function with the natural constant e as the base, np is the number of positive samples, ng is the number of negative samples, is an artificially set temperature coefficient; M refers to the number of matching pairs in a training batch in the training set, refers to the mapping loss function; After each training, the vector in the function library is corrected and fine-tuned towards the direction of the vector mapped to it to obtain the trained function matrix B: ; ; ; in, is the first vectors, In the current tth iteration, IC maps to A collection of vectors, Representing a collection The number of elements in , Yes Parameters when the value is minimum The value of For the summation symbol, is an artificially set learning rate, is the vector dimension; Indicates that the first Vector To fine-tune the vector that maps to it, express The corresponding code sentence and the first The semantic distance between the predefined features corresponding to the vectors.

3. The method for locating a discrete reconstruction coding fault based on a code change set according to claim 2, characterized in that: The specific steps of S3 are: S3-1, the S2 obtained Input the transformer-decoder based reconstructor Reconstruct to get the reconstructed matrix , , is the vector dimension, is the number of code sentences in the code, represents the i-th vector of the reconstruction matrix; S3-2. Quantify the semantic loss caused by the mapping process into a reconstruction matrix And the word embedding matrix in S2 The second-order norm of the matrix is ​​obtained by difference, and the BERT encoder and reconstructor of IC obtained in S2 are trained to reduce the semantic loss: ; in, is the second-order norm of the matrix, It is a transformer-decoder based neural network; It refers to the semantic loss function.

4. The method for locating a discrete reconstruction coding fault based on a code change set according to claim 3, characterized in that: The specific steps of S4 are: S4-1. Input the code change set in the test set into the code semantic learning module trained in S3. For each input code change set, obtain the corresponding word embedding matrix , use the BERT encoder trained by S3 to embed the word into the matrix C, encode it in units of code sentences in the source code, and obtain the preliminary encoding matrix of the code change set , , the matrix Behavior Vector , corresponding to the source code A preliminary vector representation of the sentence code, is the vector dimension, is the number of code sentences in the code; S4-2, obtained using S4-1 Mean vector And the function matrix trained in S2 Mean vector The Euclidean distance in the L-dimensional vector space is used to measure the semantic distance between the two. The vector in S2 is mapped to the trained function matrix The vectors in the middle form the final encoding matrix , is the vector dimension, is the number of code sentences in the code, The number of functions predefined in the function library; ; ; in, is the second-order norm of the matrix, Yes The value of parameter t when the value is minimum, is the number of functions predefined in the function library, Represents the preliminary coding matrix of the code change set The i-th row vector With the function matrix The t-th row vector The semantic distance of Representation and vector The vector with the closest semantic distance .

5. The method for locating a discrete reconstruction coding fault based on a code change set according to claim 4, characterized in that: The specific steps of S5 are: S5-1. In the fault report learning module, the BERT encoder is masked and pre-trained using the training set, and the parameters of the BERT encoder are fine-tuned. S5-2. Use the BERT encoder fine-tuned in S5-1 to encode the fault reports in the test set in sentences to obtain the preliminary encoding matrix of the fault reports. , , the matrix Behavior Vector , corresponding to the fault report A preliminary vector representation of a natural language sentence, is the vector dimension, is the number of statements in the report.

6. The method for locating a discrete reconstruction coding fault based on a code change set according to claim 5, characterized in that: The specific steps of S6 are: S6-1. Preliminary coding matrix of fault report obtained in S5 Mean vector and the trained feature matrix in S2 Mean vector The Euclidean distance in the L-dimensional vector space is used to measure the semantic distance between the two. The vector is mapped to The vectors in the middle form the final encoding matrix , is the vector dimension, is the number of statements in the fault report, The number of functions predefined in the function library; ; ; in is the second-order norm of the matrix, Yes The value of parameter t when the value is minimum, The number of functions predefined in the function library; S6-2. Use cross entropy to calculate similarity and train the fault report-code matching module to reduce matching loss : ; ; ; ; ; ; in, Is caused The number of all code change sets corresponding to the bug report, is the summation symbol, log is the logarithmic function with base 2, is a matrix The normalized matrix of is a matrix No. Line The elements of the column, is with The corresponding fault report matches A code change set; refers to the matching loss function, It refers to The similarity between the coding matrix corresponding to the code change set and the final coding matrix of the fault report; S6-3. Define the global loss function Loss and train the model to reduce the global loss function: ; in, is the mapping loss function proposed in S2-4 for vectors in the feature library to obtain their optimal representation, is the semantic loss function proposed in S3-2, is the matching loss function proposed in S6-2, , It is a hyperparameter set by humans.

7. The method for locating a discrete reconstruction coding fault based on a code change set according to claim 6, characterized in that: The specific steps of S7 are: S7-1, obtaining a preliminary coding matrix IR of the to-be-matched fault report in the fault report learning module, and inputting all code change sets that may cause the to-be-matched fault report into the code semantics learning module to obtain a final coding matrix OC representing its code semantics; S7-2, in the fault report-code matching module, map the IR matrix obtained in S7-1 into a matrix according to the method in S6 , is the vector dimension, is the number of statements in the fault report to be matched, The number of functions predefined in the function library; ; ; in, is the second-order norm of the matrix, Yes Parameters when the value is minimum t The value of The number of functions predefined in the function library; S7-3, input all code change sets that may cause the fault report to be matched into the code semantic learning module, and obtain the matrix sequence according to S4 , is the number of code change sets that may cause the matching fault report; express Represents a matrix sequence The i-th matrix in S7-4. Calculate the OR obtained in S7-2 and the value obtained in S7-3 The cross entropy of each matrix in gets the similarity vector S ; ; ; ; ; in, It may cause The number of all code change sets corresponding to the bug report, is the summation symbol, is the method of calculating similarity in S6-2, is a matrix The normalized matrix , is a matrix No. Line The elements of the column, is with The corresponding fault report matches A code change set; Use SoftMax to normalize S to get the pairing probability vector P , output the highest probability of matching with the fault report k code change sets as the fix for this report; ; ; in, Yes When the value is maximum The corresponding code changeset, is the summation symbol, is a natural constant, is the number of all code change sets in the project, It is with The code changeset that matches the crash report; All possible causes The code changeset, is a vector P No. elements.

Citation Information

Patent Citations

  • Method and system for improving application fault positioning efficiency, medium and electronic device

    CN110262968A

  • Method hierarchical defect positioning method based on Bert model

    CN111427775A