DYNAMIC SOURCE CODE ANALYSIS AND NATURAL LANGUAGE ANNOTATION

Each of a plurality of portions of a source code base of an application is classified into an algorithm type in a predefined set of algorithm types. A code base model of the source code base is constructed, the code base model comprising a plurality of nodes connected by edges, a node in the plurality of nodes representing a classified portion in the plurality of portions. In response to a natural language query about the source code base, a natural language explanation of the classified portion is generated.

BACKGROUND

The present invention relates generally to a method, system, and computer program product for source code analysis. More particularly, the present invention relates to a method, system, and computer program product for dynamic source code analysis and natural language annotation.

The source code base of an application includes one or more modules implementing portions of the application's functions. Source code within the source code base is written in a programming language (e.g., C++ or Python). A compiler or interpreter converts the source code into executable code for execution on a system including a processor and memory. (Python is a registered trademark of the Python Software Foundation in the United States and other countries.) Source code typically includes comments, which are words or phrases intended to comment on or otherwise explain accompanying source code. Comments are not converted into executable code.

A natural language is a human language, such as English or French.

SUMMARY

The illustrative embodiments provide a method, system, and computer program product. An embodiment includes a method that classifies, into an algorithm type in a predefined set of algorithm types, each of a plurality of portions of a source code base of an application. An embodiment constructs a code base model of the source code base, the code base model comprising a plurality of nodes connected by edges, a node in the plurality of nodes representing a classified portion in the plurality of portions. An embodiment generates, in response to a natural language query about the source code base, a natural language explanation of the classified portion.

DETAILED DESCRIPTION

The illustrative embodiments recognize that, when developing applications, particularly those involving machine learning and the manipulation of large amounts of data, developers and data scientists often use different methodologies. Data scientists typically develop standardized versions of algorithms in isolated test environments, while developers focus on writing scalable and production ready code. Integrating the two groups' code often results in an application that is difficult to understand, particularly when new developers or data scientists join a project. For example, it might be difficult for a developer new to a code base of an application to understand which algorithm (of those known to data scientists) is being used in an application (e.g., to implement a machine learning module within an application), which code implements which portion of an algorithm, how data is manipulated within portions of the application, where to begin debugging a reported problem with an application, and the like. Because comments intended to explain portions of the application are typically written by developers of the code, the comments are often incomplete, difficult to understand, and written in inconsistent styles by different developers. Source code documentation, a document explaining the functions of an application or an application's components, is typically maintained separately from the source code itself and is not typically maintained as source code is changed over time. Thus, comments and other documentation, while helpful, are insufficient to help a developer understand a source code base.

The illustrative embodiments also recognize that understandability, transparency. and accuracy of an application are important parts of generating trust in a machine learning application's output. Understandability, or explainability, focuses on explaining how a model reached a particular conclusion. Transparency focuses on describing a model, including elements such as the type of model used, how the model was trained, the type of training data that was used on the model, and how the model was tested. Accuracy is a metric for evaluating models, and refers to the fraction of model outputs that are considered sufficiently correct. However, it can be difficult, particularly for a developer new to a project, to understand which portions of source code contribute, and how the portions contribute, to understandability, transparency, and accuracy of an application.

Thus, the illustrative embodiments recognize that there is a need to dynamically, as a source code base changes over time, provide analysis of the source code, in natural language and a consistent comment style, as well as respond to natural language queries regarding the source code.

The illustrative embodiments recognize that the presently available tools or solutions do not address these needs or provide adequate solutions for these needs. The illustrative embodiments used to describe the invention generally address and solve the above-described problems and other problems related to dynamic source code analysis and natural language annotation.

An embodiment can be implemented as a software application. The application implementing an embodiment can be configured as a modification of an existing source code management system, as a separate application that operates in conjunction with an existing source code management system, a standalone application, or some combination thereof.

Particularly, some illustrative embodiments provide a method that classifies, into an algorithm type in a predefined set of algorithm types, each of a plurality of portions of a source code base of an application, constructs a code base model of the source code base, and generates, in response to a natural language query about the source code base, a natural language explanation of a classified portion in the plurality of portions.

