Software defect prediction method based on code multi-layer heterogeneous association features

By constructing a multi-layered heterogeneous association graph of the code and combining it with an attention network, the problem of insufficient feature extraction in the existing technology is solved, and the accurate location and efficient review of row-level defect prediction are achieved, meeting the needs of industrial software quality assurance.

CN122286559APending Publication Date: 2026-06-26SOUTH CHINA UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SOUTH CHINA UNIV OF TECH
Filing Date
2026-03-19
Publication Date
2026-06-26

AI Technical Summary

Technical Problem

Existing line-level defect prediction methods fail to effectively characterize the multi-layered heterogeneous relationships in code, resulting in insufficient feature extraction, making it difficult to achieve accurate defect localization and failing to meet actual industrial needs.

Method used

A multi-layer heterogeneous association graph of code is constructed. By combining horizontal and vertical attention networks, multi-layer heterogeneous association features of code are extracted. Row-level defect prediction is performed through a hierarchical graph neural network, and a defect prediction report is generated.

Benefits of technology

It achieves a complete expression of complex heterogeneous topological relationships between lines of code, improves the accuracy of defect prediction and engineering practicality, reduces the workload of code reviewers, and improves review efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122286559A_ABST
    Figure CN122286559A_ABST
Patent Text Reader

Abstract

This invention discloses a software defect prediction method based on multi-layer heterogeneous association features of code, belonging to the field of software engineering technology. The method first preprocesses the software code, parsing it into an abstract syntax tree, program dependency graph, and control flow graph. Using the program dependency graph as the core, it constructs inter-layer heterogeneous association edges, forming a multi-layer heterogeneous association graph of code. Then, through a hierarchical heterogeneous association graph neural network containing horizontal and vertical attention networks, it completes node embedding initialization, intra-layer feature refinement, inter-layer feature fusion, and global feature aggregation to extract multi-layer heterogeneous association features and node attention scores. Finally, a classifier performs overall defect judgment on the code segment, calculating the association degree between code lines and defects based on attention scores, generating a line-level defect prediction report to locate suspicious lines. This invention fully expresses the heterogeneous topological relationship of code, accurately extracts multi-layer heterogeneous association features, and integrates defect judgment and location. It has strong versatility, significantly improves code review efficiency, and adapts to the actual review needs of industry.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the technical field of software engineering, specifically relating to a software defect prediction method based on multi-layer heterogeneous correlation features of code. Background Technology

[0002] With the rapid iteration of emerging technologies such as artificial intelligence, the Internet of Things, and blockchain, software systems are accelerating their penetration into various industries, deeply integrating into all aspects of social production and life, and becoming a core engine driving high-quality economic development. At the same time, the continuous expansion of software scale and increasing complexity have brought more severe challenges to R&D process optimization and quality control. Deeply integrating artificial intelligence technology with software quality assurance, through intelligent analysis, retrieval, and matching of code and related data, can effectively improve the efficiency and accuracy of code review, promote the transformation of traditional software quality assurance models towards intelligentization, and build solid technical support for the high-quality development of the software industry.

[0003] In the entire software lifecycle management process, quality assurance technology plays an indispensable and crucial role. Various defects hidden in the code not only directly affect the operational stability of the software system, but in severe cases, they may also lead to security vulnerabilities, business interruptions, and incalculable losses. Early detection and remediation of these defects during the software development and testing phases can significantly improve software product quality while substantially reducing the cost of later maintenance. In-depth research on software defect prediction technology helps to accurately grasp the distribution patterns of defects, assists R&D teams in assessing software quality levels, rationally allocates testing resources, and provides a reliable technical basis for the successful delivery of software products. In recent years, software defect prediction has become a research hotspot in the field of intelligent software engineering, gaining widespread attention not only in high-level academic conferences and core journals both domestically and internationally, but also being continuously applied in industrial-grade platforms such as Copilot and SonarQube, fully demonstrating its important academic value and broad industrial application prospects.

[0004] Current software defect prediction has developed into a multi-granularity research system, covering different dimensions such as package level, component level, file level, and method level. Existing research has confirmed that fine-grained defect prediction is more advantageous in optimizing test resources, with file-level prediction outperforming package-level, and method-level prediction being more cost-effective than file-level. However, these methods still have significant limitations in actual code review; most can only locate defective files or methods, requiring developers to check line by line to find the specific defect location, which is insufficient to meet the efficiency requirements of large-scale software development. Therefore, line-level defect prediction has gradually become a research focus. Many scholars have proposed models such as DeepLineDP and LineDef based on techniques such as recurrent neural networks, graph convolutional networks, and attention mechanisms, attempting to achieve more refined defect localization.

