+ All Categories
Home > Documents > Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths -...

Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths -...

Date post: 09-Aug-2020
Category:
Upload: others
View: 9 times
Download: 0 times
Share this document with a friend
39
Jon Barker, Solutions Architect Getting started with Theano
Transcript
Page 1: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

Jon Barker, Solutions Architect

Getting started with Theano

Page 2: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

2

Agenda

What is Theano?

Simple first application

Theano for deep learning

Step-by-step example

Related projects

Example applications

Page 3: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

3

What is Theano?

A Python library for symbolic maths - far broader than just Deep Learning

Tightly integrated with the Python ecosystem

Fast C/CUDA back-end and transparent GPU acceleration

A mathematical symbolic expression compiler

Page 4: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

4

What is Theano?

Variables and expressions are symbolic - more like maths than code…

…but, symbolic expressions use a familiar NumPy-like syntax

Symbolic expression compiler

Page 5: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

5

What is Theano?

Developed and used since January 2008, created at Université de Montréal

Large contributor community

Tools for inspecting and debugging code

Great tutorials and examples - http://deeplearning.net/tutorial/

Additional features

Page 6: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

6

What is Theano?

Recipe for a Theano application:

Define symbolic expressions

Compile a function that can compute numeric values using those expressions

Execute that function on data

Theano defines a language, a compiler and a library

Page 7: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

7

Example Theano applicationy = a⇥ b

a, b 2 R

Page 8: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

8

Example Theano application

Initialize symbolic variables

y = a⇥ b

a, b 2 R

Page 9: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

9

Example Theano application

Initialize symbolic variables

Define symbolic expression

y = a⇥ b

a, b 2 R

Page 10: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

10

Example Theano application

Initialize symbolic variables

Define symbolic expression

Compile a function

y = a⇥ b

a, b 2 R

Page 11: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

11

Example Theano application

Initialize symbolic variables

Define symbolic expression

Compile a function

Use on numeric data

y = a⇥ b

a, b 2 R

Page 12: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

12

Theano for deep learning

Symbolic computation for tensors

Sub-modules of tensor operations relevant to DL

Highly expressive

Symbolic differentiation

Transparent GPU acceleration

Easily integrates with Python ecosystem

Page 13: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

13

Theano for deep learningSymbolic computation for tensors

x1 x2 x3

y1 y2

w11 w12

w21 w22

w31 w33

y2 = �(w12x1 + w22x2 + w32x3)y1 = �(w11x1 + w21x2 + w31x3)=)

y = �(Wx)

Page 14: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

14

Theano for deep learningHighly expressive: easily add new activation or loss functions

Page 15: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

15

Theano for deep learningSymbolic differentiation

The update is a function of partial derivative of error w.r.t

parameters

Page 16: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

16

Example: Linear model

Fit a linear model to this data, i.e. find such that

Example credit: “Introduction to Deep Learning with Python”, Alec Radford, https://www.youtube.com/watch?v=S75EdAcXHKk

w 2 R y = wx

Page 17: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

17

Example: Linear model

Initialize symbolic variables

Example credit: “Introduction to Deep Learning with Python”, Alec Radford, https://www.youtube.com/watch?v=S75EdAcXHKk

Page 18: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

18

Example: Linear model

Initialize symbolic variables

Define symbolic model

Example credit: “Introduction to Deep Learning with Python”, Alec Radford, https://www.youtube.com/watch?v=S75EdAcXHKk

Page 19: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

19

Example: Linear model

Initialize symbolic variables

Define symbolic model

Initialize model parameter

Example credit: “Introduction to Deep Learning with Python”, Alec Radford, https://www.youtube.com/watch?v=S75EdAcXHKk

Page 20: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

20

Example: Linear model

Initialize symbolic variables

Define symbolic model

Initialize model parameter

Define symbolic loss

Example credit: “Introduction to Deep Learning with Python”, Alec Radford, https://www.youtube.com/watch?v=S75EdAcXHKk

Page 21: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

21

Example: Linear model

Initialize symbolic variables

Define symbolic model

Initialize model parameter

Define symbolic lossDetermine partial derivative of loss w.r.t parameter

