Predict Module

audiovisually.predict.classify_emotions(model_path, data, text_column='Sentence', output_column='Predicted Emotion', confidence_column='Confidence Score')

Classify emotions in text using a custom trained model.

Parameters:
  • model_path (str) – Path to the trained emotion classification model.

  • data (pd.DataFrame or str) – DataFrame or string containing sentences to classify.

  • text_column (str) – Name of the column with text to classify (if DataFrame).

  • output_column (str) – Name of the column to store predicted emotions.

  • confidence_column (str) – Name of the column to store confidence scores.

Returns:

dict with keys ‘label’ (predicted emotion) and ‘confidence’ (probability score). - If input is a DataFrame: DataFrame with two new columns:

  • output_column: predicted emotion label for each row.

  • confidence_column: confidence score (probability) for each prediction.

Return type:

  • If input is a string

Example

>>> from audiovisually.predict import classify_emotions
>>> df = pd.DataFrame({'Sentence': ['I am happy', 'I am sad']})
>>> model_path = 'path/to/your/model'
>>> result_df = classify_emotions(model_path, df)
>>> classify_emotions(model_path, "I am happy")
{'label': 'happiness', 'confidence': 0.98}
audiovisually.predict.classify_emotions_huggingface(data, model_name='j-hartmann/emotion-english-distilroberta-base', text_column='Sentence', output_column='Predicted Emotion', confidence_column='Confidence Score')

Classify emotions in text using a Hugging Face model pipeline.

Parameters:
  • data (pd.DataFrame or str) – DataFrame or string containing sentences to classify.

  • model_name (str) – Hugging Face model name (default “j-hartmann/emotion-english-distilroberta-base”).

  • text_column (str) – Name of the column with text to classify (if DataFrame).

  • output_column (str) – Name of the column to store predicted emotions.

  • confidence_column (str) – Name of the column to store confidence scores.

Returns:

dict with keys ‘label’ (predicted emotion) and ‘confidence’ (probability score). - If input is a DataFrame: DataFrame with two new columns:

  • output_column: predicted emotion label for each row.

  • confidence_column: confidence score (probability) for each prediction.

Return type:

  • If input is a string

Example

>>> from audiovisually.predict import classify_emotions_huggingface
>>> df = pd.DataFrame({'Sentence': ['I am happy', 'I am sad']})
>>> result_df = classify_emotions_huggingface(df)
>>> classify_emotions_huggingface("I am happy")
{'label': 'happiness', 'confidence': 0.98}