BERTSentiment#

class BERTSentiment(config)#

Bases: Classifier

The BERT Sentiment Classifier detects the sentiments of a text fragment using transformer bases pre-trained models.

Note

  • We provide the following pre-trained models:
    • DistilBERT: The model predicts the sentiment [“positive”, “negative”] of the input text.

    • FinBERT: It is a BERT language model finetuned on a financial corpus. The model predicts the sentiment [“positive”, “neutral”, “negative”] of the input text. FinBERT is not installed by default, please install it using ´sudo yum install squirro-finbert´.

  • Truncation is activated for the execution of model. It shortens the textual input if it exceeds the maximum acceptable input length.

Input - the input field needs to be of type str.

Output - the output field is filled with data of type list [ str ]. The list contains only one element.

Parameters:
  • type (str) – bertsentiment

  • model_name (str) – finbert or distilbert

  • pretrained_models_dir (str, None) – Directory where the pre-trained models are stored (default: “/var/lib/squirro/machinelearning/pretrained_models”)

Example

{
    "step": "classifier",
    "type": "bertsentiment",
    "model_name":"distilbert",
    "input_fields": ["normalized_extract"],
    "output_field": "prediction",
    "label_field": ""
}

Methods Summary

process_doc(doc)

Process a document

Methods Documentation

process_doc(doc)#

Process a document

Parameters:

doc (Document) – Document

Returns:

Processed document

Return type:

Document