CoolFace
Modelpublic

msamilim/modernbert-turkish-sentiment-optuna-hpo

sourceHugging Faceapache-2.0updated 10mo agoView on Hugging Face
0likes14downloads
Model Card

Turkish Sentiment Analysis (3-class) — Fine-tuned

Overview

This model is a fine-tuned version of `artiwise-ai/modernbert-base-tr-uncased` for 3-class Turkish sentiment analysis. It was trained on an imbalanced dataset of e-commerce product reviews, and hyperparameters were optimized with Optuna to obtain the most effective fine-tuning configuration.

Bu model, üç sınıflı Türkçe duygu analizi için `artiwise-ai/modernbert-base-tr-uncased` taban alınarak ince ayar (fine-tuning) yapılmış bir sürümdür. Model, dengesiz bir e-ticaret ürün yorumları veri kümesi üzerinde eğitilmiş; en etkili ince ayar yapılandırmasını elde etmek için hiperparametreler Optuna ile optimize edilmiştir.

Intended Use

  • —Product reviews classification
  • —Social media analysis
  • —Customer feedback analysis
  • —Brand monitoring
  • —Market research
  • —Customer service optimization
  • —Competitive intelligence

Model Details

FieldValue
Model Namemsamilim/modernbert-turkish-sentiment-optuna-hpo
Base Modelartiwise-ai/modernbert-base-tr-uncased
TaskSentiment Analysis
LanguageTurkish
Fine-Tuning DatasetTurkish E-Commerce Product Reviews Dataset
Number of Labels3
Problem TypeSingle-label classification
Licenseapache-2.0
Fine-Tuning FrameworkHugging Face Transformers

Dataset

The dataset is a Turkish three-class sentiment corpus (negatif / notr / pozitif). Overall distribution and per-split distributions are shown below.

Dataset Distribution (Overall)

LabelIDLabelNameCountRatio (%)
0negatif946218.86
1notr7461.49
2pozitif3995279.65
—Total50160100.00

Training Procedure

  • —Objective metric: `eval_macro_f1`
  • —Hyperparameter Optimization Techniques: `Optuna`

HPO Parameter Ranges

json
params = {
        "learning_rate": trial.suggest_float("learning_rate", 5e-6, 5e-5, log=True),
        "per_device_train_batch_size": trial.suggest_categorical("per_device_train_batch_size", [16, 32]),
        "per_device_eval_batch_size":  trial.suggest_categorical("per_device_eval_batch_size",  [32]),
        "weight_decay": trial.suggest_float("weight_decay", 0.0, 0.1),
        "warmup_ratio": trial.suggest_float("warmup_ratio", 0.0, 0.2),
        "num_train_epochs": trial.suggest_int("num_train_epochs", 6, 8),
        "gradient_accumulation_steps": trial.suggest_categorical("gradient_accumulation_steps", [1, 2, 4]),
    }

Best Trial Hyperparameters

json
{
  "learning_rate": 4.292071084445416e-05,
  "per_device_train_batch_size": 16,
  "per_device_eval_batch_size": 32,
  "weight_decay": 0.0897155306921003,
  "warmup_ratio": 0.0495607080384387,
  "num_train_epochs": 7,
  "gradient_accumulation_steps": 2
}

Evaluation Results

These results are the evaluations recorded during the final fine-tuning training process. | label | precision | recall | f1-score | | --- | --- | --- | --- | | negatif | 0.8467 | 0.7930 | 0.8189 | | notr | 0.1238 | 0.1444 | 0.1333 | | pozitif | 0.9555 | 0.9668 | 0.9611 | | accuracy | | | 0.9218 | | micro avg | 0.9218 | 0.9218 | 0.9218 | | macro avg | 0.6420 | 0.6347 | 0.6378 | | weighted avg | 0.9225 | 0.9218 | 0.9219 |

Epoch-wise Metrics

epochtrain_losseval_losseval_macro_f1
10.50360.20850.5909
20.27670.23710.6065
30.12490.45570.6378
40.03490.66020.6347
50.00990.71440.6217
60.00250.76350.6341
70.00020.76920.6322

How to use - Pipeline

python
from transformers import pipeline

# Load the classification pipeline with the specified model
model_name = "msamilim/modernbert-turkish-sentiment-optuna-hpo"
pipe = pipeline("text-classification", model=model_name)

# Classify a new sentence
sentence = "Güzel ürün, tavsiye ederim."
result = pipe(sentence)

# Print the result
print(result)

# Example output : 
# [{'label': 'pozitif', 'score': 0.9998408555984497}]

How to use - Full Classification

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

model_name = "msamilim/modernbert-turkish-sentiment-optuna-hpo"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

def predict_sentiment(texts):
    inputs = tokenizer(texts, return_tensors="pt", truncation=True, padding=True, max_length=512)
    with torch.no_grad():
        outputs = model(**inputs)
    probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
    id2label = {    0: "Negatif",    1: "Nötr",    2: "Pozitif"}
    return [id2label[p] for p in torch.argmax(probabilities, dim=-1).tolist()]

texts = [
     "Güzel ürün, tavsiye ederim kullanılır.", 
     "Ürün çok güzel ve kaliteli. Maalesef yüzüme uymadığı için iade etmek zorunda kaldım.", 
     "Keşke aldıktan sonra indirime girmeseydi.",
     "Daha soluk ve mat yapısı var beğenmedim .",
]

for text, sentiment in zip(texts, predict_sentiment(texts)):
    print(f"Text: {text}\nSentiment: {sentiment}\n")

# Example output : 
# Text: Güzel ürün, tavsiye ederim kullanılır.
# Sentiment: Pozitif
# Text: Ürün çok güzel ve kaliteli. Maalesef yüzüme uymadığı için iade etmek zorunda kaldım.
# Sentiment: Pozitif
# Text: Keşke aldıktan sonra indirime girmeseydi.
# Sentiment: Negatif
# Text: Daha soluk ve mat yapısı var beğenmedim .
# Sentiment: Negatif


Framework versions

  • —transformers==4.57.0
  • —torch==2.8.0+cu128
  • —datasets==4.2.0
  • —accelerate==1.10.1
  • —evaluate==0.4.6
  • —python==3.11.13