AST Vectorization via Statement Trees and Bidirectional RNN
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing methods for program comprehension, such as tree-structured neural networks, face challenges like large AST scale causing gradient vanishing, loss of long-distance dependence information, and destruction of structural information when converting code to binary trees, limiting their effectiveness in capturing semantic information.
Innovation Solution
A vectorized representation method that divides the AST into statement trees, uses a recursive neural network for encoding, and a dynamic batch calculation algorithm to maintain original structure, followed by a bidirectional RNN to capture context dependencies and a pooling layer for final vector representation.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Measurement precision
If tree-structured neural network is used to encode entire AST, then semantic information can be captured, but gradient vanishing problem occurs due to large AST scale
Solution Approach 1:
The patent divides the AST into multiple basic block trees, each representing a basic block in the control flow graph. This segmentation reduces the size of individual trees to be encoded, preventing gradient vanishing while preserving semantic information through the sequential processing of multiple smaller units.
Solution Approach 2:
The patent introduces a control flow graph dimension to organize basic blocks sequentially. By transforming the hierarchical AST structure into a sequence of basic block trees ordered by control flow, the model can process information in manageable chunks while maintaining contextual relationships through the control flow sequence.
2Productivity
If bottom-up recursive encoding or sliding window is used, then encoding can be performed, but long-distance dependence information is lost
Solution Approach 1:
The patent performs control flow analysis and basic block extraction before encoding. By pre-organizing the AST into a control flow graph and identifying basic blocks in advance, the model preserves long-distance dependencies through the control flow structure while enabling efficient sequential encoding of basic blocks.
3Device complexity
If AST is converted to binary tree form, then tree structure can be simplified, but original structural information and semantic information are destroyed
Solution Approach 1:
The patent applies different processing strategies to different parts of the program structure. Basic blocks with simple sequential statements are encoded directly, while blocks containing control flow constructs (loops, conditionals) are processed with special attention to preserve their structural characteristics. This localized approach maintains structural information where needed while simplifying processing where appropriate.
Data Source
AI summary
The invention provides a vectorized representation method of a software source code. The vectorized representation method is an AST-based neural network which is a hierarchical vector representation method comprising the following implementation steps: step 1-1, converting an original software source code into an AST at the lowest layer, and then further dividing the AST according to source code statements to acquire a smaller statement tree sequence, wherein statement trees in the statement tree sequence are different in sequence, and the statement tree sequence is consistent with an original statement sequence; step 1-2, encoding the statement trees into statement vectors e1, e2, . . . , et by a recursive neural encoder; step 1-3, enabling an acquired statement vector sequence to pass through a bidirectional recurrent neural network layer to extract dependency features between statements; and step 1-4, sampling multi-dimensional features of all time steps of the bidirectional recurrent neural network layer through a pooling layer to acquire a final vector representation.