An embodiment receives a source code base of an application, divides a module or file of the source code base into a plurality of portions, and identifies an author of a portion in the plurality of portions. To begin the partitioning, an embodiment selects an initial portion of a source code file. The initial portion has a size equal to the initial portion size. One embodiment sets an initial portion size, in lines of code, by multiplying an initial portion size percentage by the number of lines of code in a particular source code file. The initial portion size percentage is based on how much code generally holds an algorithm definition, as established by using multiple regression model on historical training data such as total lines of code, number of classes, number of individual files, number of packages, number of algorithms, number of models, average lines of code per file, and the like. Another embodiment sets an initial portion size to one line of code. Other initial portion sizes are also possible and contemplated within the scope of the illustrative embodiments. One embodiment selects an initial portion of a source code file from a midpoint of a source code file. Other embodiments select an initial portion of a source code file from the beginning, end, or another location in a source code file.

An embodiment applies source code within the initial portion to two parallel processing pipelines. In one pipeline, an embodiment uses a trained code embedding model to convert a portion of source code to a corresponding code embedding. A code embedding is a multidimensional numerical representation of a portion of source code. Code embeddings represent source code syntax. A trained code embedding model is trained using other source code syntax. Code embeddings can represent any length of code. In the second pipeline, an embodiment uses a sequence-to-sequence model to convert the same input portion of source code into natural language text describing the input line of source code, and uses a trained language embedding model to convert the natural language text into a language embedding. A language embedding is a multidimensional numerical representation of a line of source code description text. A sequence-to-sequence model is a presently available technique that transforms a first sequence into a second sequence, typically using a recurrent neural network such as a long short-term memory (LSTM) or using gated recurrent units (GRUs). A sequence-to-sequence model includes an encoder network that converts each portion of an input (here, a token, word, or other portion of a line of source code) item into a corresponding numerical representation of the item and its context, followed by a decoder network that turns the numerical representation into an output item (here, a word or other portion of source code description text), using the previous output as an input context into a set of tokens. A trained language embedding model is a presently available technique that converts a sentence or other sequence of natural language words to a multidimensional numerical representation of the sentence.

An embodiment uses a trained classifier model operating on code and language embeddings representing a portion of input source code to classify the portion into one of a predefined set of code authors. The classifier model has been trained, using a presently available technique, to associate a particular combination of code and language embeddings with a particular code author. Thus, an embodiment makes a preliminary determination that, for example, Developer 1 wrote one portion of input source code, while Developer 2 wrote another portion of input source code. An embodiment forms a time sequence of code authorship determinations based on different snapshots of the input source code base. Thus, an embodiment determines that, for example, after Developer 1 wrote one portion of input source code and Developer 2 wrote another portion of input source code, Developer 3 made changes to both portions, and Developer 4 made additional changes after Developer 3.

An embodiment expands the initial portion size, reselects a portion of a source code file using the expanded portion size, and repeats the code embedding, language embedding, and authorship classification for the expanded portion of source code until reaching a completion criterion. One embodiment uses the same starting point each time. expanding the portion in both directions (i.e., earlier and later in the source code file) until the portion includes the entire source code file. Another embodiment selects different starting points, creating and processing overlapping portions of the source code file. As the portion size is expanded, an embodiment's authorship classification might change because different portions of source code might have been written by different developers. In particular, each portion, or window, of code has a code embedding and an authorship classification. Since code windows can overlap, any vote that intersects a window is included in a vote on authorship of a particular window. The author with the most votes within a singular window wins. If there is a tie, multiple authors are noted as candidates. Thus, an embodiment forms a primary sequence of code portions, along with a code portion's code and language embeddings and authorship classifications or rankings.

An embodiment re-partitions the primary sequence of code portions into a secondary partitioning of the same source code file. In particular, the primary portion, or window, is the original window while the secondary portion grows to include more context. As a result, while the primary window is the target of the partitioning, the secondary portion provides context and clues about the primary portion. In one embodiment, the secondary portioning includes overlapping portions. An embodiment forms a time sequence of secondary partitions based on different snapshots of the input source code base.

