Giter Club home page Giter Club logo

mlhyperparametertuning's Introduction

Author: Mario Bourgoin

Training of Python scikit-learn models on Azure

Overview

This scenario shows how to tune a Frequently Asked Questions (FAQ) matching model that can be deployed as a web service to provide predictions for user questions. For this scenario, "Input Data" in the architecture diagram refers to text strings containing the user questions to match with a list of FAQs. The scenario is designed for the Scikit-Learn machine learning library for Python but can be generalized to any scenario that uses Python models to make real-time predictions.

Design

alt text The scenario uses a subset of Stack Overflow question data which includes original questions tagged as JavaScript, their duplicate questions, and their answers. It tunes a Scikit-Learn pipeline to predict the match probability of a duplicate question with each of the original questions. The application flow for this architecture is as follows:

  1. Create an Azure ML Service workspace.
  2. Create an Azure ML Compute cluster.
  3. Upload training, tuning, and testing data to Azure Storage.
  4. Configure a HyperDrive random hyperparameter search.
  5. Submit the search.
  6. Monitor until complete.
  7. Retrieve the best set of hyperparameters.
  8. Register the best model.

Prerequisites

  1. Linux (Ubuntu).
  2. Anaconda Python installed.
  3. Azure account.

The tutorial was developed on an Azure Ubuntu DSVM, which addresses the first two prerequisites. You can allocate such a VM on Azure Portal by creating a "Data Science Virtual Machine for Linux (Ubuntu)" resource.

Setup

To set up your environment to run these notebooks, please follow these steps. They setup the notebooks to use Azure seamlessly.

  1. Create a Linux Ubuntu VM.
  2. Log in to your VM. We recommend that you use a graphical client such as X2Go to access your VM. The remaining steps are to be done on the VM.
  3. Open a terminal emulator.
  4. Clone, fork, or download the zip file for this repository:
    git clone https://github.com/Microsoft/MLHyperparameterTuning.git
    
  5. Enter the local repository:
    cd MLHyperparameterTuning
    
  6. Create the Python MLHyperparameterTuning virtual environment using the environment.yml:
    conda env create -f environment.yml
    
  7. Activate the virtual environment:
    source activate MLHyperparameterTuning
    
    The remaining steps should be done in this virtual environment.
  8. Login to Azure:
    az login
    
    You can verify that you are logged in to your subscription by executing the command:
    az account show -o table
    
  9. If you have more than one Azure subscription, select it:
    az account set --subscription <Your Azure Subscription>
    
  10. Start the Jupyter notebook server:
    jupyter notebook
    

Steps

After following the setup instructions above, run the Jupyter notebooks in order starting with 00_Data_Prep_Notebook.ipynb.

Cleaning up

The last Jupyter notebook describes how to delete the Azure resources created for running the tutorial. Consult the conda documentation for information on how to remove the conda environment created during the setup. And if you created a VM, you may also delete it.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

mlhyperparametertuning's People

Contributors

dciborow avatar grecoe avatar jreynolds01 avatar marabout2015 avatar microsoftopensource avatar msftgits avatar praneet22 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

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

mlhyperparametertuning's Issues

Use AML Hyperdrive

Modify the Happy Path to use AML with Hyperdrive in place of Batch AI.

Use Python logging in scripts

Mat: Instead of using print statements in the scripts use Python logging. Only reason is you can add debug logging statements that people can turn on or off. Print is fine in notebooks but when running things on clusters sometimes it is nice to have a verbose mode.

Add control of iteration used in testing

Currently, the testing script uses the maximum number of iterations of the trained model to score the data. Add an "early_stopping_rounds" argument to the training script so it records the best iteration on validation data found, and an argument to the testing script that controls whether that is the iteration used in scoring.

Refactor scripts into functions

Mat: Some of the scripts that are created in the notebooks could be broken up a bit. Where you are writing a comment stating what those lines below do that means it could be a function. Makes for easier composability. Completely optional though****

Add failOnStderr:true to all DevOps pipeline Bash steps

Add failOnStderr:true to all bash steps per Dan Grecoe:

There seems to be a change to the way the bash steps fail. That is, we've noticed in one of the paths that a notebook that throws an exception does not automatically stop the build as it used to.

Mathew Salvaris pointed out that there is a flag failOnStderr that is defaulted to false. We believe this used to be true. To ensure that the paths truly are building correctly I'm asking that each of the authors go through their path and make the following changes.

Remove unused metric name

The script created by the 01_Training_Script.ipynb notebook defines a variable name that is never used, which could be confusing:

# What to name the metric logged
metric_name = "logloss"

Those lines should be deleted.

Unable to run notebook in build system

Notebook:
https://github.com/Microsoft/MLHyperparameterTuning/blob/master/04_HyperDrive_Run_Recovery.ipynb

Issue:
Cell 5 Code:
run = get_run(exp, 'HyperDrive_Run_ID', rehydrate=True)
run

Cell 5 Comment:
Use the ID of the run to get a handle to it. That ID was printed with the run when it was submitted in the previous notebook. You can also find that ID in Azure Portal on your experiment's page. You may need to add a RunId column to the table of experiment runs.

The build system has no idea how to collect information from an output screen from the notebook and replace that inline in code.

Include dev-tests

Mat: There is no easy way to dev-test a set of notebooks locally. I use Makefiles but anything will do. Just something that makes it easy for someone to run one command to create environment run notebooks and tear environment down.

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.