plexus.scores.AWSComprehendSentimentScore module

class plexus.scores.AWSComprehendSentimentScore.AWSComprehendSentimentScore(**parameters)

Bases: Score

Score that uses AWS Comprehend to detect sentiment in text.

This score analyzes the sentiment of input text using AWS Comprehend’s detect_sentiment API. It returns one of four sentiment values: - POSITIVE: Text expresses positive sentiment - NEGATIVE: Text expresses negative sentiment - NEUTRAL: Text is neutral or factual - MIXED: Text contains both positive and negative sentiment

The score automatically truncates input text to AWS Comprehend’s limit of 5000 UTF-8 bytes.

Example YAML configuration:
  • name: Customer Sentiment class: AWSComprehendSentimentScore data:

    processors:
    • class: FilterCustomerOnlyProcessor

    • class: RemoveSpeakerIdentifiersTranscriptFilter

Note: Requires AWS credentials to be configured (via environment variables, AWS config file, or IAM role).

Initialize the Score instance with the given parameters.

Parameters

**parametersdict

Arbitrary keyword arguments that are used to initialize the Parameters instance.

Raises

ValidationError

If the provided parameters do not pass validation.

class Result(*, parameters: Parameters, value: str | bool, explanation: str | None = None, confidence: float | None = None, metadata: dict = {}, error: str | None = None, code: str | None = None)

Bases: Result

Result structure for sentiment classification.

Attributes:

value: Sentiment label (POSITIVE, NEGATIVE, NEUTRAL, or MIXED) explanation: Detailed explanation including confidence scores

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

__init__(**parameters)

Initialize the Score instance with the given parameters.

Parameters

**parametersdict

Arbitrary keyword arguments that are used to initialize the Parameters instance.

Raises

ValidationError

If the provided parameters do not pass validation.

async classmethod create(**parameters)

Async factory method for creating score instances.

This method is called by Scorecard when instantiating scores from API configurations. Since AWSComprehendSentimentScore doesn’t require async initialization, we just create and return the instance.

async predict(context, model_input: Input)

Predict sentiment using AWS Comprehend.

Args:

context: Prediction context (unused) model_input: Score.Input containing text to analyze

Returns:

Score.Result with sentiment value and confidence scores

predict_validation()

Placeholder method to satisfy the base class requirement.

This score doesn’t require traditional validation since it uses AWS Comprehend’s pre-trained models.

register_model()

Register the model with MLflow by logging relevant parameters.

AWS Comprehend is a managed service, so there’s no model to register.

save_model()

Save the model to a specified path and log it as an artifact with MLflow.

AWS Comprehend is a managed service, so there’s no model to save.

train_model()

Placeholder method to satisfy the base class requirement.

AWS Comprehend is a pre-trained managed service that doesn’t require training.