1
00:00:00,500 --> 00:00:07,820
In this new section, we shall be working with ragged tensors, and so we shall understand the reason

2
00:00:07,820 --> 00:00:12,920
why we need rag tensors, and also how to create them very easily.

3
00:00:12,920 --> 00:00:15,200
So let's get back.

4
00:00:15,200 --> 00:00:20,090
Let's suppose we have an a um tensor flow constant.

5
00:00:20,690 --> 00:00:26,390
And then here we have another, another um array.

6
00:00:26,390 --> 00:00:29,150
So we have 123.

7
00:00:29,150 --> 00:00:30,920
Well let's just end like that.

8
00:00:30,920 --> 00:00:34,640
And then here we have 456.

9
00:00:35,840 --> 00:00:36,740
Let's close this.

10
00:00:36,740 --> 00:00:38,330
We have 456.

11
00:00:38,330 --> 00:00:41,390
And then we have 789 okay.

12
00:00:41,390 --> 00:00:42,890
So here's our input.

13
00:00:42,890 --> 00:00:44,480
We could print out.

14
00:00:44,870 --> 00:00:47,360
We could print out a and then print out.

15
00:00:47,360 --> 00:00:48,530
Well let's just print out a.

16
00:00:48,560 --> 00:00:51,890
Now once we print out a here's the output we get.

17
00:00:52,400 --> 00:00:55,550
Uh we could suppose that we modify this.

18
00:00:55,550 --> 00:00:59,450
So let's let's change that and change this okay.

19
00:00:59,450 --> 00:01:03,170
So now uh our row has two columns.

20
00:01:03,170 --> 00:01:08,990
And the second the second row has three columns, while the last row has only a single column.

21
00:01:08,990 --> 00:01:10,550
Let's run this again.

22
00:01:10,550 --> 00:01:12,920
You see that obviously we get an error.

23
00:01:12,920 --> 00:01:16,070
Can convert a non rectangular Python sequence to a tensor.

24
00:01:16,070 --> 00:01:20,660
So, um, the number of columns has to be constant across the rows.

25
00:01:20,660 --> 00:01:24,380
And number of rows have to be constant across the different columns.

26
00:01:24,380 --> 00:01:29,510
So such that we have a rectangular array or rectangular tensor.

27
00:01:29,510 --> 00:01:33,680
Nonetheless in some cases you would need this kind of data.

28
00:01:33,680 --> 00:01:39,560
That is, you would need data where some rows will contain shorter columns as compared to the others.

29
00:01:39,560 --> 00:01:46,640
And so the way we deal with this is we convert this to, um, racked tensors, or we just simply create

30
00:01:46,640 --> 00:01:47,420
a racked tensor.

31
00:01:47,420 --> 00:01:51,050
So here we have racked instead of the TensorFlow constant.

32
00:01:51,080 --> 00:01:53,150
Now we have TensorFlow racked constant.

33
00:01:53,150 --> 00:01:58,730
So we run that again and you will see that we have a racked tensor.

34
00:01:58,760 --> 00:02:01,640
Now this racked tensors have different functions.

35
00:02:01,640 --> 00:02:07,340
Like we've just looked at the constant which constructs a constant rank tensor from a nested Python

36
00:02:07,340 --> 00:02:07,820
list.

37
00:02:07,820 --> 00:02:09,830
We could also have the boolean mask.

38
00:02:09,830 --> 00:02:11,390
So let's just check out the boolean mask.

39
00:02:11,390 --> 00:02:14,660
And you would uh feel free to check out the others later on.

40
00:02:14,660 --> 00:02:19,130
So for the boolean mask let's take let's take out this example.

41
00:02:19,130 --> 00:02:22,640
From here we have the data and then we have the mask.

42
00:02:23,180 --> 00:02:24,380
Um there we go.

43
00:02:24,380 --> 00:02:25,700
Let's copy this.

44
00:02:26,330 --> 00:02:32,870
Uh, let's copy this other one because we here we have um this non rectangular list.

45
00:02:33,050 --> 00:02:35,300
So let's copy that.

46
00:02:35,300 --> 00:02:39,530
And then we could simply paste this out here okay.

47
00:02:39,530 --> 00:02:45,620
So now here we have this um racked tensor right here.

48
00:02:45,890 --> 00:02:47,810
Or we have this two racked tensors.

49
00:02:47,810 --> 00:02:48,230
Let's see.

50
00:02:48,230 --> 00:02:50,780
This is the this is the input rank tensor.

51
00:02:50,780 --> 00:02:52,550
But this is the mask.

