<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Establishing Benchmarks For Learning Program Representations</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Anjan Karmakar Faculty of Computer Science Free University Bozen-Bolzano</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>In: Anne Etien (eds.): Proceedings of the 12th Seminar on Advanced Techniques Tools for Software Evolution</institution>
          ,
          <addr-line>Bolzano</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Recent advances in the eld of machine learning have shown great promise in solving various software engineering tasks. However, unlike machine learning techniques used in elds such as NLP (Natural Language Processing) where text-based tokens are used as model inputs, in software engineering (SE) structured representations of source code have proven to be more e ective for various SE tasks. Despite the ndings, structured representations of source code are still underused. In this paper, we propose to de ne a benchmark that promotes the usage of structured representations of source code as model inputs, via tasks that are explicitly de ned towards that goal.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>With the advent of big code, applying machine
learning techniques on large corpora of code have yielded
excellent results for a number of software
engineering tasks. Particularly, neural networks have been
very e ective since they are able to learn the
features from the input. However most of the tasks so
far use program structure in a shallow manner (name
prediction from snippets, source code summarization,
nding mappings between APIs, source code search,
etc). More recently a number of papers have utilized
the structured nature of source code and accomplished
state of the art results for certain software engineering
tasks.</p>
      <p>
        Like natural language, source code also is structured
and repetitive [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], therefore representing instances of
the input source code e ectively, while leveraging their
semantic and syntactic properties, could facilitate
better learning of machine learning models. Studies such
as [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] used source code representations in the form
of ASTs, and graphs, to essentially capture the
semantic and syntactic properties of source code and then use
them to train their model.
      </p>
      <p>Although there are a number of ways to
represent source code, such as simple token-based
representations, ASTs (Abstract Syntax Trees), call graphs,
bytecode, we are interested in the more structured
representations of code. Furthermore, we hypothesize
that the structured representation of source code as
inputs to machine learning models would perform better
for a variety of software engineering tasks, including
tasks such as code completion and defect prediction.</p>
      <p>Therefore, to evaluate our hypothesis, we aim to
propose a benchmark made up of tasks designed in
such a way that, to succeed, it is necessary to learn
more and more about the program structure. The
tasks shall be of increasing di culty (i.e., learning
more and more of the structure is necessary to yield
desirable results). We expect that on the hardest ones,
current neural approaches will fare little better than
random chance. The tasks will be de ned based on a
set of static analyses of the source code.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Background and Motivation</title>
      <p>
        Recently, there has been an increasing interest in
applying machine learning techniques to solve SE
(Software Engineering) tasks. However, most of the work
has directly tried to reuse natural language
processing (NLP) methods for SE tasks, mainly by treating
source code as a sequence of tokens - which ultimately
fail to capitalize on the unique opportunities o ered
by code's known structure and semantics [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
      </p>
      <p>
        Even though there are many similarities between
