Theano

Home » Theano

Overview

Theano is a Python library for fast numerical computation that can be run on the CPU or GPU.

It is a key foundational library for Deep Learning in Python that you can use directly to create Deep Learning models or wrapper libraries that greatly simplify the process.

In this post, you will discover the Theano Python library.

What is Theano?

Theano is an open source project released under the BSD license and was developed by the LISA (now MILA) group at the University of Montreal, Quebec, Canada (home of Yoshua Bengio). It is named after a Greek mathematician.

At its heart, Theano is a compiler for mathematical expressions in Python. It knows how to take your structures and turn them into very efficient code that uses NumPy, efficient native libraries like BLAS and native code (C++) to run as fast as possible on CPUs or GPUs.

It uses a host of clever code optimizations to squeeze as much performance as possible from your hardware. If you are into the nitty-gritty of mathematical optimizations in code, check out this interesting list.

The actual syntax of Theano expressions is symbolic, which can be off-putting to beginners used to normal software development. Specifically, the expression is defined in the abstract sense, compiled and later actually used to make calculations.

It was specifically designed to handle the types of computation required for large neural network algorithms used in Deep Learning. It was one of the first libraries of its kind (development started in 2007) and is considered an industry standard for Deep Learning research and development.

How to Install Theano

Theano provides extensive installation instructions for the major operating systems: Windows, OS X, and Linux. Read the Installing Theano guide for your platform.

Theano assumes a working Python 2 or Python 3 environment with SciPy. There are ways to make the installation easier, such as using Anaconda to quickly set up Python and SciPy on your machine as well as using Docker images.

With a working Python and SciPy environment, it is relatively straightforward to install Theano. from PyPI using pip, for example:

At the time of writing the last official release of Theano was version 0.8 which was released 21st March 2016.

New releases may be announced and you will want to update to get any bug fixes and efficiency improvements. You can upgrade Theano using pip as follows:

You may want to use the bleeding edge version of Theano checked directly out of Github.

This may be required for some wrapper libraries that make use of bleeding edge API changes. You can install Theano directly from a Github checkout as follows:

You are now ready to run Theano on your CPU, which is just fine for the development of small models.

Large models may run slowly on the CPU. If you have a Nvidia GPU, you may want to look into configuring Theano to use your GPU. Read the Using the GPU guides for Linux or Mac OS X to set up Theano to use the GPU and the Using the GPU guide for how to test whether it is working.

Simple Theano Example

In this section, we demonstrate a simple Python script that gives you a flavor of Theano.

It is taken from the Theano at a Glance guide. In this example, we define two symbolic floating point variables a and b.

We define an expression that uses these variables (c = a + b).

We then compile this symbolic expression into a function using Theano that we can use later.

Finally, we use our complied expression by plugging in some real values and performing the calculation using efficient compiled Theano code under the covers.

Source: Introduction to the Python Deep Learning Library Theano – Machine Learning Mastery

By | 2018-03-14T03:59:49+00:00 February 6th, 2018|Technologies, Theano|