Update README.md
Browse files
README.md
CHANGED
|
@@ -1,22 +1,685 @@
|
|
| 1 |
---
|
| 2 |
-
base_model: merged_model
|
| 3 |
-
tags:
|
| 4 |
-
- text-generation-inference
|
| 5 |
-
- transformers
|
| 6 |
-
- unsloth
|
| 7 |
-
- qwen3
|
| 8 |
-
- trl
|
| 9 |
-
license: apache-2.0
|
| 10 |
language:
|
| 11 |
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
- **License:** apache-2.0
|
| 18 |
-
- **Finetuned from model :** merged_model
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
|
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
language:
|
| 3 |
- en
|
| 4 |
+
- hi
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
tags:
|
| 7 |
+
- code
|
| 8 |
+
- coding
|
| 9 |
+
- python
|
| 10 |
+
- hindi
|
| 11 |
+
- bilingual
|
| 12 |
+
- unsloth
|
| 13 |
+
- qwen
|
| 14 |
+
- education
|
| 15 |
+
- programming
|
| 16 |
+
- code-generation
|
| 17 |
+
- question-answering
|
| 18 |
+
base_model: Qwen/Qwen3-0.6B
|
| 19 |
+
datasets:
|
| 20 |
+
- custom
|
| 21 |
+
pipeline_tag: text-generation
|
| 22 |
+
widget:
|
| 23 |
+
- text: |
|
| 24 |
+
Below is a coding question. Write a response that appropriately answers the question.
|
| 25 |
+
|
| 26 |
+
### Question:
|
| 27 |
+
python mei control statements kya hei?
|
| 28 |
+
|
| 29 |
+
### Answer:
|
| 30 |
+
example_title: "Hindi: Control Statements"
|
| 31 |
+
- text: |
|
| 32 |
+
Below is a coding question. Write a response that appropriately answers the question.
|
| 33 |
+
|
| 34 |
+
### Question:
|
| 35 |
+
What is a for loop in Python?
|
| 36 |
+
|
| 37 |
+
### Answer:
|
| 38 |
+
example_title: "English: For Loop"
|
| 39 |
+
- text: |
|
| 40 |
+
Below is a coding question. Write a response that appropriately answers the question.
|
| 41 |
+
|
| 42 |
+
### Question:
|
| 43 |
+
function ko define kaise karein?
|
| 44 |
+
|
| 45 |
+
### Answer:
|
| 46 |
+
example_title: "Hindi: Functions"
|
| 47 |
+
model-index:
|
| 48 |
+
- name: fine_tuned_coder
|
| 49 |
+
results: []
|
| 50 |
---
|
| 51 |
|
| 52 |
+
# π Fine-tuned Bilingual Coding Assistant
|
| 53 |
+
|
| 54 |
+
<div align="center">
|
| 55 |
+
|
| 56 |
+

|
| 57 |
+

|
| 58 |
+

|
| 59 |
+

