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 AwsClassification

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

Overview

Implements data structures for handling single-label and multi-label classification results from fine-tuned models deployed on AWS (SageMaker and Bedrock).

Description

The AwsClassification module provides the Classification and Classifications classes used to wrap classification predictions returned by Cohere fine-tuned classification models running on AWS infrastructure. The Classification class supports two response formats: a legacy format (version 1) that returns a raw prediction value, and a newer format (version 2) that includes prediction, confidence scores, and original input text. The Classifications container class enforces that all contained items share the same label type (single-label or multi-label) and supports iteration and length queries.

Usage

Use these classes when you need to parse and inspect classification results returned from Cohere fine-tuned classification models deployed via AWS SageMaker or Amazon Bedrock. They are typically instantiated internally by the AWS client rather than constructed directly by end users.

Code Reference

Source Location

  • Repository: Cohere Python SDK
  • File: src/cohere/manually_maintained/cohere_aws/classification.py

Signature

Prediction = Union[str, int, List[str], List[int]]
ClassificationDict = Dict[Literal["prediction", "confidence", "text"], Any]

class Classification(CohereObject):
    def __init__(self, classification: Union[Prediction, ClassificationDict]) -> None: ...
    def is_multilabel(self) -> bool: ...
    @property
    def prediction(self) -> Prediction: ...
    @property
    def confidence(self) -> List[float]: ...
    @property
    def text(self) -> str: ...

class Classifications(CohereObject):
    def __init__(self, classifications: List[Classification]) -> None: ...
    def __iter__(self) -> Iterator: ...
    def __len__(self) -> int: ...
    def is_multilabel(self) -> bool: ...

Import

from cohere.manually_maintained.cohere_aws.classification import Classification, Classifications

I/O Contract

Classification

Parameter Type Description
classification Union[Prediction, ClassificationDict] A raw prediction value (v1 format: str, int, List[str], or List[int]) or a dictionary (v2 format) containing keys "prediction", "confidence", and "text".
Property Return Type Description
prediction Union[str, int, List[str], List[int]] The predicted label(s). Returns the raw value for v1 format or extracts the "prediction" key for v2 format.
confidence List[float] Confidence scores per label. Only available in v2 format; raises ValueError for v1.
text str Original input text. Only available in v2 format; raises ValueError for v1.
is_multilabel() bool Returns True if the classification contains multiple labels.

Classifications

Parameter Type Description
classifications List[Classification] A list of Classification objects. All must share the same label type (single-label or multi-label).
Method Return Type Description
__iter__() Iterator Iterates over the contained Classification objects.
__len__() int Returns the number of classification results.
is_multilabel() bool Returns True if the contained classifications are multi-label.

Usage Examples

# Working with single-label classification results (v2 format)
from cohere.manually_maintained.cohere_aws.classification import Classification, Classifications

# Single-label classification with confidence scores (v2 format)
result = Classification({"prediction": "positive", "confidence": [0.95, 0.05], "text": "Great product!"})
print(result.prediction)   # "positive"
print(result.confidence)   # [0.95, 0.05]
print(result.text)         # "Great product!"
print(result.is_multilabel())  # False

# Multi-label classification (v2 format)
multi_result = Classification({"prediction": ["sports", "news"], "confidence": [0.8, 0.7], "text": "Game results announced"})
print(multi_result.is_multilabel())  # True

# Container usage
batch = Classifications([result])
print(len(batch))          # 1
for item in batch:
    print(item.prediction)

Related Pages

Page Connections

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