加载中…
加载中…
A small PHP code-completion model, fine-tuned from SmolLM2-135M. This is a personal learning project.
Do not use it in production. It can produce wrong, insecure or non-running code, so review everything it generates.
from transformers import AutoModelForCausalLM, AutoTokenizer
name = "chellen021/SmolLM2-135M-PHP"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name)
prompt = "<?php\n\nfunction add($a, $b)\n{\n"
inputs = tok(prompt, return_tensors="pt")
out = model.generate(**inputs, max_new_tokens=80, do_sample=False, repetition_penalty=1.1)
print(tok.decode(out[0], skip_special_tokens=True))
Source: The Stack v3 (GitHub snapshot up to 2025-08-07; dataset license ODC-By 1.0).
Filters applied:
language is PHP, license_type is permissive, not vendored| Files used | 245,130 train, 10,742 validation |
| Repositories | 10,914 |
| Tokens | 285,749,021 train, 16,733,639 validation |
Code in the source dataset keeps its original licenses. License detection is automatic and can be wrong. If your code should not be here, please open a discussion on this repository.
| Hardware | 1 Nvidia T4 (Kaggle) |
| Steps | 5,000 (about 14% of one pass over the training data) |
| Batch | 8, gradient accumulation 2, 512 tokens per sample |
| Learning rate | 5e-5, cosine schedule |
Bottom line: it has learned to predict PHP text better, but there is no evidence that it writes more correct code than the base model.
Validation loss, measured on 2,000 blocks from held-out repositories:
| Base model | This model | |
|---|---|---|
| Validation loss | 1.242 | 1.158 |
| Perplexity | 3.46 | 3.18 |
Code generation test on 50 fixed prompts. Generation was limited to 400 new tokens with a repetition penalty of 1.1, and each output was cut at the point where all brackets closed. 20 prompts ask for a function that is run against test cases. All 20 reference solutions passed those tests.
| Greedy, 1 output per prompt | Base model | This model | 95% CI of difference |
|---|---|---|---|
| Brackets closed (50 prompts) | 44 | 46 | -6% to +16% |
php -l passes (50 prompts) |
35 | 39 | -4% to +20% |
| Function tests pass (20 prompts) | 4 | 3 | -15% to 0% |
| Sampled, temperature 0.7, 3 outputs per prompt | Base model | This model | 95% CI of difference |
|---|---|---|---|
| Brackets closed | 82.7% | 82.0% | -8.7% to +6.7% |
php -l passes |
61.3% | 63.3% | -8.7% to +12.7% |
| Function tests pass | 8.3% | 11.7% | -3.3% to +10.0% |
Every confidence interval (bootstrap over prompts) includes zero, so none of these differences is established. The prompts were written for this project and are not a standard benchmark.
@misc{lozhkov2026stack-v3,
author = {Lozhkov, Anton and Larcher, Hugo and Morlon, Mathieu and Ben Allal, Loubna and von Werra, Leandro},
title = {The Stack v3: The Largest Open Code Dataset},
year = 2026,
url = {https://huggingface.co/datasets/HuggingFaceCode/stack-v3-train},
publisher = {Hugging Face}
}