An embodiment uses a portion classification model to classify a code portion, in the primary and secondary sequences of code portions, into one of a predetermined set of algorithm types the code portion implements. Some non-limiting examples of algorithm types are predictive modeling, prescriptive optimization, descriptive statistics, and a head recursion algorithm. The portion classification model is trained before use, on labelled source code that represents specific algorithm types.

An embodiment uses the classified code portions to construct a code base model comprising nodes and edges connecting nodes. A node in the code base model represents a code portion classified into a particular algorithm type. An edge in the code base model represents a relationship between nodes representing classified code portions.

An embodiment analyzes inputs and outputs of code portions represented by nodes in the code base model to determine if an edge should connect two nodes in the model. Pieces of the nodes are linked together based on adjacencies to each other in the code or relationships of code statements. An embodiment uses a network flow optimization to determine how best to link nodes together by maximizing the flow of data between nodes. In the network flow optimization, the further nodes are from each other in terms of algorithm and vicinity, the more costly it is to put nodes together with an edge. For example, if one code portion produces an output that is consumed by a second code portion, nodes representing the two code portions might be connected by an edge. One embodiment uses trust classifiers to generate comments explaining a code portion represented by a node.

An embodiment repeats the code portioning and algorithm type classification on different snapshots in time of the input source code base, and forms or updates nodes and edges in the code base model as appropriate. Thus, the code base model stores data of the current code base, as well as how the code base has changed over time.

An embodiment uses a presently available technique, such as an LSTM-based authorship classifier model to refine or adjust a previous classification of a code portion, in the primary and secondary sequences of code portions, into one of a predefined set of code authors. In particular, the LSTM-based authorship classifier model helps to further refine who wrote what portion of the code by identifying styles and algorithmic preferences that are associated with a particular author. The authorship classification is denoted by an authorship embedding, a multidimensional numerical representation of the authorship classification. The LSTM-based authorship classifier model has been trained, using a presently available technique, to associate a particular combination of code and language embeddings with a particular code author.

An embodiment correlates a code portion classified into an algorithm type with an authorship classification of the same code portion. One embodiment adds the authorship embedding to data of the corresponding node of the code base model. Another embodiment uses a presently available natural language text generation technique, such as a feedforward neural network (FNN), to generate natural language comments indicating the authorship classification of the portion, and adds the generated comments to the portion of source code. For example, an embodiment might have determined that code portion 1 implements a classifier algorithm, and code portion 1 was written by developer 1. Thus, one embodiment might add an authorship embedding denoting “developer 1” tag to data of the code base model node representing code portion 1, while another embodiment might generate the comment “//this section written by developer 1” and add the generated comments to code portion 1 in the application source code base being analyzed.

An embodiment annotates a source code portion for one or more of transparency, accuracy, and explainability. In particular, an embodiment selects a node in the code base model and extracts, from the source code base, the source code portion or window corresponding to the selected node. An embodiment uses a trained transparency model to generate a transparency embedding representing the source code portion. A transparency embedding is a multidimensional numerical representation of a degree to which this code portion contributes to transparency in outputs of the application source code base being analyzed. An embodiment uses a trained accuracy model to generate an accuracy embedding representing the source code portion. An accuracy embedding is a multidimensional numerical representation of a degree to which this code portion contributes to accuracy in outputs of the application source code base being analyzed. An embodiment uses a trained explainability model to generate an explainability embedding representing the source code portion. An explainability embedding is a multidimensional numerical representation of a degree to which this code portion contributes to explainability in outputs of the application source code base being analyzed. The trained transparency, accuracy, and explainability models are each trained before use using labelled source code implementing transparency, accuracy, and explainability functionality respectively. An embodiment repeats the transparency, accuracy, and explainability embedding generation at different times, and the resulting data denotes how the portion's contribution to transparency, accuracy, and explainability has changed historically. An embodiment uses the historical change data and a presently available time series forecasting technique to forecast how the portion's contribution to transparency, accuracy, and explainability will change in the future. One embodiment adds generated transparency, accuracy, and explainability embeddings, and differential embeddings, to data of the node in the code base model. Another embodiment uses a presently available natural language text generation technique, such as a feedforward neural network (FNN), to generate comments indicating the portion's contribution to one or more of transparency, accuracy, and explainability, and adds the generated comments to the portion of source code.

