Compressed-Language Models for Understanding Compressed File Formats: a JPEG Exploration

## Abstract

Abstract This study investigates whether Compressed-Language Models (CLMs), i.e. language models operating on raw byte streams from Compressed File Formats (CFFs), can understand files compressed by CFFs.
We focus on the JPEG format as a representative CFF, given its commonality and its representativeness of key concepts in compression, such as entropy coding and run-length encoding.
We test if CLMs understand the JPEG format by probing their capabilities to perform along three axes: recognition of inherent file properties,
handling of files with anomalies, and
generation of new files.
Our findings demonstrate that CLMs can effectively perform these tasks.
These results suggest that CLMs can understand the semantics of compressed data when directly operating on the byte streams of files produced by CFFs.
The possibility to directly operate on raw compressed files offers the promise to leverage some of their remarkable characteristics, such as their ubiquity, compactness, multi-modality and segment-nature.

## 1 Introduction

The digital world stores its information in files, and each file follows a format: a standard establishing how information is encoded into a byte structure, such as doc [], or wav []. These formats allow for consistent parsing and predictable encoding of data into byte streams, independent of the specifics of the storage device.
Both storage devices and bandwidth are limited, and so modern standards have defined Compressed File Formats (CFFs), e.g., mp3 [], or zip [].
Unlike traditional formats, CFFs are not directly readable in their compressed state, and must undergo a decoding process to revert the data to its usable form.
As a result, CFFs are complex components of our digital infrastructure, and they have become crucial for efficient storage and transmission of information.

We identify three characteristics of CFFs that are key to their widespread adoption:
(i) Ubiquity:
CFFs are universally recognized and used across both public and private digital collections, making them a standard in data storage.
(ii) Compactness:
CFFs reduce file size while preserving relevant information by exploiting statistical properties and local repetitive patterns, such as Huffman coding [] in JPEG [] and motion vectors in MPEG []—for instance, one GB of compressed video expands to 50-200 GB when decompressed. (iii) Generality:
despite the variety in compression techniques, each CFF method is capable of transforming any type of data, within a specific modality, into a streamlined one-dimensional array of bytes. These virtues of CFFs suggest the potential usefulness of models capable of directly manipulating information encoded with these formats.

Figure: Figure 1: Testing the understanding capacity of “Compressed-Language Models” (CLMs), i.e. language models trained for next-token prediction on byte streams produced by Compressed File Formats (CFFs). We use the JPEG format as a case study for CFFs. We test the CLMs’ understanding of JPEG files by probing their capacity to generate new files, recognize real files, and handle files with anomalies (not displayed in the figure). Our evidence suggests that CLMs can understand JPEG.
Refer to caption: x1.png

A model capable of directly processing the byte arrays in CFFs could manipulate the files’ semantics without needing to decompress them.
Such a model, referred to as a “Compressed Model” (CM), offers significant advantages over traditional models that process uncompressed data.
In particular, we note two virtues of CMs
(1) Compressed Input:
CMs would interact with compressed data, which is inherently compact and less redundant than uncompressed data.
This characteristic eliminates the need for common techniques for reducing redundancy, such as pooling or attention windowing. (2) Raw Input:
CMs could exploit vast archives of compressed data exactly as they are stored, thus bypassing the need for domain-specific pre-processing and enabling efficient data handling.
While these advantages highlight the desirability of CMs, their implementation remains under-specified.

We recognize that the sequence-like property of the byte streams produced by CFFs can inform the implementation of CMs.
Notably, these byte streams exhibit three language-like properties:
syntax, established by the CFFs that produced the streams;
semantics, inherited from the encoded information;
and a finite lexicon, corresponding to their byte alphabet.
Given these attributes, we hypothesize that an effective approach to implementing CMs is through language models [, ].
We term such models “Compressed-Language Models” (CLMs), and argue that this implementation would achieve a third property of
(3) Universality, standardizing the training pipeline:
sequence-to-sequence models as the architecture, next-token prediction as the optimization objective, and CFFs as the universal language for encoding and pre-processing diverse types of information, such as images, text, video, etc.
These facts suggest that constructing a CLM by applying the paradigm of language models on byte streams produced by CFFs is both practical and promising.

Yet, the feasibility of a CLM understanding the byte streams produced by CFFs remains largely unexplored [].
Notably, various properties of CFFs could hinder the understanding of these streams. In particular, CFFs introduce unique complexities with their layered compression schemes, which transform the original data through multiple stages to produce the final byte stream [].
The compact nature of compressed files also implies that even minor alterations in the byte stream or its interpretation could drastically affect the decoded information.
Moreover, since existing language models were not designed with these challenges in mind, it remains uncertain whether they are capable of effectively understanding the “language” of CFFs.

In this study, we test the understanding capability of Compressed-Language Models, i.e. language models trained for next-token prediction on byte streams produced by Compressed File Formats.
There is a wide variety of CFFs, and so, aiming at practicality, we focus our study on the JPEG format [] for encoding image data.
We choose JPEG due to its widespread use and because it directly exemplifies key concepts of CFFs, such as compact representation, byte level encoding, multilayered compression, and versatility.
Furthermore, JPEG files are easy to evaluate by employing the JPEG decoder and directly inspecting the resulting image raster.
We test if CLMs understand JPEG files, in two standard image datasets, by probing their capabilities across three axes: recognizing inherent properties of files, handling files with anomalies, and generating new files.
Please see Fig. 1 for an overview of our methodology for testing understanding.
To the authors’ best knowledge, this is the first study testing the understanding of language models that operate directly on CFF-encoded data.
Our evidence supports the hypothesis that CLMs can understand compressed files.

