Update README.md
Browse files
README.md
CHANGED
|
@@ -3,60 +3,274 @@ base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
|
|
| 3 |
library_name: peft
|
| 4 |
model_name: typescript-slm-1.5b
|
| 5 |
tags:
|
| 6 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
- lora
|
| 8 |
- sft
|
| 9 |
- transformers
|
| 10 |
- trl
|
| 11 |
-
|
| 12 |
pipeline_tag: text-generation
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
-
#
|
| 16 |
|
| 17 |
-
|
| 18 |
-
It has been trained using [TRL](https://github.com/huggingface/trl).
|
| 19 |
|
| 20 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
library_name: peft
|
| 4 |
model_name: typescript-slm-1.5b
|
| 5 |
tags:
|
| 6 |
+
- typescript
|
| 7 |
+
- code-generation
|
| 8 |
+
- react
|
| 9 |
+
- nextjs
|
| 10 |
+
- angular
|
| 11 |
+
- nodejs
|
| 12 |
- lora
|
| 13 |
- sft
|
| 14 |
- transformers
|
| 15 |
- trl
|
| 16 |
+
license: mit
|
| 17 |
pipeline_tag: text-generation
|
| 18 |
+
language:
|
| 19 |
+
- en
|
| 20 |
+
datasets:
|
| 21 |
+
- custom
|
| 22 |
---
|
| 23 |
|
| 24 |
+
# TypeScript SLM 1.5B
|
| 25 |
|
| 26 |
+
A specialized Small Language Model for TypeScript code generation and understanding, optimized for React, Next.js, Angular, and Node.js frameworks.
|
|
|
|
| 27 |
|
| 28 |
+
## Model Description
|
| 29 |
+
|
| 30 |
+
This model is a fine-tuned version of [Qwen/Qwen2.5-Coder-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct) using LoRA (Low-Rank Adaptation) for parameter-efficient fine-tuning. It has been trained on 2,000-8,000 high-quality TypeScript code samples focusing on modern web development frameworks.
|
| 31 |
+
|
| 32 |
+
**Key Features:**
|
| 33 |
+
- Specialized in TypeScript and popular frameworks (React, Next.js, Angular, Node.js)
|
| 34 |
+
- Quality-scored training dataset with proper type annotations
|
| 35 |
+
- Optimized for code completion, generation, and understanding tasks
|
| 36 |
+
- Efficient inference with LoRA adapters
|
| 37 |
+
|
| 38 |
+
## Intended Use
|
| 39 |
+
|
| 40 |
+
### Primary Use Cases
|
| 41 |
+
- TypeScript code completion and generation
|
| 42 |
+
- React component scaffolding
|
| 43 |
+
- Next.js API route and page generation
|
| 44 |
+
- Angular service and directive creation
|
| 45 |
+
- Node.js/Express backend code generation
|
| 46 |
+
- Type definition and interface creation
|
| 47 |
+
|
| 48 |
+
### Out-of-Scope Use
|
| 49 |
+
- Production-critical code generation without human review
|
| 50 |
+
- Non-TypeScript/JavaScript code generation
|
| 51 |
+
- General-purpose text generation
|
| 52 |
+
- Code obfuscation or malicious code generation
|
| 53 |
+
|
| 54 |
+
## Training Data
|
| 55 |
+
|
| 56 |
+
The model was trained on a curated dataset of TypeScript code samples with the following distribution:
|
| 57 |
+
|
| 58 |
+
- **React** (43-58%): Components, hooks, context, custom hooks
|
| 59 |
+
- **Angular** (33-50%): Services, directives, modules, dependency injection
|
| 60 |
+
- **Next.js** (21-23%): Pages, API routes, SSR, SSG patterns
|
| 61 |
+
- **TypeScript** (9-16%): Advanced types, generics, utility types
|
| 62 |
+
- **Node.js** (6-11%): Express, NestJS, API servers
|
| 63 |
+
|
| 64 |
+
**Dataset Quality Scoring:**
|
| 65 |
+
- Samples scored 41-64 on quality metrics
|
| 66 |
+
- Prioritizes proper type annotations
|
| 67 |
+
- Excludes test files, debug code, and incomplete modules
|
| 68 |
+
- Focuses on production-quality patterns from popular repositories
|
| 69 |
+
|
| 70 |
+
## Training Procedure
|
| 71 |
+
|
| 72 |
+
### Training Hyperparameters
|
| 73 |
+
|
| 74 |
+
**Hardware:**
|
| 75 |
+
- Google Colab A100 40GB GPU
|
| 76 |
+
- CUDA acceleration with FP16 precision
|
| 77 |
+
|
| 78 |
+
**Configuration:**
|
| 79 |
+
- Base Model: Qwen/Qwen2.5-Coder-1.5B-Instruct
|
| 80 |
+
- Training Samples: 2,000-8,000 (depending on dataset tier)
|
| 81 |
+
- Epochs: 3
|
| 82 |
+
- Batch Size: 4
|
| 83 |
+
- Gradient Accumulation Steps: 8
|
| 84 |
+
- Effective Batch Size: 32
|
| 85 |
+
- Learning Rate: 2e-4
|
| 86 |
+
- Max Sequence Length: 1024
|
| 87 |
+
- LoRA Rank (r): 32
|
| 88 |
+
- LoRA Alpha: 16
|
| 89 |
+
- LoRA Dropout: 0.1
|
| 90 |
+
- Target Modules: All linear layers
|
| 91 |
+
|
| 92 |
+
**Training Time:**
|
| 93 |
+
- train_small.jsonl (2k samples): ~20-30 minutes on A100
|
| 94 |
+
- train_medium.jsonl (5k samples): ~50-75 minutes on A100
|
| 95 |
+
- train.jsonl (8k samples): ~2-3 hours on A100
|
| 96 |
+
|
| 97 |
+
## Usage
|
| 98 |
+
|
| 99 |
+
### Basic Usage
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 103 |
+
from peft import PeftModel
|
| 104 |
+
|
| 105 |
+
# Load base model and tokenizer
|
| 106 |
+
base_model = "Qwen/Qwen2.5-Coder-1.5B-Instruct"
|
| 107 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 108 |
+
base_model,
|
| 109 |
+
device_map="auto",
|
| 110 |
+
torch_dtype="auto"
|
| 111 |
+
)
|
| 112 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model)
|
| 113 |
+
|
| 114 |
+
# Load LoRA adapter
|
| 115 |
+
model = PeftModel.from_pretrained(model, "sylvester-francis/typescript-slm-1.5b")
|
| 116 |
+
|
| 117 |
+
# Generate code
|
| 118 |
+
prompt = """Write a React component that fetches user data and displays it in a card:
|
| 119 |
+
|
| 120 |
+
```typescript
|
| 121 |
+
"""
|
| 122 |
+
|
| 123 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 124 |
+
outputs = model.generate(
|
| 125 |
+
**inputs,
|
| 126 |
+
max_new_tokens=256,
|
| 127 |
+
temperature=0.7,
|
| 128 |
+
do_sample=True,
|
| 129 |
+
top_p=0.95
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 133 |
+
print(generated_code)
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
### React Component Generation
|
| 137 |
+
|
| 138 |
+
```python
|
| 139 |
+
prompt = """Create a TypeScript React component with props for a user profile card:
|
| 140 |
+
|
| 141 |
+
```typescript
|
| 142 |
+
interface UserProfileProps {
|
| 143 |
+
"""
|
| 144 |
+
|
| 145 |
+
# Generate with the model...
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
### Next.js API Route
|
| 149 |
+
|
| 150 |
+
```python
|
| 151 |
+
prompt = """Write a Next.js API route for user authentication:
|
| 152 |
+
|
| 153 |
+
```typescript
|
| 154 |
+
// pages/api/auth/login.ts
|
| 155 |
+
"""
|
| 156 |
+
|
| 157 |
+
# Generate with the model...
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
### Angular Service
|
| 161 |
|
| 162 |
```python
|
| 163 |
+
prompt = """Create an Angular service for HTTP data fetching:
|
| 164 |
|
| 165 |
+
```typescript
|
| 166 |
+
import { Injectable } from '@angular/core';
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
# Generate with the model...
|
| 170 |
```
|
| 171 |
|
| 172 |
+
## Performance
|
| 173 |
+
|
| 174 |
+
### Code Quality Metrics
|
| 175 |
+
- Proper TypeScript type annotations
|
| 176 |
+
- Framework-specific best practices
|
| 177 |
+
- Adherence to modern ES6+ patterns
|
| 178 |
+
- Clean, readable code structure
|
| 179 |
+
|
| 180 |
+
### Generation Speed
|
| 181 |
+
- Average: ~50-100 tokens/second on A100
|
| 182 |
+
- Latency: <100ms for typical completions
|
| 183 |
+
- Memory: ~3GB VRAM with adapter loaded
|
| 184 |
+
|
| 185 |
+
## Limitations
|
| 186 |
|
| 187 |
+
1. **Specialized Domain**: Works best for TypeScript and related frameworks. Performance degrades for other languages.
|
| 188 |
|
| 189 |
+
2. **Training Data Bias**: Reflects patterns from popular open-source repositories, which may not match all coding styles.
|
| 190 |
|
| 191 |
+
3. **Context Length**: Limited to 1024 tokens, which may be insufficient for very large files.
|
| 192 |
|
| 193 |
+
4. **No Real-time Updates**: Training data is static and doesn't include the latest framework versions or patterns.
|
| 194 |
|
| 195 |
+
5. **Requires Human Review**: Generated code should always be reviewed for security, correctness, and best practices.
|
| 196 |
+
|
| 197 |
+
6. **Type Safety**: While trained on typed code, generated types may not always be complete or optimal.
|
| 198 |
+
|
| 199 |
+
## Ethical Considerations
|
| 200 |
+
|
| 201 |
+
- **Code Licensing**: Ensure generated code complies with your project's license requirements
|
| 202 |
+
- **Security**: Always review generated code for security vulnerabilities
|
| 203 |
+
- **Testing**: Generated code should be thoroughly tested before production use
|
| 204 |
+
- **Attribution**: Consider the training data sources when using generated code commercially
|
| 205 |
+
|
| 206 |
+
## Training Infrastructure
|
| 207 |
+
|
| 208 |
+
**Software Stack:**
|
| 209 |
+
- PyTorch 2.9.0+cu126
|
| 210 |
+
- Transformers 4.57.2
|
| 211 |
- PEFT 0.18.0
|
| 212 |
+
- TRL 0.25.1
|
| 213 |
+
- Datasets 4.0.0
|
| 214 |
+
- bitsandbytes 0.41.0+
|
| 215 |
+
|
| 216 |
+
**Platform:**
|
| 217 |
+
- Google Colab Pro (recommended)
|
| 218 |
+
- Supports Mac M4 (MPS) for local training (slower)
|
| 219 |
+
- Compatible with T4, A100, and other CUDA GPUs
|
| 220 |
+
|
| 221 |
+
## Repository
|
| 222 |
+
|
| 223 |
+
Full training code, dataset filtering, and usage examples:
|
| 224 |
+
https://github.com/sylvester-francis/slm-typescript-model
|
| 225 |
+
|
| 226 |
+
## Model Card Authors
|
| 227 |
+
|
| 228 |
+
- Sylvester Francis (@sylvester-francis)
|
| 229 |
|
| 230 |
## Citations
|
| 231 |
|
| 232 |
+
### Base Model
|
| 233 |
+
|
| 234 |
+
```bibtex
|
| 235 |
+
@article{qwen2.5,
|
| 236 |
+
title={Qwen2.5-Coder Technical Report},
|
| 237 |
+
author={Qwen Team},
|
| 238 |
+
year={2024},
|
| 239 |
+
journal={arXiv preprint},
|
| 240 |
+
url={https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct}
|
| 241 |
+
}
|
| 242 |
+
```
|
| 243 |
|
| 244 |
+
### Training Framework
|
| 245 |
|
|
|
|
|
|
|
| 246 |
```bibtex
|
| 247 |
@misc{vonwerra2022trl,
|
| 248 |
+
title={{TRL: Transformer Reinforcement Learning}},
|
| 249 |
+
author={Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
|
| 250 |
+
year={2020},
|
| 251 |
+
journal={GitHub repository},
|
| 252 |
+
publisher={GitHub},
|
| 253 |
+
howpublished={\url{https://github.com/huggingface/trl}}
|
| 254 |
+
}
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
### LoRA
|
| 258 |
+
|
| 259 |
+
```bibtex
|
| 260 |
+
@article{hu2021lora,
|
| 261 |
+
title={LoRA: Low-Rank Adaptation of Large Language Models},
|
| 262 |
+
author={Hu, Edward J and Shen, Yelong and Wallis, Phillip and Allen-Zhu, Zeyuan and Li, Yuanzhi and Wang, Shean and Wang, Lu and Chen, Weizhu},
|
| 263 |
+
journal={arXiv preprint arXiv:2106.09685},
|
| 264 |
+
year={2021}
|
| 265 |
}
|
| 266 |
+
```
|
| 267 |
+
|
| 268 |
+
## License
|
| 269 |
+
|
| 270 |
+
MIT License - See repository for full license text.
|
| 271 |
+
|
| 272 |
+
## Acknowledgments
|
| 273 |
+
|
| 274 |
+
- Built on Qwen 2.5 Coder by Alibaba Cloud
|
| 275 |
+
- Training powered by Hugging Face TRL and PEFT libraries
|
| 276 |
+
- Dataset curated from high-quality open-source TypeScript projects
|