Text Generation
Keras
English
text-generation-inference
TinyStories
miniGPT
llama
educational
tensorflow
Instructions to use ARX1A07/miniGPT_Project with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use ARX1A07/miniGPT_Project with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://ARX1A07/miniGPT_Project") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from ARX1A07/miniGPT_Project: direct link, hf CLI and curl.
- Browser
- Download file 8.54 kB
-
https://huggingface.co/ARX1A07/miniGPT_Project/resolve/main/README.md
- Command line
-
hf download hf://ARX1A07/miniGPT_Project/README.md
-
curl -L -o README.md https://huggingface.co/ARX1A07/miniGPT_Project/resolve/main/README.md
8.54 kB
| license: mit | |
| language: | |
| - en | |
| datasets: | |
| - roneneldan/TinyStories | |
| base_model: | |
| - openai-community/gpt2 | |
| pipeline_tag: text-generation | |
| tags: | |
| - text-generation-inference | |
| - TinyStories | |
| - miniGPT | |
| - llama | |
| - educational | |
| - tensorflow | |
| - keras | |
| library_name: keras | |
| # π§ MiniGPT β TinyStories | |
| A compact **LLaMA-inspired decoder-only Transformer** trained from scratch in TensorFlow/Keras on the TinyStories dataset. | |
| The model is designed as a small-scale experiment in implementing and training a modern decoder-only language model with components such as **RoPE, RMSNorm, SwiGLU, causal self-attention, frozen pretrained embeddings, and weight tying**. | |
| --- | |
| ## π Model Configuration | |
| | Parameter | Value | | |
| | ---------------------------- | -----------------------: | | |
| | Architecture | Decoder-only Transformer | | |
| | Architecture style | LLaMA-inspired | | |
| | Parameters | **85,791,744 (~85.8M)** | | |
| | Transformer layers | **5** | | |
| | Hidden dimension (`d_model`) | **768** | | |
| | Attention heads | **12** | | |
| | Head dimension | **64** | | |
| | FFN hidden dimension | **3072** | | |
| | Vocabulary size | **50,257** | | |
| | Context length | **256 tokens** | | |
| | Tokenizer | GPT-2 BPE | | |
| | Framework | TensorFlow / Keras | | |
| | Precision | Mixed `bfloat16` | | |
| --- | |
| ## ποΈ Model Architecture | |
| The model follows a compact LLaMA-style decoder architecture: | |
| ```text | |
| GPT-2 BPE Tokenizer | |
| β | |
| βΌ | |
| Token IDs | |
| β | |
| βΌ | |
| Frozen GPT-2 Embedding Matrix | |
| β | |
| βΌ | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β Decoder Block Γ 5 β | |
| β β | |
| β RMSNorm β | |
| β β β | |
| β βΌ β | |
| β Causal Multi-Head Self-Attention β | |
| β β β | |
| β βββ Q β | |
| β βββ K βββΊ RoPE β | |
| β βββ V β | |
| β β β | |
| β βββ Attention + Residual β | |
| β β | |
| β RMSNorm β | |
| β β β | |
| β βΌ β | |
| β SwiGLU Feed-Forward Network β | |
| β β β | |
| β βββ Residual β | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β | |
| βΌ | |
| Final RMSNorm | |
| β | |
| βΌ | |
| Weight-Tied Language Modeling Head | |
| β | |
| βΌ | |
| Logits [sequence_length Γ 50,257] | |
| ``` | |
| ### π© Decoder Block | |
| Each of the **5 decoder layers** operates on a hidden representation of size **768**. | |
| #### 1. RMSNorm | |
| The input representation is normalized before each major sub-layer using **RMSNorm** rather than LayerNorm. | |
| ```text | |
| x β RMSNorm β Attention | |
| ``` | |
| and subsequently: | |
| ```text | |
| x β RMSNorm β SwiGLU | |
| ``` | |
| This gives the block the pre-normalized structure commonly used by modern decoder-only architectures. | |
| #### 2. Causal Multi-Head Self-Attention | |
| The model uses: | |
| * **12 attention heads** | |
| * **64 dimensions per head** | |
| * `12 Γ 64 = 768` total attention dimension | |
| * causal masking to prevent access to future tokens | |
| The hidden representation is projected into: | |
| ```text | |
| Q = XWq | |
| K = XWk | |
| V = XWv | |
| ``` | |
| with attention operating independently across the 12 heads before the heads are merged back into the original `768`-dimensional representation. | |
| #### 3. Rotary Positional Embeddings | |
| **RoPE** is applied to the query and key representations inside the attention mechanism. | |
| This provides positional information without requiring a learned positional embedding table. | |
| #### 4. SwiGLU Feed-Forward Network | |
| The attention output is followed by a **SwiGLU** feed-forward block with an intermediate dimension of **3072**. | |
| Conceptually: | |
| ```text | |
| x | |
| β | |
| βββ Linear βββΊ SiLU βββ | |
| β Γ βββΊ Linear βββΊ output | |
| βββ Linear ββββββββββββ | |
| ``` | |
| The resulting representation is returned to the residual stream. | |
| #### 5. Residual Connections | |
| Each major sub-layer uses a residual connection: | |
| ```text | |
| x β RMSNorm β Attention β + x | |
| β | |
| βΌ | |
| x' | |
| β | |
| RMSNorm β SwiGLU β + x' | |
| ``` | |
| This structure is repeated **5 times**. | |
| --- | |
| ## π― Output Projection & Weight Tying | |
| After the final decoder block: | |
| ```text | |
| Hidden States | |
| β | |
| βΌ | |
| Final RMSNorm | |
| β | |
| βΌ | |
| Language Modeling Head | |
| β | |
| βΌ | |
| 50,257 vocabulary logits | |
| ``` | |
| The language-modeling projection is **weight-tied with the input token embedding representation**, reducing redundant parameters and following the common tied-embedding approach. | |
| The resulting tensor has the conceptual shape: | |
| ```text | |
| (batch, sequence_length, 50,257) | |
| ``` | |
| --- | |
| ## π Parameter Distribution | |
| The final Keras model contains: | |
| | Category | Parameters | | |
| | ------------- | -------------: | | |
| | Total | **85,791,744** | | |
| | Trainable | **47,194,368** | | |
| | Non-trainable | **38,597,376** | | |
| The large non-trainable component corresponds primarily to the **frozen pretrained GPT-2 embedding matrix**. | |
| --- | |
| ## π Training Configuration | |
| | Parameter | Configuration | | |
| | ----------------------- | --------------------- | | |
| | Dataset | TinyStories | | |
| | Training token budget | 100M tokens | | |
| | Validation token budget | 5M tokens | | |
| | Context length | 256 | | |
| | Batch size | 16 | | |
| | Epochs configured | 3 | | |
| | Optimizer | AdamW | | |
| | Weight decay | 0.01 | | |
| | Gradient clipping | `clipnorm=1.0` | | |
| | Maximum LR | `1e-4` | | |
| | Minimum LR | `1e-5` | | |
| | Warmup | 2,000 steps | | |
| | LR schedule | Warmup + cosine decay | | |
| | Precision | Mixed `bfloat16` | | |
| --- | |
| ## π Evaluation | |
| | Metric | Result | | |
| | ---------------------------------------------------- | ------------------------------------- | | |
| | Validation loss / Perplexity / Generation evaluation | **Yet to be collected and evaluated** | | |
| --- | |
| ## π οΈ Implementation & Deployment | |
| The model itself is implemented and trained in **TensorFlow/Keras**. | |
| The notebook contains the experimental training implementation and model construction. | |
| * π **Training / model-construction notebook:** `[<COLAB LINK>](https://colab.research.google.com/drive/1DUSM24y3hcrc06BduC47kyWnciu8OGZg?usp=sharing)` | |
| * π³ **Docker-based inference server:** `[<GITHUB LINK>](https://github.com/abhayramasamy/MiniGPT_Project)` | |
| * π€ **Hugging Face model / artifacts:** `[<HF LINK>](https://huggingface.co/ARX1A07/miniGPT_Project/)` | |
| > The Hugging Face integration and generation pipeline are intentionally documented separately from the core architecture. The Docker repository contains the deployment-oriented inference implementation. | |
| --- | |
| ## β οΈ Limitations | |
| This is a relatively small language model trained specifically on **TinyStories**. Its capabilities should therefore be interpreted within the scope of the dataset and parameter scale. | |
| It should **not** be considered a general-purpose language model or compared directly with substantially larger pretrained LLMs. | |
| Evaluation and generation-quality benchmarking are still pending. | |
| --- | |
| ## π References | |
| * Eldan, R. & Li, Y. β *TinyStories: How Small Can Language Models Be and Still Speak Coherent English?* (2023). | |
| * Hugging Face β TinyStories dataset. | |
| * Vaswani et al. β *Attention Is All You Need*. | |
| * Su et al. β *RoFormer: Enhanced Transformer with Rotary Position Embedding*. | |
| * Shazeer β *GLU Variants Improve Transformer*. | |
| --- | |