NeuroText is a custom Transformer-based Language Model designed for next-word prediction. The project implements a decoder-style Transformer architecture from scratch using TensorFlow/Keras, incorporating Multi-Head Self-Attention, Positional Encoding, Layer Normalization, and Feed-Forward Networks.
The model learns contextual relationships between words and predicts the most probable next word given a sequence of previous words.
- Custom Transformer architecture built from scratch
- Sinusoidal Positional Encoding
- Multi-Head Self-Attention with Causal Masking
- Pre-Normalization Transformer Blocks
- GELU Activation Function
- Residual Connections
- Dropout Regularization
- Early Stopping & Best Model Checkpointing
- Top-K Accuracy Evaluation
- Perplexity-Based Language Model Assessment
- Tokenized text sequences
- Fixed context length
Converts token IDs into dense vector representations.
Adds positional information using sinusoidal encoding:
Each Transformer block contains:
- Multi-Head Self-Attention
- Layer Normalization (Pre-Norm)
- Residual Connection
- Feed Forward Network
- Dropout
- Global Average Pooling
- Layer Normalization
- Dense Softmax Layer
Produces probability distribution over the entire vocabulary.
| Parameter | Value |
|---|---|
| Embedding Dimension | 128 |
| Transformer Blocks | 4 |
| Attention Heads | 4 |
| Feed Forward Dimension | 512 |
| Dropout | 0.1 |
| Activation | GELU |
| Output Layer | Softmax |
| Optimizer | AdamW |
| Loss Function | Sparse Categorical Crossentropy |
Custom sinusoidal positional encoding layer implemented from scratch.
Custom decoder-style Transformer block featuring:
- Causal Self-Attention
- Layer Normalization
- Residual Connections
- Feed Forward Network
- Dropout Regularization
| Metric | Score |
|---|---|
| Top-1 Accuracy | 28.19% |
| Top-3 Accuracy | 44.74% |
| Top-5 Accuracy | 51.41% |
| Top-10 Accuracy | 59.83% |
| Metric | Value |
|---|---|
| Perplexity | 55.94 |
- Correct prediction appears as the highest probability word 28.19% of the time.
- Correct prediction appears within the top 3 predictions 44.74% of the time.
- Correct prediction appears within the top 5 predictions 51.41% of the time.
- Correct prediction appears within the top 10 predictions 59.83% of the time.
- Perplexity of 55.94 indicates strong contextual learning for a custom Transformer trained from scratch.
Measures whether the correct next word appears among the top K predicted words.
Perplexity is a standard metric for language models:
[ Perplexity = e^{Loss} ]
Lower perplexity indicates better language modeling performance.
Artificial intelligence is transforming the
world
future
industry
way
technology
- Python
- TensorFlow / Keras
- NumPy
- Matplotlib
- Google Colab
- Larger vocabulary size
- Deeper Transformer stacks
- Byte Pair Encoding (BPE)
- Subword tokenization
- Beam Search Decoding
- Attention Visualization
- GPT-style autoregressive generation
- Fine-tuning on domain-specific corpora
NeuroText demonstrates that a custom-built Transformer architecture can effectively learn contextual language patterns and achieve competitive next-word prediction performance while being significantly smaller and more lightweight than large-scale language models.
Shruti Patel
Transformer-Based Language Modeling Project
Built with TensorFlow and Transformer Architecture from Scratch.