[0005] While progress has been made in line-level defect prediction, existing methods still have significant shortcomings. Most studies focus only on isomorphic relationships between code elements, neglecting diverse heterogeneous relationships such as semantics, dependencies, and data flow. Some studies attempt to simply merge multiple relationships into a single graph structure, but this often loses the inherent characteristics of each type of relationship, making it difficult for the model to identify defects caused by complex relationships. In reality, software defects often arise from the combined effects of multiple relationships, including structural dependencies, data dependencies, control dependencies, and semantic logic. Therefore, accurately mining heterogeneous relationships between code elements is crucial to improving the accuracy of line-level defect prediction. Although scholars both domestically and internationally have explored methods such as abstract syntax trees, data flow graphs, code attribute graphs, and heterogeneous graphs, problems remain, including incomplete representation of relationship information and mutual interference between multiple relationship features.

[0006] In summary, existing line-level defect prediction methods have not yet developed a mature mechanism for mining heterogeneous code relationships, making it difficult to fully extract complex topological and semantic information between code segments. Consequently, the accuracy and practicality of these models fall short of actual industrial needs. Therefore, there is an urgent need to construct a line-level defect prediction method that can effectively characterize multi-layered heterogeneous code relationships and accurately extract topological features. This would improve the accuracy of defect localization and its engineering feasibility, further refine the intelligent software quality assurance technology system, and provide stronger support for high-quality software development. Summary of the Invention

[0007] The main objective of this invention is to overcome the shortcomings and deficiencies of existing technologies and provide a software defect prediction method based on multi-layer heterogeneous association features of code. Addressing the core problems of insufficient heterogeneous association representation and inadequate feature extraction in existing line-level defect prediction methods, this invention starts from three core technical points: multi-layer heterogeneous association graph construction, hierarchical heterogeneous association graph neural network feature extraction, and line-level defect prediction and report generation. It constructs a line-level defect prediction method oriented towards mining multi-layer heterogeneous association features of code, enhancing the completeness of data representation in the software line-level defect prediction model, improving the accuracy and engineering practicality of line-level defect prediction, and meeting the actual needs of software code review and quality assurance in the industry.

[0008] To achieve the above objectives, the present invention adopts the following technical solution:

[0009] In a first aspect, the present invention provides a software defect prediction method based on multi-layer heterogeneous correlation features of code, comprising the following steps:

[0010] S1. Constructing a multi-layered heterogeneous relational graph of code: Given the code file of a software project, use code parsing tools to parse the code file into multiple heterogeneous relational graph representations, and combine the semantic features of line-level text to construct and obtain a dataset of heterogeneous relational graph representations of code;

[0011] S2. Extracting multi-layer heterogeneous association features of code: Construct a hierarchical heterogeneous association graph neural network feature extraction module containing horizontal attention network and vertical attention network. Use this module to perform node embedding and feature extraction on the multi-layer heterogeneous association graph of code to obtain the feature representation of multi-layer heterogeneous association of code and the attention score of each node.

[0012] S3. Implement line-level defect prediction and suspicious line location: Utilize the multi-layer heterogeneous association feature representation of code to construct a line-level defect prediction model, and combine it with node attention scores to generate a line-level defect prediction report, thereby completing the accurate prediction of line-level defects and the location of suspicious lines of code in the software code.

[0013] As a preferred technical solution, step S1 specifically includes:

[0014] Given a software project as a code file, read the text content of the code file and perform preprocessing.

[0015] The preprocessed code text is converted into three types of relational graph representations using code parsing tools: Abstract Syntax Tree. Program dependency graph and control flow graph ;in, and express The set of nodes and the set of edges; and express The set of nodes and the set of edges; and express The set of nodes and the set of edges;

[0016] Using the program dependency graph as the core, and employing a line-level alignment strategy, heterogeneous association edges are constructed between nodes in three types of association graphs: First, the program dependency graph nodes are aligned with nodes in the abstract syntax tree. Code lines of code to construct heterogeneous related edges from the root node of the subtree Secondly, the program dependency graph nodes are connected to the control flow graph except for the program entry node. Program exit node External code line nodes construct heterogeneous related edges ;

[0017] Integrating the three types of heterogeneous association graphs and the aforementioned inter-layer heterogeneous association edges, a multi-layer heterogeneous association graph of code is obtained. ,in , , These correspond to the abstract syntax tree, program dependency graph, and control flow graph, respectively. Given a set of heterogeneous association edges between three types of graphs, complete the construction of a multi-layered heterogeneous association graph in the code.

