/ Machine Learning

How-to: Experiment with tensorflow in an interactive notebook

I've always wanted to build something with tensorflow. I have one demo lying around with tensorflow, but never
got around to develop something for real with this framework.

Although tensorflow has a lot of samples available and documentation to get you going, it's not that easy to build
something real with it. To make it easier for me to experiment with it I've come up with a combination of tools
that allow you to experiment with tensorflow using interactive python notebooks.

Step 1: Install python on your machine

The first step to get the experimentation setup is to install Python. I use python 3 for my experiments, so this
guide will show you how to install that. If you want python 2, you install that version instead of 3.

On a mac you can install python through homebrew. Homebrew is a tool that is essence a package manager for Mac OS.
You can install all kinds of software through this tool. Follow the manual on the website to install homebrew on your mac.

After you have homebrew installed you can enter the command brew install python3.

On Windows you can use either chocolatey or
install Python 3 using the official installer.

Step 2: Create a virtual environment

After you installed python on your machine you can move on to install tensorflow and the other tools.
But before you do that, I advice you to use a version manager for python. You can install python modules
directly on your computer, but that pollutes your system.

With python you can have only one version of a module on your system. This means that if a program needs
version 1 of a module and another program needs version 2 of a module you have a problem. It can happen
that the program with version 1 does not work with version 2. This is not really what you want.

Virtualenv is a module that helps you manage the versioning problem in a very elegant way.
You can create a virtual python environment in a folder with its own modules.

To install virtualenv you need to execute the following commands in a terminal:

pip install pip --upgrade
pip install virtualenv

The first line upgrade the python package manager tool. The second line installs the virtualenv module.

After you installed virtualenv you can create a new virtual environment by executing the following
command in a terminal window:

virtualenv tensorflow

This creates a new folder underneath the current folder with the name tensorflow.
The virtualenv module copies pip and the necessary system files to the new folder to turn it
into a virtual python environment.

Step 3: Install tensorflow

Step 3 after installing virtualenv is to activate the virtual environment and install tensorflow.
Activate the virtual environment using the following command:

cd tensorflow
bin/activate

The terminal prompt is prefixed with the name of the virtual environment.
You can now install modules into the virtual environment:

pip install tensorflow

Step 4: Install ipython and jupyter

The final step is to install ipython and jupyter. These two tools make it possible
to run python code inside a browser window on your machine.

Install both these tools using the following commands:

pip install ipython
pip install jupyter

Ready to go!

jupyter is a webapplication that enables you to create notebooks. Notebooks are pages that can
contain markdown, text and python code. You can write code and annotate it with markdown to describe
what the code does.

All you need to do to start experimenting is to enter the following command in the terminal:

jupyter notebook

Have fun!