<!-- Source: https://docs.squirro.com/en/latest/api/squirro.lib.nlp.steps.classifiers.BERTSentiment.html -->
# BERTSentiment

**`class BERTSentiment(config)`**

Bases: [`Classifier`](squirro.lib.nlp.steps.classifiers.Classifier.md#squirro.lib.nlp.steps.classifiers.Classifier)

The BERT Sentiment [`Classifier`](squirro.lib.nlp.steps.classifiers.Classifier.md#squirro.lib.nlp.steps.classifiers.Classifier) detects the sentiments of a text fragment using transformer bases pre-trained models.

**Note**

- **We provide the following pre-trained models:**

  - [DistilBERT](https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english): The model predicts the sentiment [“positive”, “negative”] of the input text.
  - [FinBERT](https://huggingface.co/ProsusAI/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`](https://docs.python.org/3.11/library/stdtypes.html#str).

**Output** - the output field is filled with data of type [`list`](https://docs.python.org/3.11/library/stdtypes.html#list) [ [`str`](https://docs.python.org/3.11/library/stdtypes.html#str) ]. The list contains only one element.

Parameters

- `type` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)) – bertsentiment
- `model_name` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)) – finbert or distilbert
- `pretrained_models_dir` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)`, ``None`) – Directory where the pre-trained models are stored (default: “/var/lib/squirro/machinelearning/pretrained_models”)

**Example**

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

Methods SummaryMethods Documentation

**`process_doc(doc)`**

Process a document

Parameters

`doc` ([`Document`](../technical/libnlp/base.md#squirro.lib.nlp.document.Document)) – Document

Returns

Processed document

Return type

[Document](../technical/libnlp/base.md#squirro.lib.nlp.document.Document)
