Top
Best
New

Posted by networked 7 hours ago

Can gzip be a language model?(nathan.rs)
268 points | 100 comments
jll29 5 hours ago|
Yes: you can classify a test file by topic with gzip as follows:

  gzip -9 sports.txt   testfile.txt

  gzip -9 politics.txt testfile.txt

  gzip -9 business.txt testfile.txt
(ass. sports.txt politics.txt and business.txt are text docs pertaining from the sports, politics and business domains, respectively, and have equal size)

The test file belongs to the topic with the smallest size *.gz file.

Witten's group at Waikato uni were perhaps the first to work on this.

Also check out the Hutter prize if you are interested in this.

chris_va 1 minute ago||
We used a similar technique for a class project (N decades ago) to test this:

https://en.wikipedia.org/wiki/Baconian_theory_of_Shakespeare...

By looking at mutual information from different authors on the same topic vs same author on different topics. As I recall, it convincingly disproved the hypothesis.

mgaldys4 42 seconds ago|||
That's a bit of a stretch. The LZ77 algorithm merely finds repeated items within a sliding window and encodes them into Huffman codes. A basic model should at least be capable of classification and prediction, like very early-stage machine models. The former is a fixed, quantifiable algorithm, whereas the latter becomes difficult to quantify and understand once the scale of neurons grows large. It's not very reasonable to regard the two as the same thing.
stingraycharles 3 hours ago|||
Back in the day - maybe two decades ago - I implemented language detection like this.

I seeded gzip compressors’ dictionaries with Wikipedia articles in different languages.

I would then try to use said dictionaries on any random text, and the one that was best able to compress it, was the correct language.

Absolutely totally not the best approach, but very fast and super simple to implement.

ape4 6 minutes ago|||
Or maybe make a list of the most used 1000 words in each language. And see which list has the most occurrences.
actionfromafar 31 minutes ago|||
Sounds like the best approach. :)
ape4 3 minutes ago|||
There would be some overlap with business sports analogies - eg team huddle.
Lerc 6 minutes ago|||
I seem to remember it being shown for character recognition via JBIG. Maybe in Managing Gigabytes?
LPisGood 3 hours ago|||
There are some deep connections between machine learning, compression, and cryptography with information theory as a common thread.

Also, I’ve never seen “ass.” Used to shorten “aside” — I typically use N.B. but perhaps only for important ones.

shoo 3 hours ago|||
For anyone wanting an introductory text for information theory & that explores some of these connections & applications, it's worth checking out the late David MacKay's 2003 textbook Information Theory, Inference & Learning Algorithms https://www.inference.org.uk/itila/
matzf 2 hours ago||||
The "ass." more likely stands for "assuming".
chrisweekly 1 hour ago||
Yeah, I read it as "assuming" too.
arrowsmith 3 hours ago|||
3Blue1Brown has a good video about this: https://www.youtube.com/watch?v=l6DKRf-fAAM
myrmidon 26 minutes ago|||
Nitpick: Doing it exactly like this is flawed because you let the compressibility of your references taint the result; what you would prefer is the compressed size of testfile given sports.txt/... as a dictionary without accounting for the compressed size of that, no?

Really interesting approach though.

woadwarrior01 3 hours ago|||
aka Normalized compression distance (NCD). Its close cousin: Normalized Google distance (NGD) is also super interesting!

https://en.wikipedia.org/wiki/Normalized_compression_distanc...

m-hodges 2 hours ago||
[dead]
logicallee 1 minute ago||
It's an interesting experiment, though the examples in the article didn't really seem that coherent, so I'm not sure that the answer to the title is "yes". Along the same lines, a few years ago I made a very tiny transformer demonstration in javascript, also trained on Shakespeare, but it was too small to produce text like Shakespeare. You can try it here:

https://taonexus.com/mini-transformer-in-js.html

I guess the results are similar to the article, maybe a little more coherent since the tokens are words.