[0018] As a preferred technical solution, the preprocessing includes cleaning up spaces and comments, and standardizing variable names and method names to ensure the standardization of the code text.

[0019] As a preferred technical solution, step S2 specifically includes:

[0020] Node embedding initialization: Initial embedding of nodes in each layer of the heterogeneous multi-layer graph, including the abstract syntax tree. Each node label is embedded using the Word2Vec model; program dependency graph and control flow graph For row-level nodes, row-level text-semantic structure features are used as embedding vectors; control flow graph The program entry node and program exit node The Word2Vec model is used for embedding, and the initial embedding vectors of each node are obtained. ;

[0021] Intra-layer feature refinement: Using a horizontal network based on an attention mechanism, nodes in each layer of the graph are embedded twice. By calculating and normalizing the attention scores between nodes in the layer, the node's own information and the information of its neighboring nodes are fused to obtain the intra-layer refined embedding vector of each layer of the graph.

[0022] Inter-layer feature fusion: Constructing a vertical network based on an attention mechanism, using a program dependency graph. As the core, it calculates its relationship with the abstract syntax tree. Control Flow Graph The inter-layer attention scores of nodes are used to fuse heterogeneous association information from multiple graphs to obtain the inter-layer fusion embedding vector of program-dependent graph nodes.

[0023] Global feature aggregation: program dependency graph By employing an attention-based graph neural network, the inter-layer fused embedding vectors of all nodes are aggregated to obtain a multi-layer heterogeneous relational feature representation of the code. Attention scores for each node are generated simultaneously. This completes the feature extraction process.

[0024] As a preferred technical solution, the specific calculation formula for the intra-layer refined embedding vector in the intra-layer feature refinement is as follows:

[0025]

[0026]

[0027]

[0028] in, Indicates the first Layer diagram, and ; Indicates in Middle node and nodes Attention scores between, and ; This indicates that attention calculation is used to represent the graph. A matrix for horizontal transformation of the embedding vectors of the middle nodes; Representation diagram Attention weight vector of the middle node; Indicates to Attention weights obtained after normalization; Represents the natural exponential function; Representation diagram Middle node The neighboring nodes; Representation diagram The vector obtained after the middle node is embedded twice; express function; Indicates in Middle node The embedding vector obtained after the initial embedding.

[0029] As a preferred technical solution, the specific calculation formula for the inter-layer fusion embedding vector in inter-layer feature fusion is as follows:

[0030]

[0031]

[0032]

[0033] in, Indicates the floor number and ; and They represent from and Nodes; Represents a node With nodes Attention score between; This represents a matrix that performs a horizontal transformation on the node embedding vectors of the two graphs; Representation diagram and Attention weight vector of a node; Indicates to Attention weights obtained after normalization; In the diagram In the middle, node The neighbor vectors; This represents a linear transformation function that converts two vectors into vectors of the same dimension. Indicates will A function that aggregates the results; Representation diagram The embedded vector obtained after multi-layer graph heterogeneous association extraction; In the diagram In and nodes Connected neighboring nodes.

[0034] As a preferred technical solution, step S3 specifically includes:

[0035] The obtained multi-layer heterogeneous association features of the code are represented The code snippet is input into a classifier, which outputs the overall defect prediction result, which is divided into two categories: "defective" and "no defect".

[0036] When the defect prediction result is "defective", the node attention score is used as the basis for the prediction. It calculates the correlation between each line of code node and the defect, and then generates a line-level defect prediction report to accurately locate lines with suspected defects.

[0037] As a preferred technical solution, the specific formula for calculating the correlation between each line of code and the defect is as follows:

[0038]

[0039]

[0040] in, For line of code nodes The degree of correlation with sample defects, its value range is The higher the value, the stronger the defect relevance of the corresponding line of code.

[0041] Secondly, the present invention provides a software defect prediction system based on multi-layer heterogeneous association features of code, which is applied to the software defect prediction method based on multi-layer heterogeneous association features of code, including a data processing module, a feature extraction module and a defect prediction module.

[0042] The data processing module is used to parse the code file of a given software project into multiple heterogeneous association graph representations using a code parsing tool, and to construct and obtain a data set of heterogeneous association multi-layer graph representations of the code by combining line-level text semantic features.

[0043] The feature extraction module is used to construct a hierarchical heterogeneous association graph neural network feature extraction module that includes a horizontal attention network and a vertical attention network. This module is used to perform node embedding and feature extraction on the heterogeneous association multi-layer graph of the code to obtain the feature representation of the heterogeneous association of the code and the attention score of each node.