## 2 Preliminaries

We select the JPEG format as a case study for Compressed File Formats (CFFs) for three key reasons: commonality, representativeness and ease of evaluation.
Regarding its commonality, JPEG is widely used due to its efficient encoding and decoding algorithms, as well as its high perceptual quality, making it one of the most prevalent image formats on the internet.
Regarding its representativeness, JPEG exemplifies key concepts in CFFs, including lossy compression, quantization, domain-knowledge operations (e.g., discrete cosine transforms), and entropy coding, which are foundational in many compressed formats [, , , ].
Finally, judging the quality of generated JPEG files is straightforward by decoding the compressed data and conducting visual inspection.

Despite these virtues, JPEG may present challenges from the perspective of language modeling, as the encoding is a multi-layered procedure that produces byte streams with complex patterns and long-term dependencies.
Next, we provide a brief overview of the JPEG encoding, transforming an image into a byte stream, and refer the interested reader to [] for specifics.

JPEG Encoding Overview.
Initially, JPEG converts the image from the RGB color space to YCbCr, separating its information into luminance and chrominance.
The chrominance channels are then often down-sampled, leveraging the human eye’s lower sensitivity to color differences.
The image is then divided into 8$\times$8 pixel blocks, where each block then undergoes a discrete cosine transform (DCT) to obtain a frequency-domain representation.
The DCT coefficients are then scaled with a set of pre-defined quantization tables that control the level of lossy compression. The resulting coefficients are then subjected to run-length encoding to represent consecutive repeated values as a single value and a count.
Finally, the symbols in the sequence are compressed with Huffman or arithmetic coding, resulting in the final byte stream.
The “lossy-ness” of JPEG is tuned via a JPEG quality parameter, which balances between compression and perceptual quality by controlling the quantization tables.

Potential challenges offered by JPEG.
Considering the complex encoding procedure presented above, we enlist possible challenges that JPEG poses to language models.
Firstly, the compressed byte sequences produced by JPEG are highly sensitive to modifications, since a single change in the byte stream can drastically alter the resultant image.
This sensitivity contrasts sharply with natural language, where redundancy is common and often less crucial to the meaning of text.
Furthermore, the run-length and Huffman coding processes used in JPEG compression operate at the bit level rather than the byte level.
This fact means that the boundaries between encoded symbols may not align neatly with byte boundaries, potentially resulting in encoded symbols starting or ending in the middle of a byte. This misalignment complicates the model’s ability to learn from byte-level data, as it introduces difficulties in interpreting the encoded information with precision.
Lastly, the interactions between the DCT, quantization, and the corresponding quantization tables introduce complex inter-dependencies among the bytes.
These relationships are non-trivial and pose significant challenges for language models, which typically excel when dependencies are more reflective of patterns found in natural language.

## 3 Methodology

This section outlines our methodology for testing the hypothesis that a language model can be directly trained on data resulting from Compressed File Formats and effectively capture the underlying semantics. We propose to test the model’s understanding of JPEG data by assessing its performance along three main axes:
(i) Recognition of inherent properties of compressed files,
(ii) Discovery and correction of anomalies in compressed files and
(iii) Generation of compressed files.
These tasks rely on the model’s ability to interpret and manipulate the JPEG’s lexicon (the byte values), syntax (the structure of the byte sequences), and semantics (the meaningful interpretation of file content), and thus reflect diverse aspects of understanding the encoded byte sequence.

We minimize the impact of training schemes and network-design choices by following the current standard practices for decoder-only language architectures and optimize for next-token prediction [].
The only factor on which we diverge from these defaults is how we construct the inputs to the model, i.e. the tokenized “sentence” on which the model operates.

Vocabulary and Tokenization.
The model’s vocabulary consists of the 256 possible byte values, from 0x00 to 0xFF, with additional start (
) and end (
) of sequence tokens.
Such vocabulary enables the model to process a file’s raw byte stream directly.
That is, analogous to character-level tokenization in natural language, we represent each byte with a separate token.

Input Sequence Construction.
To enable both class-conditional generation and recognition immediately after training, we extend the input sequences to include token indicators of both (1) JPEG quality and (2) semantic class.
Specifically, each sequence or “sentence” fed to the model has both a JPEG quality and a semantic class token that surround the file’s byte sequence.
For instance, a JPEG file of quality $75$ and class $3$ is represented as:

$$ $\texttt{<q75>}\;\texttt{<class3>}\;\texttt{<bytes>}\;\texttt{0xFF}\;\ldots\; \texttt{0xD9}\;\texttt{</bytes>}\;\texttt{<q75>}\;\texttt{<class3>}$ $$

This template guides the model both for conditional generation (conditioned on JPEG quality and class) and for regression of those attributes after scanning the byte sequence.
Please refer to the appendix for an explanation of how we avoid the degenerate solution of copy-pasting these attributes.

We next describe in detail the three main axes on which we evaluate the model’s understanding of CFFs, recognizing files (Sect. 3.1), handling anomalous files (Sect. 3.2), and generating new files (Sect. 3.3), and report the corresponding results in Sect. 4.

### 3.1 File Recognition

Can the model recognize properties of a given file?
A language model should be able to understand the attributes of sentences [, , ]. Similarly, a model tuned for JPEG byte sequences should be capable of recognizing the properties of a given file. Therefore, we test the model’s capacity to recognize the JPEG quality and semantic class of real files.

