chapter three

3 Classifying user intent

 

This chapter covers

  • Classifying user commands (i.e., intent classification)
  • Taking a closer look at signatures and modules
  • Comparing using DSPy to working directly with an LM’s API
  • Viewing LM prompt and response history

To dig deeper into working with DSPy, we’ll create a simple, but realistic LM-based application: a classifier, similar to some of the examples in chapter 2. Classification is a common task in Machine Learning. One example of this is sentiment classification, where pieces of text are each classified as having one sentiment out of a set of possible options. If we define just two possible sentiments, “positive” and “negative”, then any given piece of text can be classified as having one of these two labels (that is, belonging to one of these two classes). A message such as “this is a very frustrating experience” would most likely be classified as negative, and text such as “This is such a great outcome” as positive.

3.1 Creating a baseline classifier

3.1.1 Utterances

3.1.2 Multi-class, multi-label, and dynamic classification

3.2 Download and prepare the ATIS dataset

3.3 Building a DSPy intent classifier

3.3.1 The signature

3.3.2 The module

3.4 Using the OpenAI API directly

3.4.1 Classification using the OpenAI API

3.4.2 System and user roles

3.4.3 A comparison of DSPy and the direct use of LM APIs

3.5 Dynamic labels vs static labels

3.5.1 Dynamic intent classification

3.5.2 Static intent classification

3.6 Handling multiple intents

3.7 Viewing the history

3.8 Summary