[0044] The defect prediction module is used to achieve line-level defect prediction and suspicious line location: it constructs a line-level defect prediction model using the multi-layer heterogeneous association feature representation of code, and generates a line-level defect prediction report by combining node attention scores, thereby completing the accurate prediction of line-level defects and the location of suspicious lines of code in the software code.

[0045] Thirdly, the present invention provides an electronic device, the electronic device comprising:

[0046] At least one processor; and,

[0047] A memory communicatively connected to the at least one processor; wherein,

[0048] The memory stores computer program instructions that can be executed by the at least one processor, which enables the at least one processor to execute the software defect prediction method based on multi-layer heterogeneous correlation features of code.

[0049] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0050] This invention breaks through the limitations of traditional single graph structure modeling. It uses program dependency graph as the core and combines abstract syntax tree and control flow graph to construct a multi-layer graph of heterogeneous code association. It not only preserves the original structural information in various association graphs, but also effectively mines the complex heterogeneous association relationships between multiple types of association graphs through row-level aligned heterogeneous association edges. It solves the technical problems that single graph structures easily mask the heterogeneous association characteristics of code and have high information noise, and realizes the complete expression of complex heterogeneous topological relationships between lines of code.

[0051] This invention designs a hierarchical heterogeneous association graph neural network feature extraction architecture. It completes intra-layer node attention aggregation through a horizontal network and integrates information of neighboring nodes within the layer to improve the feature expression capability of a single-class association graph. It completes inter-layer node attention aggregation through a vertical network to accurately capture heterogeneous association features between multiple layers of graphs. This completely solves the problem that existing methods can only extract homogeneous association features and do not fully mine heterogeneous associations, and realizes comprehensive and accurate extraction of multi-layer heterogeneous association features in code.

[0052] This invention achieves an integrated system of "overall defect judgment of code segments - precise location of suspected defect lines". It calculates the correlation between each line of code and the defect based on node attention scores, generates a priority defect prediction report, significantly reduces the workload of code reviewers, improves review efficiency, enhances the engineering practicality of the method, and can be directly adapted to the actual code review needs of the industry.

[0053] The method of this invention is highly versatile and does not require customized modifications for specific programming languages. It can be adapted to line-level defect prediction tasks in a variety of mainstream programming languages. Its heterogeneous correlation modeling and feature extraction approach can also provide new technical references for related fields such as software vulnerability detection and code quality assessment, enriching the intelligent software quality assurance technology system. Attached Figure Description

[0054] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0055] Figure 1 This is a flowchart of a software defect prediction method based on multi-layer heterogeneous association features of code, according to an embodiment of the present invention.

[0056] Figure 2 This is a schematic diagram of the structure of a software defect prediction system based on multi-layer heterogeneous association features of code, according to an embodiment of the present invention.

[0057] Figure 3 This is a structural diagram of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0058] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of the present application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative effort are within the scope of protection of the present application.

[0059] Please see Figure 1 This embodiment provides a software defect prediction method based on multi-layered heterogeneous code correlation features. In practical applications, this method can be deployed in the backend of an enterprise-level code review server or integrated development environment (IDE). The entire method process specifically includes the following steps:

[0060] S1. Construct a multi-layer graph of heterogeneous code relationships.

[0061] In order to fully capture the complex logic inside the code, this embodiment first performs standardization processing and multi-dimensional analysis on the acquired software code.

[0062] First, given a software project as the code file to be tested, the code text is read using a pre-written preprocessing script. The preprocessing stage focuses on removing redundant spaces, meaningless consecutive comments, and other distractors that have no substantial impact on semantics. User-defined variable names and method names are standardized / pseudo-coded to ensure the standardization of the input code text and reduce the risk of out-of-vocabulary words during subsequent feature extraction by the model.

[0063] Subsequently, the preprocessed code snippet was parsed into three isomorphic relational graph representations from different perspectives using the static code parsing tool Joern: Abstract Syntax Tree Program dependency graph and control flow graph .

[0064] After extracting the three types of isolated relationship graphs, traditional code analysis often processes them separately. To achieve multi-layered graph linkage, this embodiment uses the program dependency graph as the core hub and employs a "line-level alignment strategy" to forcibly construct heterogeneous relationship edges between graphs. Specifically:

[0065] Alignment: Traversing each node in the program dependency graph In the abstract syntax tree, find the root node of the statement subtree to which the corresponding line of code belongs. And construct directed heterogeneous association edges. ;

[0066] Alignment: Locate the row-level mapping between nodes in the program dependency graph and nodes in the control flow graph, excluding virtual nodes (entry points) that only represent the start and end of logic. and exports Connect the remaining control flow graph nodes with actual lines of code to the PDG node.

