Swedish BERT models for sentiment analysis

Recorded Future together with AI Sweden releases two language models for sentiment analysis in Swedish. The two models are based on the KB/bert-base-swedish-cased model and has been fine-tuned to solve a multi-label sentiment analysis task.

The models have been fine-tuned for the sentiments fear and violence. The models output three floats corresponding to the labels "Negative", "Weak sentiment", and "Strong Sentiment" at the respective indexes. The models have been trained on Swedish data with a conversational focus, collected from various internet sources and forums.

The models are only trained on Swedish data and only supports inference of Swedish input texts. The models inference metrics for all non-Swedish inputs are not defined, these inputs are considered as out of domain data.

The current models are supported at Transformers version >= 4.3.3 and Torch version 1.8.0, compatibility with older versions are not verified.

Swedish-Sentiment-Fear

The model can be imported from the transformers library by running

from transformers import BertForSequenceClassification, BertTokenizerFast

tokenizer = BertTokenizerFast.from_pretrained("RecordedFuture/Swedish-Sentiment-Fear")
classifier_fear= BertForSequenceClassification.from_pretrained("RecordedFuture/Swedish-Sentiment-Fear") 

When the model and tokenizer are initialized the model can be used for inference.

Sentiment definitions

The strong sentiment includes but are not limited to

Texts that:

The weak sentiment includes but are not limited to

Texts that:

Verification metrics

During training, the model had maximized validation metrics at the following classification breakpoint.

Classification Breakpoint F-score Precision Recall
0.45 0.8754 0.8618 0.8895

Swedish-Sentiment-Violence

The model be can imported from the transformers library by running

from transformers import BertForSequenceClassification, BertTokenizerFast

tokenizer = BertTokenizerFast.from_pretrained("RecordedFuture/Swedish-Sentiment-Violence")
classifier_violence = BertForSequenceClassification.from_pretrained("RecordedFuture/Swedish-Sentiment-Violence") 

When the model and tokenizer are initialized the model can be used for inference.

Sentiment definitions

The strong sentiment includes but are not limited to

Texts that:

The weak sentiment includes but are not limited to

Texts that:

Verification metrics

During training, the model had maximized validation metrics at the following classification breakpoint.

Classification Breakpoint F-score Precision Recall
0.35 0.7677 0.7456 0.791