Downloads · 30 days
23
5% of all-time downloads
daviddrzik/SK_BPE_BLM-sentiment-multidomain
SK_BPE_BLM-sentiment-multidomain is a text classification model from daviddrzik. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
This model is a fine-tuned version of the SKBPEBLM model for the task of sentiment classification. It has been trained on datasets from multiple domains, including banking, social media, movie reviews, politics, and p…
Downloads · 30 days
23
5% of all-time downloads
All-time downloads
437
Public
Parameters
58.7M
235 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors235 MB · 100%
From the Hugging Face model README
This model is a fine-tuned version of the SK_BPE_BLM model for the task of sentiment classification. It has been trained on datasets from multiple domains, including banking, social media, movie reviews, politics, and product reviews. Some of these datasets were originally in Czech and were machine-translated into Slovak using Google Cloud Translation.
Each row in the dataset is labeled with one of the following sentiments:
The dataset used for fine-tuning comprises text records from various domains. Below are the details for each domain:
The following hyperparameters were used during the fine-tuning process:
The model was trained on data from all domains simultaneously and evaluated using stratified 10-fold cross-validation on each individual domain. The weighted F1-score, including the mean, minimum, maximum, and quartile values, is presented below for each domain:
| Domain | Mean | Min | 25% | 50% | 75% | Max |
|---|---|---|---|---|---|---|
| Banking | 0.658 | 0.608 | 0.645 | 0.658 | 0.674 | 0.697 |
| Social media | 0.575 | 0.552 | 0.570 | 0.577 | 0.581 | 0.599 |
| Movies | 0.572 | 0.518 | 0.555 | 0.580 | 0.590 | 0.615 |
| Politics | 0.613 | 0.576 | 0.602 | 0.614 | 0.623 | 0.644 |
| Reviews | 0.576 | 0.555 | 0.562 | 0.575 | 0.583 | 0.608 |
This model is suitable for sentiment classification within the specific domains it was trained on, such as banking, social media, movies, politics, and product reviews. While it may not achieve high F1-scores across all text types, it is well-suited for a wide range of text within these trained domains. However, it may not generalize effectively to entirely different types of text outside these domains.
Below is an example of how to use the fine-tuned SK_Morph_BLM-sentiment-multidomain model in a Python script:
import torch
from transformers import RobertaForSequenceClassification, RobertaTokenizerFast
class SentimentClassifier:
def __init__(self, tokenizer, model):
self.model = RobertaForSequenceClassification.from_pretrained(model, num_labels=3)
self.tokenizer = RobertaTokenizerFast.from_pretrained(tokenizer, max_length=256)
def tokenize_text(self, text):
encoded_text = self.tokenizer.encode_plus(
text.lower(),
max_length=256,
padding='max_length',
truncation=True,
return_tensors='pt'
)
return encoded_text
def classify_text(self, encoded_text):
with torch.no_grad():
output = self.model(**encoded_text)
logits = output.logits
predicted_class = torch.argmax(logits, dim=1).item()
probabilities = torch.softmax(logits, dim=1)
class_probabilities = probabilities[0].tolist()
predicted_class_text = self.model.config.id2label[predicted_class]
return predicted_class, predicted_class_text, class_probabilities
# Instantiate the sentiment classifier with the specified tokenizer and model
classifier = SentimentClassifier(tokenizer="daviddrzik/SK_BPE_BLM", model="daviddrzik/SK_BPE_BLM-sentiment-multidomain")
# Example text to classify sentiment
text_to_classify = "Napriek zlepšeniu očakávaní je výhľad stále krehký."
print("Text to classify: " + text_to_classify + "\n")
# Tokenize the input text
encoded_text = classifier.tokenize_text(text_to_classify)
# Classify the sentiment of the tokenized text
predicted_class, predicted_class_text, logits = classifier.classify_text(encoded_text)
# Print the predicted class label and index
print(f"Predicted class: {predicted_class_text} ({predicted_class})")
# Print the probabilities for each class
print(f"Class probabilities: {logits}")
Here is the output when running the above example:
Text to classify: Napriek zlepšeniu očakávaní je výhľad stále krehký.
Predicted class: Positive (2)
Class probabilities: [0.003513934789225459, 0.3542619049549103, 0.642224133014679]