[0067] Through the row-level alignment operation described above, three isolated planar graphs are stitched together into a three-dimensional, multi-layered graph of heterogeneous code relationships containing multiple types of information. .

[0068] S2. Extract multi-layer heterogeneous association features from the code.

[0069] After obtaining the multi-layer graph structure, this embodiment designs a bidirectional hierarchical graph attention network with "horizontal-vertical" characteristics to fully exploit the features in the multi-layer graph.

[0070] Phase 1: Node Embedding Initialization. Before feeding the code text into the neural network, it needs to be converted into vectors. For The type label nodes in the code directly use pre-trained... The model is mapped to word vectors; for and Since line-level nodes in the code contain specific code statements, their line-level text semantic and structural features are extracted using a text analysis model as initial embedding vectors; thus, a unified-dimensional initial embedding vector is obtained. .

[0071] The second stage: Intra-layer feature refinement. Using a horizontal network based on an attention mechanism, nodes within each layer of the graph are re-embedded. By calculating and normalizing the attention scores between nodes within the layer, and fusing the node's own information with neighboring node information, the refined intra-layer embedding vectors of each graph node are obtained, as shown in the following equation:

[0072]

[0073]

[0074]

[0075] in, Indicates the first Layer diagram, and ; Indicates in Middle node and nodes Attention scores between, and ; This indicates that attention calculation is used to represent the graph. A matrix for horizontal transformation of the embedding vectors of the middle nodes; Representation diagram Attention weight vector of the middle node; Indicates to Attention weights obtained after normalization; Represents the natural exponential function; Representation diagram Middle node The neighboring nodes; Representation diagram The vector obtained after the middle node is embedded twice; express function; Indicates in Middle node The embedding vector obtained after the initial embedding.

[0076] The third stage: inter-layer feature fusion. Figure 1 In the network structure shown, the program dependency graph contains the richest logical dependencies. The main branch forms the backbone, extending upwards and downwards to the abstract syntax tree. and control flow graph Collect cross-layer interaction information. This is achieved through a cross-layer vertical attention matrix. ,calculate Nodes in Rather than , There are nodes with heterogeneous edge connections. Interlayer attention scores After normalization, the feature aggregation function is used. and feature alignment function Incorporating cross-layer features Within the nodes, a fused vector containing multi-dimensional information is obtained. .

[0077] The specific calculation formula for the inter-layer fusion embedding vector is as follows:

[0078]

[0079]

[0080]

[0081] in, Indicates the floor number and ; and They represent from and Nodes; Represents a node With nodes Attention score between; This represents a matrix that performs a horizontal transformation on the node embedding vectors of the two graphs; Representation diagram and Attention weight vector of a node; Indicates to Attention weights obtained after normalization; In the diagram In the middle, node The neighbor vectors; This represents a linear transformation function that converts two vectors into vectors of the same dimension. Indicates will A function that aggregates the results; Representation diagram The embedded vector obtained after multi-layer graph heterogeneous association extraction; In the diagram In and nodes Connected neighboring nodes.

[0082] Finally, global pooling or readout operations are used to aggregate the features of all nodes in the updated multi-layer graph into a fixed-dimensional graph-level global representation vector. Meanwhile, the model retains the final attention score of each node during the calculation process. This is used for subsequent explanation and positioning.

[0083] S3. Implement row-level defect prediction and suspicious row location.

[0084] This step transforms complex deep learning features into review suggestions that developers can read directly.

[0085] Phase 1: Overall Prediction. This involves representing the acquired multi-layered heterogeneous correlation features of the code. The input is fed into a pre-trained multilayer perceptron or classifier, which then utilizes the data. The function outputs the probability that the code snippet as a whole is defective. If the probability exceeds a set threshold, the result is "defective".

[0086] Phase Two: Precise Location and Report Generation. When the system issues a "defective" warning, to avoid the difficulty of developers checking line by line, the system will backtrack to the node attention scores generated in step S2. In graph neural networks, nodes with higher attention scores contribute more to the model's assessment of a node as "defective".

[0087] Therefore, extraction The set consists of the attention scores of all lines of code nodes. Using the minimax normalization method, the attention score is mapped to... Indicators of correlation between intervals:

[0088]

[0089] Based on calculations The system sorts lines of code in descending order by value, and automatically generates a visual "Line-Level Defect Prediction Report." Different colors are used to highlight code in the report; values ​​closer to 1 indicate a very high probability of a hidden defect, while lower values ​​indicate lower risk. Developers can use this information to prioritize reviewing high-risk lines of code, significantly improving code review efficiency and defect fixing speed.

