Hacker News new | ask | show | jobs
by TZubiri 2 days ago
I noticed something about LLM code generation and this is as good as place to post the finding as any.

It's fairly obvious, but as we know LLMs choose the highest probability next token, so when generating code, it does so from left to right, without ever reorganizing, which unless it uses a harness, that's not how WE write code, that's property 1.

Property 2 is that it will write out as many boilerplate that occurs before the actual implementation as it can, because boilerplate is always the same, and implementation is high temperature/chaotic, there's many different ways an implementation can go. For example in python, you can write your code directly, or wrap it in a main loop and later add a main guard. LLMs will always write the main loop, since it's not competing with NOT writing a main loop, it's competing with the best option in the set of non-main loop solutions. This is trivial in this case because all non main solutions are present in the main loop solution set, but for solutions where the two sets are distinct, the LLM will have a bias towards solutions that share initial tokens, e.g:

Solution 1: import lib1 and use function A 30%

Solution 2: import lib1 and use function B 25%

Solution 3: import lib2 and use function A 45%

Despite solution 3 being weighted more heavily, the LLM will opt for solution 1, since solution 2 makes it choose the import lib1 token.

This pushes towards mega-libraries instead of composable Unix libraries. Stuff like numpy, react or helper libraries get a boost since they are more like megaframeworks than specific libraries, and they get their import statements boosted.

1 comments

> unless it uses a harness

Sorry for skipping over your actual argument, but if it hinges on that assumption then it's probably moot. I'd assume almost all ai generated code that makes it into codebases is produced using a harness.

if it uses a harness, the effect is still there, just piled on and magnified.

I sometimes gen code without a harness and copy paste it or manually type it, maybe I can do like 200 lines in a day? Whenever I see someone coding with a harness it's like 100x times that, so this phenomenon will happen hundreds times more.