microsoft/unixcoder-base fine-tuned on the PECAN benchmark to
identify the programming language of a raw code fragment of at most 512 bytes, with no file name,
extension, or repository context. It predicts one of 319 languages (config.id2label; lowercased, these are exactly the PECAN labels).
Artifact repository (code, scoring, all results): https://anonymous.4open.science/r/pecan-benchmark
| Accuracy | Macro-F1 (319 labels) | Top-5 | Top-10 | Pop-20 | Head | Torso | Tail |
|---|---|---|---|---|---|---|---|
| 0.9575 | 0.9293 | 0.983 | 0.9874 | 0.866 | 0.967 | 0.931 | 0.915 |
95% bootstrap CIs are within ±0.0004 (accuracy) and ±0.0007 (macro-F1). Pop-20 is the 20 most-used languages in the 2026 Stack Overflow Developer Survey; head, torso, and tail are thirds of the 319 languages by test support. Best validation accuracy during training: 0.9837.
| Setting | Value |
|---|---|
| Base model | microsoft/unixcoder-base, with a sequence-classification head over 319 labels |
| Training data | Fixed seed-42 subset of the PECAN train split: 28,623,869 training and 5,051,271 validation fragments (the test split was not used) |
| Input | Fragment text only; tokenized, padded and truncated to 512 tokens |
| Epochs / steps | 5 epochs, 559,060 optimizer steps |
| Batch size | 256 (effective) |
| Optimizer | AdamW, learning rate 5e-5, weight decay 0.01 |
| Schedule | Cosine decay with 10% linear warmup |
| Precision | bf16 mixed precision |
| Checkpoint selection | Evaluated every epoch on the validation fragments; best validation accuracy kept (the final epoch). Early stopping with patience 3 was enabled and never triggered |
| Seed | 42 |
| Hyperparameter selection | Grid sweeps over learning rate (1e-5, 3e-5, 5e-5), epochs (3, 5, 10), and weight decay (0, 0.01) on a subset of 1,500 training fragments per language, selected by validation accuracy (configs in the artifact's configs/) |
| Framework | Hugging Face Transformers Trainer (src/training_pipeline.py in the artifact) |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
repo = "pecan-anon/unixcoder-pecan"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).eval()
fragment = "def add(a, b):\n return a + b\n"
inputs = tok(fragment, truncation=True, max_length=512, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
print(model.config.id2label[int(logits.argmax())].lower()) # PECAN labels are lowercase
To evaluate on the benchmark, write one prediction per test fragment and score it with
scripts/score_predictions.py from the artifact repository.
microsoft/unixcoder-base