Repeated defect report detection method for BERTopic-SBERT hybrid drive
By combining BERTopic and SBERT models for topic and semantic similarity calculation, and incorporating an adaptive threshold mechanism, the accuracy and generalization issues of duplicate defect report detection in existing technologies are resolved, achieving more accurate identification and filtering of duplicate defect reports.
Patent Information
- Application Number
- CN202510913483.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-03
- Publication Date
- 2025-10-17
AI Technical Summary
Existing methods for detecting duplicate defect reports have limitations in terms of topic modeling quality, feature fusion strategies, semantic encoding optimization, and classification mechanisms, making it difficult to accurately identify and filter duplicate defect reports during the software development process.
A BERTopic-SBERT hybrid-driven method for detecting duplicate defect reports is adopted. This method integrates the BERTopic topic model and the SBERT semantic encoder, combines UMAP and HDBSCAN algorithms for topic clustering, and introduces an adaptive threshold mechanism to optimize the SBERT model to improve the accuracy and generalization ability of semantic similarity calculation.
It achieves more accurate identification of duplicate defect reports, improves the model's ability to identify semantically implicit duplicate reports, adapts to the differences in feature distribution between different software projects, and improves cross-project robustness and stability.
Smart Images

Figure CN120804332A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of natural language technology, and particularly relates to a BERTopic-SBERT hybrid driven repeated defect report detection method. BACKGROUND
[0002] In view of the fact that the topic model in the natural language technology excessively focuses on the division of topics and ignores the granularity of word meaning, defect reports, as an important carrier of feedback problems in the software development process, play a key role in defect positioning and repair process. However, in actual software projects, the emergence of a large number of repeated defect reports greatly increases the review burden of developers and seriously reduces the defect processing efficiency. In addition, due to the different understanding of problems and language expression habits of each user who writes defect reports, the difficulty of developers in judging and processing repeated reports is further increased. Therefore, automatically identifying and filtering repeated defect reports has become an important task to be solved in the current software engineering field, and the core lies in accurately measuring the similarity between reports.
[0003] In recent years, researchers have proposed different types of solutions to the repeated defect report detection problem. Among them, the traditional machine learning-based method usually focuses on manual feature design, such as TF-IDF vectorization, keyword matching, and lexical overlap, and uses cosine similarity or classifiers to implement report judgment. This kind of method is simple and efficient, but it is limited to lexical level syntactic similarity and is difficult to accurately process reports with similar semantics but different expression methods. Deep learning-based methods use neural networks to automatically extract features of report texts, such as CNN, LSTM, and Transformer-based semantic encoding models. However, although these methods have improved the ability of text feature representation, they usually only focus on the semantic features of the report text itself and ignore the underlying topic structure information behind the report.
[0004] The existing LDA-BERT-based repeated defect report detection method has made an important step in integrating topic models and deep semantic models, but this method still has the following objective deficiencies:
[0005] Firstly, the LDA topic modeling capability is limited: LDA is essentially a word frequency-based probabilistic generation model, which is difficult to capture deep semantic connections between contexts, especially in defect reports and other short texts and term-intensive data. The topic clustering often has the problem of semantic drift or redundant clustering. BS-DBRD introduces the BERTopic model in the topic modeling stage, uses pre-trained SBERT as a semantic encoder, and combines UMAP and HDBSCAN to achieve high-quality semantic topic clustering, significantly enhancing the semantic expression ability and distinguishability of topic modeling.
[0006] Secondly, ignoring task-specific semantic alignment and optimization: the BERT encoder used in LDA-BERT is usually a general pre-training model that is not adapted to the duplicate detection task and lacks modeling of the semantic comparison between reports. BS-DBRD optimizes the SBERT encoder through contrastive learning, enhances the model's perception of semantic differences in positive and negative sample pairs, and further improves the discriminability of semantic vectors by combining task fine-tuning, significantly improving the similarity calculation effect.
[0007] Thirdly, the threshold determination is fixed and the generalization ability is weak: LDA-BERT usually uses a fixed similarity threshold for discrimination, which is difficult to adapt to different project data distribution differences, and has weak cross-project migration ability. BS-DBRD introduces an adaptive threshold mechanism, dynamically optimizes the decision boundary on the validation set, and significantly improves the generalization and stability of the model.
[0008] Although the LDA-BERT method effectively integrates topic and semantic information, there are still limitations in key aspects such as topic modeling quality, feature fusion strategy, semantic encoding optimization, and classification discrimination mechanism. SUMMARY
[0009] In view of the above problems existing in the prior art, the technical problem to be solved by the present application is how to improve the accuracy of duplicate defect report classification based on fine-grained semantic encoding.
[0010] To solve the above technical problems, the present application adopts the following technical solutions:
[0011] The present application focuses on topic division, integrates deep learning technology, proposes a two-level feature vector re-detection method, and proposes an LDA-BERT model. The model combines the advantages of BERT (Bidirectional Encoder Representations from Transformers) and LDA (Latent Dirichlet Allocation) models. The overall framework of the LDA-BERT model is shown in the figure, which is mainly divided into two parts: vector acquisition and vector connection part; among them, the vector acquisition module is divided into two parts: topic vector acquisition and sentence embedding vector acquisition. The topic vector acquisition establishes a topic model, inputs the training data set, and outputs the topic probability vector; the sentence embedding vector is obtained by inputting the training data set into the BERT model; after obtaining the topic vector and the sentence embedding vector, the second part of the model framework is the connection of the topic vector and the sentence embedding vector. Since the dimensions of the topic vector and the sentence embedding vector are different, an autoencoder is needed to connect the two.
[0012] A BERTopic-SBERT hybrid-driven duplicate defect report detection method includes the following steps:
[0013] S100: Selecting publicly available original defect report data, labeling all the original defect report data to obtain true labels for the original defect report data;
[0014] A duplicate defect report detection model, BS-DBRD, was constructed. BS-DBRD consists of a data preprocessing module, a similarity calculation module, and a defect report classification module. The similarity calculation module includes a topic similarity calculation module based on the BERTopic model and a semantic similarity calculation module based on the SBERT model. The defect report classification module is composed of an adaptive threshold mechanism.
[0015] The data preprocessing module is used to extract data features and perform data preprocessing operations on defect report data;
[0016] The similarity calculation module is used to calculate the topic similarity value and semantic similarity value between defect reports;
[0017] The defect report classification module is used to output the classification results of duplicate defect reports;
[0018] S200: Input the original defect report data set into the data preprocessing module to extract data features, and perform data preprocessing on all the extracted data features to obtain a training set D;
[0019] Construct a defect report group in the training set D: randomly select several defect reports from D as the main report sample set from Choose any one of the master report samples Select from D All bug reports describing the same software defect that are Together they form a defect report group; similarly, the training set D is divided into several defect report groups;
[0020] S300: Generate a positive sample pair set and a negative sample pair set using all defect report groups, where the positive sample pair set consists of multiple repeated report pairs, and the negative sample pair set consists of multiple non-repeated report pairs; wherein each positive sample pair or each negative sample pair represents a defect report pair;
[0021] S400: Input all data features in D into the topic similarity calculation module to calculate the topic similarity of each defect report pair;
[0022] Input all data features in D into the semantic similarity calculation module to calculate the semantic similarity of each defect report pair;
[0023] S500: Combine the topic similarity and semantic similarity of the defect report pair, and then input the combination result into the defect report classification module to obtain a repeated report classification result;
[0024] S600: Construct a loss function using a contrast learning method Will After data conversion, use Optimize the SBERT model, update the SBERT model parameters by the principle of gradient descent reverse update, when the training reaches the maximum value or Does not change, stop training, get trained SBERT, wherein The expression of the loss function is:
[0025]
[0026] Wherein, m=0.2 is an interval parameter to ensure the difference between positive and negative samples; v a , v p , v n and v hn represent anchor sample sentence vector encoding, positive sample sentence vector encoding, negative sample sentence vector encoding, and difficult negative sample sentence vector encoding, respectively.
[0027] Construct a loss function using binary cross-entropy Take the repeated report pair and the non-repeated report pair as the data input of the trained SBERT, and use Fine-tune the parameters of the trained SBERT, and fine-tune the parameters of the trained SBERT by the principle of gradient descent reverse update, when the training reaches the maximum value or Does not change, stop training, get trained final SBERT model SBERT', wherein The calculation expression of is as follows:
[0028]
[0029] Wherein, y ij represents the true label of the defect report pair (r i , r j ) (1 for repeated, 0 for non-repeated), s ij =cosine(v i , v j ) represents the semantic similarity of the defect report pair, and sigma(·) is a Sigmoid function.
[0030] S700: Assign the model parameters of SBERT' to BS-DBRD to obtain a trained repeated defect report detection model BS-DBRD';
[0031] S800: Select the defect report data M to be predicted, input into the BS-DBRD' model, and obtain the repetition judgment classification result of the defect report in M.
[0032] As preferred, the step of obtaining the training set D in S200 is as follows:
[0033] The text description with the core field is extracted from the defect report original data to form a core field text data set, and then regular expressions are used to remove noise data to obtain a denoised core field text data set;
[0034] The denoised core field text data set is preprocessed using natural language processing tools, and the preprocessed core field text data set is used as the training set D.
[0035] As preferred, in S300, the content of constructing positive sample pairs and negative sample pairs is as follows:
[0036] Constructing positive sample pairs: the defect reports in the same defect report group are positive samples of each other, and any two reports belonging to the same defect report group form a positive sample pair;
[0037] Constructing negative sample pairs: using a random negative sampling strategy, randomly selecting two defect reports from two different defect report groups to form a negative sample pair.
[0038] As preferred, the step of calculating the topic similarity of each defect report pair in S400 is as follows:
[0039] Using the BERTopic method for topic modeling:
[0040] S410: Defining the text content of the ith defect report r i with the core field in D as Generating the embedding vector v i of the ith defect report text through the SBERT encoder in BERTopic:
[0041]
[0042] Where i=1, 2, …, N, N represents the total number of defect reports in D;
[0043] S411: Using the UMAP algorithm for non-linear dimensionality reduction of v i to balance local structure and global distribution preservation; and dimensionality reduction of v i Through the HDBSCAN density clustering algorithm, the topic of the ith defect report r i is automatically divided;
[0044] Traverse all defect reports in D to obtain the automatic topic division results of all defect reports;
[0045] S412: Count the automatic topic division results of all defect reports to obtain T topic clusters, and each defect report is attributed to one of the T topics;
[0046] S413: Calculate the weight w of the ith defect report in D and each topic by using a dynamic topic representation method based on c-TF-IDF i,j , and the calculation expression is as follows:
[0047]
[0048] wherein w i,j represents the association strength between the defect report r i and the topic t j , f i,j represents the frequency of the defect report r i in the topic t j , N represents the total number of all defect reports, and N j represents the total number of reports in the jth topic;
[0049] S414: Calculate the normalized weight vector Θ i of r i on all topics, which is represented as follows:
[0050]
[0051] wherein Θ i is used to reflect the association strength between the defect report and each topic;
[0052] Traverse all defect reports to obtain the normalized weight vector of all defect reports;
[0053] S415: Calculate the topic similarity sim topic (·) between two defect reports:
[0054] sim topic (r i ,r j′ )=cosine(Θ i ,Θ j′ )
[0055] wherein r j′ represents the j'th defect report, cosine(·) represents a cosine similarity function, and Θ j′ represents the normalized weight vector corresponding to the j'th defect report.
[0056] As preferred, the content of calculating semantic similarity of each pair of defect reports in S400 is as follows:
[0057] Semantic similarity sim semantic The calculation formula of (·) is as follows:
[0058] sim semantic (r i ,r j )=cosine(v i ,v j )
[0059] Wherein, v j represents the embedding vector of the jth defect report r j .
[0060] As preferred, the content of obtaining the repeated report classification result in S500 is as follows:
[0061] S510: Given a pair of defect reports r i and r j , calculate the topic similarity sim topic (r i ,r j ) and the semantic similarity sim semantic (r i ,r j ), and then concatenate sim topic (r i ,r j ) and sim semantic (r i ,r j ) to form a two-dimensional joint feature vector f ij , the calculation expression is as follows:
[0062] f ij =[sim topic (r i ,r j ),sim semantic (r i ,r j )]
[0063] Set the threshold value in the adaptive threshold mechanism as τ adapt , the calculation expression is as follows:
[0064]
[0065] Wherein, y represents the true label of the validation set, represents the prediction result under the threshold τ, and F1(·) represents F1-score F1(·) represents F1-score;
[0066] S520: Use logistic regression classifier to classify f ij Perform classification prediction and combine τ adapt , and finally report the classification results of This can be determined by the following rules:
[0067]
[0068] The value range is [0,1]. Indicates reporting on (r i ,r j ), where 1 indicates a duplicate defect report and 0 indicates a non-duplicate report.
[0069] As a preference, in said S600, The data converted is as follows:
[0070] S610: From Randomly select a main report sample as the anchor sample anchor, randomly select a defect report in the same defect report group as the anchor as the positive sample positive, select a defect report from other defect report groups as the anchor corresponding negative sample negative, and the negative sample satisfies the condition sim(anchor, negative)<0.4, select a defect report that belongs to the same topic cluster as the anchor but not the same defect report group as the anchor as the hard negative sample hardnegative, and the negative sample satisfies the condition sim(anchor, hardnegative)∈[0.4,0.6];
[0071] S620: Anchor, positive, negative and hardnegative are combined into a four-tuple sample of the main report;
[0072] Traverse all In the main report, repeat S610-S620 to obtain a set of four-tuple samples
[0073] S630: The semantic similarity calculation module inputs duplicate report pairs and non-duplicate report pairs to calculate the semantic similarity between the anchor sample and the positive sample, negative sample, and difficult negative sample respectively;
[0074] in, The expression is as follows:
[0075]
[0076] Among them, anchor (k) Represents the kth anchor point sample, postitve (k) Represents the kth positive sample, negative (k) Represents the kth negative sample, hardnegative (k) represents the k-th difficult negative sample, k represents the index number of the sample and k = {1, 2, ..., K}, K represents the total number of four-tuple samples in D;
[0077] S640: Anchor (k) ,positive (k) ,negative (k) ,hardnegative (k) The corresponding sentence vector encoding is generated by SBERT, which is recorded as v a 、v p 、v n and v hn , now completed Data conversion operations;
[0078] S650: Calculate v separately a With v p 、v n 、v hn The semantic similarity between them is obtained a The calculation formula for the corresponding anchor semantic similarity value group is as follows:
[0079] s ap (v a ,v p )=cosine(v a ,v p )
[0080] s an (v a ,v n )=cosine(v a ,v n )
[0081] s ahn (v a ,v hn )=cosine(v a ,v hn )
[0082] Traversal All the four-tuple samples in are used to obtain the anchor semantic similarity value groups corresponding to all anchor samples; all the anchor semantic similarity value groups are used as data input for training the SBERT model.
[0083] Compared with the prior art, the present application has at least the following advantages:
[0084] 1. Subject-semantic dual-channel feature modeling mechanism. The present application proposes a dual-channel feature modeling method that fuses BERTopic subject features and SBERT semantic features, comprehensively utilizes the information of defect reports in the macro subject structure and the micro semantic content two levels, realizes more accurate repeated defect report identification, and overcomes the problem of insufficient recognition accuracy caused by relying only on word surface similarity or subject clustering in traditional methods.
[0085] 2. Joint feature representation method fusing semantic and subject similarity. The present application designs a joint feature representation method for defect report pairs, constructs a two-dimensional feature vector containing subject similarity and semantic similarity, and uses it as the input of the downstream classifier, which significantly improves the model's ability to identify semantic implicit repeated reports.
[0086] 3. Adaptive threshold mechanism based on validation set dynamic optimization. An adaptive threshold classification strategy is proposed to improve cross-project robustness: by searching for the optimal decision threshold on the validation set with F1-score as the objective function, the traditional fixed threshold method is replaced, and more stable classification and determination of report pairs are realized, which is especially suitable for actual scenarios where feature distribution exists between different software projects.
[0087] 4. Contrastive learning and fine-tuning mechanism for defect report semantics. The present application introduces a contrastive learning optimization mechanism in the semantic modeling part to enhance the discriminative ability of the SBERT model on the defect corpus, and combines downstream fine-tuning to further adapt to the semantics of the defect report field, solving the problem of the adaptability of the pre-trained model in the software engineering field. BRIEF DESCRIPTION OF DRAWINGS
[0088] Figure 1 Figure 1 is a schematic diagram of the SHGMAE model architecture of the present application. DETAILED DESCRIPTION
[0089] The present application will be further described below.
[0090] Firstly, the defect report original data is text extracted and data preprocessed to build repeated report pairs and non-repeated report pairs, which include positive samples, negative samples and difficult negative samples for contrastive learning training; then, the repeated defect report detection is realized through three stages, in the topic similarity analysis stage based on BERTopic, the BERTopic model is used to model the topic of defect report text to obtain the topic distribution feature and get the topic similarity; in the fine-grained semantic analysis stage based on SBERT, the SBERT is optimized by contrastive learning to improve the generalization ability of SBERT, and then the defect report data is used to fine-tune the optimized SBERT; the SBERT after the above steps is used for fine-grained semantic analysis to obtain semantic similarity; finally, in the joint feature classification stage based on the adaptive threshold mechanism, the adaptive threshold mechanism is introduced to dynamically determine the classification threshold in a data-driven manner, and based on the joint features of topic and semantic similarity, a joint classifier is constructed to realize the final classification judgment of the report.
[0091] Referring to Figure 1 A BERTopic-SBERT hybrid driven repeated defect report detection method, comprising the following steps:
[0092] S100: Selecting public defect report original data, marking all defect report original data to obtain the true label of the defect report original data;
[0093] A repeated defect report detection model BS-DBRD is constructed, BS-DBRD includes a data preprocessing module, a similarity calculation module and a defect report classification module, wherein the similarity calculation module includes a topic similarity calculation module based on the BERTopic model and a semantic similarity calculation module based on the SBERT model; the defect report classification module is composed of an adaptive threshold mechanism; the adaptive threshold mechanism is prior art, the BERTopic model and the SBERT model are prior art;
[0094] The data preprocessing module is used for data feature extraction and data preprocessing operation of the defect report data;
[0095] The similarity calculation module is used for calculating the topic similarity value and the semantic similarity value between the defect reports;
[0096] The defect report classification module is used for outputting the classification result of the repeated defect report;
[0097] S200: Input the defect report original data set into the data preprocessing module for data feature extraction, and obtain the training set D after data preprocessing of all extracted data features;
[0098] Building defect report group in training set D: randomly selecting several defect reports from D as main report sample set from any one main report sample selecting from D and all defect reports describing the same software defect, which are from together constitute a defect report group; similarly, training set D is divided into several defect report groups;
[0099] The step of obtaining training set D in S200 is as follows:
[0100] Extracting the text description with the core field from the defect report original data to form a core field text data set, and then removing the noise data in the core field text data set by using regular expression to obtain the denoised core field text data set; the noise data removed by regular expression includes HTML tags, version numbers, etc.
[0101] Using a natural language processing tool to pre-process the denoised core field text data set, and taking the pre-processed core field text data set as training set D. The natural language processing tool is a prior art, and the Python natural language processing tool package NLTK 2 (Natural Language Toolkit) can be selected; the data pre-processing includes word segmentation and data cleaning; for word segmentation, the text information is divided into words and some constraints are applied to better train the word vector; for data cleaning, not only the common stop words in English are deleted, but also the unnecessary words in the defect report are deleted, such as <, ",.org, etc.
[0102] S300: generating a positive sample pair set and a negative sample pair set using all defect report groups, the positive sample pair set being composed of multiple duplicate report pairs, and the negative sample pair set being composed of multiple non-duplicate report pairs; wherein one positive sample pair or one negative sample pair represents one defect report pair;
[0103] In S300, the contents of constructing positive sample pairs and negative sample pairs are as follows:
[0104] Constructing positive sample pairs: the defect reports in the same defect report group are positive samples of each other, and any two reports belonging to the same defect report group form a positive sample pair;
[0105] Constructing negative sample pairs: using a random negative sampling strategy to randomly select two defect reports from two different defect report groups to form a negative sample pair. The random negative sampling strategy is a prior art, which is simple and easy to implement and suitable for most scenarios, but may contain easily classified samples with large semantic differences.
[0106] S400: input all data features in D into the topic similarity calculation module to calculate the topic similarity of each pair of defect reports;
[0107] Input all data features in D into the semantic similarity calculation module to calculate the semantic similarity of each pair of defect reports;
[0108] The step of calculating the topic similarity of each pair of defect reports in S400 is as follows:
[0109] Topic modeling is performed using BERTopic:
[0110] S410: define the text content of the ith defect report r i with core fields in D as Generate the embedding vector v i of the ith defect report text through the SBERT encoder in BERTopic:
[0111]
[0112] Where i = 1, 2, …, N, N represents the total number of defect reports in D; the SBERT encoder in BERTopic is a prior art;
[0113] In this phase, a topic modeling method based on BERTopic is proposed, which realizes fine-grained extraction of defect report topic features by fusing context-aware semantic embedding and hierarchical clustering technology; unlike the LDA model based on word frequency statistics, BERTopic uses a pre-trained language model SBERT to obtain a deep semantic representation of defect reports, effectively solving the problems of short text sparsity and technical term polysemy;
[0114] S411: perform nonlinear dimensionality reduction on v i using the UMAP algorithm to balance local structure and global distribution preservation; perform dimensionality reduction on v i , and automatically divide the topic of the ith defect report r i through the HDBSCAN density clustering algorithm;
[0115] Iterate through all defect reports in D to obtain the automatic topic division results of all defect reports;
[0116] S412: count the automatic topic division results of all defect reports to obtain T topic clusters, and each defect report is assigned to one of the T topics;
[0117] UMAP algorithm and HDBSCAN density clustering algorithm are prior art, UMAP mainly aims at the redundancy problem existing in high-dimensional embedding vector; HDBSCAN density clustering algorithm avoids noise interference by minimum cluster size constraint and supports discovery of non-spherical cluster structure;
[0118] S413: Calculate the weight w of the ith defect report in D associated with each topic based on the dynamic topic representation method based on c-TF-IDF i,j , the calculation expression is as follows:
[0119]
[0120] Wherein, w i,j represents the association strength between the defect report r i and the topic t j , f i,j represents the frequency of the defect report r i in the topic t j , N represents the total number of all defect reports, N j represents the total number of reports in the jth topic;
[0121] S414: Calculate the normalized weight vector Θ i of r i on all topics, as follows:
[0122]
[0123] Wherein, Θ i is used to reflect the association strength of the defect report with each topic;
[0124] Iterate through all defect reports to obtain the normalized weight vector of all defect reports;
[0125] c-TF-IDF is an improved TF-IDF weight calculation method, which combines defect reports in the same cluster into virtual documents, the main purpose of which is to highlight the importance of topic keywords; TF-IDF is prior art, compared with traditional TF-IDF, c-TF-IDF enhances the discrimination of domain terms through cluster-level word frequency statistics;
[0126] S415: Calculate the topic similarity sim topic between each pair of defect reports (·):
[0127] sim topic (r i ,r j′ )=cosine(Θ i ,Θ j′ )
[0128] wherein r j′ represents the j'th defect report, cosine(·) represents the cosine similarity function, and Θ j′ represents the normalized weight vector corresponding to the j'th defect report.
[0129] The content of calculating the semantic similarity of each pair of defect reports in S400 is as follows:
[0130] The semantic similarity sim semantic (·) is calculated as follows:
[0131] sim semantic (r i ,r j )=cosine(v i ,v j )
[0132] wherein v j represents the embedding vector of the j'th defect report r j .
[0133] SBERT is a prior art. Compared with the traditional method, the SBERT optimization scheme proposed in this research makes the SBERT model have stronger generalization ability and can more accurately capture the subtle semantic differences between defect reports.
[0134] S500: Combine the topic similarity and semantic similarity of the pair of defect reports, then input the combination result into the defect report classification module to obtain the duplicate report classification result;
[0135] The content of obtaining the duplicate report classification result in S500 is as follows:
[0136] S510: Given a pair of defect reports r i and r j , calculate the topic similarity sim topic (r i ,r j ) and the semantic similarity sim semantic (r i ,r j ), then concatenate sim topic (r i ,r j ) and sim semantic (r i ,r j ) to form a two-dimensional joint feature vector f ij , which is calculated as follows:
[0137] f ij =[sim topic (r i ,rj ),sim semantic (r i ,r j )]
[0138] Set the threshold value in the adaptive threshold mechanism to be τ adapt , the calculation expression is as follows:
[0139]
[0140] Among them, y represents the true label of the validation set, represents the prediction result under the threshold τ, F1(·) represents F1-scoreF1(·) represents F1-score; F1-score is the existing technology;
[0141] Here we further propose an adaptive threshold mechanism (Adaptive Threshold Mechanism), which dynamically adjusts the threshold τ in a data-driven manner. adapt , to improve the generalization performance of the model across different projects; using the validation set of the training dataset, with the goal of maximizing the classifier's F1-score on the validation set, by enumerating different thresholds τ and evaluating their corresponding performance, the optimal threshold is ultimately selected as the classification judgment criterion. This adaptive threshold optimization method ensures that the model can automatically adjust the sensitivity and specificity of classification decisions based on the feature distribution differences of each project data, thereby effectively addressing the heterogeneity of data from different software projects;
[0142] S520: Use logistic regression classifier to classify f ij Perform classification prediction and combine τ adapt , and finally report the classification results of This can be determined by the following rules:
[0143]
[0144] The value range is [0,1]. Indicates reporting on (r i ,r j ), where 1 indicates a duplicate defect report and 0 indicates a non-duplicate report.
[0145] S600: Constructing loss function using contrastive learning Will After data conversion, it is used as data input. Optimize the SBERT model and update the SBERT model parameters by the gradient descent reverse update principle. When the training reaches the maximum value or When it does not change, stop training and get the trained SBERT, where The expression of the loss function is:
[0146]
[0147] where m = 0.2 is an interval parameter to ensure the difference between positive and negative samples; v a , v p , v n and v hn represent anchor sample sentence vector encoding, positive sample sentence vector encoding, negative sample sentence vector encoding, and difficult negative sample sentence vector encoding, respectively.
[0148] The binary cross-entropy method is used to construct the loss function The repeated report pair and the non-repeated report pair are input as data into the trained SBERT, and the The trained SBERT is subjected to parameter fine-tuning training, and the trained SBERT is subjected to model parameter fine-tuning optimization through the principle of gradient descent reverse update. When the training reaches a maximum value or does not change, the training is stopped, and the trained final SBERT model SBERT' is obtained, wherein The calculation expression of is as follows:
[0149]
[0150] where y ij represents the true label (1 for repeated and 0 for non-repeated) of the defect report pair (r i , r j ), s ij = cosine(v i , v j ) represents the semantic similarity of the defect report pair, and σ(·) is the Sigmoid function; through the fine-tuning step, the adaptability of the SBERT model to the specific defect report data set is further optimized.
[0151] The parameters of the SBERT model are optimized through back propagation to enhance the model's ability to distinguish between positive and negative samples. In addition, to further improve the model's ability to recognize subtle semantic differences, this study introduces difficult negative samples. By selecting reports with certain text similarity (sim Jaccard (x a , x n ) ∈ [0.4, 0.6]) but different semantics as difficult negative samples, the model's ability to distinguish between similar but different semantic texts is enhanced; the contrast loss function is the prior art;
[0152] In the S600, the The content after data conversion is as follows:
[0153] S610: randomly select one main report sample from anchor, randomly select one defect report as the positive sample corresponding to anchor in the same defect report group as anchor, select one defect report as the negative sample corresponding to anchor from other defect report groups, and the negative sample satisfies the condition sim(anchor, negative) <0.4, select one defect report belonging to the same topic cluster as anchor but not in the same defect report group as anchor as the hard negative sample corresponding to anchor, and the negative sample satisfies the condition sim(anchor, hardnegative) ∈ [0.4, 0.6]; difficult negative sampling strategy: after embedding representation of all reports using SBERT, topic clustering is performed by BERTopic to obtain several different clusters, and then non-repeated defect report pairs in the same topic cluster are selected as difficult negative sample pairs for fine-tuning training of the SBERT model; here, the difficult negative sampling strategy is introduced to improve the model's ability to recognize fine-grained semantic differences;
[0154] S620: form a quadruple sample set of the main report by anchor, positive, negative, and hardnegative;
[0155] traverse all main reports in repeat S610-S620 to obtain a quadruple sample set
[0156] S630: input repeat report pairs and non-repeated report pairs into the semantic similarity calculation module to calculate the semantic similarity between the anchor sample and the positive sample, the negative sample, and the difficult negative sample;
[0157] wherein, the expression of
[0158]
[0159] wherein, anchor (k) represents the kth anchor sample, positive (k) represents the kth positive sample, negative (k) represents the kth negative sample, hardnegative (k) represents the kth difficult negative sample, k represents the index number of the sample and k={1, 2, …, K}, K represents the total number of quadruple samples in D;
[0160] S640: Anchor (k) ,positive (k) ,negative (k) ,hardnegative (k) The corresponding sentence vector encoding is generated by SBERT, which is recorded as v a 、v p 、v n and v hn , now completed Data conversion operations;
[0161] S650: Calculate v separately a With v p 、v n 、v hn The semantic similarity between them is obtained a The calculation formula for the corresponding anchor semantic similarity value group is as follows:
[0162] s ap (v a ,v p )=cosine(v a ,v p )
[0163] s an (v a ,v n )=cosine(v a ,v n )
[0164] s ahn (v a ,v hn )=cosine(v a ,v hn )
[0165] Traversal All four-tuple samples in the dataset are used to obtain the anchor semantic similarity value groups corresponding to all anchor samples; all anchor semantic similarity value groups are used as data input for training the SBERT model. Two different types of negative sample pairs are obtained using two methods. Negative sample pairs can be generated from different defect report groups in order to improve the model's ability to distinguish different defects.
[0166] S700: Assign the model parameters of SBERT' to BS-DBRD to obtain the trained duplicate defect report detection model BS-DBRD';
[0167] S800: Select defect report data M to be predicted, input it into the BS-DBRD' model, and obtain the duplication judgment classification results of the defect reports in M.
[0168] Experiment content and results
[0169] Experimental setup
[0170] 1. Defect report dataset construction
[0171] (1) Defect report collection
[0172] Existing research on duplicate defect report detection mostly relies on classic datasets (such as the dataset constructed by Lazar et al.), however, the defect reports in these datasets are mainly concentrated before 2014, which is difficult to reflect the changes in software defect report features in recent years. Therefore, this study constructs a defect report dataset with a longer time span and wider coverage in order to more fully evaluate the generalization performance of the BS-DBRD model proposed in different time periods and different project data. Using the Bugzilla toolkit of Python, the defect report data of six typical large open source software projects from 2000 to 2022 is collected by calling the Bugzilla Webservice API, including Open Office, Eclipse, Firefox, Core, Thunderbird and Net Beans.
[0173] To ensure the quality and availability of the data, a series of data cleaning and preprocessing is performed on the initially collected defect report data. First, for each defect report, check if the bug_id and summary fields are empty. If either of the above fields is empty, delete this report to maintain the integrity of the data. In addition, according to the actual situation of the defect report life cycle, all reports in the "OPEN" state are removed, i.e. reports that have not been explicitly labeled as final state. This is because the "OPEN" state report has not been confirmed or processed, and lacks explicit duplication identification, which is not suitable for model training and evaluation data.
[0174] (2) Defect report pair generation
[0175] After completing the data collection, this method constructs a defect report pair set suitable for classification tasks based on the duplication relationship of the reports, including duplicate report pairs and non-duplicate report pairs.
[0176] Firstly, the identification of duplicate reports is processed. Generally, if a report is duplicate, its resolution field is marked as "DUPLICATE", and its dup_id field points to the bug_id of another report. However, there are two special cases in the actual data: one is that some reports marked as "DUPLICATE" have no reports pointed by their dup_id; the other is that the dup_id field is empty but the report is marked as "DUPLICATE". For these two cases, the resolution field of these reports is reset to "NONDUPLICATE" to avoid the interference of the wrong labeled reports on the training and evaluation of the model.
[0177] Next, the problem of duplicate loops is solved, that is, report A references report B as the main report, while report B also references report A as the main report. For this kind of circular reference, the following strategy is adopted for processing: sort all reports in the loop according to the submission time, and keep the earliest submitted report as the main report (i.e. set its dup_id as empty), and other reports uniformly reference this main report. This way ensures the clarity and consistency of the duplicate relationship in the data.
[0178] After that, the reports are organized into multiple report groups according to their duplicate relationship. Each report group represents the same software defect, and a main report is specified in each group, and other reports point to the main report. The selection of the main report is not strictly required to be the earliest submitted report, but the final confirmed report in the repair or processing process is selected as the main report. In this way, the normativity of the defect report group is guaranteed.
[0179] The final dataset constructed by this method not only includes all possible duplicate report pairs, but also includes sufficient non-duplicate report pairs, which provides a solid data foundation for the effective training and evaluation of the BS-DBRD model. The detailed information of the finally generated dataset is shown in Table 1.
[0180] Table 1 Details of the duplicate defect report detection dataset
[0181] Project Time Total number of reports Duplicate report pairs Non-duplicate report pairs Total number of report pairs Open Office 2000-2022 128,333 20,768 83,072 103,840 Eclipse 2010-2022 270,457 39,682 158,728 198,410 Firefox 2000-2022 186,689 24,199 96,796 120,995 Core 2010-2022 296,300 43,531 174,124 217,655 Thunderbird 2000-2022 54,893 11,835 47,340 59,175 Net Beans 2000-2022 253,428 35,056 140,224 175,280 Total 1,190,100 175,071 700,284 875,355
[0182] 2. Effectiveness of BS-DBRD model in duplicate defect report detection task
[0183] To verify the effectiveness of the BS-DBRD model in the task of duplicate defect report detection, the method is verified on the duplicate report detection dataset constructed by the method, including six projects of Open Office, Eclipse, Firefox, Core, Thunderbird and Net Beans. In the experiment, four representative classic models of DBR-CNN, DC-CNN, HINDBR and RTA are selected as the baseline. Accuracy, Precision, Recall and F1-score are used as performance evaluation indicators, and the experimental results are shown in Table 2.
[0184] The BS-DBRD model shows obvious and stable advantages in all datasets and all performance indicators. Specifically, in the Open Office dataset, the BS-DBRD model reaches 99.01%, 99.05%, 99.33% and 99.19% in Accuracy, Precision, Recall and F1-score indicators, respectively, which is significantly higher than the best performance of the RTA model in the baseline (Accuracy is 97.88%, F1-score is 98.54%). Similarly, in the Eclipse dataset, the F1-score of BS-DBRD reaches 99.23%, which is 1.41% higher than that of the RTA model (97.82%), which reflects the more accurate semantic discrimination ability of the method in judging duplicate defect reports.
[0185] Although the RTA model based on large-scale corpus pre-training strategy performs better, the BS-DBRD model still shows obvious performance improvement in each project dataset. The main reason is that BS-DBRD is specially designed for the data characteristics of the defect report field, which combines BERTopic topic semantic modeling, SBERT contrast learning optimization and adaptive threshold mechanism, so that it has stronger generalization performance and robustness when facing project differences.
[0186] Table 2 Performance comparison of BS-DBRD, DBR-CNN, DC-CNN, HINDBR and RTA in each project dataset
[0187]
[0188]
[0189] 3, Performance influence analysis of BERTopic topic modeling
[0190] To analyze the contribution of the BERTopic topic modeling module in the BS-DBRD model, the LDA topic model was used as a benchmark, and the BERTopic module in the BS-DBRD model was replaced by the traditional LDA. The other module structures and training processes were kept unchanged, and detailed comparative experiments were conducted on six project datasets.
[0191] As can be seen from the experimental results of each project in Table 3, the BS-DBRD (using the BERTopic topic model) performs significantly better than the LDA-topic model in all performance indicators. For example, in the Open Office dataset, the Accuracy and F1-score of the BS-DBRD model reached 99.01% and 99.19%, respectively, which were 0.96% and 0.46% higher than the 98.05% and 98.73% of the LDA-topic model. In the Eclipse dataset, the advantage of BERTopic was further expanded, with an increase of 1.83% in F1-score, and the Accuracy indicator increased from 98.23% of LDA-topic to 99.57%, demonstrating the powerful semantic capture ability of BERTopic.
[0192] Table 3 Comparison of BS-DBRD model and LDA-topic model in various performance indicators
[0193]
[0194]
[0195] The contrastive learning and fine-tuning strategies improve the semantic modeling effect from different dimensions, and their organic integration is the key to the excellent performance of the BS-DBRD model. Experiments fully verify that in the defect report task with complex semantics and domain-specific tasks, building a reasonable semantic modeling mechanism is crucial to improving the accuracy of duplicate report detection. BS-DBRD, as a complete framework integrating and optimizing the semantic modeling process, provides a solid foundation for further improving defect management automation.
[0196] Finally, it should be pointed out that the above examples are only used to illustrate the technical solutions of the present application and are not limiting. Although the present application has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present application can be modified or replaced by equivalents without departing from the spirit and scope of the present application, and they should be included in the scope of the claims of the present application.
Claims
1. A BERTopic-SBERT hybrid-driven duplicate defect report detection method, characterized by: The steps include: S100: Selecting publicly available original defect report data, labeling all the original defect report data to obtain true labels for the original defect report data; A duplicate defect report detection model, BS-DBRD, was constructed. BS-DBRD consists of a data preprocessing module, a similarity calculation module, and a defect report classification module. The similarity calculation module includes a topic similarity calculation module based on the BERTopic model and a semantic similarity calculation module based on the SBERT model. The defect report classification module is composed of an adaptive threshold mechanism. The data preprocessing module is used to extract data features and perform data preprocessing operations on defect report data; The similarity calculation module is used to calculate the topic similarity value and semantic similarity value between defect reports; The defect report classification module is used to output the classification results of duplicate defect reports; S200: Input the original defect report data set into the data preprocessing module to extract data features, and perform data preprocessing on all the extracted data features to obtain a training set D; Construct a defect report group in the training set D: randomly select several defect reports from D as the main report sample set from Choose any one of the master report samples Select from D All bug reports describing the same software defect that are Together they form a defect report group; similarly, the training set D is divided into several defect report groups; S300: Generate a positive sample pair set and a negative sample pair set using all defect report groups, where the positive sample pair set consists of multiple repeated report pairs, and the negative sample pair set consists of multiple non-repeated report pairs; wherein each positive sample pair or each negative sample pair represents a defect report pair; S400: Input all data features in D into the topic similarity calculation module to calculate the topic similarity of each defect report pair; Input all data features in D into the semantic similarity calculation module to calculate the semantic similarity of each defect report pair; S500: combining the topic similarity and semantic similarity of the defect report pair, and then inputting the combined result into the defect report classification module to obtain a duplicate report classification result; S600: Constructing loss function using contrastive learning Will After data conversion, it is used as data input. Optimize the SBERT model and update the SBERT model parameters by the gradient descent reverse update principle. When the training reaches the maximum value or When it does not change, stop training and get the trained SBERT, where The expression of the loss function is: Among them, m = 0.2 is the interval parameter to ensure the difference between positive and negative samples; v a 、v p 、v n and v hn They represent the anchor sample sentence vector encoding, positive sample sentence vector encoding, negative sample sentence vector encoding, and difficult negative sample sentence vector encoding respectively; The loss function is constructed using the binary cross entropy method. The repeated report pairs and the non-repeated report pairs are used as the data input of the trained SBERT. Fine-tune the parameters of the trained SBERT and optimize the model parameters of the trained SBERT through the gradient descent reverse update principle. When it does not change, stop training and get the trained final SBERT model SBERT', where The calculation expression is as follows: Among them, y ij Defect report pair (r i ,r j )’s true label (1 for duplicate, 0 for non-duplicate), s ij =cosine(v i ,v j ) represents the semantic similarity of the defect report pair, σ(·) is the Sigmoid function; S700: Assign the model parameters of SBERT' to BS-DBRD to obtain the trained duplicate defect report detection model BS-DBRD'; S800: Select defect report data M to be predicted, input it into the BS-DBRD' model, and obtain the duplication judgment and classification results of the defect reports in M.
2. The BERTopic-SBERT hybrid-driven duplicate defect report detection method according to claim 1, characterized in that: The steps of obtaining the training set D in S200 are as follows: Extract text descriptions with core fields from the original defect report data to form a core field text dataset. Then use regular expressions to remove noise data to obtain a denoised core field text dataset. Natural language processing tools are used to preprocess the denoised core field text dataset, and the preprocessed core field text dataset is used as the training set D.
3. The BERTopic-SBERT hybrid-driven duplicate defect report detection method according to claim 2, characterized in that: In S300, the contents of constructing the positive sample pair and the negative sample pair are as follows: Constructing positive sample pairs: Defect reports in the same defect report group are each other's positive samples. Any two reports belonging to the same defect report group constitute a positive sample pair. Construct negative sample pairs: Use the random negative sampling strategy to randomly select two defect reports from two different defect report groups to form a negative sample pair.
4. The BERTopic-SBERT hybrid-driven duplicate defect report detection method according to claim 3, characterized in that: The steps of calculating the topic similarity of each defect report pair in S400 are as follows: Use BERTopic for topic modeling: S410: Report the i-th defect with the core field in D to r i The text content is defined as Generate the embedding vector v of the i-th defect report text through the SBERT encoder in BERTopic i : Where i = 1, 2, ..., N, N represents the total number of defect reports in D; S411: Using UMAP algorithm to analyze v i Perform nonlinear dimensionality reduction to balance local structure and global distribution preservation; i The HDBSCAN density clustering algorithm is used to cluster the i-th defect report r i Automatic topic division; Traverse all defect reports in D and obtain the automatic topic classification results of all defect reports; S412: Statistically analyze the results of automatic topic division of all defect reports to obtain T topic clusters, and each defect report is classified into one of the T topics. S413: Calculate the weight w associated with each topic of the i-th defect report in D using the dynamic topic representation method based on c-TF-IDF i,j , the calculation expression is as follows: Among them, w i,j Defect report r i With the theme t j The strength of the correlation between i,j Defect report r i In the theme j The frequency in N represents the total number of all defect reports, N j represents the total number of reports in the jth topic; S414: Calculate r i The normalized weight vector Θ over all topics i , which is expressed as follows: Among them, Θ i Used to reflect the correlation strength between the defect report and each topic; Traverse all defect reports and obtain the normalized weight vectors of all defect reports; S415: Calculate the topic similarity sim between each pair of defect reports topic (·): sim topic (r i ,r j′ )=cosine(Θ i ,I j′ ) Among them, r j′ represents the j′th defect report, cosine(·) represents the cosine similarity function, Θ j′ represents the normalized weight vector corresponding to the j′th defect report.
5. The BERTopic-SBERT hybrid-driven duplicate defect report detection method according to claim 4, characterized in that: The content of calculating the semantic similarity of each defect report pair in S400 is as follows: Semantic similarity sim semantic The calculation formula of (·) is as follows: sim semantic (r i ,r j )=cosine(v i ,v j ) Among them, v j Denotes the j-th defect report r j The embedding vector of .
6. The BERTopic-SBERT hybrid-driven duplicate defect report detection method according to claim 5, characterized in that: The content of the duplicate report classification result obtained in S500 is as follows: S510: Given a pair of defect reports r i With r j , calculate the topic similarity sim topic (r i , r j ) and semantic similarity sim semantic (r i , r j ), then sim topic (r i , r j ) and sim semantic (r i , r j ) are concatenated to form a two-dimensional joint feature vector f ij , the calculation expression is as follows: f ij =[sim topic (r i ,r j ),sim semantic (r i ,r j )] Set the threshold value in the adaptive threshold mechanism to be τ adapt , the calculation expression is as follows: Among them, y represents the true label of the validation set, Represents the prediction result under the threshold τ, F1(·) represents F1-scoreF1(·) represents F1-score; S520: Use logistic regression classifier to classify f ij Perform classification prediction and combine τ adapt , and finally report the classification results of This can be determined by the following rules: The value range is [0, 1]. Indicates reporting on (r i , r j ), where 1 indicates a duplicate defect report and 0 indicates a non-duplicate report.
7. The BERTopic-SBERT hybrid-driven duplicate defect report detection method according to claim 6, characterized in that: In the above S600, The data converted is as follows: S610: From Randomly select a main report sample as the anchor sample anchor, randomly select a defect report in the same defect report group as the anchor as the positive sample positive, select a defect report from other defect report groups as the anchor corresponding negative sample negative, and the negative sample satisfies the condition sim(anchor, negative)<0.4, select a defect report that belongs to the same topic cluster as the anchor but not the same defect report group as the anchor as the hard negative sample hardnegative, and the negative sample satisfies the condition sim(anchor, hardnegative)∈[0.4,0.6]; S620: Anchor, positive, negative and hardnegative are combined into a four-tuple sample of the main report; Traverse all In the main report, repeat S610-S620 to obtain a set of four-tuple samples S630: The semantic similarity calculation module inputs duplicate report pairs and non-duplicate report pairs to calculate the semantic similarity between the anchor sample and the positive sample, negative sample, and difficult negative sample respectively; in, The expression is as follows: Among them, anchor (k) Represents the kth anchor point sample, positive (k) Represents the kth positive sample, negative (k) Represents the kth negative sample, hardnegative (k) represents the k-th difficult negative sample, k represents the index number of the sample and k={1, 2, ..., K), K represents the total number of four-tuple samples in D; S640: Anchor (k) , positive (k) , negative (k) , hardnegative (k) The corresponding sentence vector encoding is generated by SBERT, which is recorded as v a 、v p 、v n and v hn , now completed Data conversion operations; S650: Calculate v separately a With v p 、v n 、v hn The semantic similarity between them is obtained a The calculation formula for the corresponding anchor semantic similarity value group is as follows: with ap (in a ,in p )=cosine(in a ,in p ) with an (in a ,in n )=cosine(in a ,in n ) with ahn (in a ,in hn )=cosine(in a ,in hn ) Traversal All the four-tuple samples in are used to obtain the anchor semantic similarity value groups corresponding to all anchor samples; all the anchor semantic similarity value groups are used as data input for training the SBERT model.