News for hackers. Stuff that matters.
Re:Short Message Compression Using LLMs by gliptic on Monday December 30, 2024 @01:50PM (#42552286)
I'm pretty sure it doesn't use ranking. That leaves a lot of performance on the table. Instead you would use the actual predicted token probabilities and arithmetic coding.
Re:Short Message Compression Using LLMs by antirez on Monday December 30, 2024 @02:08PM (#42552425)
I supposed it used arithmetic coding with the ranking bacause they have a distribution easy to exploit: zero more likely, one a bit less and so forth. What's your guess? Unfortunately Bellard is as smart as hermetic. We are here guessing what should be a README file.
Re:Short Message Compression Using LLMs by gliptic on Monday December 30, 2024 @02:17PM (#42552481)
The model gives you a probability distribution over the tokens. You could use that directly with arithmetic coding, but there are ways to convert that to a distribution over e.g. the next byte instead which would improve efficiency further by removing the redundancy in alternative token encodings. ts_zip does this, and README says this works similar to ts_zip.

EDIT: Hm, or maybe ts_zip uses just the token probabilities directly. I thought it was slightly more efficient about it.

"The language model predicts the probabilities of the next token. An arithmetic coder then encodes the next token according to the probabilities."

Re:Short Message Compression Using LLMs by antirez on Monday December 30, 2024 @02:27PM (#42552568)
Oh, that makes sense! So they use the probability of the next token itself. Thanks for clarifying. Also clever trick about the multiple potential tokens to represent the same text.
Re:Short Message Compression Using LLMs by gus_massa on Monday December 30, 2024 @02:38PM (#42552652)
If you are going to zip the resulting file, it may be useful to have a lot of 0s.

If you are going to send the result as is, Huffman coding (with some escape for unusal words(?)) will be better. I think even better than the other method that forgets the probabilities and then tries to compresd it.

Re:Short Message Compression Using LLMs by antirez on Monday December 30, 2024 @02:41PM (#42552678)
Just to clarify: even storing ranking, here would likely produce good results, but not as good as storing the probability, since it exploits better the ability of arithmetic coding to store this fractional intervals. But here the fundamental trick is that the LLM can compress the "next in sequence" information in a distribution that is much better to compress than the initial data itself.
Re:Short Message Compression Using LLMs by gliptic on Monday December 30, 2024 @02:51PM (#42552753)
This is especially true for instance when you have two or more tokens that are about equally likely, or one token that is virtually certain, which ranking would obscure.
Re:Short Message Compression Using LLMs by antirez on Monday December 30, 2024 @03:55PM (#42553396)
Indeed.
Re:Short Message Compression Using LLMs by astrange on Tuesday December 31, 2024 @08:45AM (#42558662)
Arithmetic coding is better than Huffman coding because it can use a fractional number of bits per code, while Huffman has to use a whole number of bits.

IIRC the only reason it wasn't always used for everything is patents. A secondary reason being that it can be slow if you design it without thinking about performance, eg if you use divisions.

Re:Short Message Compression Using LLMs by gliptic on Tuesday December 31, 2024 @10:15AM (#42559161)
Huffman still has a performance edge for static distributions. ANS bridges some of the performance gap between arithmetic coding and huffman.
Re:Short Message Compression Using LLMs by astrange on Thursday January 02, 2025 @11:59PM (#42582606)
But there's no such thing as a static distribution :)
Re:Short Message Compression Using LLMs by bravura on Monday December 30, 2024 @10:20PM (#42556106)
antirez, it's probably identical to the approach in this paper: Li et al 2024, "Evaluating Large Language Models for Generalization and Robustness via Data Compression" (https://ar5iv.labs.arxiv.org/html//2402.00861).

There's a pretty straight line from assigning probabilities (to a sequence of tokens) to arithmetic compression as an optimal compression algorithm for that distribution.