[0090] In executing this embodiment, an empirical research approach will be adopted. Software code instances will be input into a hierarchical heterogeneous relational graph neural network model to obtain code representations, and baseline comparisons will be performed in a defect prediction task to verify the effectiveness of the proposed method. It should be noted that, for the foregoing method embodiments, for the sake of simplicity, they are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously.

[0091] It should be noted that, for the sake of simplicity, the aforementioned method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously.

[0092] Based on the same idea as the software defect prediction method based on multi-layer heterogeneous code correlation features in the above embodiments, the present invention also provides a software defect prediction system based on multi-layer heterogeneous code correlation features. This system can be used to execute the above-described software defect prediction method based on multi-layer heterogeneous code correlation features. For ease of explanation, the structural diagram of the embodiment of the software defect prediction system based on multi-layer heterogeneous code correlation features only shows the parts related to the embodiments of the present invention. Those skilled in the art will understand that the illustrated structure does not constitute a limitation on the device, and may include more or fewer components than illustrated, or combine certain components, or have different component arrangements.

[0093] Please see Figure 2 In another embodiment of this application, a software defect prediction system 100 based on multi-layer heterogeneous association features of code is provided. The system includes a data processing module 101, a feature extraction module 102, and a defect prediction module 103.

[0094] The data processing module 101 is used to parse the code file of a given software project into multiple heterogeneous association graph representations using a code parsing tool, and to construct and obtain a data set of heterogeneous association multi-layer graph representations of code by combining line-level text semantic features.

[0095] The feature extraction module 102 is used to construct a hierarchical heterogeneous association graph neural network feature extraction module that includes a horizontal attention network and a vertical attention network. This module is used to perform node embedding and feature extraction on the heterogeneous association multi-layer graph of the code to obtain the feature representation of the heterogeneous association of the code and the attention score of each node.

[0096] The defect prediction module 103 is used to realize line-level defect prediction and suspicious line location: it constructs a line-level defect prediction model by using the multi-layer heterogeneous association feature representation of code, and generates a line-level defect prediction report by combining node attention scores, thereby completing the accurate prediction of line-level defects and the location of suspicious code lines in the software code.

[0097] It should be noted that the software defect prediction system based on multi-layer heterogeneous association features of the present invention corresponds one-to-one with the software defect prediction method based on multi-layer heterogeneous association features of the present invention. The technical features and beneficial effects described in the embodiments of the software defect prediction method based on multi-layer heterogeneous association features of the above invention are applicable to the embodiments of software defect prediction based on multi-layer heterogeneous association features of the above invention. For details, please refer to the description in the embodiments of the method of the present invention. It will not be repeated here.

[0098] Furthermore, in the above embodiments of the software defect prediction system based on multi-layer heterogeneous code correlation features, the logical division of each program module is only an example. In actual applications, the above functions can be assigned to different program modules as needed, for example, for the configuration requirements of the corresponding hardware or for the convenience of software implementation. That is, the internal structure of the software defect prediction system based on multi-layer heterogeneous code correlation features is divided into different program modules to complete all or part of the functions described above.

[0099] Please see Figure 3 In one embodiment, an electronic device is provided for implementing a software defect prediction method based on multi-layer heterogeneous association features of code. The electronic device 200 may include a first processor 201, a first memory 202 and a bus, and may also include a computer program stored in the first memory 202 and executable on the first processor 201, such as a software defect prediction program 203 based on multi-layer heterogeneous association features of code.

[0100] The first memory 202 includes at least one type of readable storage medium, including flash memory, portable hard drive, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the first memory 202 can be an internal storage unit of the electronic device 200, such as the portable hard drive of the electronic device 200. In other embodiments, the first memory 202 can also be an external storage device of the electronic device 200, such as a plug-in portable hard drive, smart media card (SMC), secure digital card (SD), flash card, etc., equipped on the electronic device 200. Furthermore, the first memory 202 can include both internal storage units and external storage devices of the electronic device 200. The first memory 202 can be used not only to store application software and various types of data installed on the electronic device 200, such as the code of the software defect prediction program 203 based on multi-layer heterogeneous correlation characteristics of code, but also to temporarily store data that has been output or will be output.

[0101] In some embodiments, the first processor 201 may be composed of integrated circuits, such as a single packaged integrated circuit or multiple integrated circuits with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips. The first processor 201 is the control unit of the electronic device, connecting various components of the entire electronic device through various interfaces and lines. It executes programs or modules stored in the first memory 202 and calls data stored in the first memory 202 to perform various functions of the electronic device 200 and process data.

