A Brief About Deep Learning

WHAT IS DEEP LEARNING ;-

We are all surrounded by data. An enormous amount of it. It is not only stored on big computational servers all over the world, on the computers in our offices, and cell phones in our pockets and constantly being generated, but also being transferred at a high volume in the air. This picture in the below only signifies how you can imagine about it.

Deep learning is good at identifying patterns. Imagine for example about the image in the below. When you look at it, you can see there are bright spots in the image, whereas a lot of spots are dark. If I was to feed this image to a deep learning image recognition kind of program it would be able to identify where the bright spots are.

This schematic shows the evolution of this science. It started all the way back in 1943, and continued progress happened on it over the years. In those decades, we were significantly limited by the computational power. It is only in the recent years, that we have massive computational capabilities available and we have some amazing programmers in the world who are developing this field.

To give you an analogy between brain and deep learning, think of an owl. If your brain is like an owl, then deep learning is just like a fighter jet. An owl is far more complex creature and it can do a lot of things, but a fighter jet is complex too, and it can do a significant number of things, but they are very narrow in the scope. Although they can be very large in magnitude.

Well then, why not think about the learning process first?

When someone first made the first plane fly, it took them an enormous amounts of efforts. Humans have continued to train the planes so much over the years that now we have some really amazing planes that can carry hundreds of passengers across the borders in very little time.

So in essence, we have learned, and we have made the robots learn.

The basic premises of deep learning start from the brain. It wants to emulate in some sense exactly what the human brain does. Human brain comprises of neural networks.

Neural networks looks somewhat like the picture shown in the below. They are highly dense, and interconnected.

Here is a schematic of a neuron, and a pictorial description of it. The units of a neuron are axon, soma and dandrites. There are more, but lets stick to these basic ones for now.

The soma collect information from the dendrites and passes it over to an axon.

The dendrites can connect to the axons of next layer neurons with a process called synapse. This shows how synapse happens. Its more like an electrical activation.

To think of this pictorially, one can draw a schematic like the one shown in the belowTo think of this pictorially, one can draw a schematic like the one shown in the below.

There can be several neurons connected by the process of synapse, and they can form multiple layers.

One can form multiple nodes, and multiple layers. There is really no theoretical limits to how many layers can be formed.

A neural network is convoluted, when they are mixed up and sending many edges in the subsequent layers, and it is called deep, when there are at least ~ 3 or more layers of them.

It can be seriously deep. People have created up to ~ 128 layers.

Now here is how the deep learning process looks like.

Deep learning wants to take input, and pass it to subsequent layers, and so on until a desirable output is met. With iterative process, the weights of the branches is changed, so as to match the output with the desirable output.

For example, if you want to figure out when a restaurant is open in evening vs morning, you can create this network, and evolve the weights according the the formula: adjustment = error x gradient x delta.

For more complex examples ~ you can see that the desirable outcome is two swirls of blue and orange, but after a lot of iterations, the computer program has derived that the pattern looks somewhat similar to the input given to it.

This process is called training. Training is done iteratively until the weights no longer change, or until the error is below a reasonable value.

You can try to play with this toy model on this website: Tensorflow — Neural Network Playground

For more complex examples ~ you can see that the desirable outcome is two swirls of blue and orange, but after a lot of iterations, the computer program has derived that the pattern looks somewhat similar to the input given to it.

This process is called training. Training is done iteratively until the weights no longer change, or until the error is below a reasonable value.

You can try to play with this toy model on this website: Tensorflow — Neural Network Playground

 

FACE RECOGNITION

There are many other complex applications. One of them is face recognition and identification. The faces are converted into mathematical features, and data are passed to multiple layers and the deep learning algorithm is trained enough until a model is able to recognize the faces from images, or also identify whose faces it is able to detect. Pictorially, this can be seen in the image below.

When we feed the input as faces, it recognizes faces. When we feed the images of cars, it is able to recognize the cars.

 

MITOSIS DETECTION

There are more application of this science. One of them is in mitosis detection. Deep learning helps us understand this process.

It is in scanning the internet. Internet carries a lot of information that can be processed with deep learning engines and some really good conclusions can be derived.It is in scanning the internet. Internet carries a lot of information that can be processed with deep learning engines and some really good conclusions can be derived.

 

FLUID DYNAMICS

I have come to know that people are applying deep learning in the fluid dynamics problems where conventional methods are not enough. (Don’t forget that Navier Stokes equations are very hard to deal with).

 

MUSIC CLASSIFICATION

People classify music with this. Deep learning algorithms can simply take the whole musical album files and run them through the programs and over user data to predict which songs a person would like.

It can easily classify and segregate singers using this and can easily create music channels.

 

LIVE TRANSLATION

It can easily translate text and that too online. Look at this woman holding the picture in her hands, which carries text in English, but the cell phone camera + software + screen convert it real time into Spanish. Most likely all this was achieved with deep learning.

 