52
00:02:52,550 --> 00:02:55,670
So what this mask does is simple.

53
00:02:55,670 --> 00:02:59,240
We are going to um keep all the values.

54
00:02:59,240 --> 00:03:00,080
So let's run this.

55
00:03:00,080 --> 00:03:01,820
So you see the output.

56
00:03:01,820 --> 00:03:03,800
Um f is not defined.

57
00:03:03,800 --> 00:03:07,070
Well f is um false and t is true.

58
00:03:07,070 --> 00:03:19,190
So let's get back and then let's say here we have false false true false true and then true okay.

59
00:03:19,190 --> 00:03:20,360
Run that again.

60
00:03:21,350 --> 00:03:22,220
There we go.

61
00:03:22,220 --> 00:03:27,290
So you see that each and for every position where we have false is taken off.

62
00:03:27,290 --> 00:03:28,640
So here we have one.

63
00:03:28,640 --> 00:03:29,120
It's no more.

64
00:03:29,120 --> 00:03:30,110
It's no longer there.

65
00:03:30,110 --> 00:03:33,170
Two is no longer there because we have false to three.

66
00:03:33,590 --> 00:03:35,540
Um remains because we have true.

67
00:03:35,540 --> 00:03:41,210
So you see we are left with this three and then for the next this for false.

68
00:03:41,210 --> 00:03:42,920
So it's just taken off.

69
00:03:42,920 --> 00:03:46,250
We have this empty list and then we have the next true true.

70
00:03:46,250 --> 00:03:48,200
So five six are maintained.

71
00:03:48,200 --> 00:03:53,930
So that's it for this um boolean mask method which we have seen from the documentation.

72
00:03:53,930 --> 00:03:59,240
You could check out other methods like this cross Crosshatched range and so on and so forth.

73
00:03:59,240 --> 00:04:01,670
So we could check out those different methods.

74
00:04:01,670 --> 00:04:06,980
Um, the simple way we could check this out is by uh going through this, different examples.

75
00:04:06,980 --> 00:04:10,130
So right here we have our values.

76
00:04:10,130 --> 00:04:13,190
You see 31415926.

77
00:04:13,190 --> 00:04:21,260
So when you have this um rank tensors from row splits method and you specify the row splits.

78
00:04:21,260 --> 00:04:24,290
The way this is done is simple.

79
00:04:24,290 --> 00:04:27,800
We start from zero and then we go to four.

80
00:04:27,800 --> 00:04:31,910
So you see when we have row splits start from zero we go to four.

81
00:04:31,910 --> 00:04:36,500
So we have 0123.

82
00:04:36,590 --> 00:04:38,660
See we have 3141.

83
00:04:38,660 --> 00:04:39,800
See that.

84
00:04:39,800 --> 00:04:48,320
And then let's, let's copy this and um run the code here where we specify the row splits and we go

85
00:04:48,320 --> 00:04:49,700
from 0 to 4.

86
00:04:49,730 --> 00:04:54,740
This simply means just like with a range we're going to have um zero.

87
00:04:54,740 --> 00:04:56,480
So we will take zero.

88
00:04:56,930 --> 00:04:59,720
Then we will take one, then we will take two.

89
00:05:00,010 --> 00:05:01,060
They will take three.

90
00:05:01,060 --> 00:05:04,900
So we go from 0 to 4 minus one.

91
00:05:04,900 --> 00:05:08,230
And that's why we have three one, four one which we have here.

92
00:05:08,230 --> 00:05:15,760
And then for the next we're going to have from 4 to 4 minus one is uh, basically telling us that we

93
00:05:15,760 --> 00:05:18,370
are not going to have any elements at this position.

94
00:05:18,370 --> 00:05:20,800
And that's why, you see, we have an empty list.

95
00:05:20,800 --> 00:05:24,700
Then we go from 4 to 7, 4 to 7.

96
00:05:24,700 --> 00:05:32,650
We would have four, five, four, five and then six because we're going from 4 to 7 minus one.

97
00:05:32,650 --> 00:05:36,100
So here we have 592592.

98
00:05:36,130 --> 00:05:37,960
Then we have 7 to 8.

99
00:05:37,960 --> 00:05:40,450
So we go from seven to to eight minus one.

100
00:05:40,450 --> 00:05:42,610
So we we are at seven and that's six.

101
00:05:42,610 --> 00:05:43,450
That's a year.

102
00:05:43,480 --> 00:05:47,110
Then finally we have um 8 to 8.

103
00:05:47,110 --> 00:05:50,020
So 8 to 8 minus one is um empty.

