A project featuring a decoder-only GPT architecture built from scratch using only Python and NumPy to demonstrate the fundamental inner workings of large language models.
This repository contains a foundational implementation of the Generative Pre-trained Transformer (GPT) model, built entirely from scratch using core Python libraries. The architecture is derived directly from the seminal paper, "Attention Is All You Need" (Vaswani et al., 2017).
The project aims to provide a deep, practical understanding of the underlying mathematical and algorithmic mechanisms of modern Large Language Models (LLMs) by avoiding high-level deep learning frameworks.
The model adopts the characteristic Decoder-only structure of the GPT framework, which is optimized for autoregressive generation—predicting the next token in a sequence based on the preceding context.
The project meticulously implements the core mechanisms detailed in the paper, focusing on mathematical fidelity:
Masked Multi-Head Self-Attention:
Positional Encoding:
Normalization and Feed-Forward Networks (FFN):
A key feature developed in this repository is an autonomous generation loop that bypasses traditional conditional prompting.
[BOS] or a random word) and proceeds to generate long-form, logically coherent sequences without external input.The model has been successfully developed and trained on a designated language corpus. Key architectural parameters and statistical indicators include:
Due to the fundamental nature of the implementation and the original code contributions based on the paper's principles, a specific license (e.g., the MIT License) will be added to the repository.
The foundational academic work for this project: