Skip to content

A simple bash script to convert jupyter notebooks to python scripts.

License

Notifications You must be signed in to change notification settings

KonradSzafer/jupyter-to-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jupyter-to-script

Model training is often much easier using Python scripts due to the use of remote and virtual machines and better compatibility with multi-threaded libraries. Also, Python scripts are much more convenient when automating multiple runs or tuning hyperparameters.

The existing solution using the nbconvert tool is sometimes insufficient due to its simplicity. This repository contains an updated conversion with easy to use commands.

Usage

Some Python libraries, especially multi-threaded ones, require a Python bolerplate to function properly. The script inserts the required line and adds indentation for the rest of the code and also removes unnecessary comments and white spaces created by nbconvert.

To indicate where the script should start, simply add the following comment to the Jupyter notebook before the training code. This determines where to place the "if __name__ == '__main__':".

# !script

The script requires only one parameter - the notebook file name. It is also possible to provide the indentation size by specifying a second argument.

$ convert.sh notebook.ipynb 4

Example

Jupyter Notebook:

drawing

Python script:

drawing

Source code comes from the official Jupyterbook website.

About

A simple bash script to convert jupyter notebooks to python scripts.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages