NLP, built from scratch

A Transformer we wrote by hand, from random weights.

An emotion classifier on a Transformer encoder we wrote from scratch in PyTorch and trained from random weights. Built with Shaik Bavikadi Al Hafeez.

13.6M
parameters
6
emotions
0
pre-trained weights used

Why

We wanted to understand Transformers well enough to write one without leaning on a library.

What we built

  • Token embeddings with positional encoding.
  • Scaled dot-product self-attention and multi-head attention (8 heads), written by hand.
  • An encoder block (hidden size 256, feed-forward 1024) with Add & Norm, then mean pooling and a linear classifier.
  • The full training loop in plain PyTorch, starting from random initialization.

What it does

Give it a short piece of English text and it predicts one of six emotions: sadness, joy, love, anger, fear or surprise. It was trained on the dair-ai/emotion dataset of English Twitter messages.

The model is open-sourced on Hugging Face under the MIT license. Built with Shaik Bavikadi Al Hafeez.

↑↓ move ↵ open esc close