Skip to main content

Question Classification

Here is a quick demonstration of how to use Choose Best to perform a classification task.

Task Setup#

Let's suppose you're a phone retailer that receives dozens of customer inquiries every single day. As luck would have it, most of these customers ask basically the same question, but in completely different ways. To save time, you'd like to classify these questions into three categories: phone repairs, store hours, and discounts. For each category below, we've provided three sets of examples.

  • Option 1: 'why won't my phone turn on?', 'my phone won't turn on, what's wrong with it?', 'can you help me fix my phone?'
  • Option 2: 'what time do you open?', 'what is your schedule?', 'will you be open on Saturday?'
  • Option 3: 'do you have any discounts?', 'what is the promo code?', 'how can I get a discount on this purchase?'

Below you'll find the questions we'd like to classify, which will be passed in as queries:

  • Query 1: , 'when will my phone be fixed?'
  • Query 2: , 'when will you be closing today?'
  • Query 3: , 'can I use my coupon?'

Using the API#

Given these options, the following is an example of using the API for Query 1:

curl --location --request POST 'https://api.cohere.ai/{model}/choose-best' \
--header 'Authorization: BEARER {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
"query": "{query}",
"options": [{options}],
"mode": "{mode}"
}'

The following are the scores of the queries given each category:

QueryPhone RepairsStore HoursDiscounts
when will my phone be fixed?-1.5360342-2.6622102-3.202358
when will you be closing today?-3.5914233-2.2240033-2.9386992
can I use my coupon?-3.8678696-3.4840846-2.2333481

As you can see, the score with the largest value corresponds to the correct category!