Culonavirus 6 hours ago||
This tracks perfectly with Winrar being more profitable than OpenAI... coincidence? I think not!
wolfi1 6 hours ago|
winrar is profitable? sure? well, on the other hand, they sure don't make losses
shezi 5 hours ago||
They are a German GmbH and must publicly state their financials: https://www.northdata.de/win%C2%B7rar%20GmbH,%20Berlin/Amtsg...

Looks pretty profitable to me.

amiga386 5 hours ago|||
They're one of the few companies that actually manage to sell "boxed software" (i.e. has not changed much in years but new customers keep buying it)

That said, Windows users should use 7-Zip. Better compression format, unpacks more kinds of archives

TonyTrapp 31 minutes ago|||
While I also like 7z a lot and use it all the time, it's really not a better format that RAR. Higher compression ratios? Sure, marginally. But for archival RAR is still the better choice as it supports recovery records, which 7z still does not. I also found it more difficult to restore data from a partial 7z file (i.e. trailer data is missing) compared to an incomplete RAR file.
xxs 5 hours ago|||
> Windows users should use 7-Zip

Please no - no native zstd support. NanaZip is the better option (it's a different build of 7-zip) and it's available at windows store.

> Better compression format, unpacks more kinds of archives

winrar has supported zstd for 5 years[0]

In short - Everyone should be using zstd, and 7-zip does not support it.

[0]: https://www.win-rar.com/singlenewsview.html?&L=0&tx_ttnews%5...

ndriscoll 15 minutes ago|||
zstd is a good default for e.g. filesystem compression, but if you're making an archive file, presumably you're looking for higher compression and LZMA would be a better fit.
tnelsond4 3 hours ago||||
Yeah, zstd is awesome. I built a webapp that uses it via wasm and the decompression speed is incredible, so much so that I store everything in zstd and decompress it on the app load. My wasm binary also does advanced search and tag insertion and stuff in addition to zstd but it's only 38kb. I wish zstd was supported natively by web browsers. The 8kb implementation of zstd is only half as slow as wasm, so even that is still viable.
cgio 3 hours ago||
Lzma. I did a simple test, same payload repeated with a gap. Lzma ruled it.

|gap |gzip |bz2 |lzma | |---------|----------|-----|--------| |0 |2.7% |18.9%|*0.9%*| |8 KB |2.4% |17.8%|0.9% | |*40 KB*|*94.4%* |17.7%|0.4% | |1 MB |*104.3%*|19.7%|*0.9%*|

notpushkin 1 hour ago||
HN doesn’t support Markdown tables. You can prepend two spaces to show it in monospace though.

I don’t see zstd in your comparison?

Sweepi 21 minutes ago||
dont know the point of the table, but here it is:

  |gap      |gzip      |bz2  |lzma    | 
  |---------|----------|-----|--------|
  |0        |2.7%      |18.9%|  *0.9%*| 
  |8 KB     |2.4%      |17.8%|   0.9% |
  |*40 KB*  |*94.4%*   |17.7%|   0.4% |
  |1 MB     |*104.3%*  |19.7%|  *0.9%*|
aleph_minus_one 4 hours ago|||
> Everyone should be using zstd

Why?

shawabawa3 4 hours ago|||
It's just the best general purpose compression algorithm, in terms of compression ratio to CPU used, for the vast majority of use cases
xxs 3 hours ago|||
It's just this good.

On a more realistic note: few years back, I've added zstd compression to our log subsystem (hand written direct buffers, native code, in-process, java). For the same CPU utilization if provides twice dense compression compared to regular [-6] gzip (the topic in the title). Zstd is =much= faster on decompression as well, and it this case - unparalleledly better as it uses twice less disk.

zstd is 'silicon valley' (the tv show) - life imitates fiction, except entirely open source

dd8601fn 5 hours ago||||
Huh. I guess the warez kids grew up and have money, now?
cavoirom 57 minutes ago||
There is 2 softwares I will buy for myself if I still use Windows: WinRAR and Internet Download Manager. In fact, I will buy them in the future regardless the Windows usage.
jurgenburgen 5 hours ago||||
That’s surprising. Seems there is a niche for everything.
Betelbuddy 4 hours ago||
You need to visit Japan...
firtoz 4 hours ago|||
TIL they're Turkish
tecleandor 4 hours ago||
The original author and also creator of the RAR format, Eugene Roshal, is Russian. I think he moved to the US way back in the day, but not sure about that. He has been very private with his life.

The company doing the software distribution, is located in Berlin. The Managing Directors for that company seem to have Turkish names, but I don't know if they're Turkish.

BTW, Looking for some info I just found a website [0], clearly AI generated (but not necessarily meaning the content is false) claiming Eugene Roshal had severe kidney failure this past month, and he's waiting for surgery. They're asking for donations. There are some names on who's theoretically behind it [1] but they don't link to any LinkedIn profile or personal site. I can't find any other references. The BTC wallet they're using for donations hasn't seen any traffic ever. BE WARY, SMELLS FISHY.

--

  0: https://eugeneroshal.org/
  1: https://eugeneroshal.org/about/
grezql 37 minutes ago||
[dead]
ronfriedhaber 3 minutes ago||
See also the Hutter Prize [1]. Compression is a subset of Intelligence.

[1] https://en.wikipedia.org/wiki/Hutter_Prize

mg 6 hours ago||

    give it a normal text prompt, and it
    continues that prompt by searching
    for the byte sequences that compress
    best.
One moment, how are we supposed to know how well that search was done? There is no way to search a meaningful part of the search space.

So the result only gives us some lower bound of how well gzip works as a "plausibility tester" of a continuation of a text. The space of possible sequences is many orders of magnitude larger than what was searched. So there might be sequences in there that compress much better.

The text mentions beamsearch, but I don't see a discussion about how well beamsearch performs in finding the global optima when it comes to gzip compressibility of a text?

StilesCrisis 2 hours ago||
Read to the end: they aren't actually looking for the best-compressing output, because this quickly devolves into aaaaaaaaaaa. They keep a sliding window over a small portion of recent text and use that.

Basically I think the entire premise falls apart due to that choice--they forced an interesting-looking outcome by adjusting the algorithm until gzip started picking random slabs of letters instead of ever-larger repeating runs.

im_down_w_otp 38 minutes ago||
Meh. That’s nothing compared to the amount of curation and tuning the LLMs are coerced with.
shoo 5 hours ago||
That's a fair question. Suppose we have a way to find a byte sequence x that globally minimises len(gzip(context + prompt + x)) over all sequences x of length n. Here + denotes string concatenation.

It's unclear if this is very useful.

The reason it may not be very useful is that one of Deflate's ingredients is a pass that replaces repeated substrings with backreferences to the earlier occurrence in the plaintext input stream.

E.g. suppose we want to find an n=200 byte sequence x that minimises len(gzip(context+prompt+x)).

If there exists any 200 byte sequence y such that prompt+y is a substring of context, then Deflate can encode prompt+y as a backreference to that earlier sequence - it needs to store a match-length & a distance-length, encoded using its Huffman trees. This candidate solution y may not be a global minima to our stated objective function, but if not, it's probably going to be a very good near-optimal approximate solution.

Taking a step back, repeating huge chunks of the input context produces something that's great for minimising compressed output size but doesn't seem particularly helpful as a generative model.

edit:

Yep, I tried it out by running an experiment. Searching for the prompt in the context & then copying the following text as the solution produces solutions that are much better, in the sense of minimising the compressed output length, than beam search, while also being unhelpful as a generative tool.

With the same example as the blog post:

  context: first 30,000 bytes of tinyshakespeare.txt
  prompt: 'MENENIUS:\n'
Let x denote a solution, x is a string of length 200.

Let L(x) denote len(gzip(context+prompt+x)), our objective function

Let's call the proposed search method of searching for the prompt in the input rfind (after python's str.rfind).

