uaytug commited on
Commit
0f612a9
·
verified ·
1 Parent(s): 5798370

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +279 -1
README.md CHANGED
@@ -4,6 +4,284 @@ datasets:
4
  - uaytug/UCDS
5
  language:
6
  - en
 
 
 
 
 
 
 
 
 
 
7
  base_model:
8
  - uaytug/ucoder-mini
9
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  - uaytug/UCDS
5
  language:
6
  - en
7
+ tags:
8
+ - code
9
+ - programming
10
+ - mathematics
11
+ - reasoning
12
+ - text-generation
13
+ - conversational
14
+ - qwen2
15
+ pipeline_tag: text-generation
16
+ library_name: transformers
17
  base_model:
18
  - uaytug/ucoder-mini
19
+ ---
20
+
21
+ # uCoder Mini
22
+
23
+ > **Important:** The model is unable to produce accurate and high-quality answers to general knowledge, creative writing, or non-coding tasks, and to questions asked in languages other than English. The answers to your questions in these areas may not be satisfactory because this model was specifically trained for **coding and mathematical reasoning tasks** (competitive programming, LeetCode, algorithm problems, etc.).
24
+
25
+ ![Parameters](https://img.shields.io/badge/Parameters-1.5B-blue) ![Architecture](https://img.shields.io/badge/Architecture-Qwen2-purple) ![Context](https://img.shields.io/badge/Context-4096-green) ![Precision](https://img.shields.io/badge/Precision-bfloat16-red) ![License](https://img.shields.io/badge/License-Apache%202.0-orange)
26
+
27
+ ## Overview
28
+
29
+ **uCoder Mini** is a 1.5B parameter dense language model fine-tuned specifically for code generation and mathematical reasoning. Built on the Qwen2 architecture, this model demonstrates that small, focused models can achieve strong performance on programming tasks when trained on high-quality, curated data.
30
+
31
+ ### Key Features
32
+
33
+ - **Specialized Focus**: Trained exclusively on coding and math data for maximum performance in these domains
34
+ - **Efficient Size**: 1.5B parameters — runs on consumer GPUs, fast inference
35
+ - **Extended Context**: Supports up to 4096 tokens for longer code generation
36
+ - **Multi-Language**: Handles Python, JavaScript, C++, Java, and more
37
+ - **Competitive Programming**: Strong on algorithmic problems (LeetCode, Codeforces-style)
38
+
39
+ ## Model Details
40
+
41
+ | Attribute | Value |
42
+ |-----------|-------|
43
+ | **Architecture** | Qwen2 (Dense Transformer) |
44
+ | **Parameters** | ~1.5B |
45
+ | **Hidden Size** | 1536 |
46
+ | **Layers** | 28 |
47
+ | **Attention Heads** | 12 |
48
+ | **Context Length** | 4096 tokens |
49
+ | **Vocabulary Size** | 151,936 |
50
+ | **Training Precision** | bfloat16 |
51
+ | **Training Method** | Supervised Fine-Tuning (SFT) |
52
+
53
+ ## Intended Use
54
+
55
+ **Recommended for:**
56
+ - Competitive programming (LeetCode, Codeforces, HackerRank)
57
+ - Algorithm implementation and optimization
58
+ - Mathematical problem solving with code
59
+ - Code debugging and explanation
60
+ - Learning programming concepts
61
+
62
+ **Not recommended for:**
63
+ - General conversation or chat
64
+ - Creative writing or storytelling
65
+ - Factual Q&A or knowledge retrieval
66
+ - Non-English tasks
67
+ - Production systems without human review
68
+
69
+ ## Quick Start
70
+
71
+ ```python
72
+ from transformers import AutoModelForCausalLM, AutoTokenizer
73
+
74
+ model_id = "uaytug/ucoder-mini"
75
+
76
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
77
+ model = AutoModelForCausalLM.from_pretrained(
78
+ model_id,
79
+ torch_dtype="auto",
80
+ device_map="auto"
81
+ )
82
+
83
+ messages = [
84
+ {"role": "user", "content": "Write a Python function to find the longest palindromic substring."}
85
+ ]
86
+
87
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
88
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
89
+
90
+ outputs = model.generate(
91
+ **inputs,
92
+ max_new_tokens=1024,
93
+ temperature=0.6,
94
+ top_p=0.95,
95
+ do_sample=True
96
+ )
97
+
98
+ response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
99
+ print(response)
100
+ ```
101
+
102
+ ### Recommended Generation Parameters
103
+
104
+ For best results on coding tasks:
105
+
106
+ ```python
107
+ generation_config = {
108
+ "max_new_tokens": 2048,
109
+ "temperature": 0.6, # Use 0.6 for focused output, 1.0 for more exploration
110
+ "top_p": 0.95,
111
+ "do_sample": True,
112
+ }
113
+ ```
114
+
115
+ ## Chat Template
116
+
117
+ uCoder Mini uses the ChatML format:
118
+
119
+ ```
120
+ <|im_start|>user
121
+ Your coding question here<|im_end|>
122
+ <|im_start|>assistant
123
+ ```
124
+
125
+ ## Training Data
126
+
127
+ Trained on [UCDS (uCoder Dataset)](https://huggingface.co/datasets/uaytug/UCDS) — a curated collection of 420K+ high-quality samples:
128
+
129
+ | Source | Samples | Description |
130
+ |--------|---------|-------------|
131
+ | Codeforces | 47K+ | Competitive programming with solutions |
132
+ | Code-Contests-Plus | 10K+ | Algorithm challenges |
133
+ | CodeAlpaca | 15K+ | Instruction-following code |
134
+ | OpenMathInstruct | Various | Mathematical reasoning chains |
135
+ | Curated Sources | Various | Tool use, chain-of-thought, deduplication |
136
+
137
+ **Total**: 420,686 deduplicated samples covering Python, JavaScript, C++, Java, and more.
138
+
139
+ ## Limitations
140
+
141
+ - **Domain-Specific**: This model is trained only on code/math — it will perform poorly on general tasks
142
+ - **English Only**: Best performance in English; other languages not supported
143
+ - **Knowledge Cutoff**: May not know about recent libraries, frameworks, or API changes
144
+ - **No Verification**: Always test generated code before use in production
145
+ - **Context Limit**: 4096 tokens may not be enough for very large codebases
146
+ - **No Web Access**: Cannot fetch documentation or search for solutions
147
+
148
+ ## Example Outputs
149
+
150
+ <details>
151
+ <summary><b>Algorithm Problem</b></summary>
152
+
153
+ **Prompt:** Implement a function to find the kth largest element in an unsorted array.
154
+
155
+ ```python
156
+ import heapq
157
+
158
+ def find_kth_largest(nums, k):
159
+ # Use a min-heap of size k
160
+ # Time: O(n log k), Space: O(k)
161
+ heap = []
162
+ for num in nums:
163
+ heapq.heappush(heap, num)
164
+ if len(heap) > k:
165
+ heapq.heappop(heap)
166
+ return heap[0]
167
+
168
+ # Alternative: QuickSelect for O(n) average
169
+ def quickselect(nums, k):
170
+ k = len(nums) - k # Convert to kth smallest
171
+
172
+ def partition(left, right, pivot_idx):
173
+ pivot = nums[pivot_idx]
174
+ nums[pivot_idx], nums[right] = nums[right], nums[pivot_idx]
175
+ store_idx = left
176
+ for i in range(left, right):
177
+ if nums[i] < pivot:
178
+ nums[store_idx], nums[i] = nums[i], nums[store_idx]
179
+ store_idx += 1
180
+ nums[right], nums[store_idx] = nums[store_idx], nums[right]
181
+ return store_idx
182
+
183
+ left, right = 0, len(nums) - 1
184
+ while True:
185
+ pivot_idx = partition(left, right, right)
186
+ if pivot_idx == k:
187
+ return nums[k]
188
+ elif pivot_idx < k:
189
+ left = pivot_idx + 1
190
+ else:
191
+ right = pivot_idx - 1
192
+ ```
193
+
194
+ </details>
195
+
196
+ <details>
197
+ <summary><b>Mathematical Reasoning</b></summary>
198
+
199
+ **Prompt:** Prove that the sum of the first n odd numbers equals n².
200
+
201
+ **Response:**
202
+
203
+ Let's prove this by multiple methods:
204
+
205
+ **Method 1: Direct Calculation**
206
+ The first n odd numbers are: 1, 3, 5, ..., (2n-1)
207
+
208
+ Sum = 1 + 3 + 5 + ... + (2n-1)
209
+
210
+ This is an arithmetic sequence with:
211
+ - First term a₁ = 1
212
+ - Last term aₙ = 2n - 1
213
+ - Number of terms = n
214
+
215
+ Sum = n × (first + last) / 2 = n × (1 + 2n - 1) / 2 = n × 2n / 2 = n²
216
+
217
+ **Method 2: Induction**
218
+ - Base case: n=1 → Sum = 1 = 1² ✓
219
+ - Assume true for k: 1 + 3 + ... + (2k-1) = k²
220
+ - For k+1: k² + (2(k+1)-1) = k² + 2k + 1 = (k+1)² ✓
221
+
222
+ </details>
223
+
224
+ <details>
225
+ <summary><b>Debugging</b></summary>
226
+
227
+ **Prompt:** Why does this code give wrong results?
228
+ ```python
229
+ def binary_search(arr, target):
230
+ left, right = 0, len(arr)
231
+ while left < right:
232
+ mid = (left + right) / 2
233
+ if arr[mid] == target:
234
+ return mid
235
+ elif arr[mid] < target:
236
+ left = mid
237
+ else:
238
+ right = mid
239
+ return -1
240
+ ```
241
+
242
+ **Response:** There are several bugs:
243
+
244
+ 1. **Integer division**: `mid = (left + right) / 2` returns a float. Use `//` for integer division.
245
+
246
+ 2. **Infinite loop**: `left = mid` can cause infinite loop when `mid == left`. Should be `left = mid + 1`.
247
+
248
+ 3. **Off-by-one**: With `right = len(arr)`, using `right = mid` is correct, but the initial range setup suggests you want `right = len(arr) - 1` with `left <= right`.
249
+
250
+ **Fixed version:**
251
+ ```python
252
+ def binary_search(arr, target):
253
+ left, right = 0, len(arr) - 1
254
+ while left <= right:
255
+ mid = (left + right) // 2
256
+ if arr[mid] == target:
257
+ return mid
258
+ elif arr[mid] < target:
259
+ left = mid + 1
260
+ else:
261
+ right = mid - 1
262
+ return -1
263
+ ```
264
+
265
+ </details>
266
+
267
+ ## Hardware Requirements
268
+
269
+ | Setup | VRAM Required | Notes |
270
+ |-------|---------------|-------|
271
+ | FP16/BF16 | ~4 GB | Full precision inference |
272
+
273
+ ## Citation
274
+
275
+ ```bibtex
276
+ @misc{ucoder-mini,
277
+ author = {uaytug},
278
+ title = {uCoder Mini: A Compact Language Model for Code and Math},
279
+ year = {2026},
280
+ publisher = {Hugging Face},
281
+ url = {https://huggingface.co/uaytug/ucoder-mini}
282
+ }
283
+ ```
284
+
285
+ ## Acknowledgments
286
+
287
+ Thanks to the open-source community and creators of the datasets that made UCDS possible.