104
00:05:50,020 --> 00:05:51,520
So that's why we have this empty list.

105
00:05:51,520 --> 00:05:52,180
So that's it.

106
00:05:52,180 --> 00:05:54,550
That's how we read this row splits.

107
00:05:54,550 --> 00:05:56,260
Now for the row lengths.

108
00:05:56,260 --> 00:05:57,610
We'll take this off.

109
00:05:57,610 --> 00:05:58,840
For the row lengths.

110
00:05:58,840 --> 00:06:06,280
We simply, um, look at this four and say, okay, we're going um, one, two, three, four.

111
00:06:06,280 --> 00:06:07,000
That's it.

112
00:06:07,000 --> 00:06:07,810
The length.

113
00:06:08,110 --> 00:06:09,760
And then the next is zero.

114
00:06:09,760 --> 00:06:11,200
So we have an empty list.

115
00:06:11,200 --> 00:06:12,430
The next is three.

116
00:06:12,430 --> 00:06:13,810
So we take the next three.

117
00:06:14,860 --> 00:06:15,460
That's it.

118
00:06:15,610 --> 00:06:16,840
The next is one.

119
00:06:16,840 --> 00:06:19,540
We take this one and finally we have zero empty list.

120
00:06:19,540 --> 00:06:25,390
So we see that where the row splits or row length, we're able to generate the same output like well

121
00:06:25,390 --> 00:06:27,160
let's just let this be.

122
00:06:27,160 --> 00:06:27,880
That's fine.

123
00:06:27,880 --> 00:06:30,670
Then we go to value row IDs.

124
00:06:30,670 --> 00:06:35,140
So for value row ids we're going to say this one.

125
00:06:35,140 --> 00:06:42,580
This three we have right here is going to be part of the zeroth um row.

126
00:06:42,580 --> 00:06:45,910
So that's that's that's where this row ID comes from.

127
00:06:45,910 --> 00:06:49,330
This this three is going to be part from part of the zeroth row.

128
00:06:49,330 --> 00:06:50,590
So that's why we have three.

129
00:06:50,590 --> 00:06:52,810
One is going to be part of the zeroth row.

130
00:06:52,810 --> 00:06:53,950
That way we have one.

131
00:06:53,950 --> 00:07:00,220
And uh for the in the zeroth row um, four is going to be part and one is going to be part.

132
00:07:00,640 --> 00:07:02,500
So that's how we have this 314.

133
00:07:02,500 --> 00:07:05,320
And then if you notice we skip one.

134
00:07:05,320 --> 00:07:10,960
What this means is we have no element belonging to the um row one.

135
00:07:10,960 --> 00:07:12,520
And that's why we have an empty list.

136
00:07:12,520 --> 00:07:15,820
And then we now look at two this next three elements.

137
00:07:15,820 --> 00:07:18,640
This next three elements belong to row two.

138
00:07:18,940 --> 00:07:23,350
And then we have three meaning that this next element belongs to row three.

139
00:07:23,680 --> 00:07:26,110
And then we have no four.

140
00:07:26,110 --> 00:07:30,220
So um, there is no elements in the row four.

141
00:07:30,220 --> 00:07:35,560
Now specify the number of rows here is important because if we just if we just, um, take this off

142
00:07:35,920 --> 00:07:39,490
or let's just say if we have considering that we have four rows.

143
00:07:40,110 --> 00:07:41,520
Then you see that there.

144
00:07:41,520 --> 00:07:44,280
We do not have this this last, uh, empty list.

145
00:07:44,280 --> 00:07:50,700
But when you say we have five rows and that you don't see the four and then you don't see this four,

146
00:07:50,700 --> 00:07:52,290
it means that that's an empty list.

147
00:07:52,290 --> 00:07:55,350
So that's it for the from row stats.

148
00:07:55,350 --> 00:07:58,110
It shows us where the row starts from.

149
00:07:58,110 --> 00:08:02,670
So this this row this row starts from position zero.

150
00:08:03,000 --> 00:08:06,030
And then the next row starts from position four.

151
00:08:06,420 --> 00:08:12,030
So this is your start from position for the other row starts again from position four.

152
00:08:12,030 --> 00:08:17,940
So because these two start from the same position it means that the there is a row which is empty.

153
00:08:17,940 --> 00:08:21,360
And that's that's how we have this four this 592.

154
00:08:21,360 --> 00:08:23,880
Because the the next starts from position seven.

155
00:08:23,880 --> 00:08:28,770
So the six and then the other one starts from position eight.

156
00:08:28,770 --> 00:08:33,600
So here we have 01234567.

157
00:08:33,600 --> 00:08:34,650
But there's no position eight.

158
00:08:34,650 --> 00:08:35,850
So we have an empty list.

159
00:08:35,850 --> 00:08:39,300
Now we also have this row limits here.

160
00:08:39,300 --> 00:08:41,640
Instead we're looking at where the row ends.

161
00:08:41,640 --> 00:08:45,150
So the the first row is going to end at position four.

162
00:08:45,150 --> 00:08:48,000
It's going to end here 0123.

163
00:08:48,000 --> 00:08:51,780
Well when we say position four um it's actually four minus one.

164
00:08:51,780 --> 00:08:53,940
So it's 0123 ends right here.

165
00:08:53,940 --> 00:08:56,550
And then the next one is going to end at that same position.

166
00:08:56,550 --> 00:08:57,030
Four.

167
00:08:57,030 --> 00:09:02,610
And because it ends at that position four um we are going to make it an empty list.

168
00:09:02,610 --> 00:09:08,190
So that's why we have the empty list since it ends at the same position where the previous one ended.

169
00:09:08,190 --> 00:09:12,870
So, um, that's why we have the empty list now for the next one we have seven.

170
00:09:12,870 --> 00:09:17,640
So 01234567.

171
00:09:17,640 --> 00:09:19,110
Obviously seven minus one.

172
00:09:19,110 --> 00:09:26,610
Remember when we when we we generally have start start to end minus one actually.

173
00:09:26,610 --> 00:09:30,810
So when you say start end it's start it's actually start end minus one.

174
00:09:30,810 --> 00:09:35,790
That's why when you delete with this limits that's with the ends we take instead of minus one.

175
00:09:35,790 --> 00:09:42,930
So we get right up to this um position because this is 0123456 right up to position six.

176
00:09:42,930 --> 00:09:45,870
We stop there and we have this 592.

177
00:09:45,900 --> 00:09:47,910
Then we have eight.

178
00:09:47,910 --> 00:09:54,150
So we go zero one um 2345678 minus one.

179
00:09:54,150 --> 00:09:55,680
Obviously we have six.

180
00:09:55,680 --> 00:10:00,990
And then the, the finally we have the empty list because um, this tool uh match.

181
00:10:01,260 --> 00:10:02,220
So that's it.

182
00:10:02,220 --> 00:10:05,220
The next we have this uniform row length.

183
00:10:05,220 --> 00:10:12,060
So we want if we want to have a uniform row length then it simply means that all this will have the

184
00:10:12,060 --> 00:10:12,990
exact same length.

185
00:10:12,990 --> 00:10:17,340
So we have 314159 and two six.

186
00:10:17,340 --> 00:10:19,560
Well this is 2468.

187
00:10:19,560 --> 00:10:22,080
So let's say we had seven here.

188
00:10:22,260 --> 00:10:26,400
You see the well let's take the start end from here.

189
00:10:26,400 --> 00:10:27,600
Run that again.

190
00:10:29,130 --> 00:10:32,940
We have an error because the row splits here doesn't make sense.

191
00:10:32,940 --> 00:10:36,660
Without taking into consideration the fact that we have added an extra element.

192
00:10:36,870 --> 00:10:38,010
Run that again.

193
00:10:38,780 --> 00:10:40,070
We for that.

194
00:10:40,070 --> 00:10:40,760
That was fine.

195
00:10:40,760 --> 00:10:43,850
But we we still, um, have some errors here anyway.

196
00:10:43,850 --> 00:10:46,160
We don't want to, um, check that out for now.

197
00:10:46,160 --> 00:10:49,160
We just wanted to test out this last one.

198
00:10:49,160 --> 00:10:52,190
So let's comment all this.

199
00:10:52,190 --> 00:10:53,330
Let's just cut that out.

200
00:10:53,330 --> 00:10:54,380
Run that.

201
00:10:55,210 --> 00:10:56,950
And we're getting an error.

202
00:10:56,950 --> 00:10:59,170
All the uniform rolling has to be specified.

203
00:10:59,470 --> 00:11:04,690
So if you specify that you see now that we have the output as expected.

204
00:11:04,690 --> 00:11:09,010
So let's get back and take this off.

205
00:11:09,010 --> 00:11:10,270
Run that again.

206
00:11:10,270 --> 00:11:11,530
And that should be fine.

207
00:11:11,530 --> 00:11:14,020
So that's it for this section on Rack Tensors.

208
00:11:14,020 --> 00:11:19,720
See you in the next section where we will deal with the string tensors and variables.
