1
00:00:00,180 --> 00:00:04,260
Hi, welcome back to a new section here you learn how to build Chad boats.

2
00:00:04,650 --> 00:00:11,250
Let me show you an example often Chad boat that you built during this section of visits already, so

3
00:00:11,250 --> 00:00:14,160
I'm going to show you the ultimate only and then we build the codes.

4
00:00:14,580 --> 00:00:15,480
Step by step.

5
00:00:15,660 --> 00:00:16,800
So I'm going to run this.

6
00:00:19,140 --> 00:00:25,710
The Chubb board greets me, and he or she is asking me a question, what do I want to know?

7
00:00:25,980 --> 00:00:32,910
Now this particular chub bolt knows about vegetables, so it is specialized and bold a topic and you

8
00:00:32,910 --> 00:00:42,270
can ask a shadbolt questions such as Can you eat vegetables and the chard?

9
00:00:42,270 --> 00:00:45,310
But we will answer you this.

10
00:00:46,560 --> 00:00:47,430
So that's the answer.

11
00:00:48,660 --> 00:00:54,480
And Chapbook gets this answer from a Wikipedia article about vegetables.

12
00:00:55,230 --> 00:01:03,180
So that is a corpus word of a chad about this Chad, but gets the knowledge from let's ask another question.

13
00:01:03,630 --> 00:01:05,640
Are there vitamins?

14
00:01:07,530 --> 00:01:12,990
Oh, careful with the typos in vegetables.

15
00:01:15,170 --> 00:01:16,550
And we get this answer.

16
00:01:16,850 --> 00:01:20,240
The nutritional content of vegetables varies considerably.

17
00:01:21,440 --> 00:01:24,080
Some contains amounts of protein and so on.

18
00:01:24,560 --> 00:01:27,770
So it also talks about vitamins, as you see in here.

19
00:01:29,100 --> 00:01:34,920
And so one, if you ask an off topic question, of course, with Chad, but.

20
00:01:36,700 --> 00:01:39,520
Can you eat Facebook?

21
00:01:41,690 --> 00:01:44,240
The Chad, but will say, I don't know.

22
00:01:45,920 --> 00:01:49,370
And if you type in quits, the chat bot will quit.

23
00:01:49,670 --> 00:01:56,300
So let's build this exact chat bot in this video, I'm going to close this window.

24
00:01:59,320 --> 00:02:01,390
And open a new one soon.

25
00:02:03,940 --> 00:02:04,870
Let me clear that.

26
00:02:05,860 --> 00:02:09,889
I'm going to start from these cold, not from scratch.

27
00:02:10,270 --> 00:02:15,820
And I'm going to do that because we already built these codes in the previous section of the course.

28
00:02:16,120 --> 00:02:23,230
So if you don't know what this code is about, you have to follow the previous section, particularly

29
00:02:23,230 --> 00:02:29,920
the last video, which covers the topic of finding the most similar sentence.

30
00:02:30,460 --> 00:02:33,520
So this is the exact code that we built in that video.

31
00:02:34,030 --> 00:02:40,140
However, if you don't want to watch that video, I'll explain this code quickly now.

32
00:02:40,960 --> 00:02:46,870
So what we've got here is we impose the penalty library, which is used for natural language processing,

33
00:02:47,380 --> 00:02:48,620
and we import that.

34
00:02:48,910 --> 00:02:58,510
So kids learn a library and we need a couple of objects from theirs, which we'll use later on down

35
00:02:58,510 --> 00:02:58,780
here.

36
00:02:59,200 --> 00:03:07,070
We download some datasets which contain words and phrases in English.

37
00:03:07,420 --> 00:03:14,650
So the Chad Bolton needs this information to be able to understand the questions that we ask.

38
00:03:15,010 --> 00:03:19,090
But the user asks, and then we got this text here.

39
00:03:19,600 --> 00:03:26,860
So that is a corpus, the knowledge currently of the Chad, but we're going to replace that with content

40
00:03:26,860 --> 00:03:28,420
from a Wikipedia article.

41
00:03:28,600 --> 00:03:29,830
You'll see how we do that.

42
00:03:29,980 --> 00:03:31,360
And then we have this question here.

43
00:03:31,360 --> 00:03:32,230
What are plans?

44
00:03:32,650 --> 00:03:40,810
Then we created a limited times, for instance, in here, a Lyma function, which converts the words

45
00:03:40,810 --> 00:03:41,890
of a sentence.

46
00:03:42,100 --> 00:03:50,530
It confers the words into lammas, for example, if the word is or or is the limo that is B, so it