Here, we leverage our input-sequence template for probing the model for this task.
Specifically, we previously outlined how the JPEG quality and class token are (optionally, see appendix) provided at the start and end of the byte sequence (B).
To evaluate the model’s capability to recognize these properties from the byte sequence only, we replace the first two tokens of the sequence with the unknown “<unk>” token.
That is, we represent a validation sample as: “<unk> <unk> <bytes> *B </bytes>” (see Fig. 1).
We then use the model to auto-regressively predict the next two tokens in the sequence, corresponding to the model’s predictions for B’s JPEG quality and semantic class.
With these predictions, we then compute the model’s accuracy for individually predicting each property.

The model’s recognition capacities are a direct consequence of the model’s next-token prediction pre-training.
That is, the next-token prediction objective simultaneously tasked the model with learning to generate byte sequences and recognizing them.
However, in a sentence, the number of tokens contributing to the generation objective (hundreds of tokens) is disproportionately large w.r.t. the number of tokens contributing to the recognition objective (only two tokens).
This lack of proportion suggests that the model’s recognition capacities after pre-training is likely a lower bound to the model’s actual potential.
We thus study the possibility of leveraging the model’s generative pre-training [], and fine-tune the model to improve its recognition capabilities.
To this aim, we fine-tune the model on these same sentences, but only supervise the token on which we are interested for recognition (either the JPEG quality or the semantic class token).
After this fine-tuning, we again measure the model’s classification performance via accuracy.

### 3.2 File Anomaly Handling

Can the model handle files that contain anomalies?
A language model should be able to handle sentences with grammar errors or typos [, , , , ].
Analogously, a model that understands JPEG files should be capable of handling anomalies in these compressed files.

To test such capabilities, we consider three anomaly-related tasks:
(i) tagging a file as anomalous,
(ii) detecting the precise location of an anomaly in a file, and
(iii) correcting a given anomaly.
To study these tasks, we require a dataset of anomalous files.
We choose to generate such a dataset, based on real files, via the procedure we describe next.

Simulating Anomalous Files.
To generate a dataset of anomalous encoded files, we start by considering a collection of $M$ regular files $X=\{x_{i}\}_{i=1}^{M}$, where each file $x_{i}$ is a list of $N_{i}$ bytes, i.e. $x_{i}=[b_{1},\ldots,b_{N_{i}}]$, and $x_{i}[\>k\>]=b_{k}\in\{0,\ldots,255\}$.
Our dataset considers files with one-byte-substitution anomalies.
For each file $x_{i}$, we thus generate all one-token perturbed variants by modifying each byte in $x_{i}$ with all possible $255$ values different from its original value.
Formally, we define the perturbation function $\Psi$:

$$ $\Psi(x,v,j)=x\oplus(x[\>k\>]\rightarrow v),$ $$

where $\oplus$ denotes replacing the $k^{\text{th}}$ token in $x$.
By applying this function to each token, we construct the set of all possible perturbed sequences for file $x_{i}$ as:

$$ $\hat{X}_{i}=\left\{\Psi(x_{i},v,k)\mid v\in\{0,\ldots,255\}\setminus\{x_{i}[\> k\>]\},\>k=1,\dots,N_{i}\right\},$ (1) $$

where $v$ thus considers every byte value except the original one.
This operation yields $255\times N_{i}$ anomalous variants of each file $x_{i}$.
We aggregate this set across all files and obtain a comprehensive dataset of anomalous files $\hat{X}=\bigcup_{i=1}^{M}\hat{X}_{i}$.
This dataset provides a testbed for a thorough evaluation of the model’s sensitivity to one-byte-substitution anomalies.
Next, we detail the three tasks on which we evaluate the model’s capacity to handle anomalies.

Task #1: Tagging.
Can the model tag files as anomalous?
The ability of the model to distinguish between normal and anomalous files can be assessed by examining its likelihood estimates.
Specifically, the model should assign higher likelihoods to “correct” or “natural” files and lower likelihoods to those that are anomalous.

We formalize our testing approach.
For each original file represented by the byte sequence $x_{i}$ in our dataset, we consider all its perturbed variants. In particular, we hypothesize that the model assigns a higher likelihood to the original file $x_{i}$ than to any of its perturbed variants, denoted by
$\hat{x}_{i,j}\in\hat{X}_{i}$.
Formally, we denote the log-likelihood of a file $x_{i}$ by $L(x_{i})$, as computed by the model, and define the difference in log-likelihoods between the original sequence $x_{i}$ and one of its perturbed variants as $\Delta L_{i,j}=L(x_{i})-L(\hat{x}_{i,j})$.
Our hypothesis thus poses that $\Delta L_{i,j}$ should be positive, indicating that, according to the model, original files are more likely than their corresponding anomalous variants.
We statistically test this hypothesis by applying the Wilcoxon Signed-Rank Test [] to the set of log-likelihood differences between all files $x_{i}$ and their corresponding $255\times N_{i}$ anomalous versions, which we denote as $\mathcal{L}=\{\Delta L_{i,j}\mid x_{i}\in X,\>\hat{x}_{i,j}\in\hat{X}_{i}\}$.

In this test, the null hypothesis $H_{0}$ poses that the median of these differences is less than or equal to zero, suggesting no significant difference in likelihoods between natural and perturbed files.
Conversely, the alternative hypothesis $H_{1}$ argues that the median is greater than zero, supporting the model’s capability to identify anomalies.
Formally,

$$ $H_{0}:\text{median}(\mathcal{L})\leq 0\quad\textit{versus}\quad H_{1}:\text{ median}(\mathcal{L})>0.$ $$

We evaluate this hypothesis using a significance level of $\alpha=0.05$.
That is, we reject the null hypothesis if the resulting $p$-value from the Wilcoxon Signed-Rank Test is less than $\alpha$, supporting our conjecture that the model effectively discriminates between natural and anomalous files.

