Giter Site home page Giter Site logo

python_autocomplete's Introduction

⭐️ We rewrote a simpler version of this at lab-ml/source_code_modelling and we intend to maintain it for a while

This a toy project we started to see how well a simple LSTM model can autocomplete python code.

It gives quite decent results by saving above 30% key strokes in most files, and close to 50% in some. We calculated key strokes saved by making a single (best) prediction and selecting it with a single key.

We do a beam search to find predictions, upto ~10 characters ahead. So far it's too inefficient, if you are wondering about editor integration.

We train and predict on after cleaning comments, strings and blank lines in python code. The model is trained after tokenizing python code. It seems more efficient than character level prediction with byte-pair encoding.

A saved model is included in this repo. It is trained on tensorflow/models.

Here's a sample evaluation on a source file from validation set. Red characters are when a auto-completion started; i.e. user presses TAB to select the completion. The green character and and the following characters highlighted in gray are auto-completed. As you can see, it starts and ends completions arbitrarily. That is a suggestion could be 'tensorfl' and not the complete identifier 'tensorflow' which can be a little annoying in a real usage scenario. We can limit them to finish on end of tokens to fix that. Also you can notice that it completes across operators as well. Increasing the length of the beam search will let it complete longer pieces of code.

Try it yourself

  1. Clone this repo

  2. Install requirements from requirements.txt

  3. Copy data to ./data/source

  4. Run extract_code.py to collect all python files, encode and merge them into all.py

  5. Run evaluate.py to evaluate the model. I have included a checkpoint in the repo.

  6. Run train.py to train the model

python_autocomplete's People

Contributors

hnipun avatar vpj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python_autocomplete's Issues

About to setup Lab 2.0

Hi,

Thanks for sharing a source code of python-auto-completion.

I would like to run it, but I could not be to figure out "how can I setup Lab 2.0 in windows?" I did not find any command to install Lab 2.0.

Similarly, command "ln -s ~/repo/lab your_project/lab" is mentioned in lab 2.0 project, but it can be worked in Linux environment.

Kindly let me know about how can I set up Lab 2.0 in Windows, in order to run python-auto-completion project.

dataset

hi,
what type of file should present in the source folder are the files .py files or .txt files. I want to train my own model. can you help me with it?

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.