[0102] Figure 3 Only electronic devices with components are shown; it will be understood by those skilled in the art that... Figure 3 The structure shown does not constitute a limitation on the electronic device 200, and may include fewer or more components than shown, or combine certain components, or have different component arrangements.

[0103] The software defect prediction program 203 based on multi-layer heterogeneous code correlation features stored in the first memory 202 of the electronic device 200 is a combination of multiple instructions. When run in the first processor 201, it can achieve the following:

[0104] Constructing a multi-layered heterogeneous relational graph of code: Given the code file of a software project, use code parsing tools to parse the code file into multiple heterogeneous relational graph representations, and combine the semantic features of line-level text to construct and obtain a dataset of multi-layered heterogeneous relational graph representations of code;

[0105] Extracting multi-layer heterogeneous association features of code: Construct a hierarchical heterogeneous association graph neural network feature extraction module containing horizontal attention network and vertical attention network. Use this module to perform node embedding and feature extraction on the multi-layer heterogeneous association graph of code to obtain the feature representation of multi-layer heterogeneous association of code and the attention score of each node;

[0106] Achieve line-level defect prediction and suspicious line location: Utilize multi-layer heterogeneous association feature representation of code to construct a line-level defect prediction model, and combine node attention scores to generate a line-level defect prediction report, thereby completing accurate prediction of line-level defects and location of suspicious lines of code in the software code.

[0107] Furthermore, if the modules / units integrated in the electronic device 200 are implemented as software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium. The computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, or a read-only memory (ROM).

[0108] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.

[0109] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0110] The above embodiments are preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above embodiments. Any changes, modifications, substitutions, combinations, or simplifications made without departing from the spirit and principle of the present invention shall be considered equivalent substitutions and shall be included within the protection scope of the present invention.

Claims

1. A software defect prediction method based on multi-layer heterogeneous association features of code, characterized in that, Includes the following steps: S1. Constructing a multi-layered heterogeneous relational graph of code: Given the code file of a software project, use code parsing tools to parse the code file into multiple heterogeneous relational graph representations, and combine the semantic features of line-level text to construct and obtain a dataset of heterogeneous relational graph representations of code; S2. Extracting multi-layer heterogeneous association features of code: Construct a hierarchical heterogeneous association graph neural network feature extraction module containing horizontal attention network and vertical attention network. Use this module to perform node embedding and feature extraction on the multi-layer heterogeneous association graph of code to obtain the feature representation of multi-layer heterogeneous association of code and the attention score of each node. S3. Implement line-level defect prediction and suspicious line location: Utilize the multi-layer heterogeneous association feature representation of code to construct a line-level defect prediction model, and combine it with node attention scores to generate a line-level defect prediction report, thereby completing the accurate prediction of line-level defects and the location of suspicious lines of code in the software code.

2. The software defect prediction method based on multi-layer heterogeneous code correlation features according to claim 1, characterized in that, Step S1 specifically involves: Given a software project as a code file, read the text content of the code file and perform preprocessing. The preprocessed code text is converted into three types of relational graph representations using code parsing tools: Abstract Syntax Tree. Program dependency graph and control flow graph ;in, and express The set of nodes and the set of edges; and express The set of nodes and the set of edges; and express The set of nodes and the set of edges; Using the program dependency graph as the core, and employing a line-level alignment strategy, heterogeneous association edges are constructed between nodes in three types of association graphs: First, the program dependency graph nodes are aligned with nodes in the abstract syntax tree. Code lines of code to construct heterogeneous related edges from the root node of the subtree Secondly, the program dependency graph nodes are connected to the control flow graph except for the program entry node. Program exit node External code line nodes construct heterogeneous related edges ; Integrating the three types of heterogeneous association graphs and the aforementioned inter-layer heterogeneous association edges, a multi-layer heterogeneous association graph of code is obtained. ,in , , These correspond to the abstract syntax tree, program dependency graph, and control flow graph, respectively. Given a set of heterogeneous association edges between three types of graphs, complete the construction of a multi-layered heterogeneous association graph in the code.

3. The software defect prediction method based on multi-layer heterogeneous code correlation features according to claim 2, characterized in that, The preprocessing includes cleaning up spaces and comments, and standardizing variable names and method names to ensure the standardization of the code text.