Task #2: Detection.
Can the model identify the location of an anomaly?
We study if, given an anomalous file, the model is capable of identifying the exact location of the byte causing the anomaly in the file.
This task is analogous to how a language model should be able to identify the exact location of a typo in a sentence.

For this purpose we consider the model’s capacity for estimating the likelihood of individual tokens in the sequence.
Let $\hat{x}^{k}$ denote an anomalous sequence whose $k^{\text{th}}$ token was perturbed.
Then, we hypothesize that the model assigns a particularly low likelihood (i.e. a high perplexity) to the anomalous token.
Formally, we suggest the model can predict the location $k$ of the anomaly by simply sorting the estimated likelihoods of the individual tokens, that is:

$$ $\hat{k}=\operatorname*{arg\,min}_{l}L\left(\hat{x}^{k}[\>l\>]\mid\hat{x}^{k}[ \>:l-1\>]\right)$ (2) $$

Thus, we use the model’s per-token likelihood estimates to identify the anomaly in each sequence in the dataset $\hat{X}$.
We then interpret the task as a simple classification problem and compare each prediction $\hat{k}$ with the ground truth $k$ to compute classification accuracy.

Task #3: Correction.
Can the model correct an anomalous file?
We study if, given the exact location of an anomalous byte in a file, the model is able to replace such byte with the correct one.
This task is analogous to how a language model should be able to fix a typo in a sentence by replacing the wrong character with the right one.

We propose a correction process that uses the model’s likelihood estimates to replace the anomalous token with the most likely one.
Specifically, assume the $k^{\text{th}}$ token in a file sequence $\hat{x}^{k}$ is anomalous.
We thus propose to correct the sequence by simply substituting the anomalous token with the one that maximizes that token’s likelihood, conditioned on the preceding tokens.
This approach hypothesizes that the model, trained for next-token prediction in files, naturally suggests the correct token when given the preceding context.
Formally, we define the correction operation as follows:

$$ $\hat{x}_{\text{corrected}}=\hat{x}^{k}\oplus\left(\hat{x}^{k}[\>k\>] \rightarrow\operatorname*{arg\,max}_{b}L\left(b\mid\hat{x}^{k}[\>:k-1\>]\right )\right),$ $$

where $\hat{x}^{k}[\>k\>]$ refers to the anomalous byte value, and $\operatorname*{arg\,max}_{b}L\left(b\mid\hat{x}^{k}[\>:k-1\>]\right)$ denotes the byte that the model considers to be most likely at position $k$, given the tokens at all previous positions.

We apply this correction method to each anomalous file in our dataset of perturbed files $\hat{X}$.
Following our evaluation of Task #2: Detection, we interpret the output of the correction task as a classification problem, and compare each $\hat{x}_{\text{corrected}}$ with the ground-truth $x$ to compute classification accuracy.

### 3.3 File Generation

Can the model generate new files?
A language model should be able to generate new sentences [, , , ].
Analogously, a model that understands JPEG files should be capable of generating novel files that adhere to the JPEG standard.
We thus test the model’s capacity to generate new JPEG files.

We perform class-conditional generation by feeding the model a prompt stating the quality and semantic class of the target file (e.g., “<q30> <class0> <bytes>”) and then auto-regressively generate the file content.
We continue the generation process until the model generates the </bytes> delimiter, after which we write the generated bytes to a file with the .jpeg extension.

Checks.
File validity:
The generated file may not represent a valid JPEG file: it may include malformed headers, incorrect byte sequences, or inconsistencies in the compression structure.
To check the file’s validity, we use the standard OpenCV library to attempt opening the file, and consider the generation invalid if the library either throws an error or a warning when attempting to open the file.
We measure the model’s performance as the percentage of generated sequences that correspond to valid JPEG files.
JPEG quality:
For files that pass the validity check, we assess the JPEG quality presented by the byte stream.
To check the file’s JPEG quality, we use the ImageMagick library, which determines the compression quality based on the quantization tables in the file’s header.
We measure the model’s performance as the percentage of the valid files for which the file’s exhibited JPEG quality matches the quality token specified in the prompt.

## 4 Experimental Results

Our methodology aims at testing if a model trained for next-token prediction on JPEG data understands the information underlying the encoded data.
In this section, we first describe implementation details of our experiments, and then report results on each of the three axes we consider for testing the model’s understanding of JPEG, as described in our Methodology (Sect. 3).

### 4.1 Implementation Details

Data.
Our study tests if the standard practices for training a sequence model, when applied directly on JPEG-encoded data, result in a model that understands the information underlying the compressed data.
We thus focus on the encoding rather than on the data, and so minimize confounding factors stemming from complex data by experimenting on two simple image datasets: MNIST [] and CIFAR-10 [].
On the one hand, MNIST consists of 60K training and 10K test grayscale images of $10$ handwritten digits, providing a simple and well-defined testbed.
Its straightforward nature is ideal for isolating challenges related to the JPEG encoding process without the interference of complex image characteristics.
On the other hand, CIFAR contains 50K training images and 10K test color images across 10 classes, offering a richer diversity in textures and subjects.
This variability introduces more complexity, which allows us to assess how the model processes more intricate content when encoded in JPEG format.
To enhance the model’s generalization, we perform data augmentations in the image space and then save the augmented images in JPEG format.
In particular, for MNIST, we apply small rotations.
For CIFAR, we perform crops and horizontal flips.