47
00:03:50,890 --> 00:03:56,050
finds out the roots of the words given a sentence.

48
00:03:56,260 --> 00:03:58,540
So it's returns a list of lenders.

49
00:04:00,670 --> 00:04:08,590
Afterwards, we tokenized the text, so we make a list of sentences.

50
00:04:09,070 --> 00:04:10,480
So this sends us.

51
00:04:10,480 --> 00:04:13,630
Tokens will be a list of three items because we have three sentences.

52
00:04:13,810 --> 00:04:19,019
So each item is a shrink representing one of the sentences and then we append the question.

53
00:04:19,029 --> 00:04:21,519
So that's question we appended to that list.

54
00:04:21,790 --> 00:04:25,990
So from a list of three items, we end up with a list of four items.

55
00:04:27,460 --> 00:04:37,420
Then we apply the algorithm, which finds a coefficient which denotes the importance of each word in

56
00:04:37,420 --> 00:04:39,940
that texts.

57
00:04:40,990 --> 00:04:42,160
Plus the question.

58
00:04:42,400 --> 00:04:47,920
So it's a touch use a coefficient to each words to denote the importance of the words.

59
00:04:48,110 --> 00:04:55,900
And then it finds a similarity between the last sentence, which is the question and the entire text.

60
00:04:56,560 --> 00:05:01,780
So it finds out the similarity between the question and each of the sentences.

61
00:05:02,680 --> 00:05:06,690
And then we sort it out by the coefficient.

62
00:05:06,710 --> 00:05:13,270
The values of the greatest coefficient means there's more similarity, so we sort that out and we find

63
00:05:14,080 --> 00:05:17,060
the index that has some maximum coefficients.

64
00:05:17,080 --> 00:05:25,540
And then if the coefficient is greater than zero point three, then we return from that sort of list

65
00:05:25,540 --> 00:05:26,500
of sentences.

66
00:05:26,500 --> 00:05:33,730
We return the least that has that index, the index that points to the sentence with the highest coefficients.

67
00:05:34,000 --> 00:05:40,990
So basically, we are calculating we are finding out the sentence between these three, a sentence that

68
00:05:41,020 --> 00:05:43,300
is the most similar to the question.

69
00:05:44,260 --> 00:05:45,820
So that's how we find the answer.

70
00:05:46,540 --> 00:05:47,350
If I run that.

71
00:05:50,080 --> 00:05:56,350
You see that this is a sentence that the program chose as the best answer for this question.

72
00:05:56,560 --> 00:06:01,000
Water plants, vegetables are all plants or vegetables.

73
00:06:06,250 --> 00:06:08,650
And I expect to get the same answer.

74
00:06:09,670 --> 00:06:20,600
So that and maybe another question, can you eat vegetables run?

75
00:06:21,250 --> 00:06:23,620
I expect to get this as an answer this time.

76
00:06:27,190 --> 00:06:28,660
Yes, that's the case.

77
00:06:29,080 --> 00:06:29,800
So it's working.

78
00:06:30,220 --> 00:06:36,490
Now let's turn this program into an interactive chat bot that gets questions.

79
00:06:37,150 --> 00:06:44,680
It waits for questions from us and it returns, answers, it asks us again and so on to implement that

80
00:06:44,680 --> 00:06:45,910
interactivity.

81
00:06:47,050 --> 00:06:54,460
What we need to do is go down here and implement a while loop that runs all the time and it's asks a

82
00:06:54,460 --> 00:06:55,630
question of.

83
00:06:58,690 --> 00:06:59,290
Hi.

84
00:07:02,280 --> 00:07:05,250
What do you want to know?

85
00:07:07,860 --> 00:07:13,560
And I'll add a backslash end to make a brake line after this question.

86
00:07:13,740 --> 00:07:14,960
So it's an input function.

87
00:07:14,970 --> 00:07:17,400
If I run this, you'll see how of this changes.

88
00:07:19,190 --> 00:07:19,850
The output.

89
00:07:22,110 --> 00:07:26,130
So we get the answer first from the program and then we get this question.

90
00:07:26,340 --> 00:07:27,510
I will do want to know.

91
00:07:27,900 --> 00:07:34,950
So if we enter a question, can you eat vegetables?

92
00:07:35,250 --> 00:07:36,230
Nothing will happen.

93
00:07:36,260 --> 00:07:41,220
The Chad both will keep asking questions because that's what this wire loop does.

94
00:07:41,520 --> 00:07:43,480
It's iterates all the time.

