WEBVTT

1
00:00:00.000 --> 00:00:08.120
So we've seen that the text completions models are pretty flexible, and can do much more than answer questions.

2
00:00:08.120 --> 00:00:13.040
In this lesson, we'll take this a step further to discuss classification tasks.

3
00:00:13.040 --> 00:00:13.040


4
00:00:13.040 --> 00:00:14.040


5
00:00:14.040 --> 00:00:19.400
Classification tasks involve assigning a label to a piece of information.

6
00:00:19.400 --> 00:00:24.760
This can be identification, such as identifying the language used in a piece of text,

7
00:00:24.760 --> 00:00:31.040
categorization, such as sorting geographical locations into countries and US states, or

8
00:00:31.040 --> 00:00:37.240
even classifying a statement's sentiment, that is, whether it sounds positive or negative.

9
00:00:37.240 --> 00:00:37.240


10
00:00:37.240 --> 00:00:37.240


11
00:00:37.240 --> 00:00:42.160
The Completions endpoint can be used for all of these tasks, providing the model has

12
00:00:42.160 --> 00:00:47.320
sufficient knowledge of the subject area and that the prompt contains the necessary context.

13
00:00:47.320 --> 00:00:48.280


14
00:00:48.280 --> 00:00:48.280


15
00:00:48.280 --> 00:00:51.600
Let's use the Completions endpoint to categorize these animals.

16
00:00:51.600 --> 00:00:51.600


17
00:00:51.600 --> 00:00:51.600


18
00:00:51.600 --> 00:00:59.760
Printing the response, we see that the model categorized the animals into mammals, fish, and reptiles.

19
00:00:59.760 --> 00:00:59.760


20
00:00:59.760 --> 00:00:59.760


21
00:00:59.760 --> 00:01:03.840
This might be what we were looking for, but there's an almost infinite number of ways

22
00:01:03.840 --> 00:01:09.280
to categorize something, so it's best practice to state the desired categories in the prompt.

23
00:01:09.280 --> 00:01:10.320


24
00:01:10.320 --> 00:01:10.320


25
00:01:10.320 --> 00:01:13.920
We can update the prompt to categorize animals into those with

26
00:01:13.920 --> 00:01:15.720
and without fur,

27
00:01:15.720 --> 00:01:15.720


28
00:01:15.720 --> 00:01:19.280
and the model responds with the desired categories.

29
00:01:19.280 --> 00:01:19.280


30
00:01:19.280 --> 00:01:19.320


31
00:01:19.320 --> 00:01:22.840
Let's look at an example of classifying sentiment.

32
00:01:22.840 --> 00:01:27.200
Let's say we received a number of online reviews to our restaurant, and we

33
00:01:27.200 --> 00:01:32.560
want to extract the sentiment, as numbers one to five, for further analysis.

34
00:01:32.560 --> 00:01:32.560


35
00:01:32.560 --> 00:01:32.560


36
00:01:32.560 --> 00:01:36.680
We can write a prompt with the instruction to classify sentiment, and a

37
00:01:36.680 --> 00:01:37.800
list of statements,

38
00:01:37.800 --> 00:01:37.800


39
00:01:37.800 --> 00:01:40.320
pass it to the Completions endpoint,

40
00:01:40.320 --> 00:01:40.680


41
00:01:40.680 --> 00:01:41.720
and print the response.

42
00:01:41.720 --> 00:01:41.720


43
00:01:41.720 --> 00:01:42.840


44
00:01:42.840 --> 00:01:47.000
The model does a good job; however, because we didn't specify how to

45
00:01:47.000 --> 00:01:52.720
classify the categories, the model didn't realize we actually wanted a numerical output.

46
00:01:52.720 --> 00:01:52.720


47
00:01:52.720 --> 00:01:54.120


48
00:01:54.120 --> 00:01:58.920
We can update our prompt so the model has the context on what the categories should be.

49
00:01:58.920 --> 00:01:58.920