|
| 60 |
+
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
## π Table of Contents
|
| 64 |
+
|
| 65 |
+
- [Model Description](#-model-description)
|
| 66 |
+
- [Key Features](#-key-features)
|
| 67 |
+
- [Quick Start](#-quick-start)
|
| 68 |
+
- [Detailed Usage](#-detailed-usage)
|
| 69 |
+
- [Training Details](#-training-details)
|
| 70 |
+
- [Performance & Benchmarks](#-performance--benchmarks)
|
| 71 |
+
- [Example Prompts](#-example-prompts)
|
| 72 |
+
- [Best Practices](#-best-practices)
|
| 73 |
+
- [Limitations](#-limitations)
|
| 74 |
+
- [Use Cases](#-use-cases)
|
| 75 |
+
- [Citation](#-citation)
|
| 76 |
+
- [Acknowledgments](#-acknowledgments)
|
| 77 |
+
|
| 78 |
+
## π― Model Description
|
| 79 |
+
|
| 80 |
+
This model is a fine-tuned version of **Qwen3-0.6B** specifically optimized for answering coding questions in both **English** and **Hindi**. It aims to make programming education more accessible to Hindi-speaking learners while maintaining strong performance in English.
|
| 81 |
+
|
| 82 |
+
### Model Details
|
| 83 |
+
|
| 84 |
+
| Parameter | Value |
|
| 85 |
+
|-----------|-------|
|
| 86 |
+
| **Base Model** | Qwen/Qwen3-0.6B |
|
| 87 |
+
| **Model Type** | Causal Language Model |
|
| 88 |
+
| **Fine-tuning Method** | LoRA/QLoRA |
|
| 89 |
+
| **Training Framework** | Unsloth |
|
| 90 |
+
| **Languages** | English, Hindi (Bilingual) |
|
| 91 |
+
| **License** | Apache 2.0 |
|
| 92 |
+
| **Model Size** | 0.6 Billion Parameters |
|
| 93 |
+
| **Quantization Support** | 4-bit, 8-bit, 16-bit |
|
| 94 |
+
| **Context Length** | 2048 tokens |
|
| 95 |
+
|
| 96 |
+
### π Key Features
|
| 97 |
+
|
| 98 |
+
β
**Bilingual Support**: Seamlessly handles coding questions in both English and Hindi
|
| 99 |
+
β
**Educational Focus**: Optimized for learning and teaching programming concepts
|
| 100 |
+
β
**Fast Inference**: Powered by Unsloth for 2x faster generation
|
| 101 |
+
β
**Memory Efficient**: Supports 4-bit quantization for resource-constrained environments
|
| 102 |
+
β
**Python Specialized**: Particularly strong in Python programming concepts
|
| 103 |
+
β
**Beginner Friendly**: Excellent for students and programming beginners
|
| 104 |
+
|
| 105 |
+
## π Quick Start
|
| 106 |
+
|
| 107 |
+
### Installation
|
| 108 |
+
|
| 109 |
+
```bash
|
| 110 |
+
# Install required packages
|
| 111 |
+
pip install unsloth transformers torch accelerate bitsandbytes
|
| 112 |
+
|
| 113 |
+
# For CPU-only inference
|
| 114 |
+
pip install transformers torch
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
### Basic Usage (Unsloth - Recommended)
|
| 118 |
+
|
| 119 |
+
```python
|
| 120 |
+
from unsloth import FastLanguageModel
|
| 121 |
+
import torch
|
| 122 |
+
|
| 123 |
+
# Load model with 4-bit quantization
|
| 124 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 125 |
+
model_name = "convaiinnovations/fine_tuned_coder",
|
| 126 |
+
max_seq_length = 2048,
|
| 127 |
+
dtype = None,
|
| 128 |
+
load_in_4bit = True, # Use 4-bit for memory efficiency
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
# Enable fast inference mode
|
| 132 |
+
FastLanguageModel.for_inference(model)
|
| 133 |
+
|
| 134 |
+
# Define prompt template
|
| 135 |
+
coding_prompt = """Below is a coding question. Write a response that appropriately answers the question.
|
| 136 |
+
|
| 137 |
+
### Question:
|
| 138 |
+
{}
|
| 139 |
+
|
| 140 |
+
### Answer:
|
| 141 |
+
{}"""
|
| 142 |
+
|
| 143 |
+
# Ask a question
|
| 144 |
+
question = "python mei control statements kya hei?"
|
| 145 |
+
inputs = tokenizer(
|
| 146 |
+
[coding_prompt.format(question, "")],
|
| 147 |
+
return_tensors = "pt"
|
| 148 |
+
).to("cuda")
|
| 149 |
+
|
| 150 |
+
# Generate response with streaming
|
| 151 |
+
from transformers import TextStreamer
|
| 152 |
+
text_streamer = TextStreamer(tokenizer, skip_prompt=True)
|
| 153 |
+
|
| 154 |
+
outputs = model.generate(
|
| 155 |
+
**inputs,
|
| 156 |
+
streamer = text_streamer,
|
| 157 |
+
max_new_tokens = 512,
|
| 158 |
+
temperature = 0.7,
|
| 159 |
+
top_p = 0.9,
|
| 160 |
+
do_sample = True,
|
| 161 |
+
)
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
## π Detailed Usage
|
| 165 |
+
|
| 166 |
+
### Option 1: Using Unsloth (Fast & Efficient)
|
| 167 |
+
|
| 168 |
+
```python
|
| 169 |
+
from unsloth import FastLanguageModel
|
| 170 |
+
from transformers import TextStreamer
|
| 171 |
+
import torch
|
| 172 |
+
|
| 173 |
+
# Configuration
|
| 174 |
+
MODEL_NAME = "convaiinnovations/fine_tuned_coder"
|
| 175 |
+
MAX_SEQ_LENGTH = 2048
|
| 176 |
+
LOAD_IN_4BIT = True # Set False for full precision
|
| 177 |
+
|
| 178 |
+
# Load model and tokenizer
|
| 179 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 180 |
+
model_name = MODEL_NAME,
|
| 181 |
+
max_seq_length = MAX_SEQ_LENGTH,
|
| 182 |
+
dtype = None,
|
| 183 |
+
load_in_4bit = LOAD_IN_4BIT,
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
# Enable inference mode
|
| 187 |
+
FastLanguageModel.for_inference(model)
|
| 188 |
+
|
| 189 |
+
# Prompt template
|
| 190 |
+
coding_prompt = """Below is a coding question. Write a response that appropriately answers the question.
|
| 191 |
+
|
| 192 |
+
### Question:
|
| 193 |
+
{}
|
| 194 |
+
|
| 195 |
+
### Answer:
|
| 196 |
+
{}"""
|
| 197 |
+
|
| 198 |
+
def ask_coding_question(question, max_tokens=512, temp=0.7):
|
| 199 |
+
"""
|
| 200 |
+
Ask a coding question and get an answer
|
| 201 |
+
|
| 202 |
+
Args:
|
| 203 |
+
question (str): Your coding question
|
| 204 |
+
max_tokens (int): Maximum tokens to generate
|
| 205 |
+
temp (float): Temperature for sampling (0.1-1.5)
|
| 206 |
+
"""
|
| 207 |
+
inputs = tokenizer(
|
| 208 |
+
[coding_prompt.format(question, "")],
|
| 209 |
+
return_tensors="pt"
|
| 210 |
+
).to("cuda")
|
| 211 |
+
|
| 212 |
+
text_streamer = TextStreamer(tokenizer, skip_prompt=True)
|
| 213 |
+
|
| 214 |
+
outputs = model.generate(
|
| 215 |
+
**inputs,
|
| 216 |
+
streamer=text_streamer,
|
| 217 |
+
max_new_tokens=max_tokens,
|
| 218 |
+
temperature=temp,
|
| 219 |
+
top_p=0.9,
|
| 220 |
+
do_sample=True,
|
| 221 |
+
repetition_penalty=1.1,
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 225 |
+
|
| 226 |
+
# Example usage
|
| 227 |
+
ask_coding_question("What are control statements in Python?")
|
| 228 |
+
ask_coding_question("for loop kaise use karte hain?")
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
### Option 2: Standard Transformers (No Unsloth)
|
| 232 |
+
|
| 233 |
+
```python
|
| 234 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 235 |
+
import torch
|
| 236 |
+
|
| 237 |
+
# Load model and tokenizer
|
| 238 |
+
model_name = "convaiinnovations/fine_tuned_coder"
|
| 239 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 240 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 241 |
+
model_name,
|
| 242 |
+
torch_dtype=torch.float16,
|
| 243 |
+
device_map="auto",
|
| 244 |
+
load_in_4bit=True, # Optional: for memory efficiency
|
| 245 |
+
)
|
| 246 |
+
|
| 247 |
+
# Prompt template
|
| 248 |
+
coding_prompt = """Below is a coding question. Write a response that appropriately answers the question.
|
| 249 |
+
|
| 250 |
+
### Question:
|
| 251 |
+
{}
|
| 252 |
+
|
| 253 |
+
### Answer:
|
| 254 |
+
{}"""
|
| 255 |
+
|
| 256 |
+
# Generate function
|
| 257 |
+
def generate_answer(question, max_length=512):
|
| 258 |
+
inputs = tokenizer(
|
| 259 |
+
coding_prompt.format(question, ""),
|
| 260 |
+
return_tensors="pt"
|
| 261 |
+
).to(model.device)
|
| 262 |
+
|
| 263 |
+
outputs = model.generate(
|
| 264 |
+
**inputs,
|
| 265 |
+
max_new_tokens=max_length,
|
| 266 |
+
temperature=0.7,
|
| 267 |
+
top_p=0.9,
|
| 268 |
+
do_sample=True,
|
| 269 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 273 |
+
return answer
|
| 274 |
+
|
| 275 |
+
# Example
|
| 276 |
+
answer = generate_answer("Explain list comprehension in Python")
|
| 277 |
+
print(answer)
|
| 278 |
+
```
|
| 279 |
+
|
| 280 |
+
### Option 3: Batch Processing
|
| 281 |
+
|
| 282 |
+
```python
|
| 283 |
+
# Process multiple questions efficiently
|
| 284 |
+
questions = [
|
| 285 |
+
"python mei control statements kya hei?",
|
| 286 |
+
"What is a for loop?",
|
| 287 |
+
"function ko define kaise karein?",
|
| 288 |
+
"Explain decorators in Python",
|
| 289 |
+
]
|
| 290 |
+
|
| 291 |
+
for i, question in enumerate(questions, 1):
|
| 292 |
+
print(f"\n{'='*60}")
|
| 293 |
+
print(f"Question {i}: {question}")
|
| 294 |
+
print('='*60)
|
| 295 |
+
|
| 296 |
+
inputs = tokenizer(
|
| 297 |
+
[coding_prompt.format(question, "")],
|
| 298 |
+
return_tensors="pt"
|
| 299 |
+
).to("cuda")
|
| 300 |
+
|
| 301 |
+
outputs = model.generate(
|
| 302 |
+
**inputs,
|
| 303 |
+
max_new_tokens=512,
|
| 304 |
+
temperature=0.7,
|
| 305 |
+
top_p=0.9,
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 309 |
+
print(answer)
|
| 310 |
+
```
|
| 311 |
+
|
| 312 |
+
### Option 4: CPU Inference (No GPU Required)
|
| 313 |
+
|
| 314 |
+
```python
|
| 315 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 316 |
+
|
| 317 |
+
# Load on CPU
|
| 318 |
+
model_name = "convaiinnovations/fine_tuned_coder"
|
| 319 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 320 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 321 |
+
model_name,
|
| 322 |
+
torch_dtype=torch.float32, # Use float32 for CPU
|
| 323 |
+
device_map="cpu",
|
| 324 |
+
)
|
| 325 |
+
|
| 326 |
+
# Rest of the code remains the same
|
| 327 |
+
```
|
| 328 |
+
|
| 329 |
+
## π Training Details
|
| 330 |
+
|
| 331 |
+
### Training Configuration
|
| 332 |
+
|
| 333 |
+
| Hyperparameter | Value |
|
| 334 |
+
|----------------|-------|
|
| 335 |
+
| **Training Framework** | Unsloth |
|
| 336 |
+
| **Fine-tuning Method** | LoRA (Low-Rank Adaptation) |
|
| 337 |
+
| **Base Model** | Qwen/Qwen3-0.6B |
|
| 338 |
+
| **LoRA Rank** | 16-64 (typical) |
|
| 339 |
+
| **LoRA Alpha** | 16-32 (typical) |
|
| 340 |
+
| **Learning Rate** | 2e-4 to 5e-4 |
|
| 341 |
+
| **Batch Size** | Variable (gradient accumulation) |
|
| 342 |
+
| **Sequence Length** | 2048 tokens |
|
| 343 |
+
| **Optimizer** | AdamW |
|
| 344 |
+
| **Hardware** | NVIDIA GPU (CUDA enabled) |
|
| 345 |
+
| **Precision** | Mixed precision (fp16/bf16) |
|
| 346 |
+
|
| 347 |
+
### Training Dataset
|
| 348 |
+
|
| 349 |
+
- **Type**: Custom curated dataset
|
| 350 |
+
- **Languages**: English and Hindi
|
| 351 |
+
- **Domain**: Programming concepts, Python tutorials, coding Q&A
|
| 352 |
+
- **Format**: Question-Answer pairs
|
| 353 |
+
- **Topics Covered**:
|
| 354 |
+
- Control structures (if/else, loops)
|
| 355 |
+
- Data structures (lists, tuples, dictionaries)
|
| 356 |
+
- Functions and modules
|
| 357 |
+
- Object-oriented programming
|
| 358 |
+
- File handling
|
| 359 |
+
- Exception handling
|
| 360 |
+
- Common algorithms
|
| 361 |
+
|
| 362 |
+
### Training Process
|
| 363 |
+
|
| 364 |
+
The model was fine-tuned using:
|
| 365 |
+
1. **LoRA adapters** for parameter-efficient training
|
| 366 |
+
2. **Gradient checkpointing** for memory optimization
|
| 367 |
+
3. **Mixed precision training** for faster convergence
|
| 368 |
+
4. **Custom prompt formatting** for consistent responses
|
| 369 |
+
5. **Bilingual data balancing** for equal performance in both languages
|
| 370 |
+
|
| 371 |
+
## π Performance & Benchmarks
|
| 372 |
+
|
| 373 |
+
### Inference Speed
|
| 374 |
+
|
| 375 |
+
| Configuration | Tokens/Second | Memory Usage |
|
| 376 |
+
|--------------|---------------|--------------|
|
| 377 |
+
| **4-bit Quantization** | ~120-150 | ~2-3 GB |
|
| 378 |
+
| **8-bit Quantization** | ~100-130 | ~3-4 GB |
|
| 379 |
+
| **16-bit (FP16)** | ~80-100 | ~5-6 GB |
|
| 380 |
+
| **32-bit (FP32)** | ~40-60 | ~8-10 GB |
|
| 381 |
+
|
| 382 |
+
*Benchmarked on NVIDIA RTX 3090*
|
| 383 |
+
|
| 384 |
+
### Model Capabilities
|
| 385 |
+
|
| 386 |
+
β
**Strong Performance**:
|
| 387 |
+
- Basic Python concepts (variables, data types)
|
| 388 |
+
- Control flow (if/else, loops)
|
| 389 |
+
- Functions and scope
|
| 390 |
+
- Data structures (lists, dictionaries, tuples)
|
| 391 |
+
- Basic OOP concepts
|
| 392 |
+
- Common programming patterns
|
| 393 |
+
|
| 394 |
+
β οΈ **Moderate Performance**:
|
| 395 |
+
- Advanced algorithms
|
| 396 |
+
- Complex design patterns
|
| 397 |
+
- Async/await concepts
|
| 398 |
+
- Metaclasses and decorators
|
| 399 |
+
|
| 400 |
+
β **Limited Performance**:
|
| 401 |
+
- Very specialized libraries
|
| 402 |
+
- Complex system design
|
| 403 |
+
- Advanced computer science theory
|
| 404 |
+
|
| 405 |
+
## π‘ Example Prompts
|
| 406 |
+
|
| 407 |
+
### Hindi Examples
|
| 408 |
+
|
| 409 |
+
```python
|
| 410 |
+
# Control Statements
|
| 411 |
+
"python mei control statements kya hei?"
|
| 412 |
+
|
| 413 |
+
# Loops
|
| 414 |
+
"for loop kaise use karte hain?"
|
| 415 |
+
"while loop ka example dijiye"
|
| 416 |
+
|
| 417 |
+
# Functions
|
| 418 |
+
"function ko define kaise karein?"
|
| 419 |
+
"function mei arguments kaise pass karte hain?"
|
| 420 |
+
|
| 421 |
+
# Data Structures
|
| 422 |
+
"list aur tuple mei kya difference hai?"
|
| 423 |
+
"dictionary kya hoti hai?"
|
| 424 |
+
|
| 425 |
+
# File Handling
|
| 426 |
+
"file ko read kaise karte hain python mei?"
|
| 427 |
+
|
| 428 |
+
# Error Handling
|
| 429 |
+
"try except kaise use karte hain?"
|
| 430 |
+
|
| 431 |
+
# OOP
|
| 432 |
+
"class kya hoti hai python mei?"
|
| 433 |
+
"inheritance ko samjhaiye"
|
| 434 |
+
```
|
| 435 |
+
|
| 436 |
+
### English Examples
|
| 437 |
+
|
| 438 |
+
```python
|
| 439 |
+
# Basics
|
| 440 |
+
"What are variables in Python?"
|
| 441 |
+
"Explain data types in Python"
|
| 442 |
+
|
| 443 |
+
# Control Flow
|
| 444 |
+
"What are control statements in Python?"
|
| 445 |
+
"How do if-else statements work?"
|
| 446 |
+
|
| 447 |
+
# Loops
|
| 448 |
+
"Explain for loops with examples"
|
| 449 |
+
"What is the difference between for and while loops?"
|
| 450 |
+
|
| 451 |
+
# Functions
|
| 452 |
+
"How to define a function in Python?"
|
| 453 |
+
"What are lambda functions?"
|
| 454 |
+
|
| 455 |
+
# Data Structures
|
| 456 |
+
"What is the difference between list and tuple?"
|
| 457 |
+
"Explain dictionary comprehension"
|
| 458 |
+
|
| 459 |
+
# Advanced
|
| 460 |
+
"What are decorators in Python?"
|
| 461 |
+
"Explain generators and iterators"
|
| 462 |
+
```
|
| 463 |
+
|
| 464 |
+
### Mixed Language Examples
|
| 465 |
+
|
| 466 |
+
```python
|
| 467 |
+
# You can also mix languages
|
| 468 |
+
"Python mei list comprehension kya hai? Give me an example."
|
| 469 |
+
"What is a for loop? Iska syntax kya hai?"
|
| 470 |
+
```
|
| 471 |
+
|
| 472 |
+
## π― Best Practices
|
| 473 |
+
|
| 474 |
+
### 1. Prompt Engineering
|
| 475 |
+
|
| 476 |
+
**Always use the exact prompt template**:
|
| 477 |
+
```python
|
| 478 |
+
coding_prompt = """Below is a coding question. Write a response that appropriately answers the question.
|
| 479 |
+
|
| 480 |
+
### Question:
|
| 481 |
+
{}
|
| 482 |
+
|
| 483 |
+
### Answer:
|
| 484 |
+
{}"""
|
| 485 |
+
```
|
| 486 |
+
|
| 487 |
+
### 2. Generation Parameters
|
| 488 |
+
|
| 489 |
+
**For Educational/Explanatory Answers**:
|
| 490 |
+
```python
|
| 491 |
+
outputs = model.generate(
|
| 492 |
+
**inputs,
|
| 493 |
+
max_new_tokens=512,
|
| 494 |
+
temperature=0.7, # Balanced creativity
|
| 495 |
+
top_p=0.9,
|
| 496 |
+
do_sample=True,
|
| 497 |
+
repetition_penalty=1.1,
|
| 498 |
+
)
|
| 499 |
+
```
|
| 500 |
+
|
| 501 |
+
**For Code Generation**:
|
| 502 |
+
```python
|
| 503 |
+
outputs = model.generate(
|
| 504 |
+
**inputs,
|
| 505 |
+
max_new_tokens=256,
|
| 506 |
+
temperature=0.3, # More deterministic
|
| 507 |
+
top_p=0.95,
|
| 508 |
+
do_sample=True,
|
| 509 |
+
)
|
| 510 |
+
```
|
| 511 |
+
|
| 512 |
+
**For Creative Explanations**:
|
| 513 |
+
```python
|
| 514 |
+
outputs = model.generate(
|
| 515 |
+
**inputs,
|
| 516 |
+
max_new_tokens=768,
|
| 517 |
+
temperature=0.9, # More creative
|
| 518 |
+
top_p=0.9,
|
| 519 |
+
do_sample=True,
|
| 520 |
+
)
|
| 521 |
+
```
|
| 522 |
+
|
| 523 |
+
### 3. Memory Optimization
|
| 524 |
+
|
| 525 |
+
```python
|
| 526 |
+
# For limited GPU memory
|
| 527 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 528 |
+
model_name="convaiinnovations/fine_tuned_coder",
|
| 529 |
+
max_seq_length=2048,
|
| 530 |
+
load_in_4bit=True, # 4-bit quantization
|
| 531 |
+
dtype=None,
|
| 532 |
+
)
|
| 533 |
+
|
| 534 |
+
# Clear cache after generation
|
| 535 |
+
import torch
|
| 536 |
+
torch.cuda.empty_cache()
|
| 537 |
+
```
|
| 538 |
+
|
| 539 |
+
### 4. Error Handling
|
| 540 |
+
|
| 541 |
+
```python
|
| 542 |
+
try:
|
| 543 |
+
inputs = tokenizer(
|
| 544 |
+
[coding_prompt.format(question, "")],
|
| 545 |
+
return_tensors="pt",
|
| 546 |
+
max_length=2048,
|
| 547 |
+
truncation=True,
|
| 548 |
+
).to("cuda")
|
| 549 |
+
|
| 550 |
+
outputs = model.generate(**inputs, max_new_tokens=512)
|
| 551 |
+
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 552 |
+
|
| 553 |
+
except Exception as e:
|
| 554 |
+
print(f"Error during generation: {e}")
|
| 555 |
+
# Fallback or error handling
|
| 556 |
+
```
|
| 557 |
+
|
| 558 |
+
## β οΈ Limitations
|
| 559 |
+
|
| 560 |
+
### Language Limitations
|
| 561 |
+
- **Primary Support**: English and Hindi
|
| 562 |
+
- **Limited**: Code comments in other languages
|
| 563 |
+
- **Not Supported**: Non-Latin scripts except Devanagari (Hindi)
|
| 564 |
+
|
| 565 |
+
### Technical Limitations
|
| 566 |
+
- **Model Size**: 0.6B parameters - smaller than GPT-3/GPT-4
|
| 567 |
+
- **Context Window**: 2048 tokens - limited for very long code
|
| 568 |
+
- **Training Data**: Custom dataset - may have gaps
|
| 569 |
+
- **Knowledge Cutoff**: Training data limited to specific time period
|
| 570 |
+
|
| 571 |
+
### Domain Limitations
|
| 572 |
+
- **Strong**: Python fundamentals and common patterns
|
| 573 |
+
- **Moderate**: Advanced Python features, other programming languages
|
| 574 |
+
- **Weak**: Very specialized domains, cutting-edge techniques
|
| 575 |
+
- **Not Recommended**: Production-critical code generation, security-sensitive applications
|
| 576 |
+
|
| 577 |
+
### Performance Considerations
|
| 578 |
+
- Responses may occasionally:
|
| 579 |
+
- Contain minor inaccuracies
|
| 580 |
+
- Require fact-checking for critical applications
|
| 581 |
+
- Need refinement for production use
|
| 582 |
+
- Show bias toward training data patterns
|
| 583 |
+
|
| 584 |
+
## π― Use Cases
|
| 585 |
+
|
| 586 |
+
### β
Recommended Use Cases
|
| 587 |
+
|
| 588 |
+
1. **Educational Platforms**
|
| 589 |
+
- Interactive coding tutorials
|
| 590 |
+
- Programming course assistance
|
| 591 |
+
- Homework help for students
|
| 592 |
+
|
| 593 |
+
2. **Learning Assistance**
|
| 594 |
+
- Concept explanation
|
| 595 |
+
- Code understanding
|
| 596 |
+
- Syntax clarification
|
| 597 |
+
|
| 598 |
+
3. **Documentation**
|
| 599 |
+
- Quick reference for Python concepts
|
| 600 |
+
- Example code generation
|
| 601 |
+
- Bilingual code documentation
|
| 602 |
+
|
| 603 |
+
4. **Prototyping**
|
| 604 |
+
- Quick code snippets
|
| 605 |
+
- Algorithm exploration
|
| 606 |
+
- Concept validation
|
| 607 |
+
|
| 608 |
+
### β Not Recommended Use Cases
|
| 609 |
+
|
| 610 |
+
1. **Production Code**: Not suitable for production-critical applications
|
| 611 |
+
2. **Security**: Not for security-sensitive code generation
|
| 612 |
+
3. **Medical/Legal**: Not for domain-specific critical advice
|
| 613 |
+
4. **Financial**: Not for financial calculations or advice
|
| 614 |
+
5. **Exam Cheating**: Should not be used to bypass learning
|
| 615 |
+
|
| 616 |
+
## π Citation
|
| 617 |
+
|
| 618 |
+
If you use this model in your research or project, please cite:
|
| 619 |
+
|
| 620 |
+
```bibtex
|
| 621 |
+
@misc{convai_fine_tuned_coder_2025,
|
| 622 |
+
author = {Convai Innovations},
|
| 623 |
+
title = {Fine-tuned Bilingual Coding Assistant: A Qwen3-0.6B Based Model for English-Hindi Programming Education},
|
| 624 |
+
year = {2025},
|
| 625 |
+
publisher = {HuggingFace},
|
| 626 |
+
journal = {HuggingFace Model Hub},
|
| 627 |
+
howpublished = {\url{https://huggingface.co/convaiinnovations/fine_tuned_coder}},
|
| 628 |
+
}
|
| 629 |
+
```
|
| 630 |
+
|
| 631 |
+
## π Acknowledgments
|
| 632 |
+
|
| 633 |
+
This project builds upon exceptional work from:
|
| 634 |
+
|
| 635 |
+
- **Qwen Team** (Alibaba Cloud): For the powerful Qwen3-0.6B base model
|
| 636 |
+
- **Unsloth Team**: For the incredible training optimization framework
|
| 637 |
+
- **Hugging Face**: For the transformers library and model hosting
|
| 638 |
+
- **Open Source Community**: For tools and libraries that made this possible
|
| 639 |
+
|
| 640 |
+
### Technologies Used
|
| 641 |
+
|
| 642 |
+
- [Qwen3-0.6B](https://huggingface.co/Qwen/Qwen3-0.6B) - Base model
|
| 643 |
+
- [Unsloth](https://github.com/unslothai/unsloth) - Training framework
|
| 644 |
+
- [Hugging Face Transformers](https://huggingface.co/transformers) - Model architecture
|
| 645 |
+
- [PyTorch](https://pytorch.org/) - Deep learning framework
|
| 646 |
+
- [bitsandbytes](https://github.com/TimDettmers/bitsandbytes) - Quantization
|
| 647 |
+
|
| 648 |
+
## π§ Contact & Support
|
| 649 |
+
|
| 650 |
+
- **Organization**: Convai Innovations
|
| 651 |
+
- **Model Repository**: [HuggingFace Model Hub](https://huggingface.co/convaiinnovations/fine_tuned_coder)
|
| 652 |
+
- **Issues**: Please open an issue on the model repository for bugs or questions
|
| 653 |
+
- **Feedback**: We welcome feedback to improve the model
|
| 654 |
+
|
| 655 |
+
## π License
|
| 656 |
+
|
| 657 |
+
This model is released under the **Apache 2.0 License**, following the base model's licensing terms.
|
| 658 |
+
|
| 659 |
+
```
|
| 660 |
+
Copyright 2025 Convai Innovations
|
| 661 |
+
|
| 662 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 663 |
+
you may not use this file except in compliance with the License.
|
| 664 |
+
You may obtain a copy of the License at
|
| 665 |
+
|
| 666 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 667 |
+
|
| 668 |
+
Unless required by applicable law or agreed to in writing, software
|
| 669 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 670 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 671 |
+
See the License for the specific language governing permissions and
|
| 672 |
+
limitations under the License.
|
| 673 |
+
```
|
| 674 |
+
|
| 675 |
+
---
|
| 676 |
+
|
| 677 |
+
<div align="center">
|
| 678 |
+
|
| 679 |
+
**Made with β€οΈ by Convai Innovations**
|
| 680 |
|
| 681 |
+
β **Star this model if you find it useful!** β
|
|
|
|
|
|
|
| 682 |
|
| 683 |
+
[π€ Model Hub](https://huggingface.co/convaiinnovations/fine_tuned_coder) | [π Documentation](https://huggingface.co/convaiinnovations/fine_tuned_coder) | [π Report Issues](https://huggingface.co/convaiinnovations/fine_tuned_coder/discussions)
|
| 684 |
|
| 685 |
+
</div>
|