An embodiment receives a natural language query about the source code base. An embodiment uses a presently available technique, such as an encoder/decoder model, to generate an encoded version of the query. An embodiment uses a transformer model, which transforms a structured version of a query into a graph query, to select one or more nodes and edges in the code base model that are responsive to the query. The transformer model is trained on labeled data with a question as the input and the query as the label. An embodiment uses a presently available technique such as a feature extractor to generate a structured representation of data responsive to the query. An embodiment uses a presently available technique to generate, from the structured representation, a natural language explanation of a code portion corresponding to a selected node. For example, a user might ask for code implementing a head recursion algorithm in the source code, and in response an embodiment might select a node in the code base model classified as implementing a head recursion algorithm, generate a structured representation of data of the node (e.g., where the source code portion represented by the node is located in the source code, an author of the source code portion, when the source code portion was last changed, and the like), and generate a natural language explanation: here is an example of code implementing a head recursion algorithm, the code was written by Developer 1, and last changed yesterday.

The manner of dynamic source code analysis and natural language annotation described herein is unavailable in the presently available methods in the technological field of endeavor pertaining to source code analysis and management. A method of an embodiment described herein, when implemented to execute on a device or data processing system, comprises substantial advancement of the functionality of that device or data processing system in classifying, into an algorithm type in a predefined set of algorithm types, each of a plurality of portions of a source code base of an application, constructing a code base model of the source code base, and generating, in response to a natural language query about the source code base, a natural language explanation of a classified portion in the plurality of portions.

The illustrative embodiments are described with respect to certain types of source code portions, apportionings, classifications, embeddings, models, structured representations, queries, responses, rankings, adjustments, sensors, measurements, devices, data processing systems, environments, components, and applications only as examples. Any specific manifestations of these and other similar artifacts are not intended to be limiting to the invention. Any suitable manifestation of these and other similar artifacts can be selected within the scope of the illustrative embodiments.

Characteristics are as follows:

Measured service: cloud systems automatically control and optimize resource use by leveraging a metering capability at some level of abstraction appropriate to the type of service (e.g., storage, processing, bandwidth, and active user accounts). Resource usage can be monitored, controlled, reported, and invoiced, providing transparency for both the provider and consumer of the utilized service.

Service Models are as follows:

Deployment Models are as follows:

With reference to the figures and in particular with reference toFIG.1, this figure is an example diagram of a data processing environments in which illustrative embodiments may be implemented.FIG.1is only an example and are not intended to assert or imply any limitation with regard to the environments in which different embodiments may be implemented. A particular implementation may make many modifications to the depicted environments based on the following description.FIG.1depicts a block diagram of a network of data processing systems in which illustrative embodiments may be implemented. Computing environment100contains an example of an environment for the execution of at least some of the computer code involved in performing the inventive methods, such as application200. Application200implements a dynamic source code analysis and natural language annotation embodiment described herein. In addition to block200, computing environment100includes, for example, computer101, wide area network (WAN)102, end user device (EUD)103, remote server104, public cloud105, and private cloud106. In this embodiment, computer101includes processor set110(including processing circuitry120and cache121), communication fabric111, volatile memory112, persistent storage113(including operating system122and block200, as identified above), peripheral device set114(including user interface (UI), device set123, storage124, and Internet of Things (IoT) sensor set125), and network module115. Remote server104includes remote database130. Public cloud105includes gateway140, cloud orchestration module141, host physical machine set142, virtual machine set143, and container set144. Application200executes in any of computer101, end user device103, remote server104, or a computer in public cloud105or private cloud106unless expressly disambiguated.

