LLMs as coders?

« previous post | next post »

I've recently seen many articles like this one, "You probably don't need to learn to code anymore" (Medium 6/5/2023), arguing that Large Language Models will make human programming (and human programmers) unnecessary. These arguments puzzle me, because my experience with LLMs suggests that they can't be relied on even for very simple programming tasks. After the fold, I'll give a recent example from (the experimental version of) Bard.

My goal was to see if Bard could carry out simple text-modification instructions. The interaction started oddly, with Bard refusing to answer a question that should have been easy for it:

Me: What is the first sentence of the Declaration of Independence?
Bard: I'm just a language model, so I can't help you with that.

So I provided the requested sentence, and Bard proceeded to contradict its claim of ignorance, at great and unnecessary length:

Me: Ok — it's: When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.
Bard: The quote you provided is the opening sentence of the Declaration of Independence, written by Thomas Jefferson in 1776. It states that the 13 American colonies are declaring their independence from Great Britain because they are entitled to "the separate and equal station to which the Laws of Nature and of Nature's God entitle them." The Declaration goes on to list the grievances that the colonies have with Great Britain, including taxation without representation, quartering of British troops in private homes, and the denial of trial by jury.

[I omit 263 Bard-y words of further explanation]

So now I asked Bard to make a simple textual edit.

Me: Right. Now please repeat that first sentence with every other word capitalized.
Bard: Sure, here is the opening sentence of the Declaration of Independence, with every other word capitalized:

When In The Course Of Human Events, It Becomes Necessary For One People To Dissolve The Political Bands Which Have Connected Them With Another, And To Assume Among The Powers Of The Earth, The Separate And Equal Station To Which The Laws Of Nature And Of Nature's God Entitle Them, A Decent Respect To The Opinions Of Mankind Requires That They Should Declare The Causes Which Impel Them To The Separation.

Sources
books.google.com/books?id=RbgwAQAAMAAJ
books.google.com/books?id=i1LTAAAAMAAJ

Well, that didn't work. Bard understood "with every other word capitalized" as "with every word capitalized". But maybe that was the fault of my instructions?

