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-the-middle
|
| 9 |
+
- gpt
|
| 10 |
+
- pytorch
|
| 11 |
+
library_name: custom
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# JSCoder — JavaScript Code Completion Model (~300M)
|
| 15 |
+
|
| 16 |
+
A GPT-style decoder-only language model trained from scratch on ~1B tokens of
|
| 17 |
+
JavaScript source code (sourced from The Stack). It supports both plain
|
| 18 |
+
next-token completion and **fill-in-the-middle (FIM)** autocomplete at the
|
| 19 |
+
cursor position (StarCoder-style PSM/SPM format).
|
| 20 |
+
|
| 21 |
+
## Architecture
|
| 22 |
+
|
| 23 |
+
| Hyper-parameter | Value |
|
| 24 |
+
|---|---|
|
| 25 |
+
| Parameters | ~300M |
|
| 26 |
+
| Layers | 24 |
|
| 27 |
+
| Hidden dim | 1024 |
|
| 28 |
+
| Heads | 16 |
|
| 29 |
+
| Context window | 1024 tokens |
|
| 30 |
+
| Vocabulary | 8 192 (byte-level BPE, JS-tuned) |
|
| 31 |
+
| Positional encoding | RoPE |
|
| 32 |
+
| Normalization | RMSNorm |
|
| 33 |
+
| Activation | SwiGLU |
|
| 34 |
+
| Weight tying | Yes (embedding ↔ lm_head) |
|
| 35 |
+
|
| 36 |
+
## Files
|
| 37 |
+
|
| 38 |
+
| File | Description |
|
| 39 |
+
|---|---|
|
| 40 |
+
| `checkpoints/jscoder_300m/ckpt.pt` | PyTorch checkpoint (`model` state-dict + `config` dict) |
|
| 41 |
+
| `tokenizer/js_bpe.json` | Byte-level BPE tokenizer (HuggingFace `tokenizers` format) |
|
| 42 |
+
| `model/gpt.py` | Model definition (`GPT`, `GPTConfig`) |
|
| 43 |
+
| `tokenizer/tokenizer.py` | `JSCoderTokenizer` wrapper |
|
| 44 |
+
| `sample.py` | Inference script (plain completion + FIM) |
|
| 45 |
+
|
| 46 |
+
## Quick Start
|
| 47 |
+
|
| 48 |
+
```bash
|
| 49 |
+
git clone https://huggingface.co/YOUR_USERNAME/jscoder-300m
|
| 50 |
+
cd jscoder-300m
|
| 51 |
+
pip install torch tokenizers
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### Plain completion
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
python sample.py \
|
| 58 |
+
--ckpt checkpoints/jscoder_300m/ckpt.pt \
|
| 59 |
+
--prompt "// returns the sum of all numbers in the array
|
| 60 |
+
const sumArray = (items) => {
|
| 61 |
+
let result = 0;
|
| 62 |
+
for (const item of items) {" \
|
| 63 |
+
--max-new-tokens 80 --temperature 0.2
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
### Fill-in-the-middle (autocomplete at cursor)
|
| 67 |
+
|
| 68 |
+
```bash
|
| 69 |
+
python sample.py \
|
| 70 |
+
--ckpt checkpoints/jscoder_300m/ckpt.pt \
|
| 71 |
+
--fim \
|
| 72 |
+
--prefix $'function sum(arr) {\n let total = 0;\n ' \
|
| 73 |
+
--suffix $'\n return total;\n}' \
|
| 74 |
+
--temperature 0.2
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### Python API
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
import torch
|
| 81 |
+
from model.gpt import GPT, GPTConfig
|
| 82 |
+
from tokenizer.tokenizer import JSCoderTokenizer
|
| 83 |
+
|
| 84 |
+
ckpt = torch.load("checkpoints/jscoder_300m/ckpt.pt", map_location="cpu")
|
| 85 |
+
model = GPT(GPTConfig(**ckpt["config"]))
|
| 86 |
+
model.load_state_dict(ckpt["model"])
|
| 87 |
+
model.eval()
|
| 88 |
+
|
| 89 |
+
tok = JSCoderTokenizer.load("tokenizer/js_bpe.json")
|
| 90 |
+
|
| 91 |
+
prompt = "// parses JSON safely\nfunction parseJSON(str) {\n try {"
|
| 92 |
+
ids = tok.encode(prompt)
|
| 93 |
+
idx = torch.tensor([ids], dtype=torch.long)
|
| 94 |
+
|
| 95 |
+
with torch.no_grad():
|
| 96 |
+
out = model.generate(idx, max_new_tokens=100, temperature=0.2, top_k=50)
|
| 97 |
+
|
| 98 |
+
print(tok.decode(out[0].tolist()))
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
## Capability Tiers
|
| 102 |
+
|
| 103 |
+
The model is most reliable on patterns that dominate its training data:
|
| 104 |
+
|
| 105 |
+
**Tier 1 — high confidence:**
|
| 106 |
+
- `try/catch` JSON parse / async fetch wrappers
|
| 107 |
+
- `for-of` accumulators
|
| 108 |
+
- Throttle / memoize (when scaffolded with the outer shell)
|
| 109 |
+
|
| 110 |
+
**Tier 2 — partial (right structure, minor logic error):**
|
| 111 |
+
- Word capitalisation, type guards, number validation
|
| 112 |
+
|
| 113 |
+
**Tier 3 — scaffold required:**
|
| 114 |
+
- `Array.isArray` ternaries, `Set` dedup, `Object.assign` merge,
|
| 115 |
+
`hasOwnProperty`, deep clone
|
| 116 |
+
|
| 117 |
+
See [`inference.md`](inference.md) for detailed prompt examples and scaffolding
|
| 118 |
+
strategies for each tier.
|
| 119 |
+
|
| 120 |
+
## Training
|
| 121 |
+
|
| 122 |
+
Trained with a custom PyTorch loop (`train.py`) on sharded `.bin` token files
|
| 123 |
+
packed from ~1B tokens of JavaScript from [The Stack](https://huggingface.co/datasets/bigcode/the-stack).
|
| 124 |
+
|
| 125 |
+
```
|
| 126 |
+
Tokenizer: byte-level BPE, 8 192 vocab, trained on the same corpus
|
| 127 |
+
Optimizer: AdamW, lr=3e-4, cosine decay, warmup=500 iters
|
| 128 |
+
Batch size: 512 tokens × grad-accum 128 → ~65k tokens/step
|
| 129 |
+
Hardware: trained on cloud GPU (A5000+)
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
## Limitations
|
| 133 |
+
|
| 134 |
+
- Trained on JavaScript only; will not generalise to other languages.
|
| 135 |
+
- Small vocabulary (8 192) causes slightly longer tokenisation of uncommon
|
| 136 |
+
identifiers.
|
| 137 |
+
- Recursive / divide-and-conquer patterns are weak — the model has not seen
|
| 138 |
+
enough of them to generalise reliably.
|
| 139 |
+
- Not RLHF-tuned; outputs are raw language model completions.
|
| 140 |
+
|
| 141 |
+
## License
|
| 142 |
+
|
| 143 |
+
MIT
|