loubnabnl HF Staff commited on
Commit
105a89d
·
verified ·
1 Parent(s): 305f0b0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +61 -39
README.md CHANGED
@@ -9,6 +9,9 @@ metrics:
9
  model-index:
10
  - name: stack-edu-classifier-c
11
  results: []
 
 
 
12
  ---
13
 
14
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
@@ -16,29 +19,58 @@ should probably proofread and complete it, then remove this comment. -->
16
 
17
  # stack-edu-classifier-c
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.4660
22
- - Precision: 0.4766
23
- - Recall: 0.3489
24
- - F1 Macro: 0.3689
25
- - Accuracy: 0.5471
26
- - F1 Binary Minimum3: 0.7028
 
 
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 +87,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 | 5.6344 | 0.0030 | 0.1667 | 0.0058 | 0.0178 | 0 |
63
- | 0.5079 | 1.4493 | 1000 | 0.5017 | 0.4119 | 0.3155 | 0.3188 | 0.5307 | 0.6809 |
64
- | 0.5001 | 2.8986 | 2000 | 0.4960 | 0.4423 | 0.3275 | 0.3419 | 0.5208 | 0.7030 |
65
- | 0.4739 | 4.3478 | 3000 | 0.4846 | 0.4462 | 0.3255 | 0.3353 | 0.5374 | 0.6863 |
66
- | 0.4739 | 5.7971 | 4000 | 0.4784 | 0.4522 | 0.3223 | 0.3328 | 0.5354 | 0.6934 |
67
- | 0.4508 | 7.2464 | 5000 | 0.4890 | 0.4492 | 0.3423 | 0.3540 | 0.5409 | 0.6770 |
68
- | 0.4798 | 8.6957 | 6000 | 0.4746 | 0.4663 | 0.3353 | 0.3520 | 0.5308 | 0.7028 |
69
- | 0.4613 | 10.1449 | 7000 | 0.4775 | 0.4707 | 0.3254 | 0.3405 | 0.5385 | 0.6900 |
70
- | 0.4668 | 11.5942 | 8000 | 0.4934 | 0.4711 | 0.3347 | 0.3526 | 0.5149 | 0.7036 |
71
- | 0.4657 | 13.0435 | 9000 | 0.4690 | 0.4797 | 0.3330 | 0.3496 | 0.5390 | 0.7002 |
72
- | 0.4561 | 14.4928 | 10000 | 0.4676 | 0.4807 | 0.3375 | 0.3561 | 0.5398 | 0.7040 |
73
- | 0.4597 | 15.9420 | 11000 | 0.4668 | 0.4788 | 0.3336 | 0.3497 | 0.5413 | 0.7037 |
74
- | 0.4524 | 17.3913 | 12000 | 0.4680 | 0.4759 | 0.3353 | 0.3541 | 0.5370 | 0.7038 |
75
- | 0.4674 | 18.8406 | 13000 | 0.4660 | 0.4766 | 0.3489 | 0.3689 | 0.5471 | 0.7028 |
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
 
9
  model-index:
10
  - name: stack-edu-classifier-c
11
  results: []
12
+ language:
13
+ - code
14
+ library_name: transformers
15
  ---
16
 
17
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
 
19
 
20
  # stack-edu-classifier-c
21
 
22
+ 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.
23
+
24
+ ### How to use in transformers
25
+ To load the classifier, use the following code:
26
+
27
+ ```python
28
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
29
+
30
+ tokenizer = AutoTokenizer.from_pretrained(REPO_NAME)
31
+ model = AutoModelForSequenceClassification.from_pretrained(REPO_NAME)
32
 
33
+ text = "This is a test sentence."
34
+ inputs = tokenizer(text, return_tensors="pt", padding="longest", truncation=True)
35
+ outputs = model(**inputs)
36
+ logits = outputs.logits.squeeze(-1).float().detach().numpy()
37
+ score = logits.item()
38
+ result = {
39
+ "text": text,
40
+ "score": score,
41
+ "int_score": int(round(max(0, min(score, 5)))),
42
+ }
43
 
44
+ print(result)
45
+ # {'text': 'This is a test sentence.', 'score': 0.07964489609003067, 'int_score': 0}
46
+ ```
47
 
48
  ## Intended uses & limitations
49
 
50
+ While the classifier performs well in distinguishing high-quality code in its target language (C in this case), there are some limitations:
51
 
52
+ - 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.
53
+ - 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.
54
+ - Context: The classifier evaluates individual code files without considering broader context, which might impact its effectiveness in certain scenarios.
55
 
56
+ The training and inference code is available on GitHub
57
+ https://github.com/huggingface/cosmopedia/tree/main/classification
58
 
59
  ## Training procedure
60
 
61
+ 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).
62
+
63
+ 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.
64
+
65
+ It achieves the following results on the evaluation set:
66
+ - Loss: 0.4660
67
+ - Precision: 0.4766
68
+ - Recall: 0.3489
69
+ - F1 Macro: 0.3689
70
+ - Accuracy: 0.5471
71
+ - F1 Binary Minimum3: 0.7028
72
+
73
+ 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 C and Python and the lowest being JavaScript and PhP.
74
  ### Training hyperparameters
75
 
76
  The following hyperparameters were used during training:
 
87
  - lr_scheduler_warmup_steps: 200
88
  - num_epochs: 20
89
 
90
+ ## License
91
+
92
+ [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
93
+
94
+ ## Citation
95
+ ```bash
96
+ @misc{allal2025smollm2smolgoesbig,
97
+ title={SmolLM2: When Smol Goes Big -- Data-Centric Training of a Small Language Model},
98
+ 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},
99
+ year={2025},
100
+ eprint={2502.02737},
101
+ archivePrefix={arXiv},
102
+ primaryClass={cs.CL},
103
+ url={https://arxiv.org/abs/2502.02737},
104
+ }
105
+ ```