Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
datasets: karpathy/tiny_shakespeare
|
| 4 |
+
library_name: pytorch
|
| 5 |
+
tags:
|
| 6 |
+
- transformer
|
| 7 |
+
- decoder-only
|
| 8 |
+
- character-level
|
| 9 |
+
- text-generation
|
| 10 |
+
- shakespeare
|
| 11 |
+
license: mit
|
| 12 |
+
model_name: decoder-shakespeare-gpt
|
| 13 |
+
pipeline_tag: text-generation
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# Decoder-Only Shakespeare GPT
|
| 17 |
+
|
| 18 |
+
This is a lightweight GPT-style decoder-only transformer model trained on the Tiny Shakespeare dataset (`karpathy/tiny_shakespeare`). It uses a custom implementation in PyTorch and supports character-level text generation.
|
| 19 |
+
|
| 20 |
+
## Model Details
|
| 21 |
+
|
| 22 |
+
- **Architecture**: Decoder-only Transformer
|
| 23 |
+
- **Layers**: 2
|
| 24 |
+
- **Embedding Size**: 128
|
| 25 |
+
- **Heads**: 4
|
| 26 |
+
- **Sequence Length**: 64
|
| 27 |
+
- **Training Epochs**: 4
|
| 28 |
+
- **Tokenizer**: GPT-2 tokenizer (character-level)
|
| 29 |
+
|
| 30 |
+
## Training
|
| 31 |
+
|
| 32 |
+
Trained on the full Tiny Shakespeare dataset for 4 epochs using Adam optimizer and cross-entropy loss. Validation loss is tracked and logged using Weights & Biases (wandb).
|
| 33 |
+
|
| 34 |
+
## Usage
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
from transformers import AutoTokenizer
|
| 38 |
+
import torch
|
| 39 |
+
from model import DecoderOnlyTransformer # custom model class
|
| 40 |
+
|
| 41 |
+
tokenizer = AutoTokenizer.from_pretrained("NataliiaM15/decoder-shakespeare-gpt")
|
| 42 |
+
model = DecoderOnlyTransformer(
|
| 43 |
+
vocab_size=tokenizer.vocab_size,
|
| 44 |
+
embed_dim=128,
|
| 45 |
+
num_heads=4,
|
| 46 |
+
num_layers=2,
|
| 47 |
+
seq_len=64
|
| 48 |
+
)
|
| 49 |
+
model.load_state_dict(torch.load("pytorch_model.bin"))
|
| 50 |
+
model.eval()
|
| 51 |
+
|
| 52 |
+
# Generate text
|
| 53 |
+
prompt = "ROMEO:"
|
| 54 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
| 55 |
+
# generation loop would go here...
|