95
00:07:43,530 --> 00:07:47,100
It is this over and over again.

96
00:07:47,400 --> 00:07:53,980
So instead of letting this loop iterate, we want to add something else in here.

97
00:07:54,420 --> 00:07:59,820
We want to send this question to the algorithm for processing.

98
00:08:00,240 --> 00:08:05,370
However, we cannot do that given the structure of the codes.

99
00:08:05,970 --> 00:08:12,570
So what we need to do is we need to put all this codes where we took a nicer sentence and where we append

100
00:08:12,570 --> 00:08:17,160
the question to the sentence tokenized list.

101
00:08:17,460 --> 00:08:18,480
So we need to in.

102
00:08:18,480 --> 00:08:26,400
Then that's I selected it and I press tab and I put it in a function defined process so that it's a

103
00:08:26,400 --> 00:08:26,970
function.

104
00:08:27,480 --> 00:08:36,799
The role the purpose of this function is to get the text tokenized it as the question to the texts and

105
00:08:36,809 --> 00:08:41,010
then find the similarity between the question and the text.

106
00:08:41,460 --> 00:08:44,130
So it's processing the question and the texts.

107
00:08:44,490 --> 00:08:48,510
Therefore, it makes sense to have two parameters text and question.

108
00:08:49,530 --> 00:08:52,350
Therefore, let me put the column there.

109
00:08:52,830 --> 00:09:00,930
Therefore, now we can do something like the output, a single to process.

110
00:09:01,620 --> 00:09:04,080
So that's a function we call that function.

111
00:09:04,530 --> 00:09:09,120
The text will be equal to the text variable.

112
00:09:09,570 --> 00:09:15,660
So texts is this parameter name and text.

113
00:09:15,780 --> 00:09:17,190
The second text is.

114
00:09:18,600 --> 00:09:21,300
This variable, which contains the corpus.

115
00:09:23,940 --> 00:09:28,290
So that spirometry sequel to that big string there.

116
00:09:28,680 --> 00:09:31,020
And same for the question.

117
00:09:32,970 --> 00:09:34,830
Question a sequel to question.

118
00:09:35,760 --> 00:09:39,360
You can also just leave it like that text and question.

119
00:09:40,200 --> 00:09:42,270
And it's basically the same thing.

120
00:09:43,650 --> 00:09:48,620
So we did the output, but this function is not returning anything yet.

121
00:09:48,930 --> 00:09:52,020
It's pre-installed something, but it's not a written statement.

122
00:09:52,170 --> 00:09:57,450
So you want to convert that into a written statement instead of print.

123
00:09:58,470 --> 00:10:10,590
So no, this piece of code here is equal to that of VAT returns the best sentence that matches the question.

124
00:10:11,370 --> 00:10:19,710
So outputs is the best centers of the most similar sentence, though therefore what we can do is print

125
00:10:19,710 --> 00:10:21,720
out the outputs stop.

126
00:10:23,580 --> 00:10:24,720
And to run again.

127
00:10:27,410 --> 00:10:28,460
Hi, what do you want to know?

128
00:10:28,970 --> 00:10:32,210
Can you eat vegetables?

129
00:10:36,750 --> 00:10:40,440
Vegetables can be eaten either raw or cooked, so it's working.

130
00:10:40,710 --> 00:10:45,270
It got the best answer from this texts, which makes sense.

131
00:10:45,390 --> 00:10:46,710
Yeah, that one.

132
00:10:47,550 --> 00:10:54,030
So that means we don't need this static declaration here because we are getting the question from the

133
00:10:54,030 --> 00:10:54,270
user.

134
00:10:54,280 --> 00:10:55,560
Not so delete that.

135
00:10:56,820 --> 00:11:00,210
And what else can we add here?

136
00:11:01,230 --> 00:11:08,250
Well, sometimes you can ask of the user can ask irrelevant questions such as You have Facebook.

137
00:11:11,720 --> 00:11:13,430
And you get none.

138
00:11:14,480 --> 00:11:17,810
We get none because of this question.

139
00:11:18,560 --> 00:11:24,020
This sentence does not have a coefficient of greater than 0.3.

140
00:11:25,100 --> 00:11:30,950
So what happens in that case is this function will return a non object.

141
00:11:31,520 --> 00:11:34,880
So that is the equivalent of saying else return.

142
00:11:35,360 --> 00:11:35,810
None.

143
00:11:36,770 --> 00:11:43,370
So whether you write this part or not, the function will still return non-avian if you don't write

