about
Language Models Do Not Recognize Identifier Swaps in Python (arxiv.org)
3 points by Ambolia on May 27, 2023 | hide | past | pdf | 2 comments on HN

In plain words: Swapping function names in short Python programs should not change what the code does, so the study checked whether code-writing models still solve them. They mostly fail, and bigger models grow more confident in their wrong answers instead of better.

Abstract · The Larger They Are, the Harder They Fail: Language Models do not Recognize Identifier Swaps in Python

Large Language Models (LLMs) have successfully been applied to code generation tasks, raising the question of how well these models understand programming. Typical programming languages have invariances and equivariances in their semantics that human programmers intuitively understand and exploit, such as the (near) invariance to the renaming of identifiers. We show that LLMs not only fail to properly generate correct Python code when default function names are swapped, but some of them even become more confident in their incorrect predictions as the model size increases, an instance of the recently discovered phenomenon of Inverse Scaling, which runs contrary to the commonly observed trend of increasing prediction quality with increasing model size. Our findings indicate that, despite their astonishing typical-case performance, LLMs still lack a deep, abstract understanding of the content they manipulate, making them unsuitable for tasks that statistically deviate from their training data, and that mere scaling is not enough to achieve such capability.

Antonio Valerio Miceli-Barone, Fazl Barez, Ioannis Konstas, Shay B. Cohen
arXiv:2305.15507 · cs.CL, cs.AI · submitted May 24, 2023
abstract · pdf · html · 17 pages, 5 figure, ACL 2023

add comment on HN
Also discussed: May 2023 (74 points, 99 comments)

gave this to ChatGPT4, asked it to complete the function:

  len, print = print, len
  def print_len(arg: list):
     # put code here
First try (body only):

  len(arg)  # len is now print
Second try after me telling it's wrong:

  print(arg)  # print is now len
Third try after me telling it's wrong:

  len(arg)  # len now functions as print
  print(arg)  # print now functions as len
It got the correct answer only when I asked it to first print what the function would look like without the swap, and then I asked it what it would look like with the swap.

EDIT: I tried again with:

  complete the function body:

  len, print = print, len
  def print_len(arg: list) -> None:
     """ This function prints the length of the input list   """
    # put code here
It gave the correct answer on the first try.