File size: 7,074 Bytes
5b3470c 69f4cd6 5b3470c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
---
license: mit
datasets:
- lmsys/lmsys-chat-1m
language:
- en
base_model:
- AGofficial/AgGPT-15
---
# ๐ค AgGPT-21

A powerful and lightweight GPT-style language model built with PyTorch, featuring word-level tokenization and GRU-based architecture.
## โจ Features
- **๐ง Intelligent Architecture**: GRU-based neural network with embedding layers
- **๐ Multi-File Training**: Trains on multiple corpus files automatically
- **โก Optimized Performance**: Supports GPU (CUDA), Apple Silicon (MPS), and CPU
- **๐๏ธ Flexible Generation**: Configurable temperature, top-k, and top-p sampling
- **๐ฌ Interactive Chat**: Beautiful command-line chat interface
- **๐ Early Stopping**: Prevents overfitting with validation-based early stopping
- **๐ Progress Tracking**: Real-time training progress with tqdm
## ๐ Quick Start
### Prerequisites
```bash
pip install torch tqdm
```
### Training the Model
1. **Prepare your training data**: Place your text files in the `training_corpora/` folder
2. **Start training**:
```bash
python AgGPT21.py
```
The model will automatically:
- Load all `.txt` files from `training_corpora/`
- Build vocabulary from your data
- Train with validation split and early stopping
- Save the trained model as `AgGPT21.pt`
### Interactive Chat
Once trained, start chatting with your model:
```bash
python chat.py
```
## ๐ Project Structure
```
AgGPT-21-2/
โโโ banner.png # Project banner image
โโโ AgGPT21.py # Main training script
โโโ chat.py # Interactive chat interface
โโโ README.md # This file
โโโ AgGPT21.pt # Trained model (generated after training)
โโโ training_corpora/ # Training data folder
โโโ corpora_000.txt # Training file 1
โโโ corpora_001.txt # Training file 2
โโโ ... # More training files
โโโ corpora_041.txt # Training file N
```
## โ๏ธ Configuration
### Model Hyperparameters
| Parameter | Default | Description |
|-----------|---------|-------------|
| `SEQ_LEN` | 64 | Sequence length for training |
| `EMBED_SIZE` | 128 | Embedding dimension |
| `HIDDEN_SIZE` | 128 | GRU hidden dimension |
| `NUM_LAYERS` | 1 | Number of GRU layers |
| `DROPOUT` | 0.2 | Dropout rate |
### Training Parameters
| Parameter | Default | Description |
|-----------|---------|-------------|
| `BATCH_SIZE` | 8 | Training batch size |
| `EPOCHS` | 6 | Maximum training epochs |
| `LR` | 2e-3 | Learning rate |
| `WEIGHT_DECAY` | 1e-4 | L2 regularization |
| `CLIP_NORM` | 1.0 | Gradient clipping |
### Generation Settings
| Parameter | Default | Description |
|-----------|---------|-------------|
| `TEMPERATURE` | 0.9 | Sampling temperature (0.1-2.0) |
| `TOP_K` | 50 | Top-k sampling limit |
| `TOP_P` | 0.9 | Nucleus sampling threshold |
| `GENERATE_LENGTH` | 200 | Default generation length |
## ๐ฎ Chat Commands
In the interactive chat mode, you can use these commands:
- **Basic Chat**: Just type your message
- **`quit`/`exit`/`bye`**: End the conversation
- **`help`**: Show available commands
- **`clear`**: Clear the screen
- **`model`**: Display model information
- **`temp X`**: Set temperature (e.g., `temp 0.8`)
- **`length X`**: Set response length (e.g., `length 150`)
## ๐งช Example Usage
### Training Example
```python
# Train the model (automatic multi-file loading)
python AgGPT21.py
```
Output:
```
Found 42 training files
Reading corpora_000.txt...
Reading corpora_001.txt...
...
Total words loaded: 2,847,392
Vocabulary size: 30,000
Tokens used: 1,000,000 | device=mps
Model params: 4,099,200
Train batches per epoch: 1,562 | Val batches: 79
Epochs: 100%|โโโโโโโโโโโโ| 6/6 [05:23<00:00, 53.92s/it, train=2.1847, val=2.3456]
Saved AgGPT21.pt
```
### Chat Example
```
๐ค You: Tell me about artificial intelligence
๐ค AgGPT-21: Artificial intelligence is a fascinating field that focuses on creating systems capable of performing tasks that typically require human intelligence. These systems can learn from data, recognize patterns, make decisions, and solve complex problems. AI has applications in many areas including natural language processing, computer vision, robotics, and machine learning...
```
## ๐ง Advanced Usage
### Custom Vocabulary Size
```python
MAX_VOCAB = 50000 # Increase vocabulary size
```
### Training on Subset of Data
```python
DATA_PERCENT = 0.5 # Use only 50% of available data
MAX_TOKENS = 500_000 # Limit to 500k tokens
```
### Multi-GPU Training
```python
# The model automatically detects and uses available accelerators:
# - CUDA (NVIDIA GPUs)
# - MPS (Apple Silicon)
# - CPU (fallback)
```
## ๐ Model Architecture
```
Input โ Embedding โ Dropout โ GRU โ Dropout โ [Projection] โ Linear โ Output
โ โ โ โ
Token Vector Hidden Logits
IDs (128-dim) States (Vocab-size)
```
**Key Features:**
- **Weight Tying**: Output layer shares weights with embedding layer
- **Gradient Clipping**: Prevents exploding gradients
- **Mixed Precision**: Automatic FP16 on supported devices
- **Early Stopping**: Validation-based training termination
## ๐ฏ Performance Tips
1. **GPU Acceleration**: Use CUDA or MPS for faster training
2. **Batch Size**: Increase if you have more memory
3. **Sequence Length**: Longer sequences capture more context
4. **Vocabulary**: Smaller vocab = faster training, larger vocab = better coverage
5. **Data Quality**: Clean, relevant training data improves results
## ๐ Troubleshooting
### Common Issues
**"No .txt files found"**
- Ensure your training files are in `training_corpora/` with `.txt` extension
**"CUDA out of memory"**
- Reduce `BATCH_SIZE` or `SEQ_LEN`
- Use `DATA_PERCENT < 1.0` to train on less data
**"Model file not found"**
- Train the model first with `python AgGPT21.py`
- Ensure `AgGPT21.pt` exists in the project directory
## ๐ Training Data Format
Your training files should be plain text. The model will automatically:
- Convert to lowercase
- Split on whitespace
- Handle special tokens like `<pad>`, `<eos>`, etc.
- Build vocabulary from all files combined
Example format:
```
user: how are you today
<pad>
ai: I'm doing well, thank you for asking! How are you?
<eos>
```
## ๐ค Contributing
1. Fork the repository
2. Create a feature branch
3. Make your improvements
4. Test thoroughly
5. Submit a pull request
## ๐ License
This project is open source. Feel free to use, modify, and distribute as needed.
## ๐โโ๏ธ Support
If you encounter issues or have questions:
1. Check the troubleshooting section
2. Review your training data format
3. Ensure all dependencies are installed
4. Verify your PyTorch installation supports your hardware
---
**Made with โค๏ธ for the AI community**
*AgGPT-21 - Where conversation meets intelligence.* |