CoolFace
Modelpublic

philomath-1209/programming-language-identification

sourceHugging Facewtfplupdated 3y agoView on Hugging Face
13likes7.7kdownloads
README.md150 linesDownload Raw Back to root
1---2license: wtfpl3datasets:4- cakiki/rosetta-code5language:6- en7metrics:8- accuracy9library_name: transformers10pipeline_tag: text-classification11tags:12- code13- programming-language14- code-classification15base_model: huggingface/CodeBERTa-small-v116---17This Model is a fine-tuned version of *huggingface/CodeBERTa-small-v1* on *cakiki/rosetta-code* Dataset for 26 Programming Languages as mentioned below.18## Training Details:19Model is trained for 25 epochs on Azure for nearly 26000 Datapoints for above Mentioned 26 Programming Languages<br> extracted from Dataset having 1006 of total Programming Language.20### Programming Languages this model is able to detect vs Examples used for training21<ol>22  <li>'ARM Assembly':</li>23 <li>'AppleScript'</li>24 <li>'C'</li>25 <li>'C#'</li>26 <li>'C++'</li>27 <li>'COBOL'</li>28 <li>'Erlang'</li>29 <li>'Fortran'</li>30 <li>'Go'</li>31 <li>'Java'</li>32 <li>'JavaScript'</li>33 <li>'Kotlin'</li>34 <li>'Lua</li>35 <li>'Mathematica/Wolfram Language'</li>36 <li>'PHP'</li>37 <li>'Pascal'</li>38 <li>'Perl'</li>39 <li>'PowerShell'</li>40 <li>'Python'</li>41 <li>'R</li>42 <li>'Ruby'</li>43 <li>'Rust'</li>44 <li>'Scala'</li>45 <li>'Swift'</li>46 <li>'Visual Basic .NET'</li>47 <li>'jq'</li>48</ol>49<br>50 51## Below is the Training Result for 25 epochs.52<ul>53    <li>Training Computer Configuration: <ul>54       <li>GPU:1xNvidia Tesla T4, </li>55       <li>VRam: 16GB,</li>56       <li>Ram:112GB,</li>57       <li>Cores:6 Cores </li>58    </ul></li>59         60<li>Training Time taken: exactly 7 hours for 25 epochs</li>61<li>Training Hyper-parameters: </li>62  </ul>63 64 65 66![image/png](https://cdn-uploads.huggingface.co/production/uploads/645c859ad90782b1a6a3e957/YIYl1XZk0zpi3DCvn3D80.png)67 68 69 70![training detail.png](https://cdn-uploads.huggingface.co/production/uploads/645c859ad90782b1a6a3e957/Oi9TuJ8nEjtt6Z_W56myn.png)71 72## Inference Code73 74  ```python75import torch76from transformers import AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline77model_name = 'philomath-1209/programming-language-identification'78loaded_tokenizer = AutoTokenizer.from_pretrained(model_name)79loaded_model = AutoModelForSequenceClassification.from_pretrained(model_name)80 81  82device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')83text = """84  PROGRAM Triangle85     IMPLICIT NONE86     REAL :: a, b, c, Area87     PRINT *, 'Welcome, please enter the&88              &lengths of the 3 sides.'89     READ *, a, b, c90     PRINT *, 'Triangle''s area:  ', Area(a,b,c)91    END PROGRAM Triangle92    FUNCTION Area(x,y,z)93     IMPLICIT NONE94     REAL :: Area            ! function type95     REAL, INTENT( IN ) :: x, y, z96     REAL :: theta, height97     theta = ACOS((x**2+y**2-z**2)/(2.0*x*y))98     height = x*SIN(theta); Area = 0.5*y*height99    END FUNCTION Area100 101"""102inputs = loaded_tokenizer(text, return_tensors="pt",truncation=True)103with torch.no_grad():104    logits = loaded_model(**inputs).logits105predicted_class_id = logits.argmax().item()106loaded_model.config.id2label[predicted_class_id]107```108 109### Optimum with ONNX inference110 111Loading the model requires the 🤗 Optimum library installed.112```shell113pip install transformers optimum[onnxruntime] optimum114```115 116```python117model_path = "philomath-1209/programming-language-identification"118import torch119from transformers import pipeline, AutoTokenizer120from optimum.onnxruntime import ORTModelForSequenceClassification121 122tokenizer = AutoTokenizer.from_pretrained(model_path, subfolder="onnx")123model = ORTModelForSequenceClassification.from_pretrained(model_path, export=False, subfolder="onnx")124 125text = """126  PROGRAM Triangle127     IMPLICIT NONE128     REAL :: a, b, c, Area129     PRINT *, 'Welcome, please enter the&130              &lengths of the 3 sides.'131     READ *, a, b, c132     PRINT *, 'Triangle''s area:  ', Area(a,b,c)133    END PROGRAM Triangle134    FUNCTION Area(x,y,z)135     IMPLICIT NONE136     REAL :: Area            ! function type137     REAL, INTENT( IN ) :: x, y, z138     REAL :: theta, height139     theta = ACOS((x**2+y**2-z**2)/(2.0*x*y))140     height = x*SIN(theta); Area = 0.5*y*height141    END FUNCTION Area142 143"""144inputs = tokenizer(text, return_tensors="pt",truncation=True)145with torch.no_grad():146    logits = model(**inputs).logits147predicted_class_id = logits.argmax().item()148model.config.id2label[predicted_class_id]149 150```