mexca.text.sentiment ==================== .. py:module:: mexca.text.sentiment .. autoapi-nested-parse:: Extract sentiment from text. Classes ------- .. autoapisummary:: mexca.text.sentiment.SentimentExtractor Functions --------- .. autoapisummary:: mexca.text.sentiment.cli Module Contents --------------- .. py:class:: SentimentExtractor(model_name: Optional[str] = None, device: Optional[torch.device] = None) Extract sentiment from text. :param model_name: The name of the text sequence classification model on Hugging Face hub used for sentiment prediction. By default `'cardiffnlp/twitter-xlm-roberta-base-sentiment'`. :type model_name: str, optional :param device: The device on which sentiment extraction is performed. If `None`, defaults to `'cpu'`. :type device: torch.device, optional, default=None .. attribute:: tokenizer The pretrained tokenizer for sequence classification. Loaded automatically from `model_name`. :type: transformers.PreTrainedTokenizer .. py:property:: classifier :type: transformers.XLMRobertaForSequenceClassification The pretrained sequence classification model for sentiment prediction. Loaded automatically from `model_name`. .. py:method:: apply(transcription: mexca.data.AudioTranscription, show_progress: bool = True) -> mexca.data.SentimentAnnotation Extract the sentiment from text. Iterates over the sentences in the audio transcription and predicts the sentiment (negative, neutral, positive). :param transcription: The transcription of the speech segments in the audio fie split into sentences. Returned by `AudioTranscriber`. :type transcription: AudioTranscription :param show_progress: Whether a progress bar is displayed or not. :type show_progress: bool, optional, default=True :returns: An data class object with the positive, negative, and neutral sentiment scores for each sentence. :rtype: SentimentAnnotation .. py:function:: cli() Command line interface for sentiment extraction. See `extract-sentiment -h` for details.