python自带的ide代码自动补齐_python_autocomplete

⭐️ 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

Clone this repo

Install requirements from requirements.txt

Copy data to ./data/source

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

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

Run train.py to train the model

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值