Live data from Hacker News

Large language models do not recognize identifier swaps in Python

arxiv.org

21–30 of 103 posts

Re: Large language models do not recognize identifier swaps in Python

#21
post #6
post #3

prompt: please write a python function that prints the length of a list. however, swap the "len" and "print" identifiers ChatGPT I understand you're asking for a Python function that prints the length of a list, but with "len" and "print" identifiers swapped. As this could potentially cause confusion (since 'len' and 'print' are both built-in functions in Python), the workaround would be to create new function names…

This will experience infinite recursion through print-len-print-len...

and im pretty sure this breaks the varargs and kwargd of print, too

Re: Large language models do not recognize identifier swaps in Python

#22
post #19
post #18

Earlier quoted context omitted.

Interesting. You said Gpt4, but that link shows ChatGpt's avatar as 3.5's. And I'm convinced you were using 4 as I just tried replicating this; with 3.5 it fails and with 4 it succeeds. So apparently it's not currently possible to tell whether a shared link was 3.5 or 4? Unfortunate if so.

The shared link was from my own GPT-4 session. It shows "Model: GPT-4" in the header of my chat from which I shared the link.

No it shows Model: Default

Re: Large language models do not recognize identifier swaps in Python

#23
post #19
post #18

Earlier quoted context omitted.

Interesting. You said Gpt4, but that link shows ChatGpt's avatar as 3.5's. And I'm convinced you were using 4 as I just tried replicating this; with 3.5 it fails and with 4 it succeeds. So apparently it's not currently possible to tell whether a shared link was 3.5 or 4? Unfortunate if so.

The shared link was from my own GPT-4 session. It shows "Model: GPT-4" in the header of my chat from which I shared the link.

How do you set it to 4? I can only find 3.5 somehow.

Re: Large language models do not recognize identifier swaps in Python

#24
post #22
post #19

Earlier quoted context omitted.

The shared link was from my own GPT-4 session. It shows "Model: GPT-4" in the header of my chat from which I shared the link.

No it shows Model: Default

Yes but it's from GPT-4. "Model: Default" is a defect in their link sharing. In my private session it says "Model: GPT-4"

Re: Large language models do not recognize identifier swaps in Python

#25
post #16
post #5

Earlier quoted context omitted.

Just to point out: this doesn't work since at the point where it defines the new print function, the new len which now prints is used

Ok, but the error is more of a syntax error. If I did this in an interview, you wouldn't accuse me of a lack of some ineffable human quality of "deep understanding". Anyway, I asked it to fix it, and behold: def print(list_arg): return len(list_arg) def len(value): __builtins__.print(value)

It's more a logic error. Like swapping two variables, you usually need to create a third temporary one.

Re: Large language models do not recognize identifier swaps in Python

#26
post #19

Earlier quoted context omitted.

The shared link was from my own GPT-4 session. It shows "Model: GPT-4" in the header of my chat from which I shared the link.

How do you set it to 4? I can only find 3.5 somehow.

You must pay for it. ChatGPT Plus. $20 per month.

Re: Large language models do not recognize identifier swaps in Python

#28
post #7

Human programmers will also initially spend 10x of effort working on code base where identifier names are meanongful but swapped. Doing so will employ a lot of inner dialogue such as "this method says close but it is actually reset" and I don't doubt LLMs may be made straight by the same prompts.

Yup. The whole premise of this test is idiotic. When you give a piece of code to an LLM, it doesn't magically switch into "code focused mode". They write:

> 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.

But this is bullshit. Identifier renaming may be a no-op for the code, or even for the compiler/interpreter, but it's absolutely a meaningful change for human programmers. If it weren't, we'd all be calling functions named f0001, f0002, f0003, ... etc. to save space. Like us, LLMs process many different associations at the same time. A function named "print" has a lot of associations that together reinforce the understanding that it will make something the output of the program. Renaming it into len() makes the meaning go against all the association that go with that word.

Swapping print() and len() to use in the same program? That would trip any human up, it's tailor-made to be difficult for us to process. And, as it again turns out, so it is for LLMs, because they really seem to process associations the same way we do (at the gut/intuition/first reaction level).

Re: Large language models do not recognize identifier swaps in Python

#30
post #16
post #5

Earlier quoted context omitted.

Just to point out: this doesn't work since at the point where it defines the new print function, the new len which now prints is used

Ok, but the error is more of a syntax error. If I did this in an interview, you wouldn't accuse me of a lack of some ineffable human quality of "deep understanding". Anyway, I asked it to fix it, and behold: def print(list_arg): return len(list_arg) def len(value): __builtins__.print(value)

But that doesn't fix it? Sure, no more infinite recursion, but now print() calls len() which calls __builtins__.print(). So it's not doing the expected swapped behavior. len() is swapped, but not print().

It seems obvious that there's a lack of understanding of the underlying concept here. That's the whole point. We know that LLMs can generate valid programs, but this is demonstrating that they cannot reason about code. There is no understanding of how Python code is evaluated, and how to avoid the infinite recursion. A human who understands Python could properly handle the situation, but the LLM can't, which is ok, it just demonstrates a flaw.

Post reply on HN