multimodal_fin.processing.multimodal.text package

Submodules

multimodal_fin.processing.multimodal.text.text_emotion_analyzer module

class multimodal_fin.processing.multimodal.text.text_emotion_analyzer.TextEmotionAnalyzer(model_name='j-hartmann/emotion-english-distilroberta-base', device='cpu')[source]

Bases: object

Recognizes emotions in text using a Hugging Face transformer model.

Supports: - Full probability distribution (for emotion embeddings) - Top emotion label (mapped to standard format) - Classification of DataFrames

classify_dataframe(df, text_column='text')[source]

Classifies a column of text data and adds a new column with top predicted emotions.

Parameters:
  • df (DataFrame) – Input DataFrame with text data.

  • text_column (str) – Column containing text to analyze.

Return type:

DataFrame

Returns:

DataFrame with an additional ‘classification’ column.

device: str = 'cpu'

‘cuda’ or ‘cpu’.

Type:

Computation device

get_embeddings(text)[source]

Returns centered logits (interpreted as emotion embeddings) for the given text.

The tensor is centered by subtracting the mean log-probability.

Parameters:

text (str) – Input sentence.

Return type:

Tensor

Returns:

Tensor of centered logits (length = number of emotion labels).

get_top_emotion(text)[source]

Returns the top predicted emotion label for the given text.

Parameters:

text (str) – Input sentence.

Return type:

str

Returns:

The most likely emotion label (standard format).

model_name: str = 'j-hartmann/emotion-english-distilroberta-base'

HF model to use for classification.

predict(text)[source]

Returns full emotion probability distribution for a given text.

Parameters:

text (str) – Input sentence or phrase.

Return type:

List[Dict[str, float]]

Returns:

List of dicts with mapped label and probability score.

Module contents