pecan-anon commited on
Commit
1591719
·
verified ·
1 Parent(s): 1e2a7d1

Model card with training configuration

Browse files
Files changed (1) hide show
  1. README.md +70 -3
README.md CHANGED
@@ -3,9 +3,76 @@ library_name: transformers
3
  pipeline_tag: text-classification
4
  base_model: microsoft/codebert-base
5
  license: mit
 
 
 
 
 
 
 
 
6
  ---
 
7
  # CodeBERT-PECAN
8
 
9
- microsoft/codebert-base fine-tuned on the PECAN benchmark to identify the programming language of a raw
10
- 512-byte code fragment (319 languages, no file name or extension).
11
- Test split: accuracy 0.9575, macro-F1 0.9304. Artifact and scoring code: https://anonymous.4open.science/r/pecan-benchmark
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  pipeline_tag: text-classification
4
  base_model: microsoft/codebert-base
5
  license: mit
6
+ datasets:
7
+ - pecan-anon/pecan-anon
8
+ metrics:
9
+ - accuracy
10
+ - f1
11
+ tags:
12
+ - code
13
+ - programming-language-identification
14
  ---
15
+
16
  # CodeBERT-PECAN
17
 
18
+ `microsoft/codebert-base` fine-tuned on the [PECAN benchmark](https://huggingface.co/datasets/pecan-anon/pecan-anon) to
19
+ identify the programming language of a raw code fragment of at most 512 bytes, with no file name,
20
+ extension, or repository context. It predicts one of 319 languages (`config.id2label`).
21
+
22
+ Artifact repository (code, scoring, all results): https://anonymous.4open.science/r/pecan-benchmark
23
+
24
+ ## Results (official PECAN test split, 9,179,661 fragments)
25
+
26
+ | Accuracy | Macro-F1 (319 labels) | Top-5 | Top-10 | Pop-20 | Head | Torso | Tail |
27
+ |---|---|---|---|---|---|---|---|
28
+ | 0.9575 | 0.9304 | 0.983 | 0.9877 | 0.870 | 0.967 | 0.931 | 0.914 |
29
+
30
+ 95% bootstrap CIs are within ±0.0004 (accuracy) and ±0.0007 (macro-F1). Pop-20 is the 20 most-used
31
+ languages in the 2026 Stack Overflow Developer Survey; head, torso, and tail are thirds of the 319
32
+ languages by test support. Best validation accuracy during training: 0.9832.
33
+
34
+ ## Training configuration
35
+
36
+ | Setting | Value |
37
+ |---|---|
38
+ | Base model | `microsoft/codebert-base`, with a sequence-classification head over 319 labels |
39
+ | 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) |
40
+ | Input | Fragment text only; tokenized, padded and truncated to 512 tokens |
41
+ | Epochs / steps | 5 epochs, 559,060 optimizer steps |
42
+ | Batch size | 256 (effective) |
43
+ | Optimizer | AdamW, learning rate 5e-5, weight decay 0.01 |
44
+ | Schedule | Cosine decay with 10% linear warmup |
45
+ | Precision | bf16 mixed precision |
46
+ | 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 |
47
+ | Seed | 42 |
48
+ | 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/`) |
49
+ | Framework | Hugging Face Transformers Trainer (`src/training_pipeline.py` in the artifact) |
50
+
51
+ ## Usage
52
+
53
+ ```python
54
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
55
+ import torch
56
+
57
+ repo = "pecan-anon/codebert-pecan"
58
+ tok = AutoTokenizer.from_pretrained(repo)
59
+ model = AutoModelForSequenceClassification.from_pretrained(repo).eval()
60
+
61
+ fragment = "def add(a, b):\n return a + b\n"
62
+ inputs = tok(fragment, truncation=True, max_length=512, return_tensors="pt")
63
+ with torch.no_grad():
64
+ logits = model(**inputs).logits
65
+ print(model.config.id2label[int(logits.argmax())])
66
+ ```
67
+
68
+ To evaluate on the benchmark, write one prediction per test fragment and score it with
69
+ `scripts/score_predictions.py` from the artifact repository.
70
+
71
+ ## Limitations
72
+
73
+ - Closed-set: every input is assigned one of the 319 PECAN labels, including code in other languages.
74
+ - Labels come from file extensions; a manual audit estimates about 9% of test labels do not match the
75
+ fragment content, and the model learns some of these extension conventions.
76
+ - Trained and evaluated on 512-byte fragments from one corpus (The Stack v1.1); whole files or code
77
+ from other sources may behave differently.
78
+ - Each configuration was trained once (seed 42); scores do not reflect training variance.