Hello everyone and welcome to the tents or flow basics lecture and this lecture will show you how to
create simple constants with tensor flow and how to actually create a tensor flow session in order to
run tensor flow operations.
I'm going to go ahead and jump to a Jupiter notebook to get started.
All right.
Here I am at the Jupiter notebook.
Remember you can access the notebooks for this lecture by looking at the deep learning folder.
This note book is called tensor flow basics and it has all the code and explanations for what is going
to be working through here.
Let's go ahead and show how to create a simple constants using tensor flow.
First the importance or flow will say importance or flow as T.F. let that run and for constants intenser
flow tensor flow will store them what is as what is known as a tensor object.
So we can say T.F. constants and then you can passen an object here.
For instance a very basic constant will just be a string such as the string hello world shift center
and you can see it's a tensor object D type data type is string and it doesn't actually have a shape
.
And then what you can do is actually save this as a variable.
And if you want to check the the type again you can just say type and you'll notice it's tensor flow
and it's a tensor.
So we're going to be working of these tensor objects when dealing with tensor flow.
And just to show you one more example maybe you can say X and say T.F. constant and you comparison for
instance an integer 100.
And then if you say X you'll see it's a tensor data type is integer 32 bit and you can actually just
also check type again to see that it's again a tensor.
So these are tensor objects and they're just simple constants that we can work with with tensor flow
.
Now that we have these objects are these tensors we want to go ahead and do is create a tensor flu session
which is a class for running tensor flow operations.
Let's go ahead and do that.
I'm going to say S E S S is equal to T.F. and then capital S the tab session close parentheses.
A session object encapsulates the environment in which operation objects are executed which are going
to learn about just a little bit and then tensor objects are evaluated in those operations.
So for example here we have cesse equals T.F. session.
So we have the session object.
Now I can call SPSS and call it run off of it.
And then I can actually pass in these tensor constants that I made earlier.
For instance if I just say run Hello Number Hello was that tensor constant which was the string.
I get back this string hello world or this is just a Unicode indication.
And I can also say something like this.
Run X and they get back out that integer.
OK.
If I ever want to check out the type I can say type says Stop run X and notice I get back now an integer
if none it's no longer the tensor form.
So if I check the type of that run.
Hello.
It's just bytes here.
OK let's go ahead and move on to operations.
You may have noticed already that tensor flow kind of deals with things a little differently versus
bytes and non-pay integers instead of just basic strings or integers.
And later on we'll see why it's important to deal with things in a very specific object type or in dealing
with constants.
Right now we'll have the tensor flow constant So we created tensor flow sessions and then we have tensor
flow operations and we go and type this here operations.
Now you can line up multiple tensor for all operations to be done are run during a session.
So for example I'm going to say x is equal to T.F. constant 2.
So that's a tensor object.
And then T.F. constant.
We'll go ahead and put in three.
And what you can do is say with T.F. session as SPSS kind of similar to opening a file with Python you'll
see if this TFT session as sess we're going to do a bunch of operations just to make this clear going
to print operations with constants.
And for instance I can say SPSS run X plus why.
So I'm grabbing two constants and putting them inside of this session run command and then I'm going
to go ahead and print edition comma and then close.
Princes here.
So we're going to take this sort of format and then prints whatever operation we're doing.
And then the session son going to run let's say subtraction X minus Y and then I'm going to print that
on the same line as say Prince.
So traction comma and then close the princes there.
So have subtraction.
Let's go ahead and do multiplication and division.
Well don't just say Prince multiplication.
Comma says Stott's run and we will say X times Y and we'll do division last division sess thought run
will take the two constants X divided by Y.
We'll go ahead and run this OK.
And there you have it we're actually able to take those constants with T F session.
SS run operations on those constants.
Now let's go ahead and discuss in another object type in tensor flow which is known as a placeholder
.
You may not always have the constants right away.
You may actually want to define a placeholder that can accept values.
Let me go in and show you what I mean by that.
I'm going to go ahead and say x is equal to a dot placeholder and then pasand some sort of accepted
object type here and tensor flow actually has a bunch of builtin forms of this.
So for instance we can say T.F. dot int 32 for a 32 bit integer and then I can say why is equal to T.F.
placeholder if it's 32.
And now what I can go ahead and do is check some of these out.
We can say x.
Notice it's a placeholder and it has an unknown shape but it expects the data type to be integer 32
.
And here this is the difference between a placeholder versus an actual constant for an actual constant
.
We provided some sort of array string number value etc..
And here we're just putting in a placeholder that is directly gotten off of T.F. and you can explore
for a bunch of different placeholders such as floats.
You can click tab here and I'll start telling you that different placeholders has in store for that
.
But phrenologists this simple with X and Y into 7:57 it's 32.
Now keep in mind if you have a 64 bit computer versus a 32 bit computer if you're running tens or following
a GPS you you may have to adjust these values in a little bit in case you get a warning or error in
this next step.
You should probably get an error in 32.
But just keep that in mind.
Now that we have these placeholders we can define operations that can have variable input.
Previously we had operations that needed some sort of constant input because we're just using basic
thought run and now we can define operations using tensor flow.
So I'm going to go ahead and say add is equal to T.F..
And this is a very simple built in operation that takes an X and Y and I'm going to go ahead and make
a few more will do so.
Traction T.F. dot sub X come A-Y and we'll also do multiplication and UL's equal to T.F. thought you
will x come away.
And you should keep in mind sensor flow has a bunch of these built in operations such as matrix multiplication
division and more.
But we'll keep it simple for now.
And you could almost think of these as essentially operations that will have a variable input almost
kind of analogous to functions in normal Python where you expect some sort of input.
And later on you'll provide it.
But in this case the formatting is quite different with tensor flow.
I'm going to say with T.F. session as cesse just like we did earlier.
I'm going to go ahead and say print's operations with placeholders
and then I'm going to go and do addition.
So addition.
Previously we passed in constants but I can say cesse run passen mind defined operation that has placeholder
such as add comma and then pasan what's known as a feed dictionary.
If you actually go ahead and do here you'll see Pheed dictionary shift tab.
And basically that's going to be a dictionary of values that the operation will expect.
I'm going to go out and say Pheed underscore dict is equal to and then I need to pass in a dictionary
or passen X is going to be 20 and y is going to be 30.
Now look what I'm doing here though.
I'm not passing in x and y as strings.
I'm actually passing them as variable keys.
So keep that in mind go in and run this.
So operations of placeholders will get 20 plus 30 is 50 so that makes sense.
I'm going to go ahead and do the same for subtraction and addition subtraction.
So start ups start run well go ahead and put in sub and just above here we're to run that again and
anisette Z is equal to the dictionary.
Run that and then we'll say so the feed dictionary is equal to D for subtraction and they'll do the
same for multiplication.
So multi application says start run passen multiplication that T.F. optimal and then give it the feed
dictionary which in this case is just d or run that.
And here we have it.
So I was able to run these operations using these placeholders in conjunction with these built in tensor
flow functions.
OK.
Now finally let's see one last example of maybe a more complex operation using matrix multiplication
in order to do this we can actually create the matrices going to go ahead and import number pi as N
P and then I'm going to go ahead and say A is equal to an array and I'll go ahead and say five point
zero comma five point zero and make sure that you're putting in floats here.
Otherwise you may get an error and then we'll say in the array.
Unhearing going to say 2.0 comma 2.0.
So notice the difference in brackets here.
Basically one is a one by two and the other one is a two by one.
Just to show you what I mean by that we have a that's an array.
We check the shape of it.
It's one by 2 B.
Knows how it's printed out.
That's an array and its shape is two by one.
So what we can do now is actually multiply these matrices together.
So I'm going to go ahead and do that.
I'll say Matt one is equal to T.F. Constance pasan A.
And then we'll say two is equal to T.F..
Constant pass and B that we would convert these matrices into actual tensor objects that tensor float
can deal with then.
Then we're going to go ahead and do is create a matrix multiplication operation.
So I will say Matrix underscore multiday is equal to CFT.
Mats Moel.
And if you look at just T.F. map and click tab you'll notice that there's other operations there like
Matrix determinant matrix inverse matrix solve etc. but a very very basic one to just map mole and then
we'll say maths one comma Matt to.
Now we're going to go ahead and run the session to perform the operation we'll say with T.F. session
as s.c.s say result is equal to SEST run.
And then just pasan matrix malty.
Note that I'm not passing in a feed dictionary here because I actually put these in as constants so
this is more like what we did up here.
Except that it's also taking an account built in functions.
So kind of a mix between both topics that we just won over and then let's go ahead and print that result
and there we have it the result of these two matrices being multiplied together.
OK.
That's it for now.
These are very basic concepts that don't work.
They didn't make 100 percent sense.
They're a little vague kind of strange to get used to.
If you're just starting off with tensor flow well we're going to do next is actually perform an entire
Deep learning analysis with real data.
The data set.
It's a very famous data set of handwritten digits in the form of an array.
And a lot of times it's a student's first encounter with an actual deep learning project.
Let me go ahead and just quickly review some of the key concepts we learned about here.
And like I mentioned don't worry if you didn't completely feel comfortable of this we're going to review
all of this again in the next lecture.
Basically for tensor flow a few things I want you to know so far the importance flow is T.F. and you
can create constants with tensor flow just by passing NCF thought constants and whatever object you
want to convert to a tensor that we tensor for can work with it.
You can run a session intenser flow a specific session just by saying T.F. session and close print actually
run it set as a variable and then you can run those constants or operations off of those constants.
And we saw operations here very basic ones such as just adding two numbers together then we have placeholders
which allowed us to actually create operations or functions that will take in feed dictionaries that
way we can put in placeholder objects and later provide the actual constants that we want to work with
.
So you can think of that as almost to finding your own function except in this case we use built in
functions and then kind of combining those two ideas.
We created some matrices of pi to find them as tensor objects called a built in function off of tensor
for this T.F. thought Matt Mol Paston.
Matt 1 2 in order to multiply them together and then just ran that function with no feed dictionary
because we had already defined these two as constants.
OK that's it.
Coming up next we'll build on top of these basic skills in order to create our first deep learning model
.
Thanks everyone and I'll see you at the next lecture