Simple example of Transformer from scratch?

The simplest example is the NanoGPT project from Karpathy: GitHub - karpathy/nanoGPT: The simplest, fastest repository for training/finetuning medium-sized GPTs..

See also the training scripts of Hugging Face for causal language modeling, which are a bit more extensive/feature complete: transformers/examples/pytorch/language-modeling at main · huggingface/transformers · GitHub.