hn.today

Can gzip be a language model?

nathan.rs214 points80 comments
Screenshot of Can gzip be a language model?

This explores treating a standard DEFLATE compressor (gzip/zlib) as a simple language model by using compression as a proxy for prediction. Because compressors allocate fewer bits to expected byte sequences, continuations that resemble a priming corpus compress smaller; the score for a candidate continuation is the compressed length of (corpus + prompt + candidate). Priming gzip with tiny Shakespeare and searching for continuations yields recognizably Shakespearean fragments, showing the compressor captures distributional structure despite having no learned parameters beyond its sliding 32 KiB window and back-reference mechanism.

Generating text requires more than greedy next-byte selection because gzip reports integer compressed lengths and short increments often tie, producing poor local decisions and self-copying loops. The implementation runs beam search over byte sequences: at each step the context is the corpus window plus the recent tail of prompt+generated text; it expands bytes seen in the corpus, scores each by compressed length, keeps the top beam_width candidates, repeats for a horizon, then commits the best span (or samples with temperature). Keeping only the recent tail in context avoids trivial repeats. The system is a single Python file using zlib, and beam search substantially improves generation quality compared to naive approaches.

Read on nathan.rs80 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Security

Type Punning in C and C++

Type Punning in C and C++

Type punning involves interpreting memory as different types, which is common in low-level programming but can lead to undefined behavior. In C, unions and memcpy are safe methods, while pointer casts are unsafe and violate strict aliasing rules, especially in C++ where the compiler assumes types do not alias. (blog.pwkf.org)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.