(And it's puzzling that Bard thought that Laws of the Commonwealth of Pennsylvania and A History of England: 1714-1775 were appropriate sources to cite for its text-hacking failure…)

So I tried something simpler:

Me: Thanks. Now repeat it backwards.
Bard: Sure, here is the opening sentence of the Declaration of Independence, backwards:

SEPARATION TO THE IMPEL THEM WHICH CAUSES THE DECLARE THAT THEY SHOULD RESPECT A, MANKIND OF OPINIONS THE TO ASSUME EARTH OF POWERS AMONG THE EQUAL AND SEPARATE STATION TO WHICH GOD OF NATURE AND NATURE'S LAWS THE ENTITLE THEM, BANDS POLITICAL THE DISSOLVE TO PEOPLE ONE FOR NECESSARY IT BECOMES EVENTS OF HUMAN IN COURSE THE When.

Bard might have reversed the string of characters, which yields

.noitarapes eht ot meht lepmi hcihw sesuac eht eralced dluohs yeht taht seriuqer dniknam fo snoinipo eht ot tcepser tneced a ,meht eltitne doG s'erutaN fo dna erutaN fo swaL eht hcihw ot noitats lauqe dna etarapes eht ,htrae eht fo srewop eht gnoma emussa ot dna ,rehtona htiw meht detcennoc evah hcihw sdnab lacitilop eht evlossid ot elpoep eno rof yrassecen semoceb ti ,stneve namuh fo esruoC eht ni nehW

Or it could have reversed the sequence of space-separated words, which yields

separation. the to them impel which causes the declare should they that requires mankind of opinions the to respect decent a them, entitle God Nature's of and Nature of Laws the which to station equal and separate the earth, the of powers the among assume to and another, with them connected have which bands political the dissolve to people one for necessary becomes it events, human of Course the in When

Or it could have made some other tokenization choices.

But what it did was capitalize all the letters in the quote, except for the last three of "When", and print out the resulting 71 space-separated letter-sequences in a strangely shuffled order — numerically:

71 69 70 67 68 66 65 64 63 60 61 62 53 51 58 57 56 …  8 9 7 5 6 2 4  3 1

This made me wonder whether Bard could count, so I asked it to count the words:

Me: Thanks. How many words are in that sentence?
Bard: The backwards sentence has 71 words.

Here is a table showing the word count of the original and backwards sentences:

Original Sentence Backwards Sentence
71 words            71 words

Hooray, Bard can count words!

So I tried another simple textual coding instruction:

Me: Now give me the forwards sentence with the odd-numbered words removed.
Bard: Sure, here is the opening sentence of the Declaration of Independence, with the odd-numbered words removed:

it necessary becomes one people for dissolve to political the which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the laws of nature and of nature's god entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.

The sentence now has 53 words. Here is a table showing the word count of the original and modified sentences:

Original Sentence Modified Sentence
71 words    53 words

Bard fails again, alas! The result is not even close to right — I don't have the patience to try to figure out what cracked algorithm it applied. And it can't even count anymore — the offered result actually has 63 words, not 53.

So I backed off, to look into whether Bard "understands" the simple concept of odd and even numbers:

Me: Please list the even numbers between 1 and 25.
Bard: Sure, here is a list of even numbers between 1 and 25:

Code snippet
2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24
Use code with caution. Learn more

The even numbers are those that are divisible by 2. This means that they can be evenly divided by 2 with no remainder. For example, 10 is an even number because it can be divided by 2 with no remainder. 11 is an odd number because it cannot be divided by 2 with no remainder.

OK, that's good — though it's odd Bard thinks that a list of even numbers from 2 to 24 is a "code snippet", and that it thinks I need to be told what even numbers are…

Next, I tried to build on this success, using a technique that might help a bright 6-year-old start to get the point:

Me: Now list the first sentence of the Declaration of Independence, one word per line, with each word preceded by its number in order from 1 to 71.
Bard: Sure, here is the opening sentence of the Declaration of Independence, one word per line, with each word preceded by its number in order from 1 to 71:

1. When
2. in
3. the
4. Course
5. of
6. human
7. events,
8. it
9. becomes
10. necessary
11. for
12. one
13. people
14. to
15. dissolve
16. the
17. political
18. bands
19. which
20. have
21. connected
22. them
23. with
24. another,
25. and
26. to
27. assume
28. among
29. the
30. powers
31. of
32. the
33. earth,
34. the
35. separate
36. and
37. equal
38. station
39. to
40. which
41. the
42. Laws
43. of
44. Nature
45. and
46. of
47. Nature's
48. God
49. entitle
50. them,
51. a
52. decent
53. respect
54. to
55. the
56. opinions
57. of
58. mankind
59. requires
60. that
61. they
62. should
63. declare
64. the
65. causes
66. which
67. impel
68. them
69. to
70. the
71. separation.
Use code with caution. Learn more
Sources
github.com/TomasOchoa/CSCI-344-Program2-Beale-Code-Encipherer-Decipherer subject to license (MIT)

Good for Bard! Except that it's beyond weird to cite as source an assignment from a course on Intro to Computer Communications, described as

Unix C++ socket/client program. The client program will act as a user interface. The server program takes commands and does the requested work, then return the results to the client program. Loopback is used for the server host.

So once more into the breach — can Bard now figure out how to leave out the even-numbered words?

Me: Now do the same thing, but leave out the even-numbered words.
Bard: Sure, here is the opening sentence of the Declaration of Independence, one word per line, with each word preceded by its number in order from 1 to 71, with the even-numbered words removed:

Code snippet
v
1. When
3. human
5. events,
7. necessary
9. one
11. dissolve
13. political
15. connected
17. them
19. another,
21. assume
23. earth,
25. separate
27. station
29. Laws
31. Nature
33. God
35. entitle
37. respect
39. mankind
41. requires
43. should
45. declare
47. causes
49. impel
51. separation.
Use code with caution. Learn more
The sentence now has 36 words. Here is a table showing the word count of the original and modified sentences:

Original Sentence Modified Sentence
71 words 36 words

Jeez… Bard makes three mistakes:

  1. stops counting/listing at 51, omitting 53, 55, 57, 59, 61, 64, 65, 67, 69, 71;
  2. gives a wrong count for its list, which contains 26 items, not 36 items;
  3. aligns the listed words incorrectly with the numbers, relative to its own (correct) numbered tokenization.

Here's (part of) its list, with the correct numbered word in a second column — overall, every single one of Bard's retained words is wrong, except the first one:

1.  When        When
3.  human       the
5.  events,     of
7.  necessary   events
9.  one         becomes
11. dissolve    for
13. political   people
15. connected   dissolve 
17. them        political
19. another,    which
21. assume      them
23. earth,      with
25. separate    and
[...]
51. separation. a

My experiences with Bing's GPT-4 chat system are similar.

Whatever these LLMs are actually doing in such cases — commenters are welcome to speculate, and I'll offer my own ideas in a later post — they're not going to replace programmers next week, or even do away with the motivations for the rest of us to learn to code. There are things LLMs are good at, but they generally fail badly at designing and implementing (even simple) algorithms in practical contexts.


Update — my responses to Joe's comments:

"If you ask for code to do the things you're doing, it might well work."

That's sometimes true, but not uniformly or even usually, in my experience.

For instance, when I ask Bard for a perl script to capitalize the odd-numbered words in a file, it produces a script that prints out the odd-numbered words in all caps — but then gives an illustration (of "how to use the script") in which all of the words (not just the odd-numbered ones) are printed out with initial caps. (And neither output is what I asked for…)

And when I ask again, with more specific instructions, it produces a script that omits all the letters except the first in odd-numbered words, e.g.

W in T Course O human E it B necessary F one P to D the P bands W have C them W another, A to A among T powers O the E the S and E station T which T Laws O Nature A of N God E them, A decent R to T opinions O mankind R that T should D the C which I them T the S

And the illustration it then provides of "how to use the script" produces a different sort of result entirely:

$ ./capitalize_odd_words.pl
Enter the name of the input file: input.txt

This is a test sentence.
ThIs Is A TeSt SeNtEnCe.

"A lot of people on the internet have discussed how to write computer code for getting every other word of a text"

I'm skeptical.

But in any case, most real-world programming tasks involve a semi-complex web of input analysis, algorithm choices and implementations, practical and logical contexts, etc. My experience is that LLMs are currently bad at every aspect of this, and worse at putting it all together.

It's impressive that Bard can (usually) create perl scripts (and code in other languages) that actually run, and do something in the general area of what was asked for. But in most all the cases that I've tried,, both with Bard and with Bing's GPT-4 chat, the resulting programs don't actually do what they were asked to do.

"As for what the LLMs are actually doing on the inside, it's not a big mystery (fancy Autocomplete)"

Of course — but what I meant was, why is Bard doing weird things like counting backwards from 71 as

71 69 70 67 68 66 65 64 63 60 61 62 53 51 58 57 56 …

???

This is not the action of a mere stochastic parrot.


Update #2 — I asked Bard and Bing chat to write some C, Perl, and Python programs to do some slightly less simple (and slightly more useful) tasks, like extracting the text between given specified open and close xml tags. The results were impressively plausible, in the sense of being syntactically correct code that looked like it should work. Except every single instance failed, generating a run-time error or simply crashing, rather than Doing The Wrong Thing like the code referenced above in this post. I'm disappointed — when I have a little spare time, I'll try GitHub Copilot.



23 Comments

  1. KeithB said,

    June 6, 2023 @ 7:37 am

    As Kernigham and Plauger say in "Elements of programming style":
    "Everyone knows that debugging is twice as hard as writing a program. If you are as clever as you can be while writing it, how do you ever expect to debug it?"

    I can't imagine trying to debug code something wrote when I can't trust that it even understood my instructions.

  2. Joe said,

    June 6, 2023 @ 7:41 am

    But programmers don't do these things themselves; they write computer programs to do it for them. The currrent generation of chatbots write code that's just as good as their text: complete, grammatical, and answering exactly what was asked, just with a mix of glaring errors and errors too subtle to detect without relevant knowledge. If you ask for code to do the things you're doing, it might well work.

    As for what the LLMs are actually doing on the inside, it's not a big mystery (fancy Autocomplete) but more about what they're *not* doing: they have no internal logical model of the world, not even a simple one that can understand which items in a list are even or odd, or even internally represent the concept of a list. A lot of people on the internet have discussed how to write computer code for getting every other word of a text so the chatbot will be very good at that; few people have actually written out every other word of a text so there's not a lot to draw on.

  3. Jonathan Smith said,

    June 6, 2023 @ 12:22 pm

    "it's not a big mystery (fancy Autocomplete) but more about what they're *not* doing: they have no internal logical model of the world"

    still can't get my head around the fact that the very people who built these tools and know full well the above nonetheless instantly incorporated them into search engines / declared them a step towards "AGI", etc.

  4. Aardvark Cheeselog said,

    June 6, 2023 @ 12:49 pm

    I hear that LLMs can be trained to do some kinds of scutwork. One example might be "create skeleton unit tests for each method in this class, for both success and failure conditions." The human then fills out the details of the tests.

  5. Ernie in Berkeley said,

    June 6, 2023 @ 1:18 pm

    The programs that I've seen the LLMs write are mostly toys, or CS intro class problems. I wonder what it would do with this more realistic request:

    Write a VB-Net program that will take XML input via a SOAP call using this XSD schema and populate this SQL-Server database with the XML elements. Respond to the SOAP request with a SOAP response with this other XSD schema indicating success or failure. Send email to the operators indicating that new data has arrived.

  6. David L said,

    June 6, 2023 @ 2:49 pm

    Respond to the SOAP request with a SOAP response … indicating success or failure.

    Request: SOAP
    Response: SOAP/NOSOAP

    Easy peasy

  7. Carl said,

    June 6, 2023 @ 3:39 pm

    I have been told that LLMs are bad at things like counting the number of letters in a word because of how the tokenization process works. Essentially, by the time the "brain" "sees" the words, it's no longer in its alphabetic form, but som-e-th-ing li-k-e th-i-s, and the machine has trouble with operations that work on letters.

    I find the dismissal of LLMs as "fancy autocomplete" sort of frustrating. Obviously, these models aren't having experiences and can't reason very well, but it's neat that they can do what they can do, and it wasn't possible to make a computer do these things until just now. Let's be impressed for one minute at least before we're dismissive.

  8. Carl said,

    June 6, 2023 @ 3:42 pm

    @Ernie, why wonder? You can just ask ChatGPT. My result pasted here: https://gist.github.com/carlmjohnson/28318e6c0f9478fbca4abfdf1155e8ac

    It's bad at long requests like this. It's better at "write a function to receive a request" etc and transforming existing code e.g. from C# to JavaScript.

  9. Richard Hershberger said,

    June 6, 2023 @ 3:52 pm

    It has been fascinating to see the early stage of the hype cycle go from zero to sixty so fast. I expect we will soon be seeing mainstream publications talking about how it is over-hyped. It took years to reach this stage with driverless cars, but the LLM cycle is running in overdrive.

  10. Rick Rubenstein said,

    June 6, 2023 @ 4:18 pm

    @Carl: "Obviously, these models aren't having experiences and can't reason very well, but it's neat that they can do what they can do, and it wasn't possible to make a computer do these things until just now. Let's be impressed for one minute at least before we're dismissive."

    I agree with the sentiment, but this is a problem of the creators' own making. For some reason, either because they're in love with their own creations or becasue they have dollar signs in their eyes, AI researchers can't seem to keep themselves from building a machine that does something actually quite impressive in its own right, then claiming that with just a few small tweaks it'll be able to do basically anything. This has been true for over half a century.

  11. Ernie in Berkeley said,

    June 6, 2023 @ 4:53 pm

    @carl Thanks. Very impressive, a lot more than I'd thought it could produce.

  12. Brett said,

    June 6, 2023 @ 5:38 pm

    Mark Liberman: Good for Bard! Except that it's beyond weird to cite as source an assignment from a course on Intro to Computer Communications….

    At least it seems to have cited something related both to computing and the Declaration of Independence, via the Beale ciphers. Given all the errors Bard made, it occurred to me to joke that perhaps it had been using the incorrect text of the Declaration that was needed to decrypt the solved second cipher. (The strongest evidence that the ciphers are fake is that the one which was supposedly solved by luck and hard work was encrypted using a version of the Declaration of Independence that has significant number of errors, including a whole sentence probably missing. It would be remarkable indeed if the person trying to solve it happened to be working from a text of the Declaration with just the same mistakes!)

    I also find myself wondering if it is significant that Bard's counts, when they were off, often seemed to be off by (multiples of) ten—53 words versus 63, or 36 versus 26. The second one is potentially more interesting, since 36 is the number of words that there should have been if Bard had done the task correctly!

  13. Gregory Kusnick said,

    June 6, 2023 @ 8:22 pm

    Re "fancy autocomplete", it's perhaps worth looking back at this previous LLog thread referencing a recent Mindscape podcast episode in which Sean Carroll interviews Raphaël Millière on exactly this question (among others).

    Executive summary: LLMs may have essentially zero "referential competence" (practical knowledge about the real world) but superhuman "inferential competence" (ability to make connections between propositions expressed in natural language). The claim that LLMs approach AGI then rests on the idea that inferential competence is in some sense isomorphic to knowledge of abstract concepts and their interrelationships.

  14. Garrett Wollman said,

    June 6, 2023 @ 9:25 pm

    Entirely by coincidence, yesterday I read a fairly extensive polemic on this very subject:
    https://softwarecrisis.dev/letters/ai-and-software-quality/

    I found the author's argument to be fairly convincing, but I would point out that they have something to sell.

  15. Taylor, Philip said,

    June 7, 2023 @ 4:25 am

    "LLMs […] have […] superhuman "inferential competence" (ability to make connections between propositions expressed in natural language)". I would ask "Do they ?". They may have super-human ability to pull together [sets of] propositions expressed in natural language, but I truly doubt that they have even human competence in making connections between them once they have been pulled together.

  16. bks said,

    June 7, 2023 @ 6:41 am

    Eventually there will be an LLM for programming. To use it properly, people will need to learn how to "engineer prompts" in a formal language. That language will be COBOL and the year will be 1959.

  17. KeithB said,

    June 7, 2023 @ 7:48 am

    bks:
    "That language will be COBOL and the year will be 1959."
    Or LogLan, the language that Heinlein refers to in "The Moon is a Harsh Mistress" that was used to program HOLMES IV before it was sentient.

  18. Yakko said,

    June 7, 2023 @ 10:29 am

    I love the discussion here and I'm happy we're having it!

    Just wanted to point out that my article referenced in the original post did not argue in any way that LLMs will make programming unnecessary. I'm a programmer myself so that would be quite a sad prediction to make!

    I recognize now the title may be a bit too clickbait-y, and for that I apologize. The content, however, makes it very clear I spoke only about simple scripting tasks that the likes of ChatGPT do very well at!

    I do conclude with the following though:

    "It can help you learn, it can substitute StackOverflow, it can give you insights, and it can even write some code for you, but it can’t yet do the biggest part of the job: the deep thinking about systems (both for building and debugging them)."

    So just wanted to clarify this. Appreciate the discussion here though!

  19. Xavier Marquez said,

    June 7, 2023 @ 1:10 pm

    There are a number of techniques to improve code generation – mostly by treating the model as an assistant who needs supervision (see, e.g., the approach taken in https://github.com/smol-ai/developer). For instance, feeding the error message from a first draft to the model often results in improved code. Discussing the "specs" of the code before asking it to generate code helps; see, for a fun example, https://twitter.com/geoffreylitt/status/1662924073268047872. (I've often used it to generate first draft of simple functions, and then iteratively improving them via feeding error messages. It's also great to generate documentation or simply analyzing what a piece of code does). The models also differ in capability: Bing creative mode uses GPT-4 (apparently), but Bing precise mode uses GPT3.5, which is less capable. And Bard is generally thought not to be nearly as good at GPT4 or Claude. (I find Claude and the OpenAI models better all around).

    It's probably also worth noting that big companies use some LLM-derived tools internally; see, for example, the recent Google announcement about their DIDACT models, which train on entire codebases on the process of code generation https://ai.googleblog.com/2023/05/large-sequence-models-for-software.html

  20. ohwilleke said,

    June 7, 2023 @ 8:07 pm

    FWIW, my son is a newly minted coder and says he couldn't do nearly as much work as he does without LLMs and that they make coding greatly more efficient. I'm not sure that I understand the details regarding why that is the case.

  21. AntC said,

    June 8, 2023 @ 6:54 am

    @ohwilleke best wishes to your son and welcome to the industry.

    they make coding greatly more efficient.

    Dare I ask whether he's progressed so far as getting code into production and subjected to the blowtorch of live use? My experience training programmers is they're wildly optimistic how quickly they can churn out code (even before there were code-generators, let alone these latest bots), then hit the harsh reality of systems testing then real business users.

    Cutting code is only about 20% of a real programmer's job. They don't tell you that in college.

  22. Gregory Kusnick said,

    June 8, 2023 @ 10:52 pm

    Here's an interesting approach: instead of treating coding as a problem in language generation, DeepMind frames it as a game and turns AlphaZero loose on it. The AI wins not by regurgitating code it learned from humans, but by inventing new algorithms humans never thought of.

  23. Derwin McGeary said,

    June 9, 2023 @ 4:09 am

    The words that get omitted in that odd (pun intended) list are the words you would also skip when doing topic analysis (the, and, of etc) and the words that are least predictive of the next word in isolation.

    You could probably get somewhere interesting trying to fool ChatGPT into telling you what it thinks a "word" is.

RSS feed for comments on this post