Then we have

   search method      soln               soln length   feasible?     objective value      search time (wall clock, s)
   -------------      ----               -----------   ---------     ---------------      ---------------------------
   emptystring        ""                          0          no              13,023                     0.04s
   gzipt beam search  see blog post             200         yes              13,051                    11.93s
   rfind              see below                 200         yes              13,026                     0.04s

So 'rfind' is finding a solution that does a better job of minimising the objective function -- it only takes 3 bytes more to encode than the infeasible emptystring solution, and costs 25 fewer bytes than the solution found by the beam search implemented by gzipt per the blog post.

Here's the solution 'generated' by rfind copying and pasting from the input context, starting from the rightmost occurrence of "MENENIUS:"

   MENENIUS:
   O, true-bred!
   
   First Senator:
   Your company to the Capitol; where, I know,
   Our greatest friends attend us.
   
   TITUS:
   
   COMINIUS:
   Noble Marcius!
   
   First Senator:
   
   MARCIUS:
   Nay, let them follow:
   The Volsces 

Here's the code for 'rfind' - our complete 'generative algorithm':

    def find_candidate_solution_from_context(context, prompt, length):
        n = len(context)
        i = context.rfind(prompt, 0, n-length)
        if i < 0:
            return b''
        i += len(prompt)
        return context[i:i+length]