4. The software defect prediction method based on multi-layer heterogeneous code correlation features according to claim 1, characterized in that, Step S2 is as follows: Node embedding initialization: Initial embedding of nodes in each layer of the heterogeneous multi-layer graph, including the abstract syntax tree. Each node label is embedded using the Word2Vec model; program dependency graph and control flow graph For row-level nodes, row-level text-semantic structure features are used as embedding vectors; control flow graph The program entry node and program exit node The Word2Vec model is used for embedding, and the initial embedding vectors of each node are obtained. ; Intra-layer feature refinement: Using a horizontal network based on an attention mechanism, nodes in each layer of the graph are embedded twice. By calculating and normalizing the attention scores between nodes in the layer, the node's own information and the information of its neighboring nodes are fused to obtain the intra-layer refined embedding vector of each layer of the graph. Inter-layer feature fusion: Constructing a vertical network based on an attention mechanism, using a program dependency graph. As the core, it calculates its relationship with the abstract syntax tree. Control Flow Graph The inter-layer attention scores of nodes are used to fuse heterogeneous association information from multiple graphs to obtain the inter-layer fusion embedding vector of program-dependent graph nodes. Global feature aggregation: program dependency graph By employing an attention-based graph neural network, the inter-layer fused embedding vectors of all nodes are aggregated to obtain a multi-layer heterogeneous relational feature representation of the code. Attention scores for each node are generated simultaneously. This completes the feature extraction process.

5. The software defect prediction method based on multi-layer heterogeneous code correlation features according to claim 4, characterized in that, In the intra-layer feature refinement, the specific calculation formula for the intra-layer refined embedding vector is as follows: in, Indicates the first Layer diagram, and ; Indicates in Middle node and nodes Attention scores between, and ; This indicates that attention calculation is used to represent the graph. A matrix for horizontal transformation of the embedding vectors of the middle nodes; Representation diagram Attention weight vector of the middle node; Indicates to Attention weights obtained after normalization; Represents the natural exponential function; Representation diagram Middle node The neighboring nodes; Representation diagram The vector obtained after the middle node is embedded twice; express function; Indicates in Middle node The embedding vector obtained after the initial embedding.

6. The software defect prediction method based on multi-layer heterogeneous code association features according to claim 4, characterized in that, In inter-layer feature fusion, the specific calculation formula for the inter-layer fusion embedding vector is as follows: in, Indicates the floor number and ; and They represent from and Nodes; Represents a node With nodes Attention score between; This represents a matrix that performs a horizontal transformation on the node embedding vectors of the two graphs; Representation diagram and Attention weight vector of a node; Indicates to Attention weights obtained after normalization; In the diagram In the middle, node The neighbor vectors; This represents a linear transformation function that converts two vectors into vectors of the same dimension. Indicates will A function that aggregates the results; Representation diagram The embedded vector obtained after multi-layer graph heterogeneous association extraction; In the diagram In and nodes Connected neighboring nodes.

7. The software defect prediction method based on multi-layer heterogeneous code correlation features according to claim 1, characterized in that, Step S3 is as follows: The obtained multi-layer heterogeneous association features of the code are represented The code snippet is input into a classifier, which outputs the overall defect prediction result, which is divided into two categories: "defective" and "no defect". When the defect prediction result is "defective", the node attention score is used as the basis for the prediction. It calculates the correlation between each line of code node and the defect, and then generates a line-level defect prediction report to accurately locate lines with suspected defects.

8. The software defect prediction method based on multi-layer heterogeneous association features of code according to claim 7, characterized in that, The specific formula for calculating the correlation between each line of code and the defect is as follows: in, For line of code nodes The degree of correlation with sample defects, its value range is The higher the value, the stronger the defect relevance of the corresponding line of code.

9. A software defect prediction system based on multi-layer heterogeneous association features of code, characterized in that, The software defect prediction method based on multi-layer heterogeneous code association features, applied to any one of claims 1-8, includes a data processing module, a feature extraction module, and a defect prediction module; The data processing module is used to parse the code file of a given software project into multiple heterogeneous association graph representations using a code parsing tool, and to construct and obtain a data set of heterogeneous association multi-layer graph representations of the code by combining line-level text semantic features. The feature extraction module is used to construct a hierarchical heterogeneous association graph neural network feature extraction module that includes a horizontal attention network and a vertical attention network. This module is used to perform node embedding and feature extraction on the heterogeneous association multi-layer graph of the code to obtain the feature representation of the heterogeneous association of the code and the attention score of each node. The defect prediction module is used to achieve line-level defect prediction and suspicious line location: it constructs a line-level defect prediction model using the multi-layer heterogeneous association feature representation of code, and generates a line-level defect prediction report by combining node attention scores, thereby completing the accurate prediction of line-level defects and the location of suspicious lines of code in the software code.

10. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores computer program instructions that can be executed by the at least one processor, which enables the at least one processor to perform the software defect prediction method based on multi-layer heterogeneous code correlation features as described in any one of claims 1-8.