50
00:01:58.920 --> 00:01:58.920


51
00:01:58.920 --> 00:02:06.280
The updated response contains a reasonable numerical representation of the sentiment of each statement.

52
00:02:06.280 --> 00:02:06.280


53
00:02:06.280 --> 00:02:07.320


54
00:02:07.320 --> 00:02:12.760
The prompts we've used so far are examples of a so-called zero-shot prompts,

55
00:02:12.760 --> 00:02:16.960
where we haven't provided any examples in the prompt for the model to learn from.

56
00:02:16.960 --> 00:02:16.960


57
00:02:16.960 --> 00:02:16.960


58
00:02:16.960 --> 00:02:24.120
For many use cases, this may be fine, but for more complex cases where the model may not have a

59
00:02:24.120 --> 00:02:29.920
good understanding of the subject matter or task, we may need to provide examples for it to learn from.

60
00:02:29.920 --> 00:02:29.920


61
00:02:29.920 --> 00:02:29.920


62
00:02:29.920 --> 00:02:32.800
If one example is provided in the

63
00:02:32.800 --> 00:02:38.680
prompt, it's called one-shot prompting, and for more than one, it's called few-shot prompting.

64
00:02:38.680 --> 00:02:38.680


65
00:02:38.680 --> 00:02:38.680


66
00:02:38.680 --> 00:02:43.480
Providing examples in the prompt for the model to learn from is called

67
00:02:43.480 --> 00:02:48.920
in-context learning, as the model is learning from the context we're providing.

68
00:02:48.920 --> 00:02:48.920


69
00:02:48.920 --> 00:02:48.920


70
00:02:48.920 --> 00:02:54.080
Let's return to sentiment analysis to give these prompting techniques a go.

71
00:02:54.080 --> 00:02:54.080


72
00:02:54.080 --> 00:02:54.080


73
00:02:54.080 --> 00:03:01.040
We're again dealing with restaurant reviews, but this time, we want the sentiment to be more specific.

74
00:03:01.040 --> 00:03:01.040


75
00:03:01.040 --> 00:03:01.040


76
00:03:01.040 --> 00:03:08.040
To do this, we provide one example in the prompt, clearly separating the input and output.

77
00:03:08.040 --> 00:03:08.040


78
00:03:08.040 --> 00:03:08.040


79
00:03:08.040 --> 00:03:12.560
Sending this to the Completions endpoint and printing the result

80
00:03:12.560 --> 00:03:12.560


81
00:03:12.560 --> 00:03:14.600
shows that the model accurately

82
00:03:14.600 --> 00:03:20.840
analyzed the statement, but that it didn't provide any more detail than when we used a zero-shot prompt.

83
00:03:20.840 --> 00:03:20.840


84
00:03:20.840 --> 00:03:20.840


85
00:03:20.840 --> 00:03:26.000
In more complex cases, one example is not enough, and we'll need to

86
00:03:26.000 --> 00:03:30.480
experiment to determine the number of shots the model needs for the use case.

87
00:03:30.480 --> 00:03:30.480


88
00:03:30.480 --> 00:03:30.480


89
00:03:30.480 --> 00:03:34.880
Let's extend the prompt to provide three examples.

90
00:03:34.880 --> 00:03:34.880


91
00:03:34.880 --> 00:03:35.920


92
00:03:35.920 --> 00:03:37.240
Running the same code again,

93
00:03:37.240 --> 00:03:37.240


94
00:03:37.240 --> 00:03:40.320
we see that the model was much more specific.

95
00:03:40.320 --> 00:03:40.320


96
00:03:40.320 --> 00:03:40.320


97
00:03:40.320 --> 00:03:44.920
Hopefully you're starting to grasp just how many problems can be solved

98
00:03:44.920 --> 00:03:50.680
using the OpenAI API, and how important prompts are to obtaining good results.

99
00:03:50.680 --> 00:03:54.160
Time to practice!

