Many times in machine learning, we have to work with tensors which contain so many zeros.
And so in this cases, TensorFlow defines a sparse tensor which helps to represent in a more efficient
manner the tensors which are sparse, that is, which contains so many zeros or way more zeros compared
to the other non-zero um, values.
So here we could have our sparse tensor, sparse tensor TensorFlow sparse sparse tensor.
And then you will notice how we specify this indices.
Right here we have this indices.
And then we have values.
And then we have the dense shape.
So what this simply means is we are going to generate an output like we change this to let's say um
five by six.
There we go.
So we have an output which is going to be of shape five by six.
And then at the position zero zero we would have the value one.
Then at the position one two would have the value two.
So we would change this value to say nine.
That's fine.
Um let's say five two.
And then we run that.
So let's let's have sparse tensor.
Um yeah.
We're getting an error five six.
All the dense chips will be five by six.
So let's run that.
And we have sparse tensor.
So you could see here that we have this um sparse tensor.
Um already as we've defined we have the indices.
We have the values.
And then we have the dense shape.
You could also do TensorFlow sparse to dense and then um pass in the sparse tensor.
So you get the actual tensor um which we created.
So let's get the error.
We have um 5652 is out of bounds.
Uh when you have this.
Well that makes sense.
When you have a shape of five by six, you wouldn't expect to have, um, this, um, position five
two.
So let's run that again.
Then we get our sparse tensor.
So as you could see at the position zero zero we have the value one.
See that value one.
Now let's let's change this value to five.
Run that again.
You see now that the position zero we zero zero we have the value five at the position two five.
That's 012.
And then 012345 we have the value nine.
See.
So um this tensor which originally or which has many zeros and very few non-zero values can now be represented
as a sparse tensor.
And hence our permits us carry out computation much more efficiently.