Can hook it into gzipt.py by adding this line after out is defined, but before the beam search begins

    out += find_candidate_solution_from_context(corpus_window, prompt, length)
GodelNumbering 5 hours ago||
3blue1brown did a series on this topic: https://www.youtube.com/watch?v=l6DKRf-fAAM https://www.youtube.com/watch?v=GlYgs6v2YfU (i think one more is yet to release)
montebicyclelo 5 hours ago||
This is fun, but historically people have gone a bit overboard with saying that models like this, or n-gram language models, are anywhere close to large neural network models. There is certainly a connection though.
Matumio 4 hours ago|
Yes, but it is a useful insight that both methods try to solve the same mathematical problem. It's better than thinking of LLMs as magic.

When you say "cross-entropy loss" people without stats background go to Wikipedia, take a glance, and adjust their mental model to "inscrutable magic".

Thinking of the main difference as the trade-off in how much CPU, memory and storage is allowed is not really wrong.

The part that is wrong is to think of gzip as a method that might reach similar complexity or generalization. And more importantly, to ignore the advanced way how training data gets curated or generated for (instructed, chain-of-thought) LLMs. But even then. The mental model that the LLM's goal is text compression is not wrong. The question to ask next is what kind of text it is expecting to compress.

montebicyclelo 3 hours ago||
Yep agree, good details, and this doesn't contradict my point above, about people going "overboard" with the comparison.