JPEG quality parameters.
We resize the images to $32\times 32$ pixels and save them as JPEGs with various quality parameters $q$.
We experiment with nine quality values, $q\in Q=\{30,50,60,70,75,80,85,90,92\}$, which are common settings in GIMP, Photoshop, libjpeg, etc.

Model.
We use a small LLaMA-like model [], whose hyper-parameters are left to the appendix.

### 4.2 File Recognition

Performance before and after fine-tuning.
Before:
We find that the next-token prediction training yields a model that naturally exhibits high recognition capacity.
In particular, on MNIST’s validation set, we find that the model’s accuracy for recognizing a file’s semantic class is $97.1\pm 0.05\%$ (average and standard deviation computed across three runs), while its accuracy for recognizing the file’s JPEG quality is $100\pm 0\%$.
On CIFAR, the model reaches a more conservative accuracy of $56.9\pm 0.4\%$ for the semantic class; however, the model still reaches an accuracy of $100\%$ for recognizing JPEG quality.
After:
The models’ performance at recognizing JPEG quality is outstanding, while recognizing the semantic class has room for improvement.
We thus fine-tune the models for recognizing the semantic class.
After fine-tuning, accuracy on MNIST grows from $97\%$ to above 99%, while the accuracy on CIFAR improves more dramatically, from $57\%$ to over $74\%$.

Conclusion:
We find that generative pre-training results in perfect recognition of JPEG quality on both datasets; recognition of the semantic class is high on MNIST, though lower on CIFAR.
We also find that performance at semantic classification can easily be boosted via simple fine-tuning.

**Table 1: Anomaly Detection: accuracies for locating anomalies in JPEG files. The model displays a notable capacity for identifying the precise location of anomalies.**
| Top-k | MNIST | CIFAR |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- |
| Broken | Valid | Overall | Broken | Valid | Overall |  |
| 1 | 97.3 | 82.0 | 84.4 | 91.8 | 77.7 | 80.2 |
| 3 | 99.8 | 92.7 | 93.7 | 99.7 | 85.2 | 87.9 |
| 5 | 99.9 | 94.6 | 95.4 | 99.8 | 87.5 | 89.8 |

### 4.3 File Anomaly Handling

Anomalous Files Dataset.
We simulate anomalous files for both MNIST and CIFAR following the procedure described in Sect. 3.2.
For this procedure, we only consider $10$ files (one per class) for each dataset, given the computational and storage costs of the combinatorial space of even one-byte-substitution anomalies.
We find that this procedure yields both “broken” and “valid” files.
That is, OpenCV recognizes some of these files to be valid JPEG files, while recognizing others as invalid.

Figure: Figure 2: Histograms of log-likelihood differences, $\mathcal{L}$, for MNIST and CIFAR. Positive values dominate, indicating that the model consistently assigns higher likelihoods to natural files compared to their perturbed counterparts. This fact allows the model to correctly tag anomalous files.
Refer to caption: x2.png

For MNIST, $15\%$ of the anomalous files are broken, while the remaining $85\%$ are valid.
On CIFAR, these percentages are, correspondingly, $18\%$ and $82\%$.
We next report the results for each of the three anomaly-related tasks we described in Sect. 3.2.

Task #1: Tagging.We report the histogram of log-likelihood differences in Fig. 2.
For both datasets, we observe that the vast majority of differences are positive, indicating that the model assigns significantly higher likelihoods to the original sequences than to their perturbed counterparts.
Running the Wilcoxon Signed-Rank Test further supports the intuition from the histogram.
In particular, the test yields a $W$ statistic of $>10^{11}$ for MNIST and of $>10^{12}$ for CIFAR, with their associated $p$-values being numerically zero, and thus rejecting $H_{0}$ as described in Sect. 3.2.

Conclusion: our findings suggest that the model’s file-level likelihood estimates are extremely sensitive to the presence of single-token anomalies in JPEG files.
That is, we find that the model is capable of tagging files as anomalous even with anomalies in a single byte.

Task #2: Detection.
Our findings from Task #1: suggest that the model’s likelihood can distinguish when files have even single-token anomalies.
Such finding suggests the model may be sensitive not just at the file level but also at the finer token level.
We thus measure the performance of the anomaly detector from Eq. (2) at various prediction chances $k\in\{1,3,5\}$, and report results in Tab. 2.

For MNIST, we note that the overall accuracy at top-1 is about 85%, surpasses 90% at top-3, and reaches over 95% at top-5.
The case of anomalous but valid files follows a similar trend.
Notably, for the case of broken files, the detector’s performance is remarkably high: the top-1 prediction is correct over 95% of times, and this number reaches almost 100% when considering the top-3 predictions.
This high performance in broken JPEG files is largely expected: a file breaks when its strict format is perturbed, and deviations from that strict format are most likely easily detected by the model.
For CIFAR, we mostly observe a similar trend to that of MNIST, but with reduced values: overall performance at top-1 is 80% and reaches 90% at top-5.
Performance in broken files starts at above 90% and reaches essentially 100% when considering more prediction chances.
Finally, on CIFAR’s valid files, performance starts at 78% at top-1, and reaches 87% at top-5.

Conclusion: the model’s token-level likelihood estimates are useful for identifying the precise location of anomalous bytes in JPEGs.
This finding is particularly sound for broken files, i.e. for files in which the perturbation broke the file’s strict format.

Task #3: Correction.
Our findings from Task #2: Detection suggest that the
model has the capacity to locate an anomaly in a file’s byte sequence, and so we next explore whether it can also correct these anomalies.
We report the performance on the correction task in Tab. 2.