Example credit: “Introduction to Deep Learning with Python”, Alec Radford, https://www.youtube.com/watch?v=S75EdAcXHKk

Page 22: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

22

Example: Linear model

Initialize symbolic variables

Define symbolic model

Initialize model parameter

Define symbolic lossDetermine partial derivative of loss w.r.t parameterDefine how to update parameter based on gradient

Example credit: “Introduction to Deep Learning with Python”, Alec Radford, https://www.youtube.com/watch?v=S75EdAcXHKk

Page 23: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

23

Example: Linear model

Initialize symbolic variables

Define symbolic model

Initialize model parameter

Define symbolic lossDetermine partial derivative of loss w.r.t parameterDefine how to update parameter based on gradient

compile theano function

Example credit: “Introduction to Deep Learning with Python”, Alec Radford, https://www.youtube.com/watch?v=S75EdAcXHKk

Page 24: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

24

Example: Linear model

Initialize symbolic variables

Define symbolic model

Initialize model parameter

Define symbolic lossDetermine partial derivative of loss w.r.t parameterDefine how to update parameter based on gradient

compile theano functionIterate through data 100 times, updating parameter after each iteration

Example credit: “Introduction to Deep Learning with Python”, Alec Radford, https://www.youtube.com/watch?v=S75EdAcXHKk

Page 25: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

25

Example: Linear model

Before training After 100 iterations

Page 26: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

26

Designing more complex architectures

Layer types are typically defined as Python classes

Page 27: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

27

Designing more complex architectures

Networks can be defined symbolically as sequences of class instances

Page 28: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

28

Related projects

Blocks

Keras

Lasagne

Morb

Pylearn2

PyMC 3

sklearn-theano

theano-rnn

more…

Built on top of Theano (mostly machine learning)

Typically simplify syntax and interface for artificial neural network training at the expense of

expressiveness

Page 29: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

29

Related projectsCNN example in Keras

Input Conv MaxPool Dense DropOut Dense

Page 30: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

30

Example applicationsMusic recommendation at Spotify

http://benanne.github.io/2014/08/05/spotify-cnns.html

Audio spectrogram input

Latent factors output

Page 31: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

31

Example applicationsClassifying galaxies and plankton and winning Kaggle contests

http://benanne.github.io/2014/04/05/galaxy-zoo.html

http://benanne.github.io/2015/03/17/plankton.html

Page 32: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

32

Example applications

Many more examples at: http://deeplearning.net/tutorial/

Unsupervised training and auto-encoders

Recurrent Neural Networks

Page 33: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

33

Installation

Linux, OS X or Windows

Requirements:

Python >= 2.6

g++, python-dev

NumPy, SciPy

BLAS

Page 34: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

34

Installation

Basic instructions:

pip install Theano

easy_install Theano

Advanced instructions (for bleeding edge installs):

git clone git://github.com/Theano/Theano.git

cd Theano

python setup.py develop –-user

Page 35: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

35

Configuration

Three ways to configure Theano:

~/.theanorc: settings you always want

THEANO_FLAGS: setting for one job

theano.config: mid-code settings changes

Page 36: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

36

GPU acceleration

Three ways to invoke:

Add device=gpu to .theanorc

Add device=gpu to THEANO_FLAGS

Set theano.config.device=‘gpu’ in code

cuDNN acceleration (including v4) is automatic if installed on system

Page 37: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

37

Deep Learning Lab Series Scheduledeveloper.nvidia.com/deep-learning-courses

▪ Review the other seminars in series

Seminar #2 – Introduction to DIGITs

Seminar #3 - Getting Started with the CaffeFramework

Seminar #5 - Getting Started with the Torch Framework

Page 38: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

38

Hands-on Lab

1. Create an account at nvidia.qwiklab.com

2. Go to “Getting started with Theano” lab at bit.ly/dlnvlab4

3. Start the lab and enjoy!

Only requires a supported browser, no NVIDIA GPU necessary!

Lab is free until end of Deep Learning Lab series

Page 39: Getting started with theanoApr1 - NVIDIA...3 What is Theano? A Python library for symbolic maths - far broader than just Deep Learning Tightly integrated with the Python ecosystem

Recommended