Professional Documents
Culture Documents
Jordi Torres
Universitat Politcnica de Catalunya UPC Barcelona Tech
Barcelona Supercomputing Center (BSC)
February, 2016
WATCH THIS SPACE Collection
Fisrt edition: February 2016.
Jordi Torres
www.JordiTorres.eu
Universitat Politcncia de Catalunya - UPC Barcelona Tech
UPC Campus Nord, mdul C6
Jordi Girona 1-3
08034 Barcelona
Cover design: Jordi Torres
Ilustrations: Jordi Torres
v
This book is devoted to the open-source community,
whose work we consume every day without knowing.
Contents
Contents ............................................................................................................
Foreword ...........................................................................................................
Preface ..............................................................................................................
A practical approach ........................................................................................
1. TensorFlow basics .......................................................................................
2. Linear Regression in TensorFlow ...............................................................
3. Clustering in TensorFlow ............................................................................
4. Single Layer Neural Network in TensorFlow .............................................
5. Multi-layer Networks in TensorFlow ...........................................................
6. TensorFlow and GPUs .................................................................................
Closing ..............................................................................................................
Acknowledgments ............................................................................................
About the Author ..............................................................................................
Foreword
The area of Machine Learning has shown a great expansion thanks to
the co-development of key areas such as computing, massive data
storage and Internet technologies. Many of the technologies and
events of everyday life of many people are directly or indirectly influ-
enced by automatic learning. Examples of technologies such as speech
and visual recognition on our phones, or detection of spam emails,
have enabled apps that a decade ago would sound only possible in
science fiction. The use of machine learning in stock market models or
medical models has impacted our society massively. In addition, cars
with cruise control, drones or robots of all types will impact society in
the not too distant future.
Deep Learning, a branch of Machine Learning, has undoubtedly been
one of the fields which have had an explosive expansion since it was
rediscovered in 2006. Indeed, many of the startups in Silicon Valley
specialize in it, and big technologic companies like Google, Facebook,
Microsoft or IBM have both development and research teams for
whom it is an essential tool. Deep Learning has generated interest
even outside the university and research areas: a lot of specialized
magazines (like Wired) and even generic ones (such as New York
Times, Bloomberg or BBC) have written many articles about this sub-
ject.
This interest has led many students, entrepreneurs and investors to
join Deep Learning. Thanks to all the interest generated, several pack-
ages have been opened as "Open Source". Being one of the main pro-
moters of the library we developed at Berkeley (Caffe) in 2012 as a
PhD student, I can say that TensorFlow, presented in this book and
xi
also designed by Google (California), where I have been researching
since 2013, will be one of the main tools that researchers and SME
companies will develop their ideas about Deep Learning and Machine
Learning. A guarantee of this is the number of engineers and top re-
searchers who have participated in this project, culminated with the
Open Sourcing.
I hope this introductory book will help the reader interested in start
their adventure in this very interesting field. I would like to thank the
author, whom I have the pleasure of knowing, the effort to dissemi-
nate this technology. He has wrotten this book (first Spanish version)
in record time, two months after the open source project release was
announced. This is another example of the vitality of Barcelona and its
interest to be one of the actors in this technological scenario that un-
doubtedly will impact our future.
Oriol Vinyals
Research Scientist at Google Brain
xii
Preface
Education is the most powerful weapon
which you can use to change the world.
Nelson Mandela
The purpose of this book is helping to spread this knowledge among
engineers who want to expand their wisdom in the exciting world of
Machine Learning. I believe that anyone with an engineering back-
ground may find valuable applications of Deep Learning, and Ma-
chine Learning in general, to their work.
Given my background, the reader probably will wonder why I have
proposed this challenge of writing about this new Deep Learning
technology. Actually, my focus is gradually moving from supercom-
puting architectures and middlewares for heterogeneous loads to
novel platforms for Machine Learning on massive data.
Precisely by being an engineer, not a data scientist, I think that I can
contribute with this introductory approach to the subject, and that it
can be helpful for many engineers in the early stages; then it will be
their choice to go deeper into what they need.
I hope this book adds some value to this world of education that I
love so much. I think that knowledge is a liberation and accessible to
all. For this reason, the content of this book will be available on the
xiii
website www.JordiTorres.eu/TensorFlow completely free. If the reader
finds that this content is useful and considers appropriate to compen-
sate the effort of the author to writing it, there is a tab on the website
to make a donation. On the other hand, if the reader prefers to opt for
a paper copy, you can purchase the book through Amazon.com portal.
There is also available a Spanish version. Indeed, this book is the
translation of the Spanish one, which was finished last January.
Let me thank you for reading this book! It comforts me and justifies
my effort to writing it. Those who know me know that technological
diffusion is one of my passions, and that keep me with vigor and en-
ergy.
xiv
A practical approach
Tell me and I forget. Teach me and I remem-
ber. Involve me and I learn.
Benjamin Franklin
xvi
In the sixth chapter we enter in a more specific issue, probably not of
interest to all readers, such as harnessing the power of calculation
presented by GPUs. As introduced in Chapter 1, GPUs play an im-
portant role in the training process of neural networks.
The book ends with closing remarks, in which I highlight some con-
clusions. I would like to emphasize that the examples of code in this
book can be downloaded from the github repository of the book1.
1 Github, (2016) Fist Contact with TensorFlow. Source code [Online]. Availa-
ble at: https://github.com/jorditorresBCN/TutorialTensorFlow
[Accessed: 16/12/2015].
xvii