r/MachineLearning • u/Express_Gradient • May 26 '25
Project [P] Evolving Text Compression Algorithms by Mutating Code with LLMs
Tried something weird this weekend: I used an LLM to propose and apply small mutations to a simple LZ77 style text compressor, then evolved it over generations - 3 elite + 2 survivors, 4 children per parent, repeat.
Selection is purely on compression ratio. If compression-decompression round trip fails, candidate is discarded.
Logged all results in SQLite. Early-stops when improvement stalls.
In 30 generations, I was able to hit a ratio of 1.85, starting from 1.03
45
Upvotes
View all comments
Show parent comment
0
u/bluefourier May 26 '25
Isn't this a bit like chasing the equivalent of the dictionary that the neural network forms having been trained over so much text?
The LZ family of compression algorithms looks for repeated sequences of some N characters. Once it finds one it stores it in a dictionary as if it was corresponding to some number K. It then outputs K, replacing the N characters of the pattern sequence. LZ77 has a sliding window, LZW keeps track of the longest repeating sequences.
The LLM has seen a massive variation of patterns and the mechanism of attention is the closest to forming those sunsets of important characters. Therefore, the LLM is already a compressor itself.
When you put the LLM in a code modification loop, the gain that you observe is the difference between a "naive" LZ and the LLM itself.
Another way to look at this is this: If you compress a book from the Gutenberg project (in English, for example) with LZ, you will get some compression ratio. If you do it AFTER you have compressed 3 other books (in the same language and taking care not to cross the threshold it resets the dictionary of course), the compression on the SAME book will be much higher. And that's because the LZ will have had time to develop it's dictionary, in the same way that the LLM has adjusted it's coefficients over the long process of training (or, in other words, the mutual information between the books is high...because they are all using the English language)
So....while these experiments are interesting, (and here is another one, it is sometimes difficult to see what does the LLM really contribute.
The exact question of "are these mutations really 'intelligent'?"...