Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Tutorial for a new versioning Machine Learning pipeline

License

NotificationsYou must be signed in to change notification settings

peopledoc/mlvtools-tutorial

Repository files navigation

The aim of this repository is to show a way to handlepipelining andversioningof aMachine Learning project.

Processes exposed during this tutorial are based on 3 tools:

Use cases are based on a text classification task on 20newsgroup dataset. Adummytutorial is also available to show tools mechanisms.

Prerequisites

For this tutorial, you must be familiar with the following tools:

  • virtualenv or condaenv
  • make
  • git
  • python

Tools Overview

DVC is an open-source version control system for Machine Learning projects. It is usedfor versioning and sharing Machine Learning data, and reproducing Machine Learningexperiments and pipeline stages.

mlvtools provides tools to generate Python scripts and DVC commands from JupyterNotebooks.

Please have a look at thepresentation.

Our main features

Standard Versioning Process Establishment

Goal: find a way to version code, data and pipelines.

Initial project

Starting from an existing project composed of multiple Python modules and a set ofJupyter notebooks, we want to create an automated pipeline in order to version, shareand reproduce experiments.

│── classifier│   ├── aggregate_classif.py│   ├── __init__.py│   ├── extract.py│   └── ...│── notebooks│   ├── Augment train data.ipynb│   ├── Check data and split and train.ipynb│   ├── Extract data.ipynb│   ├── Learn text classifier.ipynb│   ├── Learn aggregated model.ipynb│   ├── Preprocess image data.ipynb│   └── Train CNN classifier on image data.ipynb│── README.md│── requirements.yml│── setup.cfg│── setup.py

The data flow is processed by applying steps and intermediary results are versionedusing metadata files. These steps are defined in Jupyter notebooks, which are thenconverted to Python scripts.

Keep in mind that:

  • The reference for the code of the step remains in the Jupyter notebook
  • Pipelines are structured according to their inputs and outputs
  • Hyperparameters are pipeline inputs

Project after refactoring

│── classifier│   ├── aggregate_classif.py│   ├── __init__.py│   ├── extract.py│   └── ...│── notebooks│   ├── Augment train data.ipynb│   ├── Check data and split and train.ipynb│   ├── Extract data.ipynb│   ├── Learn text classifier.ipynb│   ├── Learn aggregated model.ipynb│   ├── Preprocess image data.ipynb│   └── Train CNN classifier on image data.ipynb│── pipeline│   ├── dvc                                        ** DVC pipeline steps│   │   ├─ mlvtools_augment_train_data_dvc│   │   ├─ ..│   ├── scripts                                    ** Notebooks converted into Python configurable scripts│   │   ├─ mlvtools_augment_train_data.py│   │   ├─ ..│── README.md│── requirements.yml│── setup.cfg│── setup.py

Applying the process

For each Jupyter notebook a Python parameterizable and executable script is generated.This script makes it easier to version code and automate pipeline executions.

Pipelines are composed of DVC steps. Those steps can be generated directly from theJupyter notebook based on parameters described in the Docstring. (notebook -> pythonscript -> DVC command)

Each time a DVC step is run a DVC meta file ([normalized_notebook_name].dvc) iscreated. This metadata file represents a pipeline step, it is the DVC result of a stepexecution. Those files must be tracked using Git. They are used to reproducea pipeline.

Application:

For each step in the tutorial the process remain the same.

  1. Write a Jupyter notebook which corresponds to a pipeline step. (See Jupyter notebooksyntax section inmlvtools documentation)

  2. Test your Jupyter notebook.

  3. Add it under git.

  4. Convert the Jupyter notebook into a configurable and executable Python scriptusingipynb_to_python.

    ipynb_to_python -n ./pipeline/notebooks/[notebook_name] -o ./pipeline/steps/[python_script_name]
  5. Ensure Python executable and configurable script is well created into./pipeline/steps/[python_script_name].

    ./pipeline/steps/[python_script_name] -h
  6. Create a DVC commands to run the Python script using DVC.

    gen_dvc -i ./pipeline/steps/[python_script_name] \        --out-dvc-cmd ./scripts/cmd/[dvc_cmd_name]
  7. Ensure DVC command is well created.

  8. Add generated command and Python script under git.

  9. Add step inputs under DVC.

  10. Run DVC command./scripts/cmd/[dvc_cmd_name].

  11. Check DVC meta file is created./[normalized notebook _name].dvc

  12. Add DVC meta file under git

Key Features

NeedFeature
Ignore notebook cell# No effect
DVC input and ouptuts:dvc-in,:dvc-out
Add extra parameters:dvc-extra
Write DVC whole command:dvc-cmd
Convert Jupiter Notebook to Python scriptipynb_to_python
Generate DVC commandgen_dvc
Create a pipeline step from a Jupiter Notebookipynb_to_python,gen_dvc
Add a pipeline step with different IOCopy DVC step then edit inputs, outputs and meta file name
Reproduce a pipelinedvc repro [metafile]
Reproduce a pipeline with no cachedvc repro -f [metafile]
Reproduce a pipeline after an algo changedvc repro -f [metafile] or run impacted step individually then complete the pipeline.

It is allowed to modify or duplicate a DVC command to change an hyperparameter or runa same step twice with different parameters.

It is a bad idea to modify generated Python scripts. They are generated from Jupyternotebooks, so changes should be done in Jupyter notebooks and then scripts should bere-generated.

Tutorial

Environment

To complete this tutorial clone this repository:

git clone https://github.com/peopledoc/mlvtools-tutorial

Create and a Python virtual environment, and activate it:

virtualenv --python python3 venvsource venv/bin/activate

Install requirements:

make develop

All other steps are explained in each use case.

Cases

Talks

About

Tutorial for a new versioning Machine Learning pipeline

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp