Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,241 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
### Model Description
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
- **
|
| 21 |
-
- **
|
| 22 |
-
- **
|
| 23 |
-
- **
|
| 24 |
-
- **
|
| 25 |
-
- **
|
| 26 |
-
- **
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
### Out-of-Scope Use
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
|
| 64 |
### Recommendations
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
-
|
| 70 |
-
## How to Get Started with the Model
|
| 71 |
-
|
| 72 |
-
Use the code below to get started with the model.
|
| 73 |
-
|
| 74 |
-
[More Information Needed]
|
| 75 |
-
|
| 76 |
-
## Training Details
|
| 77 |
-
|
| 78 |
-
### Training Data
|
| 79 |
-
|
| 80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 81 |
-
|
| 82 |
-
[More Information Needed]
|
| 83 |
-
|
| 84 |
-
### Training Procedure
|
| 85 |
-
|
| 86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#### Training Hyperparameters
|
| 94 |
-
|
| 95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
|
| 103 |
## Evaluation
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
|
| 127 |
### Results
|
|
|
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
|
| 141 |
## Environmental Impact
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
-
|
| 148 |
-
-
|
| 149 |
-
-
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
|
| 153 |
-
## Technical Specifications
|
| 154 |
|
| 155 |
-
### Model Architecture
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
| 158 |
|
| 159 |
### Compute Infrastructure
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
|
| 165 |
-
|
| 166 |
|
| 167 |
-
|
| 168 |
|
| 169 |
-
|
| 170 |
|
| 171 |
-
|
| 172 |
|
| 173 |
-
|
| 174 |
|
| 175 |
-
|
|
|
|
|
|
|
| 176 |
|
| 177 |
-
|
|
|
|
|
|
|
| 178 |
|
| 179 |
-
**
|
| 180 |
|
| 181 |
-
|
| 182 |
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
-
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
|
| 190 |
|
| 191 |
-
|
| 192 |
|
| 193 |
-
##
|
| 194 |
|
| 195 |
-
|
| 196 |
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
+
license: mit
|
| 4 |
+
datasets:
|
| 5 |
+
- HuggingFaceFW/fineweb-edu
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
base_model:
|
| 9 |
+
- openai-community/gpt2
|
| 10 |
+
pipeline_tag: text-generation
|
| 11 |
+
tags:
|
| 12 |
+
- GPT
|
| 13 |
+
- GPT-3 Small
|
| 14 |
+
- GPT-3 Medium
|
| 15 |
+
- GPT-3 Large
|
| 16 |
+
- GPT-3 XL
|
| 17 |
+
- GPT-3 2.7B
|
| 18 |
+
- GPT-3 6.7B
|
| 19 |
+
- GPT-3 13B
|
| 20 |
+
- GPT-3 175B
|
| 21 |
+
- GPT-3
|
| 22 |
+
- GPT-2
|
| 23 |
+
- GPT-2 124M
|
| 24 |
+
- transformers
|
| 25 |
+
- mit
|
| 26 |
+
- HuggingFace
|
| 27 |
+
- fineweb-edu
|
| 28 |
+
- Decoder-Only
|
| 29 |
---
|
| 30 |
+
# Model Card for GPT-124M
|
| 31 |
|
| 32 |
+
## Overview
|
| 33 |
|
| 34 |
+
GPT-124M is a decoder-only transformer model based on OpenAI’s GPT-2 architecture. It is trained for text generation and other natural language processing (NLP) tasks. The model is designed for general-purpose language modeling, making it useful for applications such as text completion.
|
| 35 |
|
| 36 |
+
- **Library:** 🤗 `transformers`
|
| 37 |
+
- **License:** MIT
|
| 38 |
+
- **Datasets:** `HuggingFaceFW/fineweb-edu`
|
| 39 |
+
- **Language:** English
|
| 40 |
+
- **Base Model:** `openai-community/gpt2`
|
| 41 |
+
- **Pipeline Tag:** `text-generation`
|
| 42 |
+
- **Developer:** Samkeet Sangai
|
| 43 |
+
- **Funded By:** Samkeet Sangai
|
| 44 |
+
- **Shared By:** Samkeet Sangai
|
| 45 |
+
- **Model Type:** GPT Decoder-Only
|
| 46 |
|
| 47 |
+
## Model Sources
|
| 48 |
+
|
| 49 |
+
- **Paper:** [Language Models are Unsupervised Multitask Learners](https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf)
|
| 50 |
+
- **Paper:** [Language Models are Few-Shot Learners](https://arxiv.org/pdf/2005.14165)
|
| 51 |
+
- **Paper:** [Training Compute-Optimal Large Language Models](https://arxiv.org/pdf/2203.15556)
|
| 52 |
+
- **Video:** [Andrej Karpathy-Let's reproduce GPT-2 (124M)](https://youtu.be/l8pRSuU81PU?si=KAo1y9dHYQAGJmj5)
|
| 53 |
+
- **Demo:** [GPT 124M Demo](https://huggingface.co/spaces/samkeet/GPT_124M)
|
| 54 |
|
| 55 |
## Model Details
|
| 56 |
|
| 57 |
### Model Description
|
| 58 |
+
GPT-124M is a lightweight generative language model fine-tuned on the `fineweb-edu` dataset. It can generate coherent and contextually relevant text but is not fine-tuned for instruction-following, safety, or factual accuracy.
|
| 59 |
+
|
| 60 |
+
### Training Configuration
|
| 61 |
+
- **Block Size:** `1024`
|
| 62 |
+
- **Vocabulary Size:** `50304`
|
| 63 |
+
- **Number of Layers:** `12`
|
| 64 |
+
- **Number of Attention Heads:** `12`
|
| 65 |
+
- **Embedding Size:** `768`
|
| 66 |
+
- **Hardware:** `8x NVIDIA RTX 4090 GPUs`
|
| 67 |
+
- **Training Duration:** `13 hours`
|
| 68 |
+
- **Dataset:** `fineweb-edu` (10 billion tokens)
|
| 69 |
+
- **Training Date:** `January 2025`
|
| 70 |
+
- **Validation Dataset:** 100 million tokens of HuggingFaceFW/fineweb-edu
|
| 71 |
+
|
| 72 |
+
## Usage
|
| 73 |
+
You can use this model for text generation using the `transformers` library.
|
| 74 |
+
|
| 75 |
+
### Method 2: Using Pipeline
|
| 76 |
+
```python
|
| 77 |
+
# Import necessary modules from transformers
|
| 78 |
+
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
| 79 |
+
|
| 80 |
+
# Load tokenizer and model
|
| 81 |
+
model_name = "samkeet/GPT_124M"
|
| 82 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 83 |
+
|
| 84 |
+
# Create text generation pipeline
|
| 85 |
+
pipe = pipeline("text-generation", model=model_name, tokenizer=tokenizer, trust_remote_code=True, device="cpu")
|
| 86 |
+
|
| 87 |
+
# Generate text
|
| 88 |
+
result = pipe("Earth revolves around the", do_sample=True, max_length=40, temperature=0.9, top_p=0.5, top_k=50)
|
| 89 |
+
print("Pipeline Output:", result)
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
### Method 1: Direct Generation
|
| 93 |
+
```python
|
| 94 |
+
# Import necessary libraries
|
| 95 |
+
import torch
|
| 96 |
+
|
| 97 |
+
# Function for direct tokenization and text generation
|
| 98 |
+
def generate_text(input_text, device='cpu'):
|
| 99 |
+
tokens = tokenizer.encode(input_text, return_tensors='pt').to(device)
|
| 100 |
+
model.to(device)
|
| 101 |
+
|
| 102 |
+
# Generate output
|
| 103 |
+
output = model.generate(
|
| 104 |
+
tokens,
|
| 105 |
+
do_sample=True,
|
| 106 |
+
max_length=40,
|
| 107 |
+
temperature=0.9,
|
| 108 |
+
top_p=0.5,
|
| 109 |
+
top_k=50,
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
# Decode generated text
|
| 113 |
+
generated_sentence = tokenizer.decode(output)
|
| 114 |
+
return generated_sentence
|
| 115 |
+
|
| 116 |
+
# Generate text
|
| 117 |
+
input_text = "Earth revolves around the"
|
| 118 |
+
print("Direct Output:", generate_text(input_text))
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
### Fine-tuning & Downstream Use
|
| 122 |
+
This model can be fine-tuned for specific NLP applications like:
|
| 123 |
+
- Dialogue generation
|
| 124 |
+
- Text summarization
|
| 125 |
+
- Creative writing
|
| 126 |
+
- Code generation
|
| 127 |
+
|
| 128 |
+
## Limitations & Risks
|
| 129 |
|
| 130 |
### Out-of-Scope Use
|
| 131 |
+
- The model is **not instruction-tuned** for safety, ethics, or factual accuracy.
|
| 132 |
+
- It may produce **biased, misleading, or unsafe outputs**.
|
| 133 |
+
- It should **not** be used for tasks requiring high reliability, such as medical, legal, or financial applications.
|
| 134 |
|
| 135 |
+
### Bias, Risks, and Limitations
|
| 136 |
+
- The dataset may contain biases present in public web data.
|
| 137 |
+
- The model does not filter or detect offensive content.
|
| 138 |
+
- The model may **hallucinate** incorrect facts.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
### Recommendations
|
| 141 |
+
- Always **verify** generated content before use.
|
| 142 |
+
- Implement **content filtering mechanisms** for deployment.
|
| 143 |
+
- Use in supervised environments only.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
## Evaluation
|
| 146 |
|
| 147 |
+
### Training & Validation Loss
|
| 148 |
+
Validation was conducted using `100 million tokens` from the `HuggingFaceFW/fineweb-edu` dataset. The training and validation loss graph indicates a stable convergence with minimal overfitting. The training loss achieved a minimum value of 2.88, while the validation loss stabilized at 2.97.
|
| 149 |
+

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
### Results
|
| 152 |
+
The model was benchmarked against OpenAI’s GPT-2 Small and GPT-3 Small (both ~124M parameters). Remarkably, despite being trained on only `10 billion tokens`, compared to GPT-3 Small's `300 billion tokens`, GPT-124M was able to outperform both models in `HellaSwag` evaluation. This performance advantage is attributed to the specialized training data (educational content), which contrasts with GPT-3 Small’s broader multilingual and multi-domain training data.
|
| 153 |
|
| 154 |
+
According to Chinchilla’s scaling laws, an optimal token-to-parameter ratio suggests that a 124M-parameter model ideally requires `2.48 billion tokens` for training. The excess training tokens used in GPT-3 Small might have led to diminishing returns in performance.
|
| 155 |
+

|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
+
### Key Insights from Evaluation
|
| 158 |
+
- **Efficient Training:** The model demonstrates impressive performance relative to its training token count, suggesting an efficient use of resources due to training using the Distributed Data Parallel (DDP) technique.
|
| 159 |
+
- **Data-Specific Advantage:** Training exclusively on educational data may have given GPT-124M an edge in evaluation metrics like `HellaSwag`.
|
| 160 |
+
- **Scaling Considerations:** GPT-3 Small, despite being trained on 300B tokens, does not exhibit proportionally better performance due to scaling limitations.
|
|
|
|
| 161 |
|
| 162 |
## Environmental Impact
|
| 163 |
|
| 164 |
+
- **Hardware Used:** `8x NVIDIA RTX 4090 GPUs`
|
| 165 |
+
- **Training Time:** `13 hours -> 104 GPU hours`
|
| 166 |
+
- **Estimated Carbon Emissions:** `13.48 kg CO2 eq.`
|
| 167 |
+
- **Equivalent to:**
|
| 168 |
+
- `54.5 km` driven by an average ICE car
|
| 169 |
+
- `6.75 kg` of coal burned
|
| 170 |
+
- `0.22` tree seedlings sequestering carbon for 10 years
|
|
|
|
|
|
|
| 171 |
|
| 172 |
+
## Technical Specifications
|
| 173 |
|
| 174 |
+
### Model Architecture
|
| 175 |
+
GPT-124M follows the architecture of OpenAI's GPT-2, which consists of:
|
| 176 |
+
- **Transformer-based decoder model**
|
| 177 |
+
- **Self-attention mechanism**
|
| 178 |
+
- **Layer normalization & feed-forward networks**
|
| 179 |
|
| 180 |
### Compute Infrastructure
|
| 181 |
+
- **Hardware:** 8x NVIDIA RTX 4090 GPUs
|
| 182 |
+
- **Software:** PyTorch, Hugging Face Transformers
|
| 183 |
+
- **Precision:** FP32
|
| 184 |
|
| 185 |
+
Gotcha — here’s a **tight, concise section** you can drop in **as-is**.
|
| 186 |
+
It keeps only the essentials: **data, setup, choices, Kaggle**, no fluff.
|
|
|
|
| 187 |
|
| 188 |
+
## Instruction-Tuned Model
|
| 189 |
|
| 190 |
+
### Training Data
|
| 191 |
|
| 192 |
+
The instruction-tuned GPT-124M is fine-tuned on the **`tatsu-lab/alpaca`** dataset, containing high-quality instruction–response pairs across reasoning, explanation, summarization, and creative tasks. Samples are **length-filtered** to fit the 1024-token context window, counting instruction, input, response, and EOS tokens.
|
| 193 |
|
| 194 |
+
### Prompt & Objective
|
| 195 |
|
| 196 |
+
Training follows an Alpaca-style format:
|
| 197 |
|
| 198 |
+
```
|
| 199 |
+
### Instruction:
|
| 200 |
+
<instruction and optional input>
|
| 201 |
|
| 202 |
+
### Response:
|
| 203 |
+
<target output>
|
| 204 |
+
```
|
| 205 |
|
| 206 |
+
Causal language modeling is used, with **loss applied only to response tokens** (prompt tokens masked with `-100`) and an explicit EOS token appended.
|
| 207 |
|
| 208 |
+
### Training Setup
|
| 209 |
|
| 210 |
+
* **Platform:** Kaggle (GPU-backed notebooks)
|
| 211 |
+
* **Framework:** PyTorch
|
| 212 |
+
* **Precision:** FP32
|
| 213 |
+
* **Optimizer:** AdamW with warmup + cosine decay
|
| 214 |
+
* **Stability:** Gradient clipping and fixed-length batching
|
| 215 |
|
| 216 |
+
### Fine-Tuning Choices
|
| 217 |
|
| 218 |
+
* Supports **full fine-tuning** and **LoRA-based parameter-efficient tuning**
|
| 219 |
+
* LoRA can be merged into base weights for a standalone instruct model
|
| 220 |
+
* Supervised fine-tuning (SFT) chosen for simplicity and reproducibility
|
| 221 |
+
* No RLHF or safety-specific tuning applied
|
| 222 |
|
| 223 |
+
### Outcome
|
| 224 |
|
| 225 |
+
Instruction tuning improves instruction following, output structure, and task performance while preserving the base model’s generative capabilities. The model remains non-aligned and may hallucinate.
|
| 226 |
|
| 227 |
+
## Citation
|
| 228 |
|
| 229 |
+
If you use this model, please cite:
|
| 230 |
|
| 231 |
+
```bibtex
|
| 232 |
+
@article{gpt124m,
|
| 233 |
+
title={GPT-124M: A Compact Transformer Model for NLP},
|
| 234 |
+
author={Samkeet Sangai},
|
| 235 |
+
year={2024},
|
| 236 |
+
url={https://huggingface.co/samkeet/GPT_124M}
|
| 237 |
+
}
|
| 238 |
+
```
|
| 239 |
|
| 240 |
+
## Contact
|
| 241 |
+
For inquiries, contact [Samkeet Sangai](https://www.linkedin.com/in/samkeet-sangai/).
|