I do think when making these comparisons, it is worth emphasising that neural nets are really different. E.g. I used to see people equating LLMs to n-gram models, etc. which is overly simplistic, (especially in the early days when the models weren't as good).

colinmarc 3 hours ago||
Would this work with video compression? Video codecs encode a lot of meaning; they use motion vectors to track the movement of objects on screen, for example.
adityaathalye 4 hours ago||
I think language itself is compression, so the arxiv paper tracks for me.

Viz. if Language is compression (of thought / culture / the tacit je ne sait quois of being-to-being communication etc.), then definitionally, Language Modelling must also be Compression.

Except, language is an arbitrarily lossy compressor, who's "compression-prediction equivalence" is indeterminate and unstable, because Language co-evolves constantly; both as a function of or response to culture, as well as an influencer of culture.

So, the subjective-objective goodness of Language Models (of any kind of language) would be, at best, upper-bounded by the compression-prediction equivalence of the Languages corpus itself. And that is assuming the language corpus is perfect in every way---it captures all knowledge expressible by language and it is always in-sync with live evolution of all language expression and evolution (i.e. LLM training is not a batch job, but a real-time present continuous process).

For example, to my layperson eyes, the mathematical language of proofs actively weeds out ambiguity of subjective interpretation. Ideally, a proof ought to lead to the exact same conclusion on every single reading by any reader who can follow the steps. A proof also holds only if the rest of the formal, explicit, inviolable, internally-consistent set of axioms and results holds.

So it stands to reason that mathematical prose of proofs, being optimised as mechanical procedure of taking an open question to a deterministically closed solution, has better odds of approximating the tacit aspects of mathematical derivation.

Which makes an LLM able to construct a mathematical proof, which is mind-melting to say the least.

However, I wonder, can LLMs dream of mathematical sheep?

cestith 29 minutes ago|
Language is compression of a sort. A dictionary is a decompressor. You look up one word, and you may get a paragraph about its meaning. An encyclopedia can be thought of as roughly the same with more detail for some nouns.

It makes a lot of sense why dictionary-based compression is named the way it is. A shorter symbol is used to store information that would take more symbols in the uncompressed corpus, if the shorter symbol hadn't been assigned to represent it. That's in a way just what an actual dictionary on your English professor's shelf does. The big difference is your compressor is coining new short symbols all the time.

berkes 5 hours ago|
I've been pondering on something related: can an LLM be a chat?

Some models are reproducible, in that the same prompt will generate the same output. Say that we could wire up such a model to generate some code.

In that case, we could create a prompt that generates, say, an entire codebase, or a large piece of text. The prompt (or really, the tokens) would then be the compressed version of the codebase or the text.

I am not talking about an "AI agent", but really a model that we call in a reproducible manner. Preferably one call, with one prompt. An agent could just run `git clone` to "decompress" a codebase, which conflates the idea of compression. If that were compression, then the "compressed version of the git kernel" would be a single line of text: `git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...`. I am really talking about having an LLM re-generate text based on a prompt.

Does that make sense? I can imagine that this is highly impractical and inefficient. But would this count as "compression" at all?

evgpbfhnr 5 hours ago||
You're describing https://bellard.org/ts_zip/ ("Text Compression using Large Language Models") ?
stackbutterflow 4 hours ago||
Man,did that page load fast. It made me realize how slow the rest the (my) web is.
eru 4 hours ago|||
You sound a bit confused.

A large language model itself (the network) give you the probabilities for the next token given some prefix of tokens so far. You can use arithmetic coding to go from these probabilities to a deterministic compression / decompression algorithm.

When you use an LLM to generate text, you sample from that probability distribution. You can use a true random sample. Or you can make it trivially deterministic by using a seeded pseudo-random-number-generator or you just pick the highest probability each time. But that's all a red herring; really, what you want is arithmetic coding.

https://en.wikipedia.org/wiki/Arithmetic_coding

meindnoch 2 hours ago|||
>I've been pondering on something related: can an LLM be a chat?

A chat?

>I am not talking about an "AI agent", but really a model that we call in a reproducible manner.

An LLM is just as deterministic as any other computer program. For identical inputs (which includes the PRNG seed) it produces identical outputs.

>compressed version of the git kernel

The git kernel, got it.

>But would this count as "compression" at all?

Yes. The decompressor is several tens of gigabytes though.

foldr 2 hours ago||
>An LLM is just as deterministic as any other computer program. For identical inputs (which includes the PRNG seed) it produces identical outputs.

This is not really true in practice because of multi-threading and out-of-order execution. Mathematically equivalent orderings of operations are not equivalent when dealing with floating point values, so most practical LLM implementations end up being non-deterministic.

vasco 3 hours ago|||
Sounds like an interesting way for future OS included apps to be distributed.

Like when you click the Calculator button on your android, it wouldn't actually exist yet, your click actually prompts it into existence. But naively that has problems because you don't want a different UI every time. There's something to your idea.

StilesCrisis 2 hours ago||
Someone did it!

https://youtu.be/7NfyZhV1dKM?is=YOUXCHuFUiPdlD0p

dist-epoch 3 hours ago|||
This was tried many times in the past for images, even before LLMs.

https://imalogic.com/blog/2024/06/03/image-compression-decom...

flyinglizard 3 hours ago||
It makes a lot of sense. I thought about it in the context of pull requests or change sets: if the text-to-code process is reliable, why don't you give me prompts instead of code? Code becomes just an intermediate representation.
More comments...