src.classification.text package

Submodules

src.classification.text.bert_classifier module

Implementation of an emotion classifier using BERT

class src.classification.text.bert_classifier.BertClassifier(parameters: Optional[Dict] = None)

Bases: TextEmotionClassifier

Emotion classifier based on the BERT model

classify(parameters: Optional[Dict] = None, **kwargs) array

Classify method for the BERT classifier

Parameters:
  • parameters – Loading parameters which_set: Dataset to use for classification batch_size: Batch size

  • kwargs – Additional parameters Not used currently

load(parameters: Optional[Dict] = None, **kwargs) None

Loading method for the BERT classifier that loads a stored model from disk.

Parameters:
  • parameters – Loading parameters save_path: The folder to load the model from

  • kwargs – Additional parameters Not used currently

save(parameters: Optional[Dict] = None, **kwargs) None

Saving method for the BERT classifier that saves a trained model from disk.

Parameters:
  • parameters – Saving parameters save_path: The folder where the model is saved

  • kwargs – Additional parameters Not used currently

train(parameters: Optional[Dict] = None, **kwargs) None

Training method for the BERT classifier

Parameters:
  • parameters – Training parameters init_lr: initial learning rate epochs: Number of epochs to train for which_set: Which dataset to use for training batch_size: The batch size for training

  • kwargs – Additional parameters Not used currently

src.classification.text.distilbert_classifier module

Implements a text emotion classifier based on Distilbert

class src.classification.text.distilbert_classifier.DistilBertClassifier(parameters: Optional[Dict] = None)

Bases: BertClassifier

This class implements the Distilbert model for emotion classification. We can reuse the training and classification functionality from BERT.

load(parameters: Optional[Dict] = None, **kwargs) None

Loading method for the classifier that loads a stored model from disk.

Parameters:
  • parameters – Loading parameters save_path: Folder where model is loaded from

  • kwargs – Additional parameters Not used currently

save(parameters: Optional[Dict] = None, **kwargs) None

Saving method for the classifier that saves a trained model from disk.

Parameters:
  • parameters – Saving parameters save_path: Folder where model is saved at

  • kwargs – Additional parameters Not used currently

src.classification.text.nrclex_classifier module

Implementation of a text classifier using the NRCLex python library

class src.classification.text.nrclex_classifier.NRCLexTextClassifier(parameters: Optional[Dict] = None)

Bases: TextEmotionClassifier

This class implements a text classifier using the NRCLex python library. It uses a lexicon for finding emotion words that are then used to make a classification. This means that there is no training necessary.

classify(parameters: Optional[Dict] = None, **kwargs) array

Classify the emotions based on the NRCLex library.

Parameters:
  • parameters – Classification parameters which_set: Dataset to use for classification batch_size: Batch size for data loader

  • kwargs – Additional parameters Not currently used

Returns:

An array of the classification results, shape (num_samples,)

get_best_emotion(raw_scores: Dict) int

Gets the emotion scores from the NRCLex library and then gets the most likely emotion from that.

Parameters:

raw_scores – The raw scores dictionary generated by NRCLex

Returns:

The integer index of the emotion in the neutral_ekman space

load(parameters: Optional[Dict] = None, **kwargs) None

Load a stored classifier from storage. Not necessary for NRCLex.

Parameters:
  • parameters – Loading parameters

  • kwargs – Additional parameters

save(parameters: Optional[Dict] = None, **kwargs) None

Save a trained classifier in storage. Not necessary for NRCLex.

Parameters:
  • parameters – Saving parameters

  • kwargs – Additional parameters

train(parameters: Optional[Dict] = None, **kwargs) None

Training method for the classifier. The classifier does not require training as it is only a lexicon-based method.

Parameters:
  • parameters – parameters for training

  • kwargs – additional parameters

src.classification.text.text_emotion_classifier module

Base class for all text emotion classifiers

class src.classification.text.text_emotion_classifier.TextEmotionClassifier(name: str = 'text', parameters: Optional[Dict] = None)

Bases: EmotionClassifier

Base class for all text emotion classifiers. Contains common functionality that concerns all text classifiers.

abstract classify(parameters: Optional[Dict] = None, **kwargs) array

The virtual classification method for interfacing

Parameters:
  • parameters – Parameter dictionary used for classification

  • kwargs – Additional kwargs parameters

Returns:

An array with predicted emotion indices

abstract load(parameters: Optional[Dict] = None, **kwargs) None

Loading method that loads a previously trained model from disk.

Parameters:
  • parameters – Parameters required for loading the model

  • kwargs – Additional kwargs parameters

abstract save(parameters: Optional[Dict] = None, **kwargs) None

Saving method that saves a previously trained model on disk.

Parameters:
  • parameters – Parameters required for storing the model

  • kwargs – Additional kwargs parameters

abstract train(parameters: Optional[Dict] = None, **kwargs) None

Virtual training method for interfacing

Parameters:
  • parameters – Parameter dictionary used for training

  • kwargs – Additional kwargs parameters

Module contents

Package for text based emotion classifiers