Learn Basic Tensorflow Part 1
Raahul Dutta (He/Him) ??
?? Building the Protocol for Agent-to-Agent Communication <??> | 10+ Patents
Hola!!!
Last year I searched for a proper tensorflow tutorial, but I could not find, It was scattered. Google’s tensorflow documentation is so dull that every 5 minutes I needed caffeine to charge me up. So that’s the tutorial series, where I am trying to cover the tensorflow, Machine learning(supervised and reinforcement learning — Google Dopamine and Gym) and little bit differential calculus. Don’t be afraid if you don’t know Calculus; I will try to ease as much as I can. Differential calculus has a special naughty relationship with machine learning, So I can’t ignore. Hope you will enjoy the show :P, So let’s explore like Columbus.
PS: this is machine learning tutorials, not artificial intelligence. There are differences between Machine Learning and Artificial intelligence. "Machine learning is the study of computer algorithms that improve automatically through experience.” whereas "Artificial intelligence is the science and engineering of making computers behave in ways that, until recently, we thought required human intelligence.", I hope it clears — #spreadtheawareness.
Let’s start by explaining what Tensorlfow is. Tensorflow is a purely open source computational library which is implemented by Google. Not only machine learning developers are using it, but I have also seen it is widely used in the Genetic Engineering field too, where you need to play with larger arrays, computations. We will use here python for tensorflow. Tensorlfow always creates a directed acyclic graph, DAG. And how the DAG has been executed, we will cover it later. In math, a simple number like 10 or 20, we call it a scalar. A vector(not physics vector) is a 1D array. A matrix(not the movie) is a 2D array, and A tensor is a 3D array. A tensor is an n-dimensional array of data. So here, in Tensorlfow, all the tensors are flowing through the directed acyclic graph. Hence the library is called Tensorflow.
Why does tensorflow use Directed Acyclic graph to represent the computation? The main answer is Portability. You can build the DAG in python using higher configuration CPU, GPU or TPU, store it in the saved model, and the same can be restored using C++ in low latency machine like mobile or raspberry. So it will give you the language and hardware portability. This is very similar like JVM, how java works.
Now today, the model training is an expensive job. We usually use GPU or cloud to train model. So the question is- if is it possible to prepare a model on a mobile phone? The answer is partial no. One situation is that you build the model and deploy it to a bunch of mobile phones. And your goal is to personalize the model according to the user’s choice and preferences. And that point you need to update the weights of the model to reflect the user’s preferences. This type of fine tuning of a model can be possible on the phone. We have tensorfow lite, or in the browser, we can use the javascript version of tensorfow and this learning is called “federated learning”. The user may not share the personal preference, but the personal update of weights can be pushed to the cloud. This consensus change happens to the shared model on the cloud. So we deploy the model to the user’s device, rinse and repeat.
Now let’s start looking at the tensorflow hierarchy. Like most of the software libraries, tensorflow has numbers of abstraction layers. The lowest level is implemented to target the different types of hardware; The next level is Tensorflow C++ layer. Then the next layer is a wrapper python layer, is what contains much of the numeric processing code, add, subtract, divide, matrix multiply, creating variables, creating tensors, getting the shape, all the dimensions of a tensor, all that core basic numeric processing stuff, etc. Then, in the next layer, there are a set of Python modules that have a high-level representation of useful neural network components, for example, a way to create a new layer of hidden neurons, with a real activation function. It’s in tf layers, a way to compute the root mean square error and data as it comes in, tf metrics, a way to calculate cross entropy with Logics, and it’s in tf losses. These models provide components that are useful when building custom NN models. And then the highest layer — The estimator. It knows how to do this to be the training; it knows how to evaluate how to create a checkpoint, how to Save a model, how to set it up for serving. It comes with everything done sensibly, that fits most machine learning models and production. So, if you see example TensorFlow code on the Git, and it doesn’t use the estimator API, ignore that code, walk away, it’s not worth it. In the example, I will use non-estimator code first then will provide the estimator code later.
In Linkedin pulse I cant embed the Github codes.... For the full article, please visit the below link Learn Basic Tensorflow Part 1.
Next part of the series is calculus and activation function. If you enjoyed this post, I’d be very grateful if you’d help it spread by sharing it on Twitter or LinkedIn.
And Lastly Please share your comments and thoughts below. I’ll be happy to respond.
Gracias!!Thank You!!!