Getting started with TensorFlow

How can we start with TensorFlow? But before that we need to explain why we need TensorFlow? We’ll discuss that here.

Besides, we will see some code to get an idea.

Firstly, we need TensorFlow for pre-processing data. Secondly, we need it for modeling data.

Finally TensorFlow serves models so that others can use it.

But then the automatic question that comes to our mind is what is TensorFlow? Just define it in one sentence.

Well, in one sentence, TensorFlow is a machine learning library.

TensorFlow is a library

Certainly, one thing is clear from the above statements. TensorFlow is a kind of Software, or Framework, or a Library. 

And we build machine learning and deep learning models with TensorFlow.

Are you a complete beginner? Have you not coded before?

Moreover, don’t you know anything about machine learning and deep learning?

That’s fine.

We will learn everything together. And yes, with TensorFlow.

Let’s see some code to get an idea first. We’ll import the TensorFlow library, and then we’ll learn the version.

# Importing TensorFlow
import tensorflow as tf
print(tf.__version__) 

# output:
2.8.2

We see that the version is 2.8.2. 

Next, we will see some more examples. But before that, let’s know a few terms. 

A scalar is a single number. Any number that you can imagine.

On the other hand, a vector may represent one, two or more than two dimensional graphs. Therefore, in two dimension, one number represents the x coordinate, and the other number is the y coordinate.

Now, you’re probably guessing that between these two numbers one number may depend on the value of the other. Right? 

Your guess is correct.

We can write a vector as follows.

f(x) = y

As we see, the value of y depends on the value of x.

If x is equal to 2, the value of y is 2. On the contrary, if the value of x is 3, y is 3.

What do we need to learn TensorFlow?

You may wonder, why do we need to learn these scalar, vectors, etc? Is this knowledge necessary to learn TensorFlow?

The answer is “YES”.

To learn the basics of the TensorFlow, we need to learn a few mathematics, and python programming languages first.

Besides, we also need some introduction to NumPy, Pandas, and Matplotlib. However, we will talk about them later, when in TensorFlow we’ll use them.

A basic knowledge of mathematics and python is enough to get an initial idea about the TensorFlow.

However, once you get the idea, we will dig deep into machine learning and deep learning.

Why?

Because TensorFlow is a machine learning and deep learning library. As a result, the TensorFlow has tons of attributes, and methods to dig deep into machine learning and deep learning.

Let’s see some more code.

scalar = tf.constant(7)
scalar
# output:
<tf.Tensor: shape=(), dtype=int32, numpy=7>

scalar.ndim
# output:
0

vector = tf.constant([10, 10])
vector
# output:
<tf.Tensor: shape=(2,), dtype=int32, numpy=array([10, 10], dtype=int32)>


vector.ndim
# output:
1

TensorFlow method

According to the above code, we need to clarify a few terms that a beginner may find difficult to understand. 

When we import the TensorFlow as “tf”, it acts as an object of the TensorFlow. 

Next, when we write tf.constant(), it means we call a TensorFlow method and pass some arguments.

However, it is not the end. In the above code, we have used the concepts of variable, object, attribute and method.

Therefore, in python, we need to learn those things first.

Not only that, we have used two mathematical terms – scalar and vector. 

Therefore, we will learn them in the next section and we will come back again.

Once we have learned those concepts, the above TensorFlow code will look easy.

So stay tuned.

What Next?

Books at Leanpub

Books in Apress

My books at Amazon

GitHub repository

Flutter, Dart and Algorithm

Twitter

Comments

7 responses to “Getting started with TensorFlow”

  1. […] Firstly, TensorFlow is a Python library. […]

  2. […] Firstly, the seed method stands for reproducibility.  […]

  3. […] Now we can multiply these tensors using two ways. […]

  4. […] Let’s change the value of the tensor in a different way. However, this time we’re using the TensorFlow methods. […]

  5. […] Let’s import the TensorFlow first. […]

  6. […] As a result, it allows us to run the NumPy accelerated by TensorFlow. In addition, we can use other APIs of the TensorFlow also. […]

  7. […] Let’s try to define Google’s TensorFlow in one single sentence. TensorFlow is a machine learning framework. […]

Leave a Reply