Coder Social home page Coder Social logo

tonradar / contest-tglang Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 3.0 6.39 MB

The source code required to win for Telegram ML contest!

License: MIT License

C# 6.73% CMake 0.12% C 10.56% C++ 78.22% Python 2.77% Jupyter Notebook 1.61%
crawler csharp dotnet

contest-tglang's Introduction

TonRadar Solution for Telegram ML Competition 2023

This document explains how TonRadar Team developed a solution for the ML Competition 2023 organized by Telegram. The goal of the competition is to create a library that can detect the programming language of a given source code snippet. The complete source code and documentation (including this document) are available on our GitHub repository: github.com/tonradar/contest-tglang.

Source Code

The source code is structured in these folders:

  • crawler: Crawling code files from GitHub (C#)
  • model: Training the model (Python, AzureML)
  • libtglang: Building the final .so file (C)

Language Selection

We analyzed the list of languages provided by the competition and decided to exclude some of them for the following reasons:

  • Some languages are not widely used or not even real languages (e.g., 1S_ENTERPRISE, BISON).
  • Some languages are very similar to other languages and can confuse the model (e.g., Delphi~Pascal and VISUAL_BASIC~VBSCRIPT).
  • Some languages have very few or no source code files available on GitHub (e.g., HACK).

Here is the list of excluded languages:

  • 1S_ENTERPRISE
  • BISON
  • HACK
  • DELPHI (will map to PASCAL)
  • VBSCRIPT (will map to VISUAL_BASIC)

We also chose to use .aspx files instead of .asp files for the ASP language, as .aspx is the newer and more popular framework.

Data Collection

We used GitHub as our main source of data for training our model. We developed a project called TgLang.CodeCrawler that can crawl GitHub and download 1000 source code files for each language. The project is written in C# and consists of two parts:

  • TgLang.CodeCrawler: A console application that crawls GitHub and saves the files in a folder named after the language.
  • TgLang.CodeCrawler.Test: A set of unit tests and integration tests to ensure the correctness and reliability of the crawler.

Model Training

We used Python and AzureML to train our model using the collected dataset. We chose a deep neural network architecture that can learn from the syntactic and semantic features of the source code. We saved our model in ONNX format so that we could use it in a C program to create the final library.

We trained the model using AzureML and here is the result: Model Metrics

During training, we observed that some languages caused confusion using the Confusion Matrix: Confusion Matrix

As you can see in this confusion matrix, some blue columns show a high possibility of confusing most languages with the language of that column.

These confusing languages are:

  • JSON
  • REGEX
  • CSV

A common pattern in these languages is that they can be used within other languages. For example, a regex pattern or a JSON value can be used in any language.

Final Library

The final library is written in C and conforms to the specifications of the competition. It loads the ONNX model and uses it to predict the programming language of an input string. It returns the related enum of the predicted language as output.

contest-tglang's People

Contributors

mehrandvd avatar elldora avatar

Stargazers

Konstantin Moskalenko avatar Konstantin Kozlovtsev avatar

Watchers

Afshin Alizadeh avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.