JonusNattapong commited on
Commit
d662884
·
verified ·
1 Parent(s): d120453

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +79 -361
README.md CHANGED
@@ -1,361 +1,79 @@
1
- ---
2
- language: th
3
- tags:
4
- - thai
5
- - language-model
6
- - transformer
7
- - causal-lm
8
- - modern-architecture
9
- - rope
10
- - swiglu
11
- - rms-norm
12
- - gqa
13
- license: apache-2.0
14
- datasets:
15
- - custom
16
- ---
17
-
18
- # ZombitThai-GPT
19
-
20
- A cutting-edge Thai language model with **128K token context support**, featuring modern transformer architecture with advanced optimizations for superior performance and long-document processing.
21
-
22
- ## 🚀 Key Features
23
-
24
- - **🔥 128K Context Length**: Process documents up to 131,072 tokens with dynamic RoPE scaling
25
- - **🌀 Dynamic RoPE Scaling**: Adaptive positional encoding for sequences of any length
26
- - **⚡ SwiGLU Activation**: Advanced activation function for improved expressiveness
27
- - **🎯 RMSNorm**: More stable normalization compared to LayerNorm
28
- - **🚀 Grouped Query Attention (GQA)**: Efficient attention mechanism with reduced KV cache
29
- - **🇹🇭 Thai-Optimized Tokenizer**: Advanced Thai syllable-aware tokenization
30
- - **🔧 Hugging Face Integration**: Full compatibility with transformers library
31
- - **💾 Memory Efficient**: Optimized for long context processing
32
- - **🎨 Advanced Sampling**: Multiple strategies for high-quality text generation
33
-
34
- ## 📊 Model Specifications
35
-
36
- | Parameter | Value |
37
- |-----------|-------|
38
- | Model Size | 25M+ parameters |
39
- | Vocabulary Size | 50,000+ tokens |
40
- | Context Length | **131,072 tokens (128K)** |
41
- | Layers | 12 |
42
- | Attention Heads | 12 |
43
- | Key/Value Heads | 8 (GQA) |
44
- | Hidden Size | 768 |
45
- | Feed-Forward Size | 3,072 |
46
- | RoPE Scaling | Dynamic |
47
- | Architecture | Modern Transformer |
48
-
49
- ## 💻 Usage
50
-
51
- ### Hugging Face Integration (Recommended)
52
-
53
- ```python
54
- from transformers import AutoTokenizer, AutoModelForCausalLM
55
-
56
- # Load model and tokenizer from Hugging Face
57
- model_name = "ZombitX64/ZombitThai-GPT-128K"
58
- tokenizer = AutoTokenizer.from_pretrained(model_name)
59
- model = AutoModelForCausalLM.from_pretrained(
60
- model_name,
61
- trust_remote_code=True # Required for custom architecture
62
- )
63
-
64
- # Generate text with 128K context support
65
- prompt = "สวัสดีครับ วันนี้อากาศดีจังเลย"
66
- inputs = tokenizer(prompt, return_tensors="pt")
67
-
68
- # Use full 128K context for long documents
69
- outputs = model.generate(
70
- **inputs,
71
- max_length=131072, # Full 128K context
72
- temperature=0.8,
73
- do_sample=True,
74
- top_p=0.9,
75
- top_k=50
76
- )
77
- generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
78
- print(generated_text)
79
- ```
80
-
81
- ### Long Document Processing
82
-
83
- ```python
84
- # Process very long documents
85
- long_document = "..." * 50000 # 50K+ token document
86
- inputs = tokenizer(long_document, return_tensors="pt", truncation=False)
87
-
88
- # Generate with full context awareness
89
- outputs = model.generate(
90
- **inputs,
91
- max_length=min(len(inputs['input_ids'][0]) + 1000, 131072),
92
- temperature=0.7,
93
- do_sample=True
94
- )
95
- ```
96
-
97
- ### Memory-Efficient Generation
98
-
99
- ```python
100
- # For memory-constrained environments
101
- with torch.no_grad():
102
- outputs = model.generate(
103
- **inputs,
104
- max_length=16384, # Reasonable context length
105
- temperature=0.8,
106
- do_sample=True,
107
- use_cache=True # Enable KV caching
108
- )
109
- ```
110
-
111
-
112
- ### Local Usage Examples
113
-
114
- See `example_usage.py` for custom architecture usage example.
115
-
116
- ## 🎯 Use Cases
117
-
118
- - **📄 Long Document Analysis**: Process entire books, research papers, and lengthy documents
119
- - **💬 Extended Conversations**: Maintain context across very long chat sessions
120
- - **📝 Code Generation**: Generate code with full project context awareness
121
- - **🔬 Research Paper Analysis**: Analyze and summarize complex research documents
122
- - **📚 Educational Content**: Create comprehensive learning materials
123
- - **🤖 Conversational AI**: Build sophisticated chatbots with extended memory
124
- - **✍️ Creative Writing**: Generate long-form content with consistent narrative
125
- - **🔍 Document Q&A**: Answer questions about extensive documents
126
- - **📊 Data Analysis**: Process large datasets and reports
127
- - **🌐 Translation**: Handle long-form translation tasks
128
-
129
- ## 🔧 Advanced Features
130
-
131
- ### Sampling Strategies
132
-
133
- - **Temperature**: Control randomness (0.1-1.5)
134
- - **Top-k**: Limit vocabulary to top k tokens
135
- - **Top-p (Nucleus)**: Limit to tokens with cumulative probability p
136
- - **Repetition Penalty**: Reduce repetitive text
137
-
138
- ### Memory Optimization
139
-
140
- - **KV Caching**: Efficient autoregressive generation
141
- - **Gradient Checkpointing**: Memory-efficient training
142
- - **Flash Attention**: Optimized attention computation
143
-
144
- ## 📈 Performance
145
-
146
- ### Context Length Support
147
- - **Maximum Context**: 131,072 tokens (128K)
148
- - **Dynamic Scaling**: Automatic RoPE scaling for any sequence length
149
- - **Memory Scaling**: O(n) for RoPE, O(n²) for attention (optimizable)
150
-
151
- ### Benchmarks
152
- - **Perplexity**: < 15 on Thai text corpus
153
- - **Generation Speed**: ~30-50 tokens/second (batch_size=1)
154
- - **Memory Usage**: 2-8GB depending on context length
155
- - **Training Stability**: Improved convergence with modern optimizations
156
-
157
- ### Long Context Performance
158
- - **16K tokens**: ~2-3GB memory, fast generation
159
- - **32K tokens**: ~4-5GB memory, moderate speed
160
- - **64K tokens**: ~8-10GB memory, slower but functional
161
- - **128K tokens**: ~16-20GB memory, optimized for batch processing
162
-
163
- ## 🏗️ Architecture Details
164
-
165
- ### Core Components
166
-
167
- 1. **Advanced Thai Tokenizer**: Syllable-aware tokenization with 50K+ vocabulary
168
- 2. **Dynamic Token Embedding**: Maps tokens to 768-dimensional vectors
169
- 3. **Dynamic RoPE**: Rotary position embeddings with automatic scaling for long contexts
170
- 4. **12 Transformer Layers**:
171
- - **Grouped Query Attention**: 12 heads (8 KV groups) for efficiency
172
- - **SwiGLU Feed-Forward**: 3072 hidden dimensions with gating
173
- - **RMSNorm**: Stable layer normalization
174
- - **Residual Connections**: Optimized gradient flow
175
- 5. **Language Modeling Head**: Probability distribution over vocabulary
176
-
177
- ### Long Context Optimizations
178
-
179
- - **Dynamic RoPE Scaling**: Automatically adjusts position encodings for sequences up to 128K
180
- - **Memory-Efficient Attention**: Grouped queries reduce KV cache size by 37.5%
181
- - **Optimized Feed-Forward**: SwiGLU activation for better parameter efficiency
182
- - **Stable Normalization**: RMSNorm prevents training instabilities
183
-
184
- ### Training Details
185
-
186
- - **Dataset**: Large-scale Thai text corpus
187
- - **Training Steps**: 100K+ steps
188
- - **Batch Size**: 8 (with gradient accumulation)
189
- - **Learning Rate**: 3e-4 with cosine decay
190
- - **Mixed Precision**: FP16 training for efficiency
191
-
192
- ## 🔍 Model Architecture
193
-
194
- ```
195
- ZombitThai-GPT-128K Architecture
196
- ├── Advanced Thai Tokenizer (50K+ vocab, syllable-aware)
197
- ├── Token Embedding (50K → 768)
198
- ├── Dynamic RoPE Position Encoding (up to 128K tokens)
199
- ├── 12 × Modern Transformer Block
200
- │ ├── Grouped Query Attention (12 heads, 8 KV groups)
201
- │ ├── RMSNorm + Residual Connection
202
- │ ├── SwiGLU Feed-Forward (768 → 3072 → 768)
203
- │ └── RMSNorm + Residual Connection
204
- ├── Final RMSNorm
205
- └── Language Modeling Head (768 → 50K)
206
- ```
207
-
208
- ### Key Innovations
209
-
210
- - **Dynamic RoPE Scaling**: Automatic position encoding adaptation
211
- - **Grouped Query Attention**: 37.5% reduction in KV cache size
212
- - **SwiGLU Activation**: Better parameter efficiency than standard FFN
213
- - **RMSNorm**: Improved training stability
214
- - **Thai-Specific Tokenization**: Optimized for Thai language patterns
215
-
216
- ## 📁 Files Structure
217
-
218
- ```
219
- ZombitThai-GPT/
220
- ├── config.json # Model configuration (custom architecture)
221
- ├── tokenizer.json # BPE tokenizer
222
- ├── tokenizer_config.json # Tokenizer settings
223
- ├── special_tokens_map.json # Special token mappings
224
- ├── generation_config.json # Generation parameters
225
- ├── pytorch_model.bin # PyTorch model weights
226
- ├── modeling.py # Custom model implementation
227
- ├── __init__.py # Package initialization
228
- ├── example_usage.py # Custom architecture usage example
229
- ├── README.md # This file
230
- └── requirements.txt # Dependencies
231
- ```
232
-
233
- ## 📋 Requirements
234
-
235
- ```txt
236
- torch >= 2.0.0
237
- transformers >= 4.21.0
238
- tokenizers >= 0.13.0
239
- safetensors >= 0.3.0
240
- accelerate >= 0.20.0
241
- ```
242
-
243
- ## 🛠️ Installation
244
-
245
- ### Quick Start (Hugging Face)
246
- ```bash
247
- # Install required packages
248
- pip install transformers torch huggingface_hub
249
-
250
- # Load the model
251
- from transformers import AutoTokenizer, AutoModelForCausalLM
252
-
253
- tokenizer = AutoTokenizer.from_pretrained("ZombitX64/ZombitThai-GPT-128K")
254
- model = AutoModelForCausalLM.from_pretrained("ZombitX64/ZombitThai-GPT-128K", trust_remote_code=True)
255
- ```
256
-
257
- ### For Long Context Processing
258
- ```bash
259
- # Install additional packages for optimization
260
- pip install transformers torch accelerate
261
- # For Flash Attention support (optional)
262
- pip install flash-attn
263
- ```
264
-
265
- ## 🚨 Limitations & Considerations
266
-
267
- ### Current Limitations
268
- - **Model Weights**: Currently initialized randomly (not fully trained)
269
- - **Training Data**: Limited to available Thai text corpus
270
- - **Domain Knowledge**: May not excel in highly specialized domains
271
- - **Memory Requirements**: 128K context requires substantial GPU memory (16-32GB+)
272
- - **Generation Speed**: Longer contexts result in slower generation speeds
273
-
274
- ### Long Context Considerations
275
- - **Memory Scaling**: Very long sequences (>64K) may require optimized hardware
276
- - **Generation Time**: 128K context generation can be 10-20x slower than short contexts
277
- - **Quality Trade-offs**: Extremely long contexts may impact output coherence
278
- - **Hardware Requirements**: A100/H100 GPUs recommended for optimal 128K performance
279
-
280
- ### Language Coverage
281
- - **Modern Thai**: Optimized for contemporary Thai language
282
- - **Dialects**: May have limited support for regional dialects
283
- - **Historical Texts**: Not optimized for ancient Thai or historical documents
284
- - **Code Mixing**: Limited support for Thai-English code switching
285
-
286
- ### Recommendations
287
- - **Short Tasks**: Use 4K-16K context for best speed/quality balance
288
- - **Long Documents**: Use 32K-64K context for document analysis
289
- - **Maximum Context**: Reserve 128K for specialized long-document tasks
290
- - **Memory Optimization**: Consider Flash Attention for better memory efficiency
291
-
292
- ## 🤝 Contributing
293
-
294
- We welcome contributions! Please feel free to:
295
-
296
- - Report bugs and issues
297
- - Suggest improvements
298
- - Submit pull requests
299
- - Share your use cases
300
-
301
- ## 📄 License
302
-
303
- This model is released under the Apache 2.0 License. See LICENSE file for details.
304
-
305
- ## 🎯 128K Context Capabilities
306
-
307
- ### What You Can Do with 128K Context
308
-
309
- 1. **📄 Document Analysis**
310
- - Process entire research papers (50K-100K tokens)
311
- - Analyze complete books and novels
312
- - Review legal documents and contracts
313
-
314
- 2. **💬 Extended Conversations**
315
- - Maintain context across multi-hour conversations
316
- - Remember user preferences and history
317
- - Provide consistent personality across sessions
318
-
319
- 3. **🔧 Code Generation**
320
- - Generate code with full project context
321
- - Understand and modify large codebases
322
- - Maintain consistency across multiple files
323
-
324
- 4. **📚 Educational Applications**
325
- - Create comprehensive study guides
326
- - Analyze lengthy educational materials
327
- - Generate detailed explanations
328
-
329
- 5. **🔬 Research & Analysis**
330
- - Process scientific papers and datasets
331
- - Analyze complex technical documentation
332
- - Generate research summaries
333
-
334
- ### Performance Tips
335
-
336
- - **Batch Processing**: Use smaller batches for very long sequences
337
- - **Memory Management**: Monitor GPU memory usage
338
- - **Quality vs Speed**: Balance context length with generation quality
339
- - **Caching**: Enable KV caching for better performance
340
-
341
- ## 🙏 Acknowledgments
342
-
343
- - **Modern Transformer Research**: Inspired by LLaMA, PaLM, GPT-4, and Claude architectures
344
- - **Thai NLP Community**: Built for the Thai language processing community
345
- - **Hugging Face**: For providing excellent model hosting and tools
346
- - **Open Source**: Standing on the shoulders of countless contributors
347
- - **Research Community**: For advancing the field of large language models
348
-
349
- ---
350
-
351
- **🚀 ZombitThai-GPT-128K - Pushing the boundaries of Thai language AI with extreme context understanding**
352
-
353
- ## 📞 Contact
354
-
355
- For questions or support:
356
- - Join our Discord community [discord](https://discord.gg/xmVABwsDFU)
357
- - Email: Jonusnattapong@gmail.com)
358
-
359
- ---
360
-
361
- **ZombitThai-GPT - Generated with ❤️ for the Thai NLP community**
 
