Skip to content

rubzip/Transformers-Implementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Transformers-Implementation

An educational from-scratch implementation of the Transformer architecture in PyTorch, based on the paper "Attention Is All You Need".

This repository demonstrates how the encoder–decoder Transformer works by building all of its core components step by step.


🧰 Project Structure

Transformers-Implementation/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ add_and_norm.py # Add & Norm layer
β”‚ β”œβ”€β”€ attention.py # Scaled Dot-Product Attention + Multi-Head Attention
β”‚ β”œβ”€β”€ decoder.py # Transformer Decoder
β”‚ β”œβ”€β”€ encoder.py # Transformer Encoder
β”‚ β”œβ”€β”€ positional_encoding.py # Sinusoidal Positional Encoding
β”‚ β”œβ”€β”€ position_wise_fnn.py # Position-wise Feed-Forward Network
β”‚ └── transformer.py # Full Transformer model
β”œβ”€β”€ test/ # Unit tests
β”œβ”€β”€ pytest.ini # Pytest configuration
β”œβ”€β”€ .gitignore
└── README.md

πŸš€ Features

  • Add & Norm Layer – residual connection + layer normalization.
  • Scaled Dot-Product Attention with optional causal masking.
  • Multi-Head Attention – parallel attention across multiple heads.
  • Position-wise Feed-Forward Network – two linear layers with ReLU.
  • Encoder & Decoder Layers – stacked with attention and feed-forward sublayers.
  • Positional Encoding – sinusoidal encodings to inject sequence order.
  • Full Transformer Model – combines encoder, decoder, and positional encoding.

πŸ”§ Requirements

  • Python 3.7+
  • PyTorch
  • pytest (for running tests)

Install dependencies:

pip install -r requirements.txt

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages