r/compression • • 4d ago

Neuralzip: lossless neural text compression, including model weights in the archive

Disclosure: I used AI assistance for development

I built Neuralzip, an open-source Python library for lossless text compression using a small neural model and arithmetic coding.

The model is trained on the input text. Its weights are stored alongside the encoded stream, metadata, and checksum in one archive. Decoding uses the saved model without retraining.

Results from two saved research models:

InputOriginalgzip-9Neuralzip
5 book collection3,120,899 B1,191,527 B791,134 B
Alice in Wonderland151,094 B53,249 B63,048 B

The five-book archive is 33.6% smaller than gzip-9. Gzip wins on Alice, and PPMd produced a smaller five-book archive at 763,603 bytes.

Neuralzip sizes include the model weights and complete encoded stream. Shared decoder/runtime installation sizes are excluded. Both archives were decoded and compared with the original bytes.

Encoding requires training, decoding also evaluates the model, and both are much slower than conventional codecs. Small inputs can grow because of model overhead. These measurements use saved research checkpoints; fresh training runs can differ.

python -m pip install neuralzip
neuralzip encode notes.txt
neuralzip decode notes.txt.nzip

Source · PyPI

I’d appreciate feedback on the archive accounting, implementation, and which datasets and baselines would make the next evaluation useful.

2 Upvotes

3 comments sorted by

3

u/red38dit 4d ago

A text file with a lot of json:

Original - 109.6 KB Neuralzip - 53.5 KB (sloooooooow) XZ - 16.5 KB (fast)

-1

u/Agatsuma_Zenitsu_21 4d ago

i didn't test a lot of json files, but i wasn't focussing on actual practical usecases right away. embedding info within models just sounded fun to me