cognition.language.classification¶
Selecting from amongst enumerated values based upon natural language input
Attributes¶
Default field name for response schema |
Classes¶
Fractional confidence from |
|
Function to classify an utterance (with confidence) |
Functions¶
|
Produces a validation schema for |
Module Contents¶
- cognition.language.classification.DEFAULT_SCHEMA_FIELD_NAME: str = 'value'¶
Default field name for response schema
- class cognition.language.classification.EmpiricalConfidence¶
Fractional confidence from a probabilistic process
- selected: int¶
Number of positive outcomes
- trials: int¶
Number of opportunities
- __float__()¶
- Return type:
float
- cognition.language.classification.enum_schema(enum_type, field_name=DEFAULT_SCHEMA_FIELD_NAME)¶
Produces a validation schema for producing an optional value from amongst a supplied enumerated type
- class cognition.language.classification.EnumClassifier[T: enum.Enum](enum_type, task_desc)¶
Function to classify an utterance (with confidence) with respect to an enumerated type.
- Parameters:
enum_type (type[T]) – type representing options
task_desc (str | None) – textual description of the task
- prompt(utterance)¶
Produces the prompt for a supplied utterance
- Parameters:
utterance (str) – user input
- Returns:
resulting classifier llm prompt
- Return type:
str
- __call__(utterance, llm, num_trials=3, timeout_secs=10)¶
Classifies the utterance (with confidence) based upon a timeout budget.
- Parameters:
utterance (str) – text to classify
llm (pydantic_ai.models.Model) – textual model to utilize
num_trials (int) – number of classifications to perform & aggregate
timeout_secs (int)
- Timeout_secs:
time given per LLM call
- Returns:
most common classification with confidence
- Return type:
tuple[T | None, EmpiricalConfidence]
- classmethod classify(utterance, enum_type, llm, task_desc, num_trials=3, timeout_secs=10)¶
One-off instantiation and calling of a classifier
- Parameters:
utterance (str) – text to classify
enum_type (type[T]) – type representing options
llm (pydantic_ai.models.Model) – textual model to utilize
task_desc (str | None) – textual description of the task
num_trials (int) – number of classifications to perform & aggregate
timeout_secs (int)
- Timeout_secs:
time given per LLM call
- Returns:
most common classification with confidence
- Return type:
tuple[T | None, EmpiricalConfidence]