Quick Introduction to TensorFlow ( For Beginners )

Original article was published by Nidhifab on Deep Learning on Medium


Quick Introduction to TensorFlow ( For Beginners )

This article is for Machine Learning aspirants who wish to learn and have quick introduction about Deep Learning framework TensorFlow. I have tried my best to keep it easy and understandable.

TensorFlow is an end-to-end open source platform for machine learning.

It is end-to-end open source platform for building models.

It has a comprehensive, flexible ecosystem of tools, libraries, and community resources that led developers easily build and deploy ML-powered applications. TensorFlow was originally developed by researchers and engineers working on the Google Brain team within Google’s Machine Intelligence Research organization to conduct machine learning and deep neural networks research. The system is general enough to be applicable in a wide variety of other domains, as well.

To install the current release

$ pip install tensorflow

Tensor + Flow = TensorFlow

Tensors are the building blocks of TensorFlow, as all computations are done using tensors.

At the end of the day, a tensor is also a mathematical entity with which to represent different properties, similar to a scalar, vector, or matrix. A vector is a one-dimensional tensor, whereas two-dimensional tensors are matrices. Tensors can be of two types: constant or variable.

Rank

Ranking tensors can sometimes be confusing for some people, but in terms of tensors, rank simply indicates the number of directions required to describe the properties of an object, meaning the dimensions of the array contained in the tensor itself. Breaking this down for different objects, a scalar doesn’t have any direction and, hence, automatically becomes a rank 0 tensor, whereas a vector, which can be described using only one direction, becomes a first rank tensor. The next object, which is a matrix, requires two directions to describe it and becomes a second rank tensor.

Shape

The shape of a tensor represents the number of values in each dimension.

Scalar — 32: The shape of the tensor would be [ ].

Vector — [3, 4, 5]: The shape of the first rank tensor would be [3].

Matrix =

1 4 7

2 5 8

3 6 9

: The second rank tensor would

have a shape of [3, 3]

In TensorFlow, all the operations are conducted inside a graph. The graph is a set of computation that takes place successively. Each operation is called an op node and are connected to each other. One type of node is a constant. Like all TensorFlow constants, it takes no inputs, and it outputs a value it stores internally. Another type of node is Variables that store different parameters. We also have placeholder that also stores different values. In placeholder you don’t have to provide an initial value and you can specify it at runtime with dictionary argument inside Session. run , whereas in tf.Variable you can provide initial value when you declare it.

List of Prominent Algorithms supported by TensorFlow

Currently, TensorFlow 1.10 has a built-in API for:

  • Linear regression: tf.estimator.LinearRegressor
  • Classification:tf.estimator.LinearClassifier
  • Deep learning classification: tf.estimator.DNNClassifier
  • Deep learning wipe and deep: tf.estimator.DNNLinearCombinedClassifier
  • Booster tree regression: tf.estimator.BoostedTreesRegressor
  • Boosted tree classification: tf.estimator.BoostedTreesClassifier

Simple TensorFlow Example

import numpy as np

import tensorflow as tf

Defining the variable

X_1 = tf.placeholder(tf.float32, name = "X_1")X_2 = tf.placeholder(tf.float32, name = "X_2")multiply = tf.multiply(X_1, X_2, name = "multiply")

To execute operations in the graph, we have to create a session. In Tensorflow, it is done by tf.Session().

with tf.Session() as session:result = session.run(multiply, feed_dict={X_1:[1,2,3], X_2:[4,5,6]})print(result)

Please share to help others find it. Feel free to leave a comment.