loubnabnl HF staff commited on
Commit
6716fbb
·
verified ·
1 Parent(s): c835b64

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +64 -41
README.md CHANGED
@@ -11,34 +11,67 @@ model-index:
11
  results: []
12
  ---
13
 
14
- <!-- This model card has been generated automatically according to the information the Trainer had access to. You
15
- should probably proofread and complete it, then remove this comment. -->
16
 
17
  # stack-edu-classifier-ruby
 
18
 
19
- This model is a fine-tuned version of [bigcode/starencoder](https://huggingface.co/bigcode/starencoder) on an unknown dataset.
20
- It achieves the following results on the evaluation set:
21
- - Loss: 0.3282
22
- - Precision: 0.4623
23
- - Recall: 0.3260
24
- - F1 Macro: 0.3536
25
- - Accuracy: 0.6657
26
- - F1 Binary Minimum3: 0.6101
27
 
28
- ## Model description
 
 
 
 
 
 
 
 
 
29
 
30
- More information needed
 
 
31
 
32
  ## Intended uses & limitations
33
 
34
- More information needed
35
 
36
- ## Training and evaluation data
 
 
37
 
38
- More information needed
 
39
 
40
  ## Training procedure
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  ### Training hyperparameters
43
 
44
  The following hyperparameters were used during training:
@@ -55,29 +88,19 @@ The following hyperparameters were used during training:
55
  - lr_scheduler_warmup_steps: 200
56
  - num_epochs: 20
57
 
58
- ### Training results
59
-
60
- | Training Loss | Epoch | Step | Validation Loss | Precision | Recall | F1 Macro | Accuracy | F1 Binary Minimum3 |
61
- |:-------------:|:-------:|:-----:|:---------------:|:---------:|:------:|:--------:|:--------:|:------------------:|
62
- | No log | 0 | 0 | 4.7647 | 0.0010 | 0.1667 | 0.0020 | 0.0062 | 0 |
63
- | 0.358 | 1.4368 | 1000 | 0.3549 | 0.4093 | 0.2953 | 0.3072 | 0.6513 | 0.5882 |
64
- | 0.3559 | 2.8736 | 2000 | 0.3425 | 0.4649 | 0.3087 | 0.3294 | 0.6571 | 0.6143 |
65
- | 0.3534 | 4.3103 | 3000 | 0.3391 | 0.4318 | 0.3144 | 0.3349 | 0.6586 | 0.6149 |
66
- | 0.3539 | 5.7471 | 4000 | 0.3394 | 0.4219 | 0.3244 | 0.3446 | 0.6579 | 0.6298 |
67
- | 0.3585 | 7.1839 | 5000 | 0.3359 | 0.4756 | 0.3106 | 0.3350 | 0.6622 | 0.6069 |
68
- | 0.3476 | 8.6207 | 6000 | 0.3339 | 0.4551 | 0.3178 | 0.3415 | 0.6638 | 0.6082 |
69
- | 0.3496 | 10.0575 | 7000 | 0.3307 | 0.4512 | 0.3263 | 0.3505 | 0.6656 | 0.6204 |
70
- | 0.3362 | 11.4943 | 8000 | 0.3307 | 0.4657 | 0.3228 | 0.3485 | 0.6640 | 0.6178 |
71
- | 0.3442 | 12.9310 | 9000 | 0.3307 | 0.4771 | 0.3248 | 0.3517 | 0.6677 | 0.6095 |
72
- | 0.344 | 14.3678 | 10000 | 0.3287 | 0.4774 | 0.3222 | 0.3496 | 0.6660 | 0.6147 |
73
- | 0.3332 | 15.8046 | 11000 | 0.3281 | 0.4678 | 0.3240 | 0.3504 | 0.6658 | 0.6168 |
74
- | 0.3359 | 17.2414 | 12000 | 0.3300 | 0.4658 | 0.3203 | 0.3471 | 0.6643 | 0.6100 |
75
- | 0.3306 | 18.6782 | 13000 | 0.3282 | 0.4623 | 0.3260 | 0.3536 | 0.6657 | 0.6101 |
76
-
77
-
78
- ### Framework versions
79
-
80
- - Transformers 4.43.4
81
- - Pytorch 2.4.0+cu121
82
- - Datasets 2.21.0
83
- - Tokenizers 0.19.1
 
11
  results: []
12
  ---
13
 
 
 
14
 
15
  # stack-edu-classifier-ruby
16
+ This is a classifier for scoring the educational value of code files in The Stack v2 dataset, it is a finetuned version of [bigcode/starencoder](https://huggingface.co/bigcode/starencoder) with a classification head on code files annotated by Llama3.1-70B-Instruct. We use this classifier for building Stack-Edu dataset used for training SmolLM2, see [paper](https://arxiv.org/pdf/2502.02737). Each classifier is trained on one programming language.
17
 
18
+ ### How to use in transformers
19
+ To load the classifier, use the following code:
20
+
21
+ ```python
22
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
23
+
24
+ tokenizer = AutoTokenizer.from_pretrained(REPO_NAME)
25
+ model = AutoModelForSequenceClassification.from_pretrained(REPO_NAME)
26
 
27
+ text = "This is a test sentence."
28
+ inputs = tokenizer(text, return_tensors="pt", padding="longest", truncation=True)
29
+ outputs = model(**inputs)
30
+ logits = outputs.logits.squeeze(-1).float().detach().numpy()
31
+ score = logits.item()
32
+ result = {
33
+ "text": text,
34
+ "score": score,
35
+ "int_score": int(round(max(0, min(score, 5)))),
36
+ }
37
 
38
+ print(result)
39
+ # {'text': 'This is a test sentence.', 'score': 0.07964489609003067, 'int_score': 0}
40
+ ```
41
 
42
  ## Intended uses & limitations
43
 
44
+ While the classifier performs well in distinguishing high-quality code in its target language (Ruby in this case), there are some limitations:
45
 
46
+ - Scope: The model's performance might change for other datasets, in particular for out of distribution samples. The classifier's context is 1024 tokens, which might not be sufficient to assess the quality of some long code files.
47
+ - Bias: The model's performance is dependent on the quality and representativeness of the training data and the LLM used for the annotation. Biases in both can affect the classifier's judgments. It might overfit to thoroughly commented code.
48
+ - Context: The classifier evaluates individual code files without considering broader context, which might impact its effectiveness in certain scenarios.
49
 
50
+ The training and inference code is available on GitHub
51
+ https://github.com/huggingface/cosmopedia/tree/main/classification
52
 
53
  ## Training procedure
54
 
55
+ The classifier was trained on 500,000 pairs of code files and their scores from 0 to 5, generated by Llama3.1. The samples were annotated based on their educational quality with 1 being not educational and 5 being highly educational and relevant for teaching programming. You can find the prompt used for building the annotations in the appendix of [SmolLM2 paper](https://arxiv.org/pdf/2502.02737).
56
+
57
+ We added a classification head with a single regression output to StarEncoder and trained the model for 20 epochs with a learning rate of 3e-4. During training, the embedding and encoder layers were frozen to focus on the classification head.
58
+
59
+ It achieves the following results on the evaluation set:
60
+ - Loss: 0.3282
61
+ - Precision: 0.4623
62
+ - Recall: 0.3260
63
+ - F1 Macro: 0.3536
64
+ - Accuracy: 0.6657
65
+ - F1 Binary Minimum3: 0.6101
66
+
67
+ While the macro F1 scores across the 1-5 rating scale are relatively low due to the model's difficulty in distinguishing between higher-rated samples, the classifier performs well for our primary filtering task. When converting to binary classification, using a threshold of 2 achieves the F1 scores ranges between 0.8 and 0.9 for most Stack-Edu classifiers, whereas a threshold of 3 yields F1 scores between 0.55 and 0.70. With the Highest being Python, C, Rust and the lowest being TypeScript and PHP.
68
+
69
+ <div style="display: flex; justify-content: center; gap: 20px;">
70
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/61c141342aac764ce1654e43/z0lCnH2nqYMu09JsxPvFb.png" width="600">
71
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/61c141342aac764ce1654e43/W6BQO6Rkafpj-96fWdCOv.png" width="600">
72
+ </div>
73
+ We validated these classifiers by filtering Stack v2 data and testing on an intermediate SmolLM2 checkpoint. Filtering with a threshold of 3 improved performance across most languages while maintaining adequate data volume, though Java showed better results with a threshold of 2.
74
+
75
  ### Training hyperparameters
76
 
77
  The following hyperparameters were used during training:
 
88
  - lr_scheduler_warmup_steps: 200
89
  - num_epochs: 20
90
 
91
+ ## License
92
+
93
+ [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
94
+
95
+ ## Citation
96
+ ```bash
97
+ @misc{allal2025smollm2smolgoesbig,
98
+ title={SmolLM2: When Smol Goes Big -- Data-Centric Training of a Small Language Model},
99
+ author={Loubna Ben Allal and Anton Lozhkov and Elie Bakouch and Gabriel Martín Blázquez and Guilherme Penedo and Lewis Tunstall and Andrés Marafioti and Hynek Kydlíček and Agustín Piqueres Lajarín and Vaibhav Srivastav and Joshua Lochner and Caleb Fahlgren and Xuan-Son Nguyen and Clémentine Fourrier and Ben Burtenshaw and Hugo Larcher and Haojun Zhao and Cyril Zakka and Mathieu Morlon and Colin Raffel and Leandro von Werra and Thomas Wolf},
100
+ year={2025},
101
+ eprint={2502.02737},
102
+ archivePrefix={arXiv},
103
+ primaryClass={cs.CL},
104
+ url={https://arxiv.org/abs/2502.02737},
105
+ }
106
+ ```