mexca.text.sentiment
Extract sentiment from text.
Module Contents
Classes
Extract sentiment from text. |
Functions
|
Command line interface for sentiment extraction. |
- class mexca.text.sentiment.SentimentExtractor(model_name: str | None = None, device: torch.device | None = None)[source]
Extract sentiment from text.
- Parameters:
model_name (str, optional) – The name of the text sequence classification model on Hugging Face hub used for sentiment prediction. By default ‘cardiffnlp/twitter-xlm-roberta-base-sentiment’.
device (torch.device, optional, default=None) – The device on which sentiment extraction is performed. If None, defaults to ‘cpu’.
- tokenizer
The pretrained tokenizer for sequence classification. Loaded automatically from model_name.
- Type:
transformers.PreTrainedTokenizer
- property classifier: transformers.XLMRobertaForSequenceClassification[source]
The pretrained sequence classification model for sentiment prediction. Loaded automatically from model_name.
- apply(transcription: mexca.data.AudioTranscription, show_progress: bool = True) mexca.data.SentimentAnnotation [source]
Extract the sentiment from text.
Iterates over the sentences in the audio transcription and predicts the sentiment (negative, neutral, positive).
- Parameters:
transcription (AudioTranscription) – The transcription of the speech segments in the audio fie split into sentences. Returned by AudioTranscriber.
show_progress (bool, optional, default=True) – Whether a progress bar is displayed or not.
- Returns:
An data class object with the positive, negative, and neutral sentiment scores for each sentence.
- Return type: