-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsc-openai-c2-L5-vid6_1.srt
1653 lines (1301 loc) · 31.1 KB
/
sc-openai-c2-L5-vid6_1.srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1
00:00:05,166 --> 00:00:07,666
In this video, we'll learn how to split
complex
2
00:00:07,666 --> 00:00:11,966
tasks into a series of simpler subtasks
by chaining multiple prompts together.
3
00:00:12,733 --> 00:00:16,033
You might be wondering why would you split
up a task into multiple prompts
4
00:00:16,200 --> 00:00:18,000
when you could achieve it with one prompt
5
00:00:18,000 --> 00:00:20,700
and chain of thought reasoning
like we learned in the previous video?
6
00:00:21,300 --> 00:00:24,300
We've already shown that language
models are very good at following complex
7
00:00:24,300 --> 00:00:27,600
instructions, especially the more advanced
models like GPT four.
8
00:00:28,466 --> 00:00:31,400
So let me explain why we would do this
with two analogies
9
00:00:31,400 --> 00:00:34,366
comparing chain of thought,
reasoning and chaining multiple prompts.
10
00:00:34,866 --> 00:00:37,433
The first analogy to compare
the two is the difference between
11
00:00:37,433 --> 00:00:41,066
cooking a complex meal in one go versus
cooking it in stages.
12
00:00:41,866 --> 00:00:45,133
Using one long, complicated instruction
can be like trying
13
00:00:45,133 --> 00:00:48,200
to cook a complex meal all at once
while you have to manage
14
00:00:48,200 --> 00:00:52,100
multiple ingredients, cooking techniques
and timings simultaneously.
15
00:00:52,533 --> 00:00:53,366
It can be challenging
16
00:00:53,366 --> 00:00:56,700
to keep track of everything and ensure
that each component is cooked perfectly.
17
00:00:57,400 --> 00:01:00,433
Training prompts, on the other hand,
is like cooking the meal in stages
18
00:01:00,733 --> 00:01:03,433
where you focus on one component
at a time, ensuring
19
00:01:03,433 --> 00:01:06,000
that each part is cooked
correctly before moving on to the next.
20
00:01:06,600 --> 00:01:09,133
This approach breaks down
the complexity of the task,
21
00:01:09,133 --> 00:01:12,033
making it easier to manage
and reducing the likelihood of errors.
22
00:01:12,466 --> 00:01:14,666
However,
this approach might be unnecessary
23
00:01:14,666 --> 00:01:16,800
and overcomplicated
for a very simple recipe.
24
00:01:17,700 --> 00:01:20,966
A slightly better analogy for the same
thing is the difference between reading
25
00:01:20,966 --> 00:01:25,133
spaghetti code with everything in one long
file and a simple modular program.
26
00:01:25,633 --> 00:01:28,433
The thing that can make spaghetti code bad
and difficult to debug
27
00:01:28,566 --> 00:01:32,200
is ambiguity and complex dependencies
between different parts of the logic.
28
00:01:32,600 --> 00:01:36,600
The same can be true of a complex single
step task submitted to a language model.
29
00:01:37,233 --> 00:01:39,466
Chaining problems is a powerful strategy.
30
00:01:39,466 --> 00:01:40,666
When you have a workflow
31
00:01:40,666 --> 00:01:43,800
where you can maintain
the state of the system at any given point
32
00:01:44,000 --> 00:01:46,366
and take different actions
depending on the current state.
33
00:01:46,800 --> 00:01:50,100
And so an example of the current state
would be after you've classified
34
00:01:50,100 --> 00:01:54,366
an incoming customer query,
the state would be the classification.
35
00:01:54,366 --> 00:01:58,200
So the it's an account question
or it's a product question.
36
00:01:58,200 --> 00:02:00,400
And then based on the state,
you might do something different.
37
00:02:01,733 --> 00:02:04,466
Each subtasks
contains only the instructions required
38
00:02:04,466 --> 00:02:08,000
for a single state of the task,
which makes the system easier to manage.
39
00:02:08,366 --> 00:02:09,333
Make sure the model has
40
00:02:09,333 --> 00:02:12,333
all the information
it needs to carry out a task and reduces
41
00:02:12,333 --> 00:02:13,800
the likelihood of errors.
42
00:02:13,800 --> 00:02:17,666
As I mentioned, this approach
can also reduce and lower costs
43
00:02:17,866 --> 00:02:20,633
since longer problems
with more tokens cost more to run.
44
00:02:20,900 --> 00:02:24,000
And outlining all steps
might be unnecessary in some cases.
45
00:02:24,600 --> 00:02:27,966
Another benefit of this approach
is that it is also easier to test
46
00:02:27,966 --> 00:02:31,533
which steps might be failing more often,
or to have a human in the loop
47
00:02:31,766 --> 00:02:33,166
at a specific step.
48
00:02:33,166 --> 00:02:35,633
So to summarize,
because this is a long explanation.
49
00:02:35,900 --> 00:02:39,000
Instead of describing a whole complex
workflow and dozens of bullet points
50
00:02:39,000 --> 00:02:42,000
or several paragraphs in one prompt,
like in the previous video,
51
00:02:42,233 --> 00:02:44,833
it might be better
to keep track of the state externally
52
00:02:45,000 --> 00:02:47,400
and then inject relevant
instructions as needed.
53
00:02:48,066 --> 00:02:50,133
And what makes a problem complex?
54
00:02:50,566 --> 00:02:52,400
I think in general a problem is complex.
55
00:02:52,400 --> 00:02:54,166
If there are many different instructions
56
00:02:54,166 --> 00:02:57,800
and potentially all of them could apply
to any given situation, as these
57
00:02:57,800 --> 00:03:01,200
are the cases where it could become hard
for the model to reason about what to do.
58
00:03:01,233 --> 00:03:03,500
And as you build with and interact
with these models more,
59
00:03:03,700 --> 00:03:06,800
you'll gain an intuition for when
to use this strategy versus the previous.
60
00:03:07,300 --> 00:03:09,500
And one additional benefit
that I didn't mention yet
61
00:03:09,833 --> 00:03:13,200
is that it also allows the model
to use external tools
62
00:03:13,400 --> 00:03:15,833
at certain points of the workflow
if necessary.
63
00:03:16,200 --> 00:03:18,900
For example,
it might decide to look something up
64
00:03:18,900 --> 00:03:22,566
in a product catalog
or call an API or search a knowledge base,
65
00:03:22,933 --> 00:03:25,033
something that could not be achieved
with a single prompt.
66
00:03:25,933 --> 00:03:27,900
So with that, let's dive into an example.
67
00:03:29,000 --> 00:03:31,866
So we're going to use the same example
as in the previous video
68
00:03:31,866 --> 00:03:34,933
when we want to answer a customer's
question about a specific product.
69
00:03:35,300 --> 00:03:38,100
But this time we'll use more products
and also break the steps
70
00:03:38,100 --> 00:03:40,566
down into a number of different prompts.
71
00:03:42,366 --> 00:03:43,966
So we'll use the same delimiter
72
00:03:43,966 --> 00:03:46,200
that we've been using
in the previous videos,
73
00:03:47,700 --> 00:03:51,433
and that's read through our system
message.
74
00:03:53,033 --> 00:03:55,200
You will be provided with customer service
queries.
75
00:03:55,466 --> 00:03:59,700
The customer service query will be
delimited with four hashtag characters.
76
00:04:00,366 --> 00:04:03,700
I'll put a python list of objects
where each object has the following format
77
00:04:05,100 --> 00:04:08,466
category,
which is one of these predefined fields
78
00:04:09,333 --> 00:04:12,400
or products and this is a list of products
79
00:04:12,400 --> 00:04:14,800
that must be found in the allowed products
below.
80
00:04:14,800 --> 00:04:18,000
While the categories and products must be
found in the customer service query.
81
00:04:19,600 --> 00:04:21,633
If a product
does mentioned, it must be associated
82
00:04:21,633 --> 00:04:24,100
with the correct category
in the allowed products list below.
83
00:04:24,566 --> 00:04:27,400
If no products or categories
are found, output an empty list.
84
00:04:27,866 --> 00:04:30,533
So now we have allowed list of products.
85
00:04:30,566 --> 00:04:35,833
So we have the categories and
then the products within those categories.
86
00:04:35,900 --> 00:04:38,066
Now, final instruction is only output.
87
00:04:38,066 --> 00:04:41,533
The list of objects with nothing else.
88
00:04:43,566 --> 00:04:45,966
So next we have our user message.
89
00:04:45,966 --> 00:04:47,766
And so this messages.
90
00:04:47,766 --> 00:04:52,800
Tell me about the small x profile on
the photo is not camera the DSL one.
91
00:04:53,166 --> 00:04:55,200
Also tell me about your TV's.
92
00:04:55,200 --> 00:04:57,966
So we're asking
about two specific products
93
00:04:58,733 --> 00:05:02,166
and also the general category
of televisions
94
00:05:03,500 --> 00:05:07,133
on both of these products are mentioned
in the allowed products list.
95
00:05:07,600 --> 00:05:13,033
Then we have a television section as well,
96
00:05:13,033 --> 00:05:17,333
and we format the system message
and user message into the messages array,
97
00:05:18,066 --> 00:05:24,900
and then we get the completion
from the model.
98
00:05:24,900 --> 00:05:30,366
So as you can see for our output,
we have a list of objects
99
00:05:30,833 --> 00:05:34,633
and each object has category and products.
100
00:05:35,033 --> 00:05:37,600
So we have the small X pro phone
101
00:05:38,000 --> 00:05:41,633
and the photo snapped DSLR camera.
102
00:05:41,966 --> 00:05:44,700
And then in the final object
we actually only have a category
103
00:05:44,700 --> 00:05:46,766
because we didn't
mention any specific TVs.
104
00:05:47,833 --> 00:05:48,366
And so
105
00:05:48,366 --> 00:05:52,433
the benefit of outputting
this structured response is that we can
106
00:05:52,433 --> 00:05:57,866
then read it into a list in Python,
which is very nice.
107
00:05:58,433 --> 00:06:01,200
And so let's try another example.
108
00:06:01,500 --> 00:06:04,266
So our second user message is
109
00:06:05,900 --> 00:06:07,800
my router isn't working.
110
00:06:07,800 --> 00:06:10,833
And if you notice in the list,
we don't actually have any routers
111
00:06:11,766 --> 00:06:13,033
and then
112
00:06:14,000 --> 00:06:20,400
format this correctly
and get the completion.
113
00:06:20,400 --> 00:06:23,866
And so as you can see in this case,
the output is an empty list.
114
00:06:25,300 --> 00:06:28,700
And so now that we have this step
to identify the category and products,
115
00:06:29,533 --> 00:06:32,700
if we find any products and categories,
we want to note some information
116
00:06:32,700 --> 00:06:35,666
about those requested products
and categories into the prompt
117
00:06:35,700 --> 00:06:38,233
so that we can better
answer the customer question.
118
00:06:38,233 --> 00:06:42,033
And so in our workflow,
the state now after this prompt is run
119
00:06:42,300 --> 00:06:45,533
as either products have been listed
or they haven't been listed.
120
00:06:45,800 --> 00:06:46,800
And in that case
121
00:06:46,800 --> 00:06:50,400
we wouldn't try to look anything up
because there's nothing to look up.
122
00:06:50,566 --> 00:06:52,900
Well, so if I were to actually build this
into a system,
123
00:06:52,900 --> 00:06:56,700
I might use category
names, maybe something like
124
00:06:57,700 --> 00:07:00,666
computers and laptops or something
125
00:07:01,633 --> 00:07:04,933
to avoid any weirdness
with spaces and special characters.
126
00:07:05,400 --> 00:07:07,333
But this should work for now.
127
00:07:07,333 --> 00:07:09,200
So now we want to look up some information
128
00:07:09,200 --> 00:07:10,966
about the products
that the user mentioned.
129
00:07:10,966 --> 00:07:14,233
So about this phone, this camera,
and about the TV's in general.
130
00:07:14,900 --> 00:07:15,833
And so we need to have
131
00:07:15,833 --> 00:07:18,300
some kind of product catalog
to look up this information from.
132
00:07:18,833 --> 00:07:20,833
So here we have our product information.
133
00:07:21,266 --> 00:07:24,466
I just paste it in.
134
00:07:24,466 --> 00:07:26,866
So as you can see,
we have a large number of products
135
00:07:28,733 --> 00:07:32,200
available at our store
136
00:07:32,500 --> 00:07:34,600
and all of these products are fake
137
00:07:34,600 --> 00:07:36,900
and were actually generated by GBG for.
138
00:07:37,933 --> 00:07:40,933
And so for each product
we have a couple of different fields.
139
00:07:40,933 --> 00:07:43,566
We have name category, brand
140
00:07:44,166 --> 00:07:46,500
warranty and so on.
141
00:07:46,800 --> 00:07:50,133
And so the products is just a dictionary
from product name
142
00:07:50,433 --> 00:07:53,700
to this object that contains
the information about the product.
143
00:07:54,933 --> 00:07:57,133
And notice
that each product has a category.
144
00:07:57,633 --> 00:07:59,533
So remember,
we want to look up information
145
00:07:59,533 --> 00:08:01,433
about the products
that the user asks about.
146
00:08:01,433 --> 00:08:05,300
So we need to define some helper functions
to allow us to look up
147
00:08:05,700 --> 00:08:08,666
product information by product name.
148
00:08:08,666 --> 00:08:10,866
So let's create a function
149
00:08:10,866 --> 00:08:13,366
gap, product by name,
150
00:08:14,533 --> 00:08:16,766
the input the name,
151
00:08:16,866 --> 00:08:19,366
and then we're going to return
152
00:08:19,366 --> 00:08:22,733
product dictionary
and we're going to get the value
153
00:08:22,966 --> 00:08:26,400
for the item with the name as the key.
154
00:08:26,400 --> 00:08:28,933
And then I'll pull
back is just going to be none.
155
00:08:29,266 --> 00:08:32,000
And so we also want to define
another helper function
156
00:08:32,000 --> 00:08:34,366
to get all of the products
for a certain category.
157
00:08:34,366 --> 00:08:35,333
For example,
158
00:08:35,333 --> 00:08:37,500
when the user is asking about the TVs
we have,
159
00:08:37,500 --> 00:08:40,966
we want to load all of the information
about all of the different TVs.
160
00:08:42,400 --> 00:08:45,266
So get products
161
00:08:45,266 --> 00:08:47,100
by category,
162
00:08:47,133 --> 00:08:51,000
the input, the category name string.
163
00:08:51,000 --> 00:08:55,300
And to do this, we want to look through
all of the products
164
00:08:55,300 --> 00:08:58,300
in the product's dictionary and check
165
00:08:59,100 --> 00:09:02,366
each one to see if the category
is equal to the input category.
166
00:09:02,366 --> 00:09:04,666
And if so, we want to return that.
167
00:09:04,666 --> 00:09:07,233
So we'll do this as follows.
168
00:09:07,766 --> 00:09:12,000
So first we want to loop through
each product and we have to get the values
169
00:09:12,000 --> 00:09:16,833
because we need to actually
access the category, which is the value.
170
00:09:18,033 --> 00:09:21,300
And then we'll return this product.
171
00:09:21,300 --> 00:09:23,633
If the product
172
00:09:25,166 --> 00:09:27,200
category
173
00:09:28,500 --> 00:09:30,800
is equal to
174
00:09:30,966 --> 00:09:36,900
our input category.
175
00:09:36,900 --> 00:09:38,533
So let's
176
00:09:39,066 --> 00:09:41,400
do an example
for each of these helper functions.
177
00:09:42,033 --> 00:09:43,800
So first
178
00:09:44,433 --> 00:09:46,866
we have a product called the Tech pro
Ultrabook,
179
00:09:47,166 --> 00:09:51,766
so let's get the product information
by name.
180
00:09:51,766 --> 00:09:54,600
So here you can see we've just fetched all
of the product information
181
00:09:57,033 --> 00:10:00,533
and let's do an example to
get all of the products for our category.
182
00:10:00,533 --> 00:10:07,000
So let's get all of the products
in the computers and laptops category.
183
00:10:07,000 --> 00:10:09,700
Hey, you see,
we fetched one of the products
184
00:10:10,233 --> 00:10:16,800
with this category.
185
00:10:16,800 --> 00:10:20,833
So let's continue our example.
186
00:10:20,833 --> 00:10:24,000
And just to remember where we are,
that's the user message.
187
00:10:24,300 --> 00:10:27,166
So the user message was
tell me about the smart X pro
188
00:10:27,200 --> 00:10:29,733
phone on the camera, on the TVs.
189
00:10:30,300 --> 00:10:32,900
And then the initial output from the model
190
00:10:32,900 --> 00:10:34,900
from the first step was this.
191
00:10:36,033 --> 00:10:37,966
And so what we also need to do
192
00:10:37,966 --> 00:10:40,800
is read this output from the model,
which is a string.
193
00:10:41,066 --> 00:10:45,100
We need to pass that into a list
so that we can use it as input
194
00:10:45,500 --> 00:10:49,066
to the help of functions
that we just wrote.
195
00:10:49,066 --> 00:10:54,733
So that's why
a helper function to do this.
196
00:10:54,733 --> 00:10:56,300
So we're going to use the Python
197
00:10:57,366 --> 00:11:00,366
JSON module and we're going to write
a function
198
00:11:00,366 --> 00:11:03,166
called read string to list and very
199
00:11:04,200 --> 00:11:05,500
descriptive title.
200
00:11:05,500 --> 00:11:09,700
The input string.
201
00:11:09,700 --> 00:11:12,900
And so first we'll just check
if the input string
202
00:11:12,900 --> 00:11:13,966
is non
203
00:11:15,900 --> 00:11:17,966
in case something in the previous step
failed.
204
00:11:17,966 --> 00:11:20,900
We're just going to return nothing
205
00:11:22,133 --> 00:11:22,466
and now
206
00:11:22,466 --> 00:11:24,766
we're going to have a try except block
207
00:11:25,833 --> 00:11:29,366
to make sure that we catch any errors.
208
00:11:29,366 --> 00:11:31,500
And so first
209
00:11:31,500 --> 00:11:36,400
we replace any single quotes
with double quotes in the input string
210
00:11:36,900 --> 00:11:42,033
to make sure we can pass the Jason
and then we're going to use the JSON nodes
211
00:11:42,033 --> 00:11:46,766
function to read the input string
into the array or the left.
212
00:11:47,266 --> 00:11:49,233
And then we're going to return this.
213
00:11:49,233 --> 00:11:54,100
And if there's a decode error, we're going
to print the error and then return non.
214
00:11:55,533 --> 00:11:57,700
So let's try this with our example.
215
00:11:58,366 --> 00:12:05,700
So we're going to get our category
and product list using the read string
216
00:12:05,700 --> 00:12:10,300
to list helper function and apply it
to this response from the model.