For MNIST, we observe that the model performs the correction task exceptionally well, with top-1 correction accuracy achieving 100% for broken files and 76% overall.
The performance increases notably with more prediction chances, reaching over 90% at top-5.
CIFAR exhibits a similar pattern, albeit with slightly lower accuracy: starting at 78% for top-1 and climbing to almost 84% for top-5.
This evidence demonstrates the model’s capability to rectify anomalies, even more effectively in broken files where the format deviations are clear-cut.

Conclusion: The model performs remarkably well in the correction task, particularly when dealing with severely corrupted, i.e. broken, JPEG files.

### 4.4 File Generation

We generate files by sampling from the model with greedy decoding.
We thus generate $90=10\times 9$ files for each dataset, i.e. for the $10$ semantic classes of MNIST/CIFAR and the $9$ JPEG quality values we considered.
For MNIST, we find that $99\%$ of the files we generate, i.e. all except one file,
(i) are valid JPEG files, and
(ii) have JPEG quality matching the one in the corresponding prompt.
In CIFAR, the percentage of valid JPEG files lowers slightly to $97\%$, i.e. all except three files, while all the valid JPEGs have a quality matching the corresponding prompt.
Thus, in both datasets, essentially all sampled files are valid JPEGs, except for only four samples (one in MNIST and three in CIFAR).
The warnings raised by OpenCV when trying to open these files mention issues such as the presence of extraneous bytes, premature ends of data segments, and wrong Huffman tables.
In general, we find that sampling from the model with greedy decoding, in general, yields files that adhere to the JPEG format and also exhibit the correct JPEG quality parameter that was stated in the prompt.

We check the visual properties of the generated samples by decoding the JPEG files into image arrays. We report a subset of these samples, including both positive and negative (i.e. corrupt) results, in Fig. 3. We make three observations from these qualitative results:
(1) Corrupt files in both MNIST (quality 85 and class “2”) and CIFAR (quality 75 and class “1”) are still decodable by OpenCV, and exhibit strongly-structured errors that mirror JPEG’s $8\times 8$-block standard.
For the broken MNIST image, for example, sampling is successful in generating over half of the blocks but, after a certain block (in raster order), the sample displays checkerboard patterns and color shifts.
(2) All samples lack strong artifacts except the corrupt files.
That is, all samples are positive results w.r.t. visual quality except for a single one.
(3) On the one hand, essentially all MNIST samples display the right semantic class as provided in the prompt; on the other hand, on CIFAR, the model seems to suffer from mode collapse in various classes.
We report samples from beam search in the appendix.

Figure: Figure 3: Qualitative results of file generation. We sample files from the model, via greedy decoding, and use the JPEG decoder to obtain an image raster. Here we report images of various JPEG qualities (30, 70, 75, and 85) and all semantic classes from both MNIST (first two rows) and CIFAR (bottom two rows). The bottom row of each dataset displays one sample that was recognized by OpenCV to be a corrupt JPEG. The offending samples are noticeable by their block-like artifacts (MNIST: quality 85, class “2”; CIFAR: quality 75, class “1”).
Refer to caption: extracted/5621256/Images/greedy-sampling/likely-sweep-225/JPEGq30/class0.jpeg

## 5 Related Work

Models trained on partially-decoded JPEGs.
Instead of operating on RGB pixel values of images, a few works have devised Convolutional Neural Network (CNN) [, ] or Vision Transformer (ViT) [] architectures that operate on partially decoded JPEG images.
For instance, [] introduced a CNN [] that processes these images, allowing for faster image handling by omitting some decoding stages.
Similarly, [] applied a ViT [] to partially decoded JPEGs, enhancing the ability of models to interact with data in a more compressed state.
These approaches mark a significant shift towards using the structural properties inherent in compressed formats, albeit still involving some level of decoding.

Byte Sequence Modeling for Uncompressed Data.
Transitioning to the modeling of byte sequences, significant innovations have been introduced to manage the complexities associated with raw data streams.
The MegaByte framework [], for instance, features a multi-scale decoder transformer architecture that addresses the challenges posed by long byte sequences through a novel “byte patchification” technique.
Concurrently, bGPT [] leverages a decoder-only Transformer model for autoregressive generation of byte sequences.
These methods underscore developments in processing byte sequences, yet they focus on uncompressed data, neglecting the more common and practical compressed file formats.
In contrast, our work tackles the challenge of processing compressed formats, specifically using JPEG as a case study.

Direct Operations on Compressed JPEG Byte Sequences.
ByteFormer [] ventured into processing compressed file formats at the byte level, and revealed that JPEG byte sequences introduce significant challenges due to their nonlinear encoding and variable length.
This work showed that traditional byte patching methods could degrade performance, owing to the high density of information in compressed formats.
Unlike ByteFormer, which employs a tailored encoder architecture for byte sequences, our work uses a straightforward decoder-only Transformer language model trained with the vanilla next-token prediction objective.
We find that, despite the simplicity of this design choices, this vanilla Transformer effectively works on JPEG sequences for multiple tasks.

## 6 Conclusions

In this study, we found evidence suggesting that Compressed-Language Models (CLMs) can effectively understand JPEG-encoded byte streams.
In particular, we found CLMs exhibit abilities in file recognition, anomaly handling, and file generation, without requiring decompression.
Our findings pave the way for future developments in efficient data processing techniques that directly operate on files encoded by Compressed File Formats, or even segments of these files.

## Supplementary Material

## Appendix A Limitations

Our study is limited by its focus on JPEG-encoded MNIST and CIFAR datasets, which may not represent the complexity of more varied real-world images.
This restriction could impact the generalizability of our findings, as the characteristics and challenges of JPEG compression in more varied and natural images are not fully explored.

