pliers.extractors.BertSentimentExtractor

class pliers.extractors.BertSentimentExtractor(pretrained_model='distilbert-base-uncased-finetuned-sst-2-english', tokenizer='bert-base-uncased', framework='pt', return_softmax=True, return_input=False, model_kwargs=None, tokenizer_kwargs=None)[source]

Bases: BertExtractor

Extracts sentiment for sequences using BERT (or similar, e.g.

DistilBERT) models fine-tuned for sentiment classification.

Parameters
  • pretrained_model (str) – A string specifying which transformer model to use (must be one fine-tuned for sentiment classification)

  • tokenizer (str) – Type of tokenization used in the tokenization step.

  • framework (str) – name deep learning framework to use. Must be ‘pt’ (PyTorch) or ‘tf’ (tensorflow). Defaults to ‘pt’.

  • return_softmax (bool) – If True, the extractor returns softmaxed sentiment scores instead of raw model predictions.

  • return_input (bool) – If True, the extractor returns an additional feature column with the encoded sequence.

  • model_kwargs (dict) – Named arguments for pretrained model.

  • tokenizer_kwargs (dict) – Named arguments for tokenizer.

__init__(pretrained_model='distilbert-base-uncased-finetuned-sst-2-english', tokenizer='bert-base-uncased', framework='pt', return_softmax=True, return_input=False, model_kwargs=None, tokenizer_kwargs=None)[source]
transform(stim, *args, **kwargs)

Executes the transformation on the passed stim(s).

Parameters
  • stims (str, Stim, list) –

    One or more stimuli to process. Must be one of:

    • A string giving the path to a file that can be read in as a Stim (e.g., a .txt file, .jpg image, etc.)

    • A Stim instance of any type.

    • An iterable of stims, where each element is either a string or a Stim.

  • validation (str) –

    String specifying how validation errors should be handled. Must be one of:

    • ’strict’: Raise an exception on any validation error

    • ’warn’: Issue a warning for all validation errors

    • ’loose’: Silently ignore all validation errors

  • args – Optional positional arguments to pass onto the internal _transform call.

  • kwargs – Optional positional arguments to pass onto the internal _transform call.