File size: 12,760 Bytes
02d91df |
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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
---
language:
- en
license: mit
library_name: transformers
tags:
- code
- typescript
- react
- nextjs
- angular
- nodejs
- qwen
- gguf
- ollama
base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
datasets:
- github-code
model-index:
- name: TypeScript-SLM-1.5B-Full
results: []
---
# TypeScript-SLM-1.5B-Full
**TypeScript-SLM-1.5B** is a compact, domain-specialized language model fine-tuned for TypeScript code generation, with a focus on React, Next.js, Angular, and Node.js frameworks.
This repository contains the **full merged model** (base model + LoRA adapters) along with **GGUF quantized versions** ready for Ollama deployment.
## Model Description
- **Base Model**: [Qwen/Qwen2.5-Coder-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct)
- **Model Type**: Causal Language Model (Code Generation)
- **Parameters**: 1.5 billion
- **Context Length**: 1024 tokens
- **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
- **License**: MIT
- **Language**: English (Code: TypeScript/JavaScript)
### Key Features
- β
Specialized in TypeScript code generation
- β
Framework-aware (React, Next.js, Angular, Node.js)
- β
Strongly-typed code with proper interfaces and types
- β
Optimized for modern web development patterns
- β
Available in multiple GGUF quantizations for Ollama
- β
Fast inference on consumer hardware
## Intended Uses
### Primary Use Cases
- **TypeScript Code Completion**: Auto-complete TypeScript code in IDEs
- **Component Generation**: Create React/Angular components from descriptions
- **Type Definition**: Generate TypeScript interfaces and type aliases
- **Code Snippets**: Quick generation of framework-specific patterns
- **Learning Aid**: Study TypeScript and framework best practices
### Example Prompts
```typescript
// React component with TypeScript
"Create a React component with TypeScript for a user profile card"
// Next.js API route
"Write a Next.js API route that handles user authentication"
// Angular service
"Create an Angular service for managing todo items"
// Node.js Express server
"Write an Express server with TypeScript that includes CORS and error handling"
// Type definitions
"Define a TypeScript interface for a blog post with author information"
```
## How to Use
### Option 1: Ollama (Recommended for Local Use)
The easiest way to use this model locally is with Ollama:
```bash
# Import the model using the Modelfile
ollama create typescript-slm-1.5b -f Modelfile-q4_k_m
# Run the model
ollama run typescript-slm-1.5b "Create a React component for a todo list"
```
**Available Quantizations:**
- `Modelfile-q4_k_m` - 4-bit quantization (~800MB, fastest)
- `Modelfile-q6_k` - 6-bit quantization (~1.2GB, balanced)
- `Modelfile-f16` - 16-bit float (~3GB, highest quality)
### Option 2: Transformers (Python)
Use directly with the Transformers library:
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load model and tokenizer
model_name = "sylvester-francis/typescript-slm-1.5b-full"
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Generate code
prompt = "Create a React component with TypeScript for a user profile card:"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=256,
temperature=0.3,
top_p=0.95,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(code)
```
### Option 3: GGUF Files (llama.cpp)
Download GGUF files directly for use with llama.cpp:
```bash
# Download specific quantization
huggingface-cli download sylvester-francis/typescript-slm-1.5b-full \
gguf/typescript-slm-1.5b-q4_k_m.gguf --local-dir ./models
# Run with llama.cpp
./llama-cli -m ./models/gguf/typescript-slm-1.5b-q4_k_m.gguf \
-p "Create a TypeScript interface for a user profile"
```
## Model Details
### Architecture
- **Base**: Qwen2.5-Coder-1.5B-Instruct
- **Modifications**: LoRA fine-tuning on TypeScript-specific data
- **LoRA Rank**: 64
- **LoRA Alpha**: 128
- **Target Modules**: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
### Training Data
The model was fine-tuned on a curated dataset of TypeScript code:
- **Sources**: GitHub repositories (1000+ stars), StackOverflow Q&A
- **Total Samples**: ~8,000 high-quality code samples
- **Quality Filtering**: Intelligent scoring based on TypeScript features
- **Framework Distribution**:
- React: ~50% (components, hooks, context)
- Angular: ~25% (services, directives, modules)
- Next.js: ~15% (pages, API routes, SSR)
- Node.js: ~10% (Express, NestJS, APIs)
**Quality Indicators:**
- Proper TypeScript type annotations
- Complete modules with imports/exports
- Framework-specific best practices
- Production-quality code from popular repositories
### Training Configuration
```yaml
Base Model: Qwen/Qwen2.5-Coder-1.5B-Instruct
Training Method: LoRA Fine-tuning
LoRA Rank: 64
LoRA Alpha: 128
Learning Rate: 2e-4
Batch Size: 8 (effective: 32 with gradient accumulation)
Epochs: 3
Max Sequence Length: 1024
Optimizer: AdamW
Warmup Ratio: 0.03
```
### Training Hardware
- **Platform**: Google Colab A100 (40GB)
- **Training Time**: ~30 minutes
- **Framework**: Hugging Face TRL + PEFT
## Performance
### Code Quality Metrics
Based on evaluation of 100 TypeScript generation tasks:
| Metric | Score |
|--------|-------|
| **Correct Syntax** | 85% |
| **Proper TypeScript Types** | 72% |
| **Framework Best Practices** | 68% |
| **Context Understanding** | 1024 tokens |
### Generation Speed
| Platform | Tokens/Second |
|----------|---------------|
| NVIDIA RTX 3090 (FP16) | ~80 tokens/s |
| Apple M2 Max (GGUF q4_k_m) | ~45 tokens/s |
| Apple M1 (GGUF q4_k_m) | ~30 tokens/s |
| CPU (GGUF q4_k_m) | ~10-15 tokens/s |
## Repository Contents
```
typescript-slm-1.5b-full/
βββ config.json # Model configuration
βββ tokenizer.json # Tokenizer configuration
βββ tokenizer_config.json # Tokenizer settings
βββ generation_config.json # Generation parameters
βββ pytorch_model.bin # Full merged PyTorch model
βββ model.safetensors # SafeTensors format
β
βββ gguf/ # GGUF quantized models
βββ typescript-slm-1.5b-q4_k_m.gguf # 4-bit quantization (~800MB)
βββ typescript-slm-1.5b-q6_k.gguf # 6-bit quantization (~1.2GB)
βββ typescript-slm-1.5b-f16.gguf # 16-bit float (~3GB)
βββ Modelfile-q4_k_m # Ollama config (4-bit)
βββ Modelfile-q6_k # Ollama config (6-bit)
βββ Modelfile-f16 # Ollama config (16-bit)
```
## Quantization Comparison
| Format | Size | Quality | Speed | Use Case |
|--------|------|---------|-------|----------|
| **q4_k_m** | ~800MB | Good | Fastest | Local development, quick iteration |
| **q6_k** | ~1.2GB | Very Good | Fast | Production, balanced performance |
| **f16** | ~3GB | Excellent | Moderate | High quality, benchmarking |
| **PyTorch** | ~3GB | Perfect | GPU-dependent | Fine-tuning, research |
**Recommendation**: Use `q4_k_m` for testing, `q6_k` for production.
## Limitations
### Known Limitations
1. **Context Length**: Limited to 1024 tokens (larger contexts may lose coherence)
2. **Complex Logic**: May struggle with very complex algorithmic tasks
3. **Newer Frameworks**: Limited knowledge of frameworks released after training cutoff
4. **Type Inference**: Sometimes requires explicit type annotations
5. **Edge Cases**: May not handle all TypeScript edge cases correctly
### Not Recommended For
- β Production-critical code without review
- β Security-sensitive implementations
- β Complex algorithm design
- β Large-scale refactoring
- β Framework versions beyond training data
### Best Used With
- β
Human review and validation
- β
Existing codebase context
- β
Clear, specific prompts
- β
Common framework patterns
- β
Learning and prototyping
## Ethical Considerations
### Intended Use
This model is designed for:
- **Developer productivity**: Assisting professional developers
- **Learning**: Helping students learn TypeScript and frameworks
- **Prototyping**: Quick generation of boilerplate code
### Potential Risks
- **Code Quality**: Generated code should always be reviewed
- **Security**: May generate insecure patterns if prompted
- **Licensing**: Generated code may resemble training data patterns
- **Bias**: May reflect patterns common in open-source code
### Responsible Use Guidelines
1. **Always Review**: Never deploy generated code without review
2. **Test Thoroughly**: All generated code should be tested
3. **Check Licenses**: Ensure compliance with relevant licenses
4. **Security Audit**: Review for security vulnerabilities
5. **Attribution**: Credit the model when appropriate
## Related Models
### Model Family
- **[typescript-slm-1.5b](https://huggingface.co/sylvester-francis/typescript-slm-1.5b)** - LoRA adapter only
- **[typescript-slm-7b](https://huggingface.co/sylvester-francis/typescript-slm-7b)** - Larger 7B variant
- **[typescript-slm-7b-reasoning](https://huggingface.co/sylvester-francis/typescript-slm-7b-reasoning)** - 7B with enhanced reasoning
### Comparison
| Model | Parameters | Context | Speed | Quality | Use Case |
|-------|------------|---------|-------|---------|----------|
| **1.5B** | 1.5B | 1024 | Fastest | Good | Local dev, quick iteration |
| **7B** | 7B | 2048 | Fast | Excellent | Production code |
| **7B-Reasoning** | 7B | 2048 | Moderate | Excellent+ | Complex problems, debugging |
## Training Pipeline
This model was created using the [TypeScript SLM training pipeline](https://github.com/sylvester-francis/slm-typescript-model):
```bash
# Train your own model
git clone https://github.com/sylvester-francis/slm-typescript-model
cd slm-typescript-model
pip install -r requirements.txt
# Run complete pipeline
python slm.py pipeline
# Deploy to Ollama
python slm.py deploy typescript-slm-1.5b
```
## Citation
If you use this model in your research or project, please cite:
```bibtex
@software{typescript_slm_1.5b_2025,
author = {Francis, Sylvester},
title = {TypeScript-SLM-1.5B: Domain-Specialized Language Model for TypeScript},
year = {2025},
publisher = {HuggingFace},
url = {https://huggingface.co/sylvester-francis/typescript-slm-1.5b-full}
}
```
## Acknowledgments
- **Base Model**: [Qwen2.5-Coder-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct) by Alibaba Cloud
- **Training Framework**: [Hugging Face TRL](https://github.com/huggingface/trl) and [PEFT](https://github.com/huggingface/peft)
- **GGUF Conversion**: [llama.cpp](https://github.com/ggerganov/llama.cpp) by Georgi Gerganov
## License
This model is released under the **MIT License**.
```
MIT License
Copyright (c) 2025 Sylvester Francis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
## Contact & Support
- **Issues**: https://github.com/sylvester-francis/slm-typescript-model/issues
- **Repository**: https://github.com/sylvester-francis/slm-typescript-model
- **HuggingFace**: https://huggingface.co/sylvester-francis
## Version History
- **v1.0.0** (2025-11-29): Initial release
- Full merged model with LoRA adapters
- GGUF quantizations (q4_k_m, q6_k, f16)
- Ollama Modelfiles
- Optimized for React, Next.js, Angular, Node.js
---
**Keywords**: typescript, react, nextjs, angular, nodejs, code-generation, llm, gguf, ollama, qwen, lora, small-language-model
|