Silly Lossy Text Compression Idea
snufk.in
snufk.in
I think if you have the luxury of assuming every token is a dictionary word, you can do much better by simply encoding each word as its index in the dictionary. Using the pidgeonhole principle, you can probably prove that this is at least as good as the autocorrect approach no matter how sophisticated the autocorrect is.
Then you have to store the dictionary.
Not to mention of course that your computer probably already has 50 copies of it somewhere if you really don't want to bundle it
I see it only working where there's massive pooling, like you say. An OS or a tool provides a known dictionary service and you call into it with a text string and get back an array of indices that you can then decode with another call. That amortizes the dictionary cost among all possible uses of the service, which is a lot if it's a standard well-known service. Another scenario is perhaps in a database\cloud storage\social media, any single text object might be small but the total text they store overall is massive.
You win if the original array of duplicate objects was so long or so duplicated that replacing it with references into the pool is a worthwhile reduction. The objectSize/indexSize ratio also plays some role.
Decades later, they would gather and sit in silence for long periods until one or the other of them would just say something like "47" and all the other would laugh.
The downside is that by reducing redundancy, you reduce your resilience to errors. A single typo could even propagate decoding errors to neighboring words. So maybe get fancier, and include at least one-letter errors in the list of possible words, with lower initial probabilities.
One way to do this would be to use the Viterbi algorithm: https://en.wikipedia.org/wiki/Viterbi_algorithm
Spoken and written languages have roughly a 3x overhead for channel coding. You can get a message across while losing characters and even whole words. Does lossless compression to entropy of text really capture all of the data saving possible? What if you undid some of the channel coding by dropping sets of characters or words then compressing? We don't need to do it (bits are quite cheap), so we don't, but it is an interesting problem that helps think about other problems.
How many letters could be removed from a word and still uniquely identify it? eg. typing -> typg, uniquely -> unqy.
So I thought of applying this process of iterative letter removal to the entire English language: keep removing letters until you conflict with an existing (shortened) word. You'd start with the most commonly used words, so they would be assigned the shortest words.
(Though perhaps a better measure would be typing effort, ie. how much of a pain it is to reach for each key...)
Of course you wouldn't actually communicate in this language, you'd use a text expander software to replace them on the fly with the full words (this exists and works great).
I never ended up doing this, and forgot about it until now. (It would probably only take half an hour though, might do it this afternoon :)
Other fun ideas: make a crappy speech synthesizer, made up of tiny samples of your voice, and a codec that compresses audio of your speech by converting it to a sequence of those samples. (Also works for eg. music, see also: MOD files, which are like MIDI but with custom drum and instrument audio embedded!)
---
Edit: Here's a first draft https://gist.github.com/avelican/fa34a425770c3a8f914c96d75e2...
Used a naive approach, just start with the first letter and see if that's taken, then the first two letters and so on. The output is not optimal and be compressed further (but my lunch break's almost over ;)
Also this one is based on a word frequency list based on Wikipedia, which results in a weird word list and unusual words (that Wikipedia really likes) being near the top of the list. I'll have to collect some of my own conversations and run it on those.
Here's the code if anyone's interested... less than 20 lines of Python (what a great language)
https://gist.github.com/avelican/58f1468df04c3ff542e03288bfd...
Whereas what I'm looking at is a way to put in less effort immediately, ie. just stop typing words (very) early because I have already given my computer enough information to complete them for me.
This suggests using a {first letter}#{last letter} encoding for words where the decompression replaces # with that number of letters chosen randomly.
Even better, it turns out.
byte -> btye -> bt5e
letters -> leertts -> le0,13,2,0s
You'd need to encode the offsets differently of course.
There's probably other compression you can do when order doesn't matter.
"I'm not so sure that would be reliable. Well, I guess that was pretty reliable."
"I'm not so sure that would be reliable. Well, I guess that was pretty readable."
That reduces almost every English word to 4 bytes.
However, it might be possible to do the same trick with pairs of words.
I used a crossword helper this time though.
Can you link me some resources on those optimizations?
But basically, we would be storing the missing information in the decoder, not in the data (which is not bad idea, considering that most most languages are used more than once). If we also only modify the letters that can be recovered successfully...
And also, this would not contradict the pigeonhole principle. Some words would be impossible to store, like a text full of typos. It would require escaping the word somehow, producing documents longer than the original.
>> In the banning go crate the hens and the earth no the earth was formless and empty darkness was or the surface of the dept and the sort of God was hovering ver the worse
(note ideally you could specify more that one character for language selection, which would massively increase the encoding compression but jjst one would be a good start!) Plz help
TL;DR ASCII char encoding can only represent 255 1 byte characters My proposed scheme enable to have N * 255 * 255 1 byte characters. With a constant cost per string of 1 byte. This seems revolutionary.
So, in essence, you want to add metadata to switch dictionaries, it is feasible: {Dictionary}{id}. You would have to consider out of dictionary words too.
By the way, note that UTF-8 is "compressed" (unlike UTF-32). Some languages don't use spaces to separate words, so you would have metadata problems in common languages like Chinese.
What I have done, and works pretty well, is using dictionary compression: sort a dictionary by frequency, replace the word with the rank in the dictionary (in base64 or something high), use spaces to separate words and use a dedicated symbol to escape out of dictionary words. Oh, and I was compressing lower case, mostly Spanish words. It gave me around 50% compression AND it can be used to run NLP algorithms without decompressing the data (like word2vec or TF-IDF).
https://arxiv.org/abs/1311.2540
> The modern data compression is mainly based on two approaches to entropy coding: Huffman (HC) and arithmetic/range coding (AC). The former is much faster, but approximates probabilities with powers of 2, usually leading to relatively low compression rates. The latter uses nearly exact probabilities - easily approaching theoretical compression rate limit (Shannon entropy), but at cost of much larger computational cost. Asymmetric numeral systems (ANS) is a new approach to accurate entropy coding, which allows to end this trade-off between speed and rate: the recent implementation [1] provides about 50% faster decoding than HC for 256 size alphabet, with compression rate similar to provided by AC. This advantage is due to being simpler than AC: using single natural number as the state, instead of two to represent a range. Beside simplifying renormalization, it allows to put the entire behavior for given probability distribution into a relatively small table: defining entropy coding automaton. The memory cost of such table for 256 size alphabet is a few kilobytes. There is a large freedom while choosing a specific table - using pseudorandom number generator initialized with cryptographic key for this purpose allows to simultaneously encrypt the data. This article also introduces and discusses many other variants of this new entropy coding approach, which can provide direct alternatives for standard AC, for large alphabet range coding, or for approximated quasi arithmetic coding.
Check out his other papers / the github project (looked super interesting and similar).
> My proposed scheme enable to have N * 255 * 255 1 byte characters. With a constant cost per string of 1 byte. This seems revolutionary.
The main issue in this context would be limitations in encoding enough languages - there are too many characters (144k in unicode) to encode in 256 code pages (16k max). Additionally, frequently switching code pages (for example swapping back to ascii to use Latin chars / numbers) would incur a large cost on the size of the string
Also note that some of the 'earlier' unicode symbols that don't fit into ascii are in 2 bytes as well, it's not just 1/3/4!
[0] https://github.com/DennisMitchell/jellylanguage/wiki/Tutoria...