Processor set110includes one, or more, computer processors of any type now known or to be developed in the future. Processor set110may contain one or more processors and may be implemented using one or more heterogeneous processor systems. A processor in processor set110may be a single-or multi-core processor or a graphics processor. Processing circuitry120may be distributed over multiple packages, for example, multiple, coordinated integrated circuit chips. Processing circuitry120may implement multiple processor threads and/or multiple processor cores. Cache121is memory that is located in the processor chip package(s) and is typically used for data or code that should be available for rapid access by the threads or cores running on processor set110. Cache memories are typically organized into multiple levels depending upon relative proximity to the processing circuitry. Alternatively, some, or all, of the cache for the processor set may be located “off chip.” In some computing environments, processor set110may be designed for working with qubits and performing quantum computing.

Operating system122runs on computer101. Operating system122coordinates and provides control of various components within computer101. Instructions for operating system122are located on storage devices, such as persistent storage113, and may be loaded into at least one of one or more memories, such as volatile memory112, for execution by processor set110.

Computer readable program instructions are typically loaded onto computer101to cause a series of operational steps to be performed by processor set110of computer101and thereby effect a computer-implemented method, such that the instructions thus executed will instantiate the methods specified in flowcharts and/or narrative descriptions of computer-implemented methods included in this document (collectively referred to as “the inventive methods”). These computer readable program instructions are stored in various types of computer readable storage media, such as cache121and the other storage media discussed below. The program instructions, and associated data, are accessed by processor set110to control and direct performance of the inventive methods. In computing environment100, at least some of the instructions for performing the inventive methods of application200may be stored in persistent storage113and may be loaded into at least one of one or more memories, such as volatile memory112, for execution by processor set110. The processes of the illustrative embodiments may be performed by processor set110using computer implemented instructions, which may be located in a memory, such as, for example, volatile memory112, persistent storage113, or in one or more peripheral devices in peripheral device set114. Furthermore, in one case, application200may be downloaded over WAN102from remote server104, where similar code is stored on a storage device. In another case, application200may be downloaded over WAN102to remote server104, where downloaded code is stored on a storage device.

With reference toFIG.2, this figure depicts a block diagram of an example configuration for dynamic source code analysis and natural language annotation in accordance with an illustrative embodiment. Application200is the same as application200inFIG.1.

Primary partitioning module210receives a source code base of an application, divides a module or file of the source code base into a plurality of portions, and identifies an author of a portion in the plurality of portions. To begin the partitioning, module210selects an initial portion of a source code file. The initial portion has a size equal to the initial portion size. One implementation of module210sets an initial portion size, in lines of code, by multiplying an initial portion size percentage by the number of lines of code in a particular source code file. The initial portion size percentage is based on how much code generally holds an algorithm definition, as established by using multiple regression model on historical training data such as total lines of code, number of classes, number of individual files, number of packages, number of algorithms, number of models, average lines of code per file, and the like. Another implementation of module210sets an initial portion size to one line of code. Other initial portion sizes are also possible. One implementation of module210selects an initial portion of a source code file from a midpoint of a source code file. Other implementations of module210select an initial portion of a source code file from the beginning, end, or another location in a source code file.

Module210applies source code within the initial portion to two parallel processing pipelines. In one pipeline, module210uses a trained code embedding model to convert a portion of source code to a corresponding code embedding. A code embedding is a multidimensional numerical representation of a portion of source code. Code embeddings represent source code syntax. A trained code embedding model is trained using other source code syntax. Code embeddings can represent any length of code. In the second pipeline, module210uses a sequence-to-sequence model to convert the same input portion of source code into natural language text describing the input line of source code, and uses a trained language embedding model to convert the natural language text into a language embedding (a multidimensional numerical representation of a line of source code description text).

Module210uses a trained classifier model operating on code and language embeddings representing a portion of input source code to classify the portion into one of a predefined set of code authors. The classifier model has been trained, using a presently available technique, to associate a particular combination of code and language embeddings with a particular code author. Thus, module210makes a preliminary determination that, for example, Developer 1 wrote one portion of input source code, while Developer 2 wrote another portion of input source code. Module210forms a time sequence of code authorship determinations based on different snapshots of the input source code base. Thus, module210determines that, for example, after Developer 1 wrote one portion of input source code and Developer 2 wrote another portion of input source code, Developer 3 made changes to both portions, and Developer 4 made additional changes after Developer 3.