1
+ ---
2
+ language: th
3
+ license: apache-2.0
4
+ tags:
5
+ - thai
6
+ - language-model
7
+ - transformer
8
+ - long-context
9
+ - 128k-context
10
+ - rope-scaling
11
+ - grouped-query-attention
12
+ ---
13
+
14
+ # ZombitThai-GPT
15
+
16
+ A modern Thai language model with 128K token context support, built with advanced transformer architectures.
17
+
18
+ ## Model Details
19
+
20
+ - **Model Type**: Transformer with RoPE and Grouped Query Attention
21
+ - **Context Length**: 131,072 tokens (128K)
22
+ - **Architecture**: Modern GPT with dynamic RoPE scaling
23
+ - **Language**: Thai
24
+ - **License**: Apache 2.0
25
+
26
+ ## Key Features
27
+
28
+ - 🚀 **Long Context**: Supports up to 128K tokens with dynamic RoPE scaling
29
+ - 🧠 **Advanced Architecture**: Grouped Query Attention, RMSNorm, SwiGLU activation
30
+ - 🇹🇭 **Thai Optimized**: Specialized tokenizer with Thai syllable awareness
31
+ - ⚡ **Memory Efficient**: Optimized for long context processing
32
+ - 🔧 **HF Compatible**: Full Hugging Face transformers integration
33
+
34
+ ## Usage
35
+
36
+ ```python
37
+ from transformers import AutoTokenizer, AutoModelForCausalLM
38
+
39
+ tokenizer = AutoTokenizer.from_pretrained("JonusNattapong/ZombitThai-GPT-128K")
40
+ model = AutoModelForCausalLM.from_pretrained("JonusNattapong/ZombitThai-GPT-128K")
41
+
42
+ text = "สวัสดีครับ วันนี้อากาศดีมาก"
43
+ inputs = tokenizer(text, return_tensors="pt")
44
+ outputs = model.generate(**inputs, max_length=100)
45
+ result = tokenizer.decode(outputs[0])
46
+ ```
47
+
48
+ ## Training Details
49
+
50
+ - **Architecture**: Custom transformer with modern optimizations
51
+ - **Position Encoding**: RoPE with dynamic scaling for long contexts
52
+ - **Attention**: Grouped Query Attention for efficiency
53
+ - **Normalization**: RMSNorm instead of LayerNorm
54
+ - **Activation**: SwiGLU for better performance
55
+
56
+ ## Performance
57
+
58
+ - Supports sequences up to 131,072 tokens
59
+ - Efficient memory usage with KV caching
60
+ - Optimized for Thai language processing
61
+ - Compatible with standard HF generation pipelines
62
+
63
+ ## Limitations
64
+
65
+ - Model weights are randomly initialized (not trained)
66
+ - Requires significant computational resources for long contexts
67
+ - Optimized for Thai text processing
68
+
69
+ ## Citation
70
+
71
+ ```bibtex
72
+ @misc{zombit-thai-gpt,
73
+ title={ZombitThai-GPT: Modern Thai Language Model with 128K Context},
74
+ author={AI Assistant},
75
+ year={2024},
76
+ publisher={Hugging Face},
77
+ url={https://huggingface.co/JonusNattapong/ZombitThai-GPT-128K}
78
+ }
79
+ ```