jll29
5 days 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.
stingraycharles
4 days 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
4 days ago
Or maybe make a list of the most used 1000 words in each language. And see which list has the most occurrences.
wongarsu
4 days ago
That requires you to decide what a "word" is, which is not trivial (if you think that ignoring punctuation gets you to a clean "letters surrounded by spaces" you will get lots of issues with various Asian languages)
Also some languages have a lot of prefixes and suffixes on their verbs or even nouns, which dilutes your list of 1000 words by just adding the same common words over and over again with different suffixes designating grammatical tense, grammatical gender, etc.
The gzip version sounds more general and more obviously correct
basilgohar
4 days ago
Instead of deciding on words, maybe you can break them up into smaller, subword parts – let's call them "quantums". And these quantums can be the units the quantumizer works on to operate on inputs and outputs. We can then use them to build Expansive Dictionary Models, or EDMs. I suppose we'd need a software library to mak working on this easier, think something speedy, fast, hot, like fire: we can call it PHPFlame...
ashkankiani
4 days ago
I'm guessing this is an allusion to reinventing something that already exists, but do you mind explaining what that is to me, since I don't know?
dspillett
4 days ago
It is describing essentially how tokenisation is done for LLMs (Large Language Model → Expansive Dictionary Model).
giancarlostoro
4 days ago
You mean Quantumnisation ;)
BobaFloutist
4 days ago
I suspect they're talking about LLM tokens.
colejohnson66
4 days ago
Even German has issues with "letters surrounded by spaces". They love to smash words together to get one giant word.
thesz
4 days ago
Byte Pair Encoding [1] will be different for different languages. Application of the per-language BPEs to the input text will produce encodings with different lengths.
[1] https://en.wikipedia.org/wiki/Byte-pair_encoding
It naturally takes care of common prefixes and suffixes.
It is easy and fast to apply using radix tree or with finite automata. Even without radix tree, it is possible to have processing speed in the range of hundredths of thousands of bytes per second.
kragen
4 days ago
You can just use 2-grams of Unicode code points.
npb
3 days ago
Very much agree. Character bigrams will solve this perfectly with tiny amounts of training data (like a couple KB).
ignoramous
4 days ago
See: Fast Static Symbol Table: https://github.com/duckdb/duckdb/pull/4366
FSST is based on a fixed size (255 items) dictionary of high frequency variable length strings/substrings (learned from the corpus) encoded as one byte.
wodenokoto
4 days ago
Just collect common bi- and trigrams and a naive bayesian classifier.
actionfromafar
4 days ago
Sounds like the best approach. :)
LPisGood
4 days 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
4 days 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
4 days ago
The "ass." more likely stands for "assuming".
chrisweekly
4 days ago
Yeah, I read it as "assuming" too.
arrowsmith
4 days ago
3Blue1Brown has a good video about this: https://www.youtube.com/watch?v=l6DKRf-fAAM
myrmidon
4 days 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.
user
4 days ago
akoboldfrying
4 days ago
You're right, you should subtract off the compressed sizes of the respective reference files before comparing. (This suffices if we assume that later input data does not influence the compression of earlier input data, which is true except for certain unusual conditions like a repeated substring at the end of the reference data that also appears at the beginning of the test data.)
woadwarrior01
4 days 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...
chris_va
4 days 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.
mrtnmcc
4 days ago
You might also want the topic files to be compressed against each other to get a baseline matrix and then multiply any results by the inverse, assuming equal priors on the topics.
user
4 days ago
Lerc
4 days ago
I seem to remember it being shown for character recognition via JBIG. Maybe in Managing Gigabytes?
ape4
4 days ago
There would be some overlap with business sports analogies - eg team huddle.
jjtheblunt
4 days ago
we were doing this in Qualcomm 20 years ago
anthk
4 days ago
Is pigz faster?
m-hodges
4 days ago
[dead]