Coder Social home page Coder Social logo

pyformer's Introduction

PyFormer

PyFormer is a transformer machine translation model that converts english sentences to python code.

Dataset

The dataset is a small set of english text and their respective python code, approx 4000 entries. You can download the dataset here

Project Setup

Training

Place the dataset file in the root folder.
You can set the configuration in the config file.
To train the model execute the below command.
$ python3 main.py

Inferencing

The training script saves the model and the source and target vocabularies.
If you wish to migrate to another machine, please place save them in the root directory of the project.
Add your english sentences to a file and add the filename to the config.
The below command can be used to inference the model.

$ python3 pyformer.py

Data Cleaning and Preparation

The data was cleaned manually by removing unneccessary indentation and comments.

The data needs to be tokenized properly before feeding it to the model. The english sentences were tokenized using spacy. To tokenize the python code, a lexical analyzer tool is written which tokenizes the code according to python.
If you wish to use the model for your language you can modify the tool here

Embeddings Training

The embeddings are trained using glove. If you wish not to train the embeddings you can set embeddings_training to False in config. Glove uses weighted mean square error to find the corelation between the tokens for the vocabulary. The trained embeddings weights are directly copied to the Decoder embeddings layer of the model.

Model Architecture

The model uses a Encoder Decoder architecture with Multihead Attention.
architecure_image
Click here for clear explanation and visualization of the architecture.

Results

The model gives pretty good results.
ss14
The above is a sample example. You can view the results of 35+ examples here

Metrics

The model uses cross entropy loss function.
The model achieves a minimum validation loss of 1.4 at 15th epoch. The validation perplexity is 4.1

The model achieves a minimum training loss of 0.2 at 50th epoch. The training perplexity is 1.2

The model was also tested for bleu_score and word error rate. Since the code length depends on logic, both of which are not suitable metrics for the problem.

pyformer's People

Contributors

vpsingh22 avatar

Watchers

 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.