144
00:11:43,370 --> 00:11:49,100
this part, therefore, we can see if outputs.

145
00:11:51,260 --> 00:11:59,000
Then print out the output, so if outputs means if the output is not known, if it's none, this will

146
00:11:59,000 --> 00:12:00,230
not be executed.

147
00:12:01,130 --> 00:12:08,030
So this is the equivalent of seeing if output is different from NAND, then you execute that.

148
00:12:08,270 --> 00:12:14,180
But this is more polyphonic if outputs than print outputs.

149
00:12:14,840 --> 00:12:17,270
And I'll also like to add something else.

150
00:12:18,060 --> 00:12:29,090
If question is equal to qubits, so if the user enters qubits, quits will be saved in the question

151
00:12:29,090 --> 00:12:29,510
variable.

152
00:12:29,510 --> 00:12:37,780
So if it's quits, then we break the loop, the wire loop and the program ends else print.

153
00:12:38,780 --> 00:12:40,670
I don't know.

154
00:12:41,960 --> 00:12:49,670
So we have three scenarios where the output exists, when the user enters quits or when the output doesn't

155
00:12:49,670 --> 00:12:50,240
exist.

156
00:12:50,570 --> 00:12:54,260
So there is not a similar question to that question.

157
00:12:57,100 --> 00:12:58,090
What do you want to know?

158
00:12:58,540 --> 00:13:02,290
Can you eat vegetables?

159
00:13:03,310 --> 00:13:09,550
The chat bots answer us with this, and then it asks again, the same question Hi, what do you want

160
00:13:09,550 --> 00:13:09,910
to know?

161
00:13:10,550 --> 00:13:17,230
Um, well, how can I fix my pants zipper?

162
00:13:19,310 --> 00:13:22,280
The chatbot doesn't know that, of course, we get vets.

163
00:13:22,670 --> 00:13:26,570
And lastly, let's try quit and the program quits.

164
00:13:27,600 --> 00:13:32,780
No, we're working so far on these limited techs here.

165
00:13:33,980 --> 00:13:37,550
So how can we replace that with a content from a Wikipedia article?

166
00:13:38,000 --> 00:13:44,540
We can do that by importing Wikipedia, let's say, third party library.

167
00:13:44,900 --> 00:13:55,840
And then instead of texts, you see, Wikipedia told Page, What's page do you want to have here?

168
00:13:56,840 --> 00:13:57,350
Vegetables.

169
00:13:57,360 --> 00:13:59,840
So this chatbot knows about vegetables.

170
00:14:00,170 --> 00:14:03,350
You can also find ways to make this dynamic.

171
00:14:03,710 --> 00:14:08,480
So to us of the user first what topic they want to know about.

172
00:14:08,480 --> 00:14:11,930
And then you answer that topic in here as a string.

173
00:14:12,980 --> 00:14:16,490
And then you start the conversation again.

174
00:14:16,490 --> 00:14:20,180
What do you want to know about that topic that the user chose?

175
00:14:20,330 --> 00:14:23,750
But for this, let's keep it simple and just talk about vegetables.

176
00:14:24,680 --> 00:14:34,370
So vegetables, not content that will give you the Wikipedia content about vegetables stored in the

177
00:14:34,370 --> 00:14:35,150
text available.

178
00:14:35,480 --> 00:14:40,370
So now we can talk about more things with our Chad Wood.

179
00:14:41,500 --> 00:14:44,410
Let's see what you want to know.

180
00:14:44,740 --> 00:14:48,220
Are there vitamins in?

181
00:14:49,350 --> 00:14:50,010
Vegetables.

182
00:14:53,590 --> 00:14:57,520
And we get this answer, which is about vitamins.

183
00:15:01,780 --> 00:15:08,470
So it's something that the Chad both gets from the Wikipedia article, of course, and some people may

184
00:15:08,470 --> 00:15:09,570
find it's limited.

185
00:15:10,480 --> 00:15:18,040
The best bits of gets a very, very accurate answer for this like yes or no or yes, there are vitamins.

186
00:15:18,790 --> 00:15:20,770
But I think this is still very good.

187
00:15:21,730 --> 00:15:24,040
So it's quite an accurate match.

188
00:15:24,430 --> 00:15:32,920
Give the sentences you you find in the Wikipedia articles of vegetables, so all that content is used

189
00:15:32,920 --> 00:15:33,970
by the chat boards.

190
00:15:36,310 --> 00:15:37,840
So that concludes this video.

191
00:15:37,840 --> 00:15:40,840
I thank you for following, and I'll talk to you later.