natural language and source code, one interesting
aspect that di erentiates source code from natural
language is that source code is highly structured, which
can be leveraged to obtain a greater understanding
of the context of the code. Owing to this structured
nature of code, program elements are usually
dependent on each other, and therefore when building
models to predict program properties, simple
sequencebased models, which treat these program elements to
be independent aspects, fail to make use of the
interdependence on other code elements [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. Also, simple
sequence-based models fail to determine which
variables are in scope at any point in the program, which
can be resolved simply by embracing more structured
representations of code [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. Some recent studies which
have utilized this structured representation of source
code have accomplished state of the art results on
many SE tasks.
      </p>
      <p>
        For example, Alon et al. [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] introduce the use of
di erent path-based abstractions of the program's
abstract syntax tree (AST) to represent source code. The
goal is to extract a representation that captures
relevant and interesting properties from the program's
AST, while keeping the representation open for
generalization. One such way to produce such a
representation of source code is to decompose the AST into
paths between nodes that repeat across programs but
can also discriminate between di erent programs.
      </p>
      <p>The authors show that representing source code as
AST paths can be useful in a diverse set of
programming tasks such as predicting variable names,
predicting method names, and predicting types of variables.
Furthermore, they claim that the use of AST paths
can signi cantly improve the performance of the
various learning algorithms without modifying them, while
achieving state of the art results.</p>
      <p>
        In yet another recent work by Zhang et al. [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ],
the authors address the challenge of source code
representation, to e ectively capture syntactic and
semantic information, with an AST-based Neural Network
(ASTNN) to learn vector representations of source
code. The model decomposes large ASTs of code
fragments into sequences of smaller statement trees, and
then obtains statement vectors by recursively encoding
multi-way statement trees. Based on the sequence of
statement vectors, a bidirectional RNN model learns
the vector representations of code fragments by
leveraging the naturalness of statements, which is then
evaluated on two tasks, namely source code classi cation
and code clone detection, producing state-of-the-art
results.
      </p>
      <p>
        Allamanis et al. [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] propose a new method to
represent code to capture the syntactic and semantic
structure of code using graphs, and then use graph-based
deep learning methods to learn to reason over program
structures. The authors propose a new
representation technique by encoding source code as graphs, in
which edges represent syntactic relationships as well
as semantic relationships. They observe that exposing
source code semantics explicitly as structured input
to a machine learning model reduces the requirements
on the amounts of training data and model capacity
making way for solving tasks, such as variable naming
(VarNaming), and detecting instances misused
variables (VarMisuse), and achieving state of the art
results.
      </p>
      <p>From the studies above, it is clear that structured
representations of code fare much better than simple
text-based token representations, for the tasks
investigated above. For our study, we are going to speci cally
focus the defect prediction tasks and attempt to use
structured representations of code as input to a
learning model to predict bugs. To evaluate the e
ectiveness of utilizing the structured representations of code,
the task of bug prediction is particularly potent since
there is a wide range of available bug types - some are
easily detected while others require a thorough
understanding of the syntactic formulation, semantics, and
structure of the code.
3</p>
    </sec>
    <sec id="sec-3">
      <title>Benchmarking</title>
      <p>Our intention is to build a neural network model that
is able to highlight buggy code in a given code corpus.
In order to accomplish the said goal our methodology
would require an amalgamation of di erent techniques
that have already been proposed in the literature for
diverse tasks. For the speci c case of bug detection
task, however, the techniques need to be applied
together and evaluated in the right manner, since all our
research questions are subject to experimental
evaluation, preferably against established benchmarks.</p>
      <p>
        An established benchmark, when embraced by a
community, can have a strong positive e ect on the
scienti c maturity of a community [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. Benchmarking
can result in a more rigorous examination of research
contributions and pave the way for the rapid
development and evaluation of new methods and tools.
      </p>
      <p>
        While looking for established benchmarks in the
eld, we have discovered datasets like the publicly
available PROMISE dataset [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], which also include
contributions from the NASA Metrics Data Program
[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], where a lot of defect prediction datasets are
available. However, the tests conducted on these datasets
are mostly metric-based, essentially using static
measures to guide software quality predictions, and are
essentially too "coarse" meaning they often highlight
bugs on the le level based on the complexity
measures such as essential complexity, cyclomatic
complexity, design complexity and lines of Code. On the
other hand, we would like to have tests which are more
" ne-grained", in the sense that, they could not only
identify suspicious or buggy les but also highlight the
exact bug locations in the lines of code.
      </p>
      <p>Thus, as a preliminary goal, we need to rst
determine some benchmarks that de ne tasks that would
require a thorough understanding of the programs
structure and semantics. We then need to evaluate the
performance of our trained model on these tasks and
compare it against the tasks comprising our benchmark.</p>
      <p>
        An additional desirable aspect of a benchmark is
to control the di culty of the tasks. An example in
NLP is the work of Weston et al. [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ], which de nes
20 NLP tasks in increasing levels of complexity. The
tasks are arti cial, but establish minimum levels of
complexity that a prediction model must ful ll. While
any model that can solve these tasks is not necessarily
close to full reasoning, however, if a model fails on any
of these tasks then there are likely to fail in real-world
tasks too.
      </p>
      <p>In the case of bug prediction, we would like a similar
property, but with more realism. These could range
from basic tasks for which the information is directly
accessible without needing to understand the program
structure - where sequential processing is still viable,
to more advanced tasks where understanding of
nonlocal and indirect structure is necessary.</p>
      <p>To sum up, unlike existing benchmarks we need
tasks where the output is ne-grained, and where we
can control the complexity of the tasks, so that we can
provide incentives for models that leverage the
program structure. One candidate that ful lls these
conditions is to leverage static analysis tools. Static
analysis tools leverage program structure and nd real bugs.
The static analyses can point out precise program
locations, and the analyses vary in complexity, from simple
and local pattern matching to full-program analyses.</p>
      <p>Therefore, we could consider proceeding in de
ning certain tasks which would form the benchmark to
evaluate machine learning models using the structured
nature of code. The range of tasks based on di culty
could be categorized as:
1. \Easy" tasks: tasks for which the information
is directly accessible without needing structure.
E.g. a property of a method that can be deduced
by information in the method body.
2. \Medium" tasks: tasks for which some degree
of structure is necessary. E.g. a property of a
method or variable that can be deduced, but you
need to take the entire le context into account,
not just the method body.
3. \Hard" tasks: tasks for which non-local
structure is necessary. E.g. a property of a method
that needs information from its direct callers.
4. \Very hard" tasks: tasks for which non-local
and also indirect structure is necessary. E.g. you
have to look into the callers of the callers.
5. \Inaccessible" tasks: tasks for which
information very distant from the source is necessary.
E.g., one statement in one method that is
indirectly called by the method, but they are 5-10
steps away.</p>
      <p>
        For example, the VarMisuse task de ned by
Allamanis et al. [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] serves as a good sample task for bug
detection. The missing variables in the VarMisuse task
must be predicted properly else they risk causing
system failure, and thereby, when applied to our case our
model could highlight or detect whether a variable has
been misused and whether the module is buggy.
      </p>
      <p>In essence, some variables are omitted from a given
code snippet and fed as input to Allamanis et al's
model. The learned model from Allamanis et al.
then accurately predicts the expected variables with
a high accuracy for all the variables but the last.
Such a task could be categorized as a Medium task,
since to accurately predict the omitted variable the
model needs to take the code from the entire le into
consideration, rather than just the local method.</p>
      <p>
        To successfully tackle the task of bug detection,
one needs to understand the role and function of the
program elements and understand how they relate to
each other. In the VarMisuse task discussed above,
the model learns to predict the correct variable that
should be used at a given program location. Since the
model produces near accurate results, any variable in
the code that does not match the expected variable
predicted by the model could then be a point of
inspection. This task could be complementary to our
bug detection task. Given a certain code snippet, we
must therefore ascertain whether it contains certain
buggy fragments and then we can compare our results
with the predictions made by the model proposed by
Allamanis et al. [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
      </p>
      <p>These tasks from the established benchmark will
also help us compare our results against those of static
bug nders, which use approaches ranging from simple
code pattern-matching techniques to static analyses
that process semantic abstractions of code. From the
list of tasks de ned in our benchmarks, simple static
bug nders would likely be able to detect bugs "easy"
and "medium" tasks but fare poorly for "hard" tasks
where a greater understanding of the program
structure is required.</p>
      <p>Making a direct comparison with static bug nders
against our model could reveal the e ectiveness and/or
weakness of our model. We could match the
highlighted faulty lines of code or defect locations from the
static bug nders and our model, and evaluate them
for false positives and false negatives.</p>
      <p>There are a number of Static Bug Finders (SBF)
we could compare our results with to conclude on the
e ectiveness of our model. For example, Hybrid tools
like FindBugs which incorporate both static data- ow
analysis, and pattern matching, could be a good
evaluation candidate. Also, tools like ESC-Java and
CodeSonar could be considered, since their analyses
are reportedly more e ective and they could possibly
highlight bugs in "hard" tasks.</p>
      <p>Advanced tools like Infer could even understand the
program structure and fare better than traditional bug
detection tools, and it will be interesting to compare
their results against the set of tasks from the
established benchmarks, and whether they are able to
detect bugs in "hard" and "very hard" tasks.
4</p>
    </sec>
    <sec id="sec-4">
      <title>Discussion</title>
      <p>The eventual goal of our research is to enable learned
models to e ectively detect bugs from a new corpus
which is not an easy task. Detecting code faults is a
task that requires through understanding of the code
and reasoning about the program semantics. Even for
an experienced programmer this is a challenging task.</p>
      <p>To allow a learning model to grasp the
correlations between code fragments and understand how
they work, we need a better way to map code
fragments instead of simple sequential token-based
mapping. Even though code fragments have something in
common with plain texts, they should not be simply
dealt with text-based or token-based methods due to
their richer and more explicit structural information.</p>
      <p>
        Recent work [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] provides strong evidence that
semantic and syntactic knowledge from source code
as structured representations contributes a great deal
in modeling source code and can obtain better results
than traditional sequential token-based methods.
Because of the highly structured nature of code,
treating code snippets as structured representations for the
machine learning models, can capture critical
semantic information that re ects common code patterns,
and even signi cantly lessens the requirements on the
amount of training data compared to learning over
sequential token-based representations [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], and it is still
general enough so that it can be applied to a diverse
range of tasks.
      </p>
      <p>However, to measure the e ectiveness of the models
based on various representations of code, and to
compare against the results from static analysis, we need a
set of tasks as a benchmark. Therefore, in our
preliminary work we attempt to de ne a benchmark
measuring the accuracy and usefulness of a model based on
certain type of representation. The tasks comprising
the benchmark would essentially test the
understanding of the model, starting from simple tests for which
the information is directly accessible without needing
to understand the program structure, to increasingly
di cult tests where understanding of non-local and
indirect structure is necessary. Furthermore, this
benchmark would also serve new models with novel
representation techniques for their evaluation purposes - to
compare against current state of the art.</p>
      <p>Once our benchmarks are established, as a part of
our future work, we could begin our bug detection
approach by rst mining programs in our training set
as Abstract Syntax Trees (ASTs). Then selecting the
most e ective paths in the ASTs, we could derive code
embeddings from the program as an input for our
learning model. And nally, train the learning model
with pairs of buggy and correct code, based on the
vectors representations of the code fragments. When the
model is trained it should be able to highlight buggy
fragments of code from the input - an unseen code
corpus. Another approach could be to mine the
programs as ASTs and represent them as graphs which
could be used as a direct input to feed Graph
Neural Networks. Establishing a solid benchmark for the
defect prediction task, would boost the development
and evaluation of new techniques and tools in defect
prediction, and allow for the comparison of their
effectiveness. Our aim with this paper is to introduce
the notion of benchmarking for learner models based
on structured representations of code, and propose a
set of tasks categories that would evaluate the usage
of program structure speci cally for the task of defect
prediction.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>Miltiadis</given-names>
            <surname>Allamanis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Marc</given-names>
            <surname>Brockschmidt</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Mahmoud</given-names>
            <surname>Khademi</surname>
          </string-name>
          .
          <article-title>Learning to represent programs with graphs</article-title>
          .
          <source>CoRR, abs/1711.00740</source>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>Uri</given-names>
            <surname>Alon</surname>
          </string-name>
          , Meital Zilberstein,
          <string-name>
            <surname>Omer Levy</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Eran</given-names>
            <surname>Yahav</surname>
          </string-name>
          . code2vec:
          <article-title>Learning distributed representations of code</article-title>
          . CoRR, abs/
          <year>1803</year>
          .09473,
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Uri</given-names>
            <surname>Alon</surname>
          </string-name>
          , Meital Zilberstein,
          <string-name>
            <surname>Omer Levy</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Eran</given-names>
            <surname>Yahav</surname>
          </string-name>
          .
          <article-title>A general path-based representation for predicting program properties</article-title>
          . CoRR, abs/
          <year>1803</year>
          .09544,
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <surname>Jackson</surname>
            <given-names>W. Chapman SM.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Callis</surname>
            <given-names>P</given-names>
          </string-name>
          .
          <article-title>Metrics data program</article-title>
          .
          <source>NASA IV and V Facility</source>
          ,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>Abram</given-names>
            <surname>Hindle</surname>
          </string-name>
          , Earl T. Barr, Zhendong Su,
          <string-name>
            <given-names>Mark</given-names>
            <surname>Gabel</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Premkumar</given-names>
            <surname>Devanbu</surname>
          </string-name>
          .
          <article-title>On the naturalness of software</article-title>
          .
          <source>In Proceedings of the 34th International Conference on Software Engineering</source>
          , ICSE '
          <volume>12</volume>
          , pages
          <fpage>837</fpage>
          {
          <fpage>847</fpage>
          ,
          <string-name>
            <surname>Piscataway</surname>
          </string-name>
          , NJ, USA,
          <year>2012</year>
          . IEEE Press.
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <surname>Chris</surname>
            <given-names>J.</given-names>
          </string-name>
          <string-name>
            <surname>Maddison</surname>
            and
            <given-names>Daniel</given-names>
          </string-name>
          <string-name>
            <surname>Tarlow</surname>
          </string-name>
          .
          <article-title>Structured generative models of natural source code</article-title>
          .
          <source>CoRR, abs/1401.0514</source>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>Veselin</given-names>
            <surname>Raychev</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Martin</given-names>
            <surname>Vechev</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Andreas</given-names>
            <surname>Krause</surname>
          </string-name>
          .
          <article-title>Predicting program properties from "big code"</article-title>
          .
          <source>In Proceedings of the 42Nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '15</source>
          , pages
          <fpage>111</fpage>
          {
          <fpage>124</fpage>
          , New York, NY, USA,
          <year>2015</year>
          . ACM.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>J Sayyad</given-names>
            <surname>Shirabad and Tim J Menzies.</surname>
          </string-name>
          <article-title>The promise repository of software engineering databases</article-title>
          .
          <source>School of Information Technology and Engineering</source>
          , University of Ottawa, Canada,
          <volume>24</volume>
          ,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>S. E.</given-names>
            <surname>Sim</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Easterbrook</surname>
          </string-name>
          , and
          <string-name>
            <given-names>R. C.</given-names>
            <surname>Holt</surname>
          </string-name>
          .
          <article-title>Using benchmarking to advance research: a challenge to software engineering</article-title>
          .
          <source>In Proceedings of the 25th International Conference on Software Engineering</source>
          , ICSE '
          <volume>03</volume>
          , pages
          <fpage>74</fpage>
          {
          <fpage>83</fpage>
          , May
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <surname>Jason</surname>
            <given-names>Weston</given-names>
          </string-name>
          , Antoine Bordes, Sumit Chopra, Alexander M Rush, Bart van Merrienboer, Armand Joulin, and
          <string-name>
            <given-names>Tomas</given-names>
            <surname>Mikolov</surname>
          </string-name>
          .
          <article-title>Towards aicomplete question answering: A set of prerequisite toy tasks</article-title>
          .
          <source>arXiv preprint arXiv:1502.05698</source>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>Zhang H Sun H Wang K Liu X Zhang J.</surname>
          </string-name>
          ,
          <string-name>
            <surname>Wang</surname>
            <given-names>X.</given-names>
          </string-name>
          <article-title>A novel neural source code representation based on abstract syntax tree</article-title>
          .
          <source>In Proceedings of the 41st International Conference on Software Engineering</source>
          , ICSE '19, May
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>