1
00:00:00,260 --> 00:00:06,560
Many times in machine learning, we have to work with tensors which contain so many zeros.

2
00:00:06,560 --> 00:00:16,070
And so in this cases, TensorFlow defines a sparse tensor which helps to represent in a more efficient

3
00:00:16,070 --> 00:00:23,210
manner the tensors which are sparse, that is, which contains so many zeros or way more zeros compared

4
00:00:23,210 --> 00:00:26,000
to the other non-zero um, values.

5
00:00:26,000 --> 00:00:33,080
So here we could have our sparse tensor, sparse tensor TensorFlow sparse sparse tensor.

6
00:00:33,080 --> 00:00:36,770
And then you will notice how we specify this indices.

7
00:00:36,770 --> 00:00:39,260
Right here we have this indices.

8
00:00:40,040 --> 00:00:41,780
And then we have values.

9
00:00:41,780 --> 00:00:43,130
And then we have the dense shape.

10
00:00:43,130 --> 00:00:49,670
So what this simply means is we are going to generate an output like we change this to let's say um

11
00:00:49,670 --> 00:00:52,250
five by six.

12
00:00:52,250 --> 00:00:52,880
There we go.

13
00:00:52,880 --> 00:00:56,120
So we have an output which is going to be of shape five by six.

14
00:00:56,120 --> 00:01:01,550
And then at the position zero zero we would have the value one.

15
00:01:01,550 --> 00:01:05,150
Then at the position one two would have the value two.

16
00:01:05,150 --> 00:01:07,310
So we would change this value to say nine.

17
00:01:07,310 --> 00:01:08,270
That's fine.

18
00:01:08,900 --> 00:01:11,150
Um let's say five two.

19
00:01:12,010 --> 00:01:13,270
And then we run that.

20
00:01:13,270 --> 00:01:16,960
So let's let's have sparse tensor.

21
00:01:17,440 --> 00:01:18,700
Um yeah.

22
00:01:18,700 --> 00:01:21,670
We're getting an error five six.

23
00:01:21,670 --> 00:01:23,740
All the dense chips will be five by six.

24
00:01:23,740 --> 00:01:24,400
So let's run that.

25
00:01:24,400 --> 00:01:26,050
And we have sparse tensor.

26
00:01:26,050 --> 00:01:30,010
So you could see here that we have this um sparse tensor.

27
00:01:30,340 --> 00:01:33,610
Um already as we've defined we have the indices.

28
00:01:33,610 --> 00:01:35,890
We have the values.

29
00:01:35,890 --> 00:01:37,840
And then we have the dense shape.

30
00:01:38,110 --> 00:01:47,110
You could also do TensorFlow sparse to dense and then um pass in the sparse tensor.

31
00:01:47,110 --> 00:01:52,210
So you get the actual tensor um which we created.

32
00:01:52,210 --> 00:01:54,280
So let's get the error.

33
00:01:54,280 --> 00:01:58,030
We have um 5652 is out of bounds.

34
00:01:58,060 --> 00:01:59,320
Uh when you have this.

35
00:01:59,320 --> 00:02:00,430
Well that makes sense.

36
00:02:00,430 --> 00:02:07,060
When you have a shape of five by six, you wouldn't expect to have, um, this, um, position five

37
00:02:07,060 --> 00:02:07,270
two.

38
00:02:07,300 --> 00:02:08,740
So let's run that again.

39
00:02:08,890 --> 00:02:10,720
Then we get our sparse tensor.

40
00:02:10,720 --> 00:02:15,100
So as you could see at the position zero zero we have the value one.

41
00:02:15,160 --> 00:02:16,570
See that value one.

42
00:02:16,570 --> 00:02:19,150
Now let's let's change this value to five.

43
00:02:19,690 --> 00:02:20,530
Run that again.

44
00:02:20,530 --> 00:02:25,330
You see now that the position zero we zero zero we have the value five at the position two five.

45
00:02:25,330 --> 00:02:28,180
That's 012.

46
00:02:28,180 --> 00:02:33,700
And then 012345 we have the value nine.

47
00:02:33,700 --> 00:02:34,240
See.

48
00:02:34,240 --> 00:02:44,380
So um this tensor which originally or which has many zeros and very few non-zero values can now be represented

49
00:02:44,380 --> 00:02:46,690
as a sparse tensor.

50
00:02:46,690 --> 00:02:51,250
And hence our permits us carry out computation much more efficiently.
