tiny-embedder
Text, Image and Audio Embeddings from Scratch
Text, images and sounds as vectors: three small embedding models built on my own tiny-bert.
- Text, image, audio → 256-d vectors
- 15 training sources, weighted mix
- Sanity check: R@1 0.12 → 1.00
Built withPyTorch
NumPy
Hugging Face Datasets
pytest
JavaScript
Code is in a private repository for now.

Overview
tiny-embedder is three embedding models written from scratch in PyTorch. Each one turns its input into a 256-number, L2-normalised vector, so a dot product is a cosine similarity.
The text model is a bi-encoder for search. The image model puts pictures and captions in one space, like CLIP. The audio model does the same for sounds and music, like CLAP. All three use tiny-bert, my own pre-trained encoder, as the text tower.
It is part of my tiny family: tiny-bert gives the encoder and tokenizer, and tiny-nn-search and tiny-rag load the finished checkpoints from a shared model store.
The question
Can one small pre-trained encoder carry a text search model, a CLIP-style image model and a CLAP-style audio model, all trained from scratch?
Key features
- Text bi-encoder with in-batch and BM25 hard negatives
- Tiny ViT on 96 px images (64 patches) next to the tiny-bert text tower
- Audio transformer on log-mel patches, mel features in plain torch; long sounds = mean of 10 s windows
- Symmetric InfoNCE loss with duplicate masking and a learned temperature
- 15 training sources mixed by weight, with leak filters against every test set
- One API: TextEmbedder, ImageEmbedder, AudioEmbedder; self-contained checkpoints
How it works
One encoder, three towers
The text tower is tiny-bert (6 blocks × 256, RoPE, RMSNorm, SwiGLU). The image and audio towers cut their input into patches and run them through the same kind of tiny-bert blocks.
Find your partner in the batch
Each query, caption, image or sound must pick its own pair among everything else in the batch. Every other item is a free negative; text also gets one BM25 hard negative.
Realistic, held-out data
Batches mix MS MARCO, NQ, GooAQ and SQuAD for text, COCO, Flickr30k, Tiny-ImageNet and CIFAR-100 for images, and AudioCaps, Clotho, MusicCaps, FMA and more for audio. Test sets are never sampled.
Benchmark and publish
One script trains the 6 runs, evaluates everything on held-out tests, writes the tables and plots, and publishes the checkpoints to the family's model store.
Examples




Tech stack
The three towers, the contrastive loss, the log-mel features and training
Memory-mapped token caches and the embedding API outputs
Downloading and preparing the text, image and audio datasets
Tests for shapes, loss, data loaders, leak filter and training scripts
Project page with real test examples
What I learned
- Leaks are easy to miss: I had to drop training rows that overlap any test set, including MS MARCO rows that tiny-reranker tests on, and AudioCaps clips matched by audio hash.
- A mixture of weighted sources needs class datasets turned into captions: 8 prompt templates, one drawn per step.
Limitations
- The models are not trained yet: there are no benchmark numbers, only the sanity check.
- Data preparation downloads about 60 GB.
- This is a learning project, not a production system.
Related projects

Tiny BERT — A Small Encoder and Its BPE Tokenizer, From Scratch
Code is in a private repository for now.
A 9M-parameter BERT-style encoder and its byte-level BPE tokenizer, written and pre-trained from scratch in PyTorch, with no Hugging Face transformers. It is the encoder the rest of my tiny family starts from.
Built with:
PyTorch
Hugging Face Datasets
NumPy
scikit-learnMatplotlib
pytest

Tiny NN Search — Vector and Keyword Search from Scratch
Code is in a private repository for now.
A small vector and keyword search engine I wrote from scratch in NumPy: exact search, IVF, PQ, IVF-PQ, HNSW, LSH, BM25 and hybrid fusion, with one engine each for text, images and audio. It is the retrieval engine of tiny-rag.
Built with:
NumPy
Gradio
PyTorchMatplotlib
pytest

tiny-rag — Ask Your Texts, Images and Sounds
Code is in a private repository for now.
A retrieval-augmented generation system over texts, images and sounds, built on my own tiny-* models. Each query is searched with its own kind of model, then Qwen2.5-0.5B-Instruct, run inside tiny-llm, answers from numbered sources.
Built with:
PyTorch
Gradio
NumPy
Hugging Face Datasets
pytest

tiny-reranker — Text, Image and Audio Rerankers from Scratch
Code is in a private repository for now.
Three small cross-encoders that reorder the top results of a first search stage. One reads a query with a passage, one a caption with a picture, one a caption with a sound. All three are built from scratch in PyTorch on top of tiny-bert.
Built with:
PyTorch
NumPy
Hugging Face Datasets
pytest
JavaScript