GOOGLE DEEPMIND

Look at this classic picture. This is a game called Go. I don’t know how to play this, but the claim of fame is that Google’s Deep Mind company trained a massive computer to play this game. Then it made the computer play against itself ~ 30 million times, and then they invited the world champion of the game. Their original thought was that they were at least 10 years away from playing against the world champion, but they actually achieved this feat in just one year.

I want to say that this is scary. This is exactly why Elon Musk is afraid of it. I have answered this sometime back, and I want to claim, that now I understand it much better why!

What company is Elon Musk referring as the one company he fears of their AI?

You can watch this whole video to learn how it all worked out. It was quite fascinating to me.

Now! The bigger question:

How do I learn deep learning?

There are some really good python libraries available. The two major backend platforms available are Tensorflow, and Theano.

Currently they both have good performance, but tensorflow is being considered to be better, because of ease of use, and performance on CPUs. I think thano works better on GPUs, so it has some advantages there.

Tensorflow website is in the link. TensorFlow

Theano is here. Welcome – Theano 0.8.2 documentation

To use them, one of the best frontend wrapper is called Keras. Keras Documentation.

Keras documentation is really amazing, and within a weekend, you can start your deep learning journey. You can follow Dan Van Boxel to learn this more hands on. The training sessions are not very long, and he shows lots of aspects systematically, and shows how you can figure out things by Googling them, and by reading documentation systematically. I think he is a very nice instructor. I certainly went through some of these instructive videos to see what he is doing and how he is applying it.

Here is my simplest deep learning code. Some of you who have deep knowledge of deep learning would probably suggest improvement, but I barely started on this weekend.

You can take a look at some examples on Kaggle, and learn Keras within no time. Here is how it will look like and feel in Python.


  1. import keras
  2. from sklearn.preprocessing import StandardScaler
  3. from sklearn.preprocessing import LabelEncoder
  4. from keras.utils.np_utils import to_categorical
  5. from keras.models import Sequential
  6. from keras.layers import Dense, Dropout, Activation
  7. from keras.optimizers import SGD
  8. from sklearn.model_selection import train_test_split
  9. from sklearn.preprocessing import LabelEncoder
  10. from sklearn import metrics
  11. df = pd.read_csv(path+‘InputFile.csv’)
  12. df_copy = pd.get_dummies(df)
  13. df_copy.head()
  14. result_column = ‘result_column’
  15. df1 = df_copy
  16. y = df1[result_column].values
  17. df1 = df1.drop([result_column],axis=1)
  18. X = df1.values
  19. Xtrain, Xtest, ytrain, ytest = train_test_split(X, y, test_size=0.30)
  20. print Xtrain.shape
  21. print Xtest.shape
  22. print ytrain.shape
  23. print ytest.shape
  24. Using Theano backend.
  25.  
  26. (10499L, 20L)
  27. (4500L, 20L)
  28. (10499L,)
  29. (4500L,)
  30. from keras.models import Sequential
  31. from keras.layers import Dense, Activation
  32. from keras.utils import np_utils
  33. input_dimenstions = Xtrain.shape[1]
  34. print ‘Building model’
  35. print ‘—————————————————————‘
  36. model = Sequential()
  37. model.add(Dense(output_dim=64, input_dim=input_dimenstions))
  38. model.add(Activation(“relu”))
  39. #model.add(keras.layers.core.Dropout(0.2))
  40. model.add(Dense(output_dim=64))
  41. model.add(Activation(“relu”))
  42. model.add(Dense(output_dim=2))
  43. model.add(Activation(“softmax”))
  44. print ‘Compiling model’
  45. print ‘—————————————————————‘
  46. model.compile(loss=‘categorical_crossentropy’, optimizer=‘adam’, metrics=[‘accuracy’])
  47. ytrain = np_utils.to_categorical(ytrain)
  48. print ‘Fitting model’
  49. print ‘—————————————————————‘
  50. a = model.fit(Xtrain, ytrain, nb_epoch=1000, verbose = 0,shuffle=True)
  51. print ‘Calculating loss and metrics’
  52. print ‘—————————————————————‘
  53. ytest = np_utils.to_categorical(ytest)
  54. score, acc = model.evaluate(Xtest, ytest, verbose=0)
  55. print(‘Test score:’, score)
  56. print(‘Test accuracy:’, acc)
  57. print(“Generating test predictions…”)
  58. testpreds = model.predict_classes(Xtest, verbose=0)
  59. testpreds
  60. Building model
  61. —————————————————————
  62. Compiling model
  63. —————————————————————
  64. Fitting model
  65. —————————————————————
  66. Calculating loss and metrics
  67. —————————————————————
  68. (‘Test score:’, 0.17593039979454544)
  69. (‘Test accuracy:’, 0.96288888883590695)
  70. Generating test predictions

And I want to close out by saying the following.