Live data from Hacker News

OpenAI is good at unminifying code

glama.ai

261–270 of 321 posts

Re: OpenAI is good at unminifying code

#261
post #97

Author of HumanifyJS here! I've created specifically a LLM based tool for this, which uses LLMs on AST level to guarantee that the code keeps working after the unminification step: https://github.com/jehna/humanify

Does it work with huge files? I'm talking about something like 50k lines. Edit: I'm currently trying it with a mere 1.2k JS file (openai mode) it's only 70% done after 20 minutes. Even if it works therodically with 50k LOC file, I don't think you should try.

It does work with any sized file, although it is quite slow if you're using the OpenAI API. HumanifyJS works so it processes each variable name separately, and keeps the context size manageable for an LLM.

I'm currently working on parallelizing the rename process, which should give orders of magnitude faster processing times for large files.

Re: OpenAI is good at unminifying code

#262

You can do this on minified code with beautifiers like js-beautify, for example. It's not clear why we need to make this an LLM task when we have existing simple scripts to do it?

While this doesn't restore minified identifiers, like the LLM version claims to do, it tends to help a lot with understanding the code. Usually minified code still has the original identifiers in global function names, object attributes, DOM classes and a few other places where it is hard to guarantee no side effects of name mangling. This makes guessing the purpose of the remaining identifiers substantially easier to a human, and it is probably also the main reason why an LLM is capable of making reasonable guesses at what they could reasonably be called.

Re: OpenAI is good at unminifying code

#263
post #97

Author of HumanifyJS here! I've created specifically a LLM based tool for this, which uses LLMs on AST level to guarantee that the code keeps working after the unminification step: https://github.com/jehna/humanify

how do you make an LLM work on the AST level? do you just feed a normal LLM a text representation of the AST, or do you make an LLM where the basic data structure is an AST node rather than a character string (human-language word)?

I'm using both a custom Babel plugin and LLMs to achieve this.

Babel first parses the code to AST, and for each variable the tool:

1. Gets the variable name and surrounding scope as code

2. Asks the LLM to come up with a good name for the given variable name, by looking at the scope where the variable is

3. Uses Babel to make the context-aware rename to AST based on the LLM's response

Re: OpenAI is good at unminifying code

#264
post #97

Author of HumanifyJS here! I've created specifically a LLM based tool for this, which uses LLMs on AST level to guarantee that the code keeps working after the unminification step: https://github.com/jehna/humanify

Thanks for your tool. Have you been able to quantify the gap between your local model and chatgpt in terms of ‘unminification performance’?

At the moment I haven't found good ways of measuring the quality between different models. Please share if you have any ideas!

For small scripts I've found the output to be very similar between small local models and GPT-4o (judging by a human eye).

Re: OpenAI is good at unminifying code

#265
post #97

Author of HumanifyJS here! I've created specifically a LLM based tool for this, which uses LLMs on AST level to guarantee that the code keeps working after the unminification step: https://github.com/jehna/humanify

How well does it compare to the original un-minified code if you compare it against minify + humanify. Would be neat if it can improve mediocre code.

Re: OpenAI is good at unminifying code

#266
post #97

Author of HumanifyJS here! I've created specifically a LLM based tool for this, which uses LLMs on AST level to guarantee that the code keeps working after the unminification step: https://github.com/jehna/humanify

Finally someone else using ASTs while working with LLMs and modifying code! This is such an under-utilized area. I am also doing this with good results: https://codeplusequalsai.com/static/blog/prompting_llms_to_m...

Super interesting! Since you're generating code with LLMs, you should check out this paper:

https://arxiv.org/pdf/2405.15793

It uses smart feedback to fix the code when LLMs occasionally do hiccups with the code. You could also have a "supervisor LLM" that asserts that the resulting code matches the specification, and gives feedback if it doesn't.

Re: OpenAI is good at unminifying code

#267
post #97

Author of HumanifyJS here! I've created specifically a LLM based tool for this, which uses LLMs on AST level to guarantee that the code keeps working after the unminification step: https://github.com/jehna/humanify

How well does it compare to the original un-minified code if you compare it against minify + humanify. Would be neat if it can improve mediocre code.

On structural level it's exactly 1-1: HumanifyJS only does renames, no refactoring. It may come up with better names for variables than the original code though.

Re: OpenAI is good at unminifying code

#270

This is an example of superior intellectual performance to humans. There’s no denying it. This task is intellectual. Does not involve rote memorization. There are not tons and tons of data pairs on the web of minimized code and unminified code for llms to learn from. The llm understands what it is unminifying and it is in general superior to humans on this regard. But only in this specific subject.

Umm yeah there are tons of examples in Github repos.
Post reply on HN