This endpoint makes a prediction about which label fits the specified text inputs best. To make a prediction, Classify uses the provided examples of text + label pairs as a reference.

Note: Custom Models trained on classification examples don't require the examples parameter to be passed in explicitly.

Set up

Install the SDK.

$ pip install cohere

Set up the Cohere client.

import cohere  
co = cohere.Client(api_key)

Add examples

These are the training examples we give the model to show the classes we want it to classify. Each example contains the text itself and the corresponding label, or class. The minimum number of examples required is two per class.

from cohere.classify import Example

  Example("Example 1", "Label 1"),
  Example("Example 2", "Label 1"),
  Example("Example 1", "Label 2"),
  Example("Example 2", "Label 2")

Add inputs

These are the list of text pieces you’d like to classify.

inputs=["Example Query 1”,
        "Example Query 2"

Get classifications

With the Classify endpoint, setting up the model is quite straightforward. The main thing to do is to define the model type. For our example, we’ll use the default, which is medium. Putting everything together with the Classify endpoint looks like the following:

response = co.classify(  

Click Try It! to start a request and see the response here!