## Appendix B Training sentences

In Sect 3, we described the general template for our sentences as

$$ $\texttt{<q75>}\;\texttt{<class3>}\;\texttt{<bytes>}\;\texttt{0xFF}\;\ldots\; \texttt{0xD9}\;\texttt{</bytes>}\;\texttt{<q75>}\;\texttt{<class3>}$ $$

In practice, we introduce additional delimiters for the condition, but omit them here for clarity.
Furthermore, notice that we introduced condition tokens (JPEG quality and semantic class) both before and after the segment corresponding to the file’s bytes.
On the one hand, the condition tokens before the file allow the model to condition its output on a specific condition, i.e. conditional generation.
On the other hand, the condition token after the file instruct the model to scan the entire file and then predict the file properties corresponding to the condition.
Unfortunately, the model may learn to solve the recognition task by copying the condition token provided before the file and pasting it after the file.
To prevent this degenerate solution, we stochastically feed the model with either a “generation” or a “recognition” version of the sample during training.
In the generation version, we remove supervision for the condition tokens after the file, so the model lacks incentives to copy-paste.
In the recognition version, we restore that supervision, but replace the condition tokens before the file with an <unk> token, preventing copy-pasting and thus forcing the model to rely on the file to predict the class.

## Appendix C Model Training

#### Architecture and training objective.

We use a decoder-only Transformer architecture [].
The training objective is to predict the next token in a sequence, which aligns with the typical setup for auto-regressive language models
The next-token prediction objective involves training the model to predict the probability distribution of the next token given the preceding sequence:

$$ $\max_{\theta}\>\mathbb{E}_{x\sim D}\left[\sum_{t=1}^{n}\log p_{\theta}\left(x[ t]\mid x[:t-1]\right)\right].$ (3) $$

## Appendix D Generation: sampling with beam search

In Sect. 4.4 we found that sampling from the model with greedy decoding generated valid and reasonable JPEG files.
We thus also experiment with beam search sampling.
For sampling sensibly-looking JPEGs with beam search, we find important to constrain sampling to consider only the smallest set of tokens whose accumulated probabilities surpass a given hyper-parameter.(^1^11This constraint is enforced via beam search’s top_p hyper-parameter in the HuggingFace library.)
We report samples from beam search in Fig. 4.

## Appendix E Implementation Details

#### Learning hyper-parameters

We base our implementation on the llama-recipes codebase [], and so follow their defaults when unspecified.
We report training hyper-parameters in Tab. 3.

**Table 3: Training hyper-parameters. The parameters follow the template “(MNIST) | (CIFAR)”**
| Configuration | Value |
| --- | --- |
| Precision | bfloat16 |
| Optimizer | AdamW |
| Optimizer momentum | $\beta_{1},\beta_{2}=0.9,0.999$ |
| Weight decay | 0.0 |
| Learning rate | $7\times 10^{-4}$ | $6\times 10^{-4}$ |
| Learning rate schedule | cosine decay |
| Warm-up iterations | 10 | 11 |
| Total epochs | 6 | 5 |
| Batch size | 32 | 16 |

#### Computer Resources.

We conduct all our trainings in an A100 GPU of 80 GB.
We run training on MNIST for 24 hours, and on CIFAR for 72.
The experiment on MNIST shows signs of convergence, while the one on CIFAR does not.

Testing a trained model for recognition requires less than 10 minutes on either dataset.
Sampling an MNIST file requires around 5 seconds, while sampling a CIFAR files requires almost 9, due to the difference in sequence length.

Figure: Figure 4: Qualitative results of file generation via beam search. We sample files from the model via beam search and use the JPEG decoder to obtain an image raster.
Refer to caption: extracted/5621256/Images/beam-search/JPEGq90/class0/sample_0.jpeg

## Peer Reviews

confidence: 4
contribution: 2
initial_rating: 5
presentation: 2
questions: None
soundness: 3
strengths: The authors have investigated the effectiveness of CLMs in handling raw byte streams from compressed files. Specifically, they have used the JPEG format as the compression mechanism. They have employed three datasets: MNIST, CIFAR-10, and TinyImagenet. The models used are standard models available in the literature (e.g., a small LLaMA-like model). Their tokenization is somewhat new. In general, the results indicate that CLMs are good in dealing with compressed data.

For instance, the accuracy they obtain for file recognition are: 99% on MIST and 74% on CIFAR. The model seems to be very effective in anomalies detection and files generation. For example, in the context of MNIST, 99% of the files generated are valid JPEG files.
summary: The main goal of this project is to study the effectiveness of Compressed-Language Models (CLMs) in understanding raw byte streams from compressed file formats (CFFs). Specifically, they have used JPEG data in this study and evaluated the performance of CLMs on three functions: identifying inherent properties of compressed files, discovery of anomalies in compressed files, and generation of compressed files.
weaknesses: The novelty of the work is modest.

---

confidence: 3
contribution: 2
initial_rating: 3
presentation: 3
questions: 1. Why there is only single-byte replacement anomalies considered when simulating anomalous files, would other types of anomalies have a more significant impact on model performance?

2.   It seems the results of Section 4.2 are not presented in any table or figure in this section. does the term “MNIST’s validation set” refer to the validation set used during training? If so, what are the results on the test set? Could you clarify how the dataset was actually split?

