Upload folder using huggingface_hub
Browse files- README.md +106 -0
- example_usage.py +15 -0
- model_config.json +9 -0
- model_weights.pt +3 -0
- requirements.txt +2 -0
- tokenizer.json +21 -0
README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: mit
|
| 4 |
+
tags:
|
| 5 |
+
- text-generation
|
| 6 |
+
- transformer
|
| 7 |
+
- custom-model
|
| 8 |
+
- pytorch
|
| 9 |
+
datasets:
|
| 10 |
+
- custom
|
| 11 |
+
metrics:
|
| 12 |
+
- perplexity
|
| 13 |
+
widget:
|
| 14 |
+
- text: "artificial intelligence"
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Custom Transformer Text Generation Model
|
| 18 |
+
|
| 19 |
+
## Model Description
|
| 20 |
+
|
| 21 |
+
This is a custom-built Transformer model trained from scratch for text generation tasks.
|
| 22 |
+
|
| 23 |
+
### Model Architecture
|
| 24 |
+
|
| 25 |
+
- **Model Type**: Transformer (Decoder-only)
|
| 26 |
+
- **Parameters**: 397,572
|
| 27 |
+
- **Embedding Dimension**: 128
|
| 28 |
+
- **Number of Layers**: 2
|
| 29 |
+
- **Attention Heads**: 4
|
| 30 |
+
- **Vocabulary Size**: 4
|
| 31 |
+
- **Context Length**: 128 tokens
|
| 32 |
+
|
| 33 |
+
### Training Details
|
| 34 |
+
|
| 35 |
+
- **Framework**: PyTorch
|
| 36 |
+
- **Perplexity**: 3.76
|
| 37 |
+
- **Training Data**: Custom corpus
|
| 38 |
+
- **Optimizer**: Adam
|
| 39 |
+
- **Loss Function**: Cross-Entropy Loss
|
| 40 |
+
|
| 41 |
+
## Usage
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
import torch
|
| 45 |
+
import json
|
| 46 |
+
|
| 47 |
+
# Load model configuration
|
| 48 |
+
with open('model_config.json', 'r') as f:
|
| 49 |
+
config = json.load(f)
|
| 50 |
+
|
| 51 |
+
# Load tokenizer
|
| 52 |
+
with open('tokenizer.json', 'r') as f:
|
| 53 |
+
tokenizer_data = json.load(f)
|
| 54 |
+
|
| 55 |
+
# Load model weights
|
| 56 |
+
model = TransformerModel(**config)
|
| 57 |
+
model.load_state_dict(torch.load('model_weights.pt'))
|
| 58 |
+
model.eval()
|
| 59 |
+
|
| 60 |
+
# Generate text
|
| 61 |
+
def generate(prompt, max_length=50):
|
| 62 |
+
# Add your generation code here
|
| 63 |
+
pass
|
| 64 |
+
|
| 65 |
+
text = generate("artificial intelligence")
|
| 66 |
+
print(text)
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Limitations
|
| 70 |
+
|
| 71 |
+
- Trained on limited custom data
|
| 72 |
+
- May generate repetitive text
|
| 73 |
+
- Context window limited to 128 tokens
|
| 74 |
+
- Not fine-tuned for specific domains
|
| 75 |
+
|
| 76 |
+
## Training Procedure
|
| 77 |
+
|
| 78 |
+
Model was trained using:
|
| 79 |
+
- Custom transformer architecture
|
| 80 |
+
- Gradient clipping for stability
|
| 81 |
+
- Learning rate scheduling
|
| 82 |
+
- Dropout for regularization
|
| 83 |
+
|
| 84 |
+
## Evaluation
|
| 85 |
+
|
| 86 |
+
**Perplexity**: 3.76
|
| 87 |
+
|
| 88 |
+
Lower perplexity indicates better performance. This model achieved a perplexity of 3.76 on the validation set.
|
| 89 |
+
|
| 90 |
+
## Citation
|
| 91 |
+
|
| 92 |
+
If you use this model, please cite:
|
| 93 |
+
|
| 94 |
+
```
|
| 95 |
+
@misc{custom-transformer-4,
|
| 96 |
+
author = {Your Name},
|
| 97 |
+
title = {Custom Transformer Model},
|
| 98 |
+
year = {2025},
|
| 99 |
+
publisher = {Hugging Face},
|
| 100 |
+
howpublished = {\url{https://huggingface.co/YOUR-USERNAME/YOUR-MODEL-NAME}}
|
| 101 |
+
}
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
## Contact
|
| 105 |
+
|
| 106 |
+
For questions or feedback, please open an issue on the model repository.
|
example_usage.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import torch
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
# Load configuration
|
| 6 |
+
with open('model_config.json', 'r') as f:
|
| 7 |
+
config = json.load(f)
|
| 8 |
+
|
| 9 |
+
# Load tokenizer
|
| 10 |
+
with open('tokenizer.json', 'r') as f:
|
| 11 |
+
tokenizer_data = json.load(f)
|
| 12 |
+
|
| 13 |
+
print("Model loaded successfully!")
|
| 14 |
+
print(f"Vocabulary size: {config['vocab_size']}")
|
| 15 |
+
print(f"Model dimensions: {config['d_model']}")
|
model_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"vocab_size": 4,
|
| 3 |
+
"d_model": 128,
|
| 4 |
+
"num_heads": 4,
|
| 5 |
+
"num_layers": 2,
|
| 6 |
+
"d_ff": 1024,
|
| 7 |
+
"dropout": 0.1,
|
| 8 |
+
"max_len": 512
|
| 9 |
+
}
|
model_weights.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bf352bac08def50c4d2ff83b116b73b5f2750845f189cb6e6507e8f698f2191b
|
| 3 |
+
size 1866227
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.0.0
|
| 2 |
+
numpy>=1.24.0
|
tokenizer.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"word2idx": {
|
| 3 |
+
"<PAD>": 0,
|
| 4 |
+
"<UNK>": 1,
|
| 5 |
+
"<SOS>": 2,
|
| 6 |
+
"<EOS>": 3
|
| 7 |
+
},
|
| 8 |
+
"idx2word": {
|
| 9 |
+
"0": "<PAD>",
|
| 10 |
+
"1": "<UNK>",
|
| 11 |
+
"2": "<SOS>",
|
| 12 |
+
"3": "<EOS>"
|
| 13 |
+
},
|
| 14 |
+
"vocab_size": 10000,
|
| 15 |
+
"special_tokens": [
|
| 16 |
+
"<PAD>",
|
| 17 |
+
"<UNK>",
|
| 18 |
+
"<SOS>",
|
| 19 |
+
"<EOS>"
|
| 20 |
+
]
|
| 21 |
+
}
|