Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Cohere ai Cohere python ClassifyResponseItem Model

From Leeroopedia
Knowledge Sources
Domains SDK, Classification, NLP
Last Updated 2026-02-15 14:00 GMT

Overview

ClassifyResponseClassificationsItem is a Pydantic model representing a single classification result returned by the Cohere classify endpoint.

Description

The ClassifyResponseClassificationsItem model contains the full classification output for a single input text. It includes:

  • An id that uniquely identifies the classification result.
  • The input text that was classified.
  • A prediction field containing the top predicted label (for single-label classification).
  • A predictions list containing all predicted labels.
  • A confidence score for the top prediction (single-label only).
  • A confidences list with confidence scores for all predictions in order.
  • A labels dictionary mapping each label name to a ClassifyResponseClassificationsItemLabelsValue containing its confidence score. For single-label classification, all confidences sum to 1. For multi-label classification, label confidences are independent.
  • A classification_type field indicating whether the classification is "single-label" or "multi-label".

Usage

Use ClassifyResponseClassificationsItem when processing results from the Cohere classify endpoint. Each item in the response's classifications list is an instance of this model, providing the full prediction details for a single input text.

Code Reference

Source Location

  • Repository: Cohere Python SDK
  • File: src/cohere/types/classify_response_classifications_item.py

Signature

class ClassifyResponseClassificationsItem(UncheckedBaseModel):
    id: str
    input: typing.Optional[str] = pydantic.Field(default=None)
    prediction: typing.Optional[str] = pydantic.Field(default=None)
    predictions: typing.List[str] = pydantic.Field()
    confidence: typing.Optional[float] = pydantic.Field(default=None)
    confidences: typing.List[float] = pydantic.Field()
    labels: typing.Dict[str, ClassifyResponseClassificationsItemLabelsValue] = pydantic.Field()
    classification_type: ClassifyResponseClassificationsItemClassificationType = pydantic.Field()

Import

from cohere.types import ClassifyResponseClassificationsItem

I/O Contract

Fields

Field Type Required Description
id str Yes Unique identifier for this classification result.
input Optional[str] No The input text that was classified.
prediction Optional[str] No The predicted label for the associated query (single-label only).
predictions List[str] Yes An array containing the predicted labels for the associated query.
confidence Optional[float] No The confidence score for the top predicted class (single-label only).
confidences List[float] Yes An array containing the confidence scores of all predictions in the same order.
labels Dict[str, ClassifyResponseClassificationsItemLabelsValue] Yes A map of each label to its confidence score. Sums to 1 for single-label; independent for multi-label.
classification_type ClassifyResponseClassificationsItemClassificationType Yes The type of classification performed: "single-label" or "multi-label".

Usage Examples

from cohere.types import ClassifyResponseClassificationsItem

# Classify endpoint returns a list of ClassifyResponseClassificationsItem
response = client.classify(
    inputs=["This is great!", "This is terrible."],
    examples=[
        {"text": "I love it", "label": "positive"},
        {"text": "I hate it", "label": "negative"},
        {"text": "Amazing work", "label": "positive"},
        {"text": "Awful experience", "label": "negative"},
    ],
)

for item in response.classifications:
    print(f"ID: {item.id}")
    print(f"Input: {item.input}")
    print(f"Prediction: {item.prediction}")
    print(f"Confidence: {item.confidence}")
    print(f"Classification type: {item.classification_type}")
    # Inspect per-label confidences
    for label_name, label_value in item.labels.items():
        print(f"  {label_name}: {label_value.confidence}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment