Python Autocomplete
The full length Python autocompletion Video and a Twitter thread describing how it works
This is a learning/demo project to show how deep learning can be used to auto complete Python code. You can experiment with LSTM and Transformer models. We also have built a simple VSCode extension to try out the trained models.
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.
The dataset we use is the python code found in repos linked in Awesome-pytorch-list. We download all the repositories as zip files, extract them, remove non python files and split them randomly to build training and validation datasets.
We train a character level model without any tokenization of the source code, since it's the simplest.
Try it yourself
- Clone this repo
- Install requirements from
requirements.txt - Run
python_autocomplete/create_dataset.py.- It collects repos mentioned in PyTorch awesome list
- Downloads the zip files of the repos
- Extract the zips
- Remove non python files
- Collect all python code to
data/train.pyand,data/eval.py
- Run
python_autocomplete/train.pyto train the model. Try changing hyper-parameters like model dimensions and number of layers. - Run
evaluate.pyto evaluate the model.
You can also run the training notebook on Google Colab.
VSCode extension
-
Clone this repo
-
Install requirements from
requirements.txt -
Install npm packages
You need to have Node.JS installed
cd vscode_extension
npm install # This will install the NPM packages
-
Start the server
python_autocomplete/serve.py -
Open the extension project (folder) in VSCode
cd vscode_extension
code . # This will open vscode_extension in VSCode
If you don't have VSCode command line launcher
start VSCode and open the project with File > Open
- Run the extension from VSCode
Run > Start Debugging
This will open another VSCode editor window, with the extension
- Create or open a python file and start editing!
Sample
Here's a sample evaluation of a trained transformer model.
Colors:
- yellow: the token predicted is wrong and the user needs to type that character.
- blue: the token predicted is correct and the user selects it with a special key press, such as TAB or ENTER.
- green: autocompleted characters based on the prediction
Metadata
Release files for labml-python-autocomplete 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| labml_python_autocomplete-0.0.8.tar.gz | 17.8 kB | Without provenance | Details for labml_python_autocomplete-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| labml_python_autocomplete-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for labml_python_autocomplete-0.0.8-py3-none-any.whl |
Total release size: 45.6 kB
Release files / labml_python_autocomplete-0.0.8.tar.gz
| Download URL | labml_python_autocomplete-0.0.8.tar.gz |
|---|---|
| Size | 17.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d65f2b714d8b869a1ef0debe9f4996e307315ccb186b491b9795f32962f9eb70
|
|
BLAKE2b-256 checksum How to use checksums |
cd0bd19a9cc30d5f5648d02b29b6974136959b77994653753756fbaf03ef708e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5
|
Release files / labml_python_autocomplete-0.0.8-py3-none-any.whl
| Download URL | labml_python_autocomplete-0.0.8-py3-none-any.whl |
|---|---|
| Size | 27.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6df9949bd44b6bcb0fcf10f6e17aca4d766b545a0c577334cc69460148ebf099
|
|
BLAKE2b-256 checksum How to use checksums |
bf1fe730dfb9e9072a9d3f6156738b75fe43bafeff1f56fae3ec737bb2152e9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5
|
Security for labml-python-autocomplete 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.