├── git ├── 06_Train_GPT-2 └── homework │ ├── Ghamarani │ └── checkpoint.pdf │ └── nima_kaveh │ ├── figure │ ├── 2.1.png │ ├── 2.2.png │ ├── 2.3.png │ ├── 3.png │ ├── 4.png │ ├── 5.1.png │ ├── 5.2.png │ ├── 6.png │ ├── 7.1.png │ └── 7.2.png │ └── Train_GPT-2.pdf ├── README.md ├── 05_Train_Eval_Gen_Functions └── 1_Train_Eval_Gen_General.ipynb └── 08_Evaluation └── Evaluation.ipynb /git: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/Ghamarani/checkpoint.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/Ghamarani/checkpoint.pdf -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/figure/2.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/figure/2.1.png -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/figure/2.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/figure/2.2.png -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/figure/2.3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/figure/2.3.png -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/figure/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/figure/3.png -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/figure/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/figure/4.png -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/figure/5.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/figure/5.1.png -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/figure/5.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/figure/5.2.png -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/figure/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/figure/6.png -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/figure/7.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/figure/7.1.png -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/figure/7.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/figure/7.2.png -------------------------------------------------------------------------------- /06_Train_GPT-2/homework/nima_kaveh/Train_GPT-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/howsam/Building-a-ChatGPT-like-Model-from-Scratch/HEAD/06_Train_GPT-2/homework/nima_kaveh/Train_GPT-2.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Building-a-ChatGPT-like-Model-from-Scratch 2 | This repository contains a step-by-step implementation of a ChatGPT-like model from scratch using PyTorch. It covers everything from tokenization and transformer architecture to training and fine-tuning on conversational data. The course is designed for those who want to deeply understand how large language models work and build their own! 🚀 3 | -------------------------------------------------------------------------------- /05_Train_Eval_Gen_Functions/1_Train_Eval_Gen_General.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "collapsed_sections": [ 8 | "VrFCH9hpEyip", 9 | "3in1e9BksgIh", 10 | "xv32RDGrJhqv", 11 | "w_a3OXnSeV0z", 12 | "RwaY_YcgRayy", 13 | "mf-QHos1nK3D", 14 | "RTql4Ftiunfr", 15 | "ZnBQs-C8PNrY", 16 | "lAoYRsvKN_8l", 17 | "WTVewgG-m7nq", 18 | "ih6sV9ljndzW", 19 | "LCzTHf8iitEt", 20 | "Q1Gx0mlvVJsV", 21 | "W0QNbC0YPCKZ", 22 | "ACjVH6bBpAEV", 23 | "G9HgVWslPGsH", 24 | "6kSRpX11o6Dm", 25 | "o_5f69nwPtY2", 26 | "CgpgXUYbuwHn" 27 | ], 28 | "gpuType": "T4", 29 | "include_colab_link": true 30 | }, 31 | "kernelspec": { 32 | "name": "python3", 33 | "display_name": "Python 3" 34 | }, 35 | "language_info": { 36 | "name": "python" 37 | }, 38 | "accelerator": "GPU" 39 | }, 40 | "cells": [ 41 | { 42 | "cell_type": "markdown", 43 | "metadata": { 44 | "id": "view-in-github", 45 | "colab_type": "text" 46 | }, 47 | "source": [ 48 | "\"Open" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": { 54 | "id": "-uXkcYhkIxS-" 55 | }, 56 | "source": [ 57 | "# 💎 Train, Evaluate, and Generate Functions (General)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": { 63 | "id": "VrFCH9hpEyip" 64 | }, 65 | "source": [ 66 | "# 🔴 **Environment Setup**" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": { 72 | "id": "3in1e9BksgIh" 73 | }, 74 | "source": [ 75 | "## 🟠 Change the font size of the output cells" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": null, 81 | "metadata": { 82 | "colab": { 83 | "base_uri": "https://localhost:8080/" 84 | }, 85 | "id": "1_nYkVog8SUR", 86 | "outputId": "f02c5706-3dfe-4b6d-f0e5-0ce5920432b2" 87 | }, 88 | "outputs": [ 89 | { 90 | "output_type": "stream", 91 | "name": "stdout", 92 | "text": [ 93 | "Salam Howsam!\n" 94 | ] 95 | } 96 | ], 97 | "source": [ 98 | "print('Salam Howsam!')" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": { 105 | "id": "BmMM0EfKsSiO" 106 | }, 107 | "outputs": [], 108 | "source": [ 109 | "from IPython.display import HTML\n", 110 | "shell = get_ipython()\n", 111 | "\n", 112 | "def adjust_font_size():\n", 113 | " display(HTML('''