Skip to main content
QUICK REVIEW

[Paper Review] Bytes Are All You Need: Transformers Operating Directly On File Bytes

Maxwell Horton, Sachin Mehta|arXiv (Cornell University)|May 31, 2023
Adversarial Robustness in Machine LearningComputer Science3 citations
TL;DR

This paper introduces ByteFormer, a Vision Transformer that performs image and audio classification directly on raw file bytes without decoding into modality-specific representations. It achieves 77.33% top-1 accuracy on ImageNet using TIFF files and 95.42% on Speech Commands v2, demonstrating strong performance across modalities with no hyperparameter tuning, while also enabling privacy-preserving inference through obfuscation and partial image input.

ABSTRACT

Modern deep learning approaches usually utilize modality-specific processing. For example, the most common deep learning approach to image classification involves decoding image file bytes into an RGB tensor which is passed into a neural network. Instead, we investigate modality-independent representation learning by performing classification directly on file bytes, without the need for decoding files at inference time. This enables models to operate on various modalities without any hand-designed, modality-specific processing. Our model, ByteFormer, improves ImageNet Top-1 classification accuracy by $5\%$ (from $72.2\%$ to $77.33\%$) relative to DeIT models of similar size. Compared to Perceiver IO, our model requires absolutely no modality-specific processing at inference time, and uses an order of magnitude fewer parameters at equivalent accuracy on ImageNet. We demonstrate that the same ByteFormer architecture can perform audio classification without modifications or modality-specific preprocessing. We achieve $95.42\%$ classification accuracy on the Speech Commands V2 dataset (comparable to the state-of-the-art accuracy of $98.7\%$). Additionally, we demonstrate that ByteFormer can operate jointly on images and audio, handling joint classification without explicit knowledge of the input modality. We release our code at https://github.com/apple/corenet/tree/main/projects/byteformer.

Motivation & Objective

  • To eliminate modality-specific input preprocessing by performing deep learning inference directly on raw file bytes.
  • To develop a unified model architecture capable of handling diverse input modalities without architectural changes.
  • To explore privacy-preserving inference by operating on obfuscated or partially formed inputs without accuracy loss.
  • To evaluate whether byte-level representations alone can support high-accuracy classification across image and audio domains.
  • To analyze the model's sensitivity to byte ordering and its ability to learn meaningful representations from file-level structure.

Proposed method

  • Train a Vision Transformer backbone (similar to DeiT-Ti) to classify inputs directly from raw file bytes, bypassing any decoding step.
  • Use learnable token embeddings to project each byte into a vector representation, treating each byte as a discrete token.
  • Apply shifted window self-attention to handle long sequences efficiently, avoiding full self-attention’s quadratic complexity.
  • Use a permutation function φ to obfuscate input bytes during inference, testing robustness to non-standard byte ordering.
  • Implement a privacy-preserving camera simulation by masking 90% of pixel channels during input capture, feeding only unmasked bytes into the model.
  • Visualize learned token and position embeddings to analyze how the model encodes byte-level structure and spatial locality.

Experimental results

Research questions

  • RQ1Can a transformer-based model achieve high accuracy on image and audio classification tasks when trained and tested directly on raw file bytes, without decoding into RGB or spectral features?
  • RQ2How sensitive is the model’s performance to byte ordering, and does it rely on local byte patterns or merely frequency statistics?
  • RQ3To what extent can byte-level obfuscation via permutation functions preserve model accuracy, and can this serve as a privacy-preserving input transformation?
  • RQ4Can the model maintain high accuracy when fed partially formed image inputs (e.g., 90% masked pixels), simulating privacy-preserving capture?
  • RQ5How do the learned token and position embeddings reflect the structural properties of different file encodings (e.g., JPEG, TIFF, WAV)?

Key findings

  • ByteFormer achieves 77.33% top-1 accuracy on ImageNet when trained and tested on raw TIFF file bytes, outperforming DeiT-Ti’s 72.2% accuracy on RGB inputs with the same backbone.
  • On the Speech Commands v2 dataset, ByteFormer attains 95.42% accuracy on raw WAV files without any hyperparameter tuning or architectural changes, approaching the SOTA of 98.7%.
  • The model maintains 71.35% accuracy on ImageNet when inputs are derived from a privacy-preserving camera that masks 90% of pixel channels, demonstrating robustness to incomplete data.
  • Byte ordering significantly affects performance: random shuffling degrades accuracy, while cyclic shifts and reversals preserve it, indicating that the model learns spatial locality, not just byte frequencies.
  • Learned token embeddings show strong correlation between neighboring bytes in TIFF, PNG, and fCHW formats, but weaker correlations in JPEG and float32-encoded audio due to compression and encoding schemes.
  • Positional embeddings reveal distinct patterns in file headers and across Huffman-encoded regions, suggesting the model learns structural features from byte-level file organization.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.