← back to projects

Transformers from Sctrach

A complete Transformer architecture built from scratch in Python — implementing multi-head self-attention, positional encoding, encoder-decoder structure, and training loop without relying on high-level framework abstractions.

PythonPyTorchTransformersAttention MechanismDeep LearningNLPNeural Networks

The Transformer architecture changed everything in AI — it powers GPT, BERT, Cohere’s Command models, and virtually every modern language model. This project builds the entire architecture from scratch to demonstrate a deep understanding of how these models actually work under the hood, not just how to call them through an API. The implementation covers every core component: multi-head self-attention, scaled dot-product attention, positional encoding, layer normalization, feed-forward networks, and the full encoder-decoder structure. Each part is built step by step with clear code and explanations, showing how raw input text gets transformed into meaningful representations through stacked attention layers. This project pairs with the “Attention Is All You Need” paper by Vaswani et al. — the foundational paper co-authored by Cohere CEO Aidan Gomez that introduced the architecture in 2017.