Is GitHub Copilot a blessing, or a curse?
[Warning: long comment ahead]<p>I haven&#x27;t used Copilot yet (I&#x27;m not coding in any of the languages it covers)
but I&#x27;ve tried to understand it from the few articles (most critical) posted
about it on the internet and from my understanding of program synthesis and
languae modelling. I don&#x27;t fully trust lay users to be able to exercise a
machine learning model comprehensively enough to precisely understand its pros
and cons, but I think I&#x27;ve formed some intuition about how Copilot works from
the demonstrations I&#x27;ve seen. Here&#x27;s my thoughts:<p>a) As TFA points out, Copilot was trained on _all_ code on github (for select
languages). &quot;All&quot; includes good code and bad code, code with bugs and code with,
er, fewer bugs, code that does what it should and code that doesn&#x27;t. The result
is that Copilot models _all_ that code, regardless of whether it&#x27;s got bugs or
not.<p>b) Copilot is (based on) a language model that predicts the next sequence of
tokens, not a discriminator of good&#x2F;bad code. That means it can generate code
but it can&#x27;t generate &quot;correct&quot; code. It doesn&#x27;t have a concept of
correct&#x2F;incorrect code.<p>b.1) More generally, it&#x27;s impossible to discriminate between &quot;correct&quot; and
&quot;incorrect&quot; code from features (tokens, in the case of language models) alone.
The correctness of code depends on the programer&#x27;s intent. In program synthesis,
the programmer&#x27;s intent is encoded as a specification and the correctness of a
synthesised program must be considered in the context of that specification. A
language model <i>could</i> be trained to include a specification as a feature, or as
an additional modality (similar to training on images and text together to
generate captions for images, or images from captions). However, this is not how
Copilot was trained. The upshot of all this is that Copilot can&#x27;t generate
&quot;correct programs&quot; because it doesn&#x27;t know what &quot;correct programs&quot; are.<p>b.2) But wait! Copilot <i>can</i> generate code from a specification! From a <i>natural
language specification</i>, in the form of inline comments given as part of a
prompt. This seems to be a favourite mode of testing Copilot and its results are
impressive, but there are two problems: i) natural language specifications are
imprecise and get more so the longer they grow; and, ii) Copilot still has no
way to determine whether the code it generates satisfies a natural language
specification, or not.<p>b.3) For program synthesis with guarantees of correctness, a specification is
not enough: a verification procedure is also necessary -and those tend to be
very tricky because Halting Problem.<p>c) Copilot has memorised at least part of its training set. This is evident in
the demonstrations of verbatim generation of known code, e.g. the Inverse Square
Root function (from Quake... III Arena I think?) etc.<p>c.1) This observation is helpful in understanding language models in general.
The assumption is often stated that a model can&#x27;t possibly be memorising its
training set because models are smaller on disk than their training sets. And
yet it seems that large language models <i>are</i> memorising <i>parts</i> of their
training sets- most likely, the ones that are more common, and therefore most
likely.<p>c.2) This in turn means that the programs that Copilot is most likely to generate
are variations of programs included in its training set and that have been
memorised. Why is this most likely? Because those programs are themselves &quot;most
likely&quot; - they are programs with the highest prior probability in the space of
programs represented by Copilot&#x27;s model.<p>c.3.1) That said, Copilot doesn&#x27;t always generate memorised programs verbatim. It
clearly has the ability to &quot;mix and match&quot; and generate programs that are <i>not</i>
included in its training set. How does Copilot (or language models in general)
achieve that? A language model is essentially a representation of a dense region
of Cartesian space bounded by the elements (tokens, expressions, whole programs)
of the training set. Anything within that dense geometric region, a language
model can recognise and generate. Anything outside it, is down to luck.<p>c.3.2) To generate programs not included in its training set, Copilot
<i>interpolates</i> between the programs in its training set and other programs in
its model (&quot;interpolates&quot; as in &quot;finds a point on a gradient between two
programs&#x27; representations&quot;). However, this interpolation is <i>stochastic</i>.
Fudging very, very much, we can imagine Copilot traversing the AST of a
memorised program and applying slight peturbations to that AST, at random,
though according to its learned prior probabilities. This is why Copilot will
generate different code each time it&#x27;s run even with the same prompt, and the
generated code is closer or farther away from memorised code according to its
&quot;temperature&quot; parameter (that controls the randomness of &quot;perturbations&quot;).<p>c.4) Suppose you take some program P and walk down its AST, perturbing the nodes
at random, <i>without</i> having any way to know whether a perturbation results in
correct code, incorrect code, or pure garbage. What is the expected result? The
expected result is correct code, incorrect code, or garbage. Remember: Copilot
can&#x27;t tell which is which. So we don&#x27;t know which we&#x27;ll get.<p>d) All that said, I think that i) Copilot can make a great boilerplate generator
but ii) only if people learn to use it right. So far I think most demonstrations
I&#x27;ve seen are &quot;holding it wrong&quot;.<p>d.1) As to ii) above, I think the best use-case of Copilot is to generate short
code snippets, spanning at most a couple of lines, rather than entire functions.
I think it&#x27;s also going to work a lot better if it&#x27;s allowed to complete <i>code</i>
rather than <i>comments</i> (with code). See point b.2 above. The demonstrations I&#x27;ve
seen so far seem to try to get Copilot to act as an <i>Autopilot</i> (sorry, couldn&#x27;t
resist). In that, it fails in the ways it should be expected to fail . I suspect
that as users get more familiar with Copilot&#x27;s abilities the best way to use it
will become evident and Copilot will take its rightful place as a useful tool in
the programmer&#x27;s toolbox that can simplify, but not replace, day-to-day
programming work.<p>e) Rumours of the imminent demise of the programming profession have, of course,
been greately exaggerated. Wait another couple of generations, maybe. <i>Human</i>
generations.<p>f) If you&#x27;re interested in program synthesis and the progress that has been
achieved so far in this old, but still active field of research, the following
is a good recent survey of the field:<p><a href="https:&#x2F;&#x2F;www.microsoft.com&#x2F;en-us&#x2F;research&#x2F;wp-content&#x2F;uploads&#x2F;2017&#x2F;10&#x2F;program_synthesis_now.pdf" rel="nofollow">https:&#x2F;&#x2F;www.microsoft.com&#x2F;en-us&#x2F;research&#x2F;wp-content&#x2F;uploads&#x2F;...</a>