3.  What’s the detail of fine-tune the models for recognizing the semantic class.? What was the data used for fine-tuning like?
soundness: 2
strengths: The research topic is novel as it explores the understanding capabilities of language models on compressed file formats, specifically focusing on JPEG. This area has potential for applications in efficient data storage and retrieval.
summary: This paper investigates whether Compressed-Language Models (CLMs) can understand files compressed in the JPEG format. The authors test the models' capabilities in three aspects: recognition of file properties, handling of anomalous files, and generation of new files. 
The study uses simple image datasets (MNIST and CIFAR-10) presented in encoded format as sequence data to train a small LLaMA-like model to conduct the experiment. The results suggest the model can effectively perform these tasks without decompression.
weaknesses: The paper claim that the focus of the research is on testing the understanding capabilities of compressed language models (CFFs). Besides, they draw the conclusion that “CLMs can understand the semantics of compressed data”. But the test is conduct on only one model trained by the author, instead of any existing language models. Therefore, I think the result is insufficient to support the conclusions drawn in the paper.
 It looks that JPEG-encoded formats exhibit language-like properties like any other sequences and the object is also to optimize for next-token prediction. It is not that surprising to see a model trained on sequence data works well within the same datasets (CIFAR-10 and MINIST, though as encoded data). Therefore, I think the main finding of this paper lacks some novelty.
The paper outlines the characteristics of compressed file formats (CFF) and the challenges compressed language models (CLMs) encounter when meeting CFFs but does not clarify enough the need for CLMs to address CFFs or the importance of testing their understanding capabilities.

---

confidence: 4
contribution: 1
initial_rating: 3
presentation: 2
questions: 1. File anomaly handling (section 3.2) only considers one-token (one-byte) perturbation.  How realistic such anomaly exists in real world applications and results in actual problems? 

2. line 361, "For this procedure, we only consider 10 files (one per class) for each dataset". How do the 10 files produce a result that "15% of the anomalous files are broken"? Did I miss anything?
soundness: 1
strengths: Evaluating language model's capability on JPEG byte stream is interesting. It is a bold idea with a potential to show unseen capability or to reveal important limitations of language models.
summary: The paper studies whether language models trained on compressed file format can be used on three tasks on JPEG files, including recognition of file properties, handling anomalies and generating new files.
weaknesses: 1. Models trained on text and models trained on compressed data have significantly different token space. While the token space of text is demonstrated learnable with various language models, the binary streams produced by compression algorithms may not have generic patterns that are generalisable for a variety of compressed data. It has been argued that the data distribution properties may be the key that drives in-context learning in transformers[1]. I feel that a detailed examination of the token distribution in the compressed data should be provided to justify the approach.

[1] Chan, S., Santoro, A., Lampinen, A., Wang, J., Singh, A., Richemond, P., McClelland, J. and Hill, F., 2022. Data distributional properties drive emergent in-context learning in transformers. Advances in Neural Information Processing Systems, 35, pp.18878-18891. 

2. The experiments are done on images with very small dimensions (28x28 for MNIST and 32x32 for CIFAR, additional experiment in appendix with an image dimension of 64x64 ). It is not a surprise that a large model can fit the small search space and provide predicting and generative capability on these datasets. 

3. It is likely the language model is tuned to overfit a set of small images. This is little evidence based on the technical presentation of this paper that the model has learned the format of JPEG, therefore the method is unlikely to generalise to data in compressed file formats.

---

confidence: 5
contribution: 1
initial_rating: 3
presentation: 3
questions: None
soundness: 2
strengths: S1. The exploration of LLMs to directly handle compressed data is interesting. Even if it may not turn out to be of notable relevance in practice, it may help to shed more insights into the limitations of LLM.

S2. The evaluation tasks are reasonable first steps and shed some light into the compression/decompression capabilities of plain LLMs.
summary: Experimental study that trains and evaluates a decoder-only Transformer model directly on JPEG byte streams (= JPEG-compressed images). Training is done autoregressively as usual. Evaluation tasks are (i) predict JPEG image quality setting and class of example, (ii) detect/locate/fix single-byte errors, (iii) data generation. The key takeaway is that this works reasonably well.
weaknesses: W1. Paper positioning not convincing. The paper is motivated by a large argument that directly working on compressed format is beneficial. These arguments, however, are inherently flawed. First, arguments about ubiquity, compactness and generality are invalid because if one simply decompresses before training the LLM, these advantages would still hold. Second, while I do see the worth of studying compressed file formats (see S1), I fail to see practical relevance. On the one hand, real-world machine learning pipelines do consist of many domain-specific techniques; e.g., data augmentation (e.g., crop/scale images), helpful tokenization (e.g., SentencePiece), task-specific training objectives (e.g., BERT training) or models (e.g., CNNs). On the other hand, spending resources to "teach" a model to decompress/compress when we actually know how to do this more efficiently (JPEG encoder/decoder) is a waste of resources.

W2. Training and evaluation setup not convincing. For task (i), the prediction targets of image quality and class are fed into the training process in a somewhat contrived way to deal with problems of decoder-only models for this task. It's not clear why a decoder-only LLM is the right approach in the first place. For task (ii), the authors make "erroneous bytes" are less likely than "correct bytes" arguments. But when doing so, they ignore the entire input after the erroneous token (for localization/correction). This, again, a consequence of using decoder-only models. For task (iii), the automatic check is solely on file validity, but ignores the quality of the generated samples (other than the anecdotal examples of Fig. 3).

W3. Limited insight. This is for two main reasons. First, the papers make broad claims about compressed file formats, but then only considers JPEG, includes JPEG-specific information into the training pipeline (quality setting), and use only one image size. Second, the paper puts too much focus on whether tasks (i)-(iii) work reasonably well with an out-of-the-box LLM training pipeline. What's much more interesting, however, is exploring where such approaches would fail and why.