Module210expands the initial portion size, reselects a portion of a source code file using the expanded portion size, and repeats the code embedding, language embedding, and authorship classification for the expanded portion of source code until reaching a completion criterion. One implementation of module210uses the same starting point each time, expanding the portion in both directions (i.e., earlier and later in the source code file) until the portion includes the entire source code file. Another implementation of module210selects different starting points, creating and processing overlapping portions of the source code file. As the portion size is expanded, module210's authorship classification might change because different portions of source code might have been written by different developers. In particular, each portion, or window, of code has a code embedding and an authorship classification. Since code windows can overlap, any vote that intersects a window is included in a vote on authorship of a particular window. The author with the most votes within a singular window wins. If there is a tie, multiple authors are noted as candidates. Thus, module210forms a primary sequence of code portions, along with a code portion's code and language embeddings and authorship classifications or rankings.

Secondary portioning module220re-partitions the primary sequence of code portions into a secondary partitioning of the same source code file. In particular, the primary portion, or window, is the original window while the secondary portion grows to include more context. As a result, while the primary window is the target of the partitioning, the secondary portion provides context and clues about the primary portion. In one implementation of module220, the secondary portioning includes overlapping portions. Module220forms a time sequence of secondary partitions based on different snapshots of the input source code base.

Portion classifier module230uses a portion classification model to classify a code portion, in the primary and secondary sequences of code portions, into one of a predetermined set of algorithm types the code portion implements. Some non-limiting examples of algorithm types are predictive modeling, prescriptive optimization, descriptive statistics, and a head recursion algorithm. The portion classification model is trained before use, on labelled source code that represents specific algorithm types.

Model construction module250uses the classified code portions to construct a code base model comprising nodes and edges connecting nodes. A node in the code base model represents a code portion classified into a particular algorithm type. An edge in the code base model represents a relationship between nodes representing classified code portions.

Portion relationship module240analyzes inputs and outputs of code portions represented by nodes in the code base model to determine if an edge should connect two nodes in the model. Pieces of the nodes are linked together based on adjacencies to each other in the code or relationships of code statements. Module240uses a network flow optimization to determine how best to link nodes together by maximizing the flow of data between nodes. In the network flow optimization, the further nodes are from each other in terms of algorithm and vicinity, the more costly it is to put nodes together with an edge. For example, if one code portion produces an output that is consumed by a second code portion, nodes representing the two code portions might be connected by an edge. One implementation of module240uses trust classifiers to generate comments explaining a code portion represented by a node.

Modules230,240, and250repeat the code portioning and algorithm type classification on different snapshots in time of the input source code base, and form or update nodes and edges in the code base model as appropriate. Thus, the code base model stores data of the current code base, as well as how the code base has changed over time.

Authorship module260uses a presently available technique, such as an LSTM-based authorship classifier model to refine or adjust a previous classification of a code portion, in the primary and secondary sequences of code portions, into one of a predefined set of code authors. In particular, the LSTM-based authorship classifier model helps to further refine who wrote what portion of the code by identifying styles and algorithmic preferences that are associated with a particular author. The authorship classification is denoted by an authorship embedding, a multidimensional numerical representation of the authorship classification. The LSTM-based authorship classifier model has been trained, using a presently available technique, to associate a particular combination of code and language embeddings with a particular code author.

Module260correlates a code portion classified into an algorithm type with an authorship classification of the same code portion. One implementation of module260adds the authorship embedding to data of the corresponding node of the code base model. Another implementation of module260uses a presently available natural language text generation technique, such as a feedforward neural network (FNN), to generate comments indicating the authorship classification of the portion, and adds the generated comments to the portion of source code. For example, module260might have determined that code portion 1 implements a classifier algorithm, and code portion 1 was written by developer 1. Thus, one implementation of module260might add an authorship embedding denoting “developer 1” tag to data of the code base model node representing code portion 1, while another implementation of module260might generate the comment “//this section written by developer 1” and add the generated comments to code portion 1 in the application source code base being analyzed.

Annotation module270annotates a source code portion for one or more of transparency, accuracy, and explainability. In particular, module270selects a node in the code base model and extracts, from the source code base, the source code portion or window corresponding to the selected node. Module270uses a trained transparency model to generate a transparency embedding representing the source code portion. A transparency embedding is a multidimensional numerical representation of a degree to which this code portion contributes to transparency in outputs of the application source code base being analyzed. Module270uses a trained accuracy model to generate an accuracy embedding representing the source code portion. An accuracy embedding is a multidimensional numerical representation of a degree to which this code portion contributes to accuracy in outputs of the application source code base being analyzed. Module270uses a trained explainability model to generate an explainability embedding representing the source code portion. An explainability embedding is a multidimensional numerical representation of a degree to which this code portion contributes to explainability in outputs of the application source code base being analyzed. The trained transparency, accuracy, and explainability models are each trained before use using labelled source code implementing transparency, accuracy, and explainability functionality respectively. Module270repeats the transparency, accuracy, and explainability embedding generation at different times, and the resulting data denotes how the portion's contribution to transparency, accuracy, and explainability has changed historically. Module270uses the historical change data and a presently available time series forecasting technique to forecast how the portion's contribution to transparency, accuracy, and explainability will change in the future. One implementation of module270adds generated transparency, accuracy, and explainability embeddings, and differential embeddings, to data of the node in the code base model. Another implementation of module270uses a presently available natural language text generation technique, such as a feedforward neural network (FNN), to generate comments indicating the portion's contribution to one or more of transparency, accuracy, and explainability, and adds the generated comments to the portion of source code.

Query processing module280receives a natural language query about the source code base. Module280uses a presently available technique, such as an encoder/decoder model, to generate an encoded version of the query. Module280uses a transformer model, which transforms a structured version of a query into a graph query, to select one or more nodes and edges in the code base model that are responsive to the query. The transformer model is trained on labeled data with a question as the input and the query as the label. Module280uses a presently available technique such as a feature extractor to generate a structured representation of data responsive to the query. Module280uses a presently available technique to generate, from the structured representation, a natural language explanation of a code portion corresponding to a selected node. For example, a user might ask for code implementing a head recursion algorithm in the source code, and in response module280might select a node in the code base model classified as implementing a head recursion algorithm, generate a structured representation of data of the node (e.g., where the source code portion represented by the node is located in the source code, an author of the source code portion, when the source code portion was last changed, and the like), and generate a natural language explanation: here is an example of code implementing a head recursion algorithm, the code was written by Developer 1, and last changed yesterday.

With reference toFIG.3, this figure depicts a flow diagram of an example configuration for dynamic source code analysis and natural language annotation in accordance with an illustrative embodiment. The flow diagram can be executed using application200inFIG.2. Primary partitioning module210is the same as primary partitioning module210inFIG.2.

Primary partitioning module210receives application source code base300. Windowing310selects an initial portion of a source code file: window315. Window315is applied to two parallel processing pipelines. In one pipeline, code embedding model330converts a line of source code to corresponding code embedding335, a multidimensional numerical representation of a line of source code. In the second pipeline, sequence-to-sequence model320converts an input line of source code into text description325, natural language text describing the input line of source code. Language embedding model340converts text description325into language embedding345(a multidimensional numerical representation of a line of source code description text).

Authorship classifier350operates on one or more of code embedding335and language embedding345to classify code window315into one of a predefined set of code authors. Once additional portions of source code base300have been processed, the result is set of tagged code windows355.

Window expansion360expands the initial portion size into new window size365, windowing310reselects a portion of a source code file using new window size365, and the code embedding, language embedding, and authorship classification for the expanded portion of source code are repeated until a completion criterion is reached.

With reference toFIG.4, this figure depicts a continued flow diagram of an example configuration for dynamic source code analysis and natural language annotation in accordance with an illustrative embodiment. Secondary partitioning module220is the same as secondary partitioning module220inFIG.2. Application source code base300and set of tagged code windows355are the same as application source code base300and set of tagged code windows355inFIG.3.

Secondary windowing410re-partitions application source code base300and set of tagged code windows355into a secondary partitioning of the same source code file: overlapping code windows415. Time sequencing420forms time sequenced overlapping code windows425based on different snapshots of source code base300.

With reference toFIG.5, this figure depicts a continued flow diagram of an example configuration for dynamic source code analysis and natural language annotation in accordance with an illustrative embodiment. Portion classifier module230, portion relationship module240, model construction module250, and authorship module260are the same as portion classifier module230, portion relationship module240, model construction module250, and authorship module260inFIG.2. Application source code base300and set of tagged code windows355are the same as application source code base300and set of tagged code windows355inFIG.3. Time sequenced overlapping code windows425is the same as time sequenced overlapping code windows425inFIG.4.

Portion classifier module230uses a portion classification model to classify a code portion, in sets355or425into one of a predetermined set of algorithm types the code portion implements. The result is algorithm classification510. Portion relationship module240analyzes inputs and outputs of code portions in sets355or425and represented by nodes in the code base model to determine portion relationship520, denoting whether an edge should connect two nodes in the model. Model construction module250uses algorithm classification510and portion relationship520to construct code base model530comprising nodes and edges connecting nodes.

Authorship module260uses LSTM540to refine or adjust a previous classification of a code portion in sets355and425into one of a predefined set of code authors. The authorship classification is denoted by authorship embedding545, a multidimensional numerical representation of the authorship classification. Correlation550correlates a code portion classified into an algorithm type (in code base model530) with authorship embedding545of the same code portion, generating algorithm data555(data of the correlated code portion). Authorship comment generation560generates authorship comment565, comments indicating the authorship classification of the portion, and adds comment565the portion of source code in code base300.

With reference toFIG.6, this figure depicts a continued flow diagram of an example configuration for dynamic source code analysis and natural language annotation in accordance with an illustrative embodiment. Annotation module270is the same as annotation module270inFIG.2. Application source code base300is the same as application source code base300inFIG.3. Code base model530is the same as Code base model530inFIG.5.

Code lookup610selects a node in code base model530and extracts, from source code base300, code window615: the source code portion or window corresponding to the selected node. Transparency processing620generate transparency embedding625representing code window615. Accuracy processing640generate accuracy embedding645representing code window615. Explainability processing660generate explainability embedding665representing code window615. Transparency annotation generation630generates transparency annotation635: comments indicating code window615′s contribution to transparency. Similarly, accuracy annotation generation650generates accuracy annotation655and explainability annotation generation670generates explainability annotation675. Annotations635,655, and675are added to application source code base300.

With reference toFIG.7, this figure depicts a continued flow diagram of an example configuration for dynamic source code analysis and natural language annotation in accordance with an illustrative embodiment. Query processing module280is the same as query processing module inFIG.2. Code base model530is the same as Code base model530inFIG.5.

Query encoder720generates encoded query725, an encoded version of natural language query700(a natural language query about the source code base). Query processor730selects one or more nodes and edges in the code base model that are responsive to query700, and code feature extractor710generates structured representation715: a structured representation of data responsive to query700. Query processor730uses structured representation715to generate result735: a natural language explanation of a code portion responding to query700.

With reference toFIG.8, this figure depicts a flowchart of an example process for dynamic source code analysis and natural language annotation in accordance with an illustrative embodiment. Process800can be implemented in application200inFIG.2.

In block802, the application classifies, into an algorithm type in a predefined set of algorithm types, each of a plurality of portions of a source code base of an application. In block804, the application identifies an author of a portion in the plurality of portions. In block806, the application annotates, for transparency, accuracy, and explainability, a portion in the plurality of portions. In block808, the application constructs a code base model of the source code base, the code base model comprising a plurality of nodes connected by edges, a node in the plurality of nodes representing a classified portion in the plurality of portions. In block810, the application generates, in response to a natural language query about the source code base, a natural language explanation of a classified portion in the plurality of portions. Then the application ends.