The dataset is a Turkish three-class sentiment corpus (negatif / notr / pozitif). Overall distribution and per-split distributions are shown below.
1params = {
2 "learning_rate": trial.suggest_float("learning_rate", 5e-6, 5e-5, log=True),
3 "per_device_train_batch_size": trial.suggest_categorical("per_device_train_batch_size", [16, 32]),
4 "per_device_eval_batch_size": trial.suggest_categorical("per_device_eval_batch_size", [32]),
5 "weight_decay": trial.suggest_float("weight_decay", 0.0, 0.1),
6 "warmup_ratio": trial.suggest_float("warmup_ratio", 0.0, 0.2),
7 "num_train_epochs": trial.suggest_int("num_train_epochs", 6, 8),
8 "gradient_accumulation_steps": trial.suggest_categorical("gradient_accumulation_steps", [1, 2, 4]),
9 }
10
1{
2 "learning_rate": 2.0021958728380746e-05,
3 "per_device_train_batch_size": 16,
4 "per_device_eval_batch_size": 32,
5 "weight_decay": 0.0515273094797082,
6 "warmup_ratio": 0.1122927021129482,
7 "num_train_epochs": 8,
8 "gradient_accumulation_steps": 2
9}
These results are the evaluations recorded during the final fine-tuning training process.
1from transformers import pipeline
2
3# Load the classification pipeline with the specified model
4model_name = "msamilim/electra-turkish-sentiment-optuna-hpo"
5pipe = pipeline("text-classification", model=model_name)
6
7# Classify a new sentence
8sentence = "Güzel ürün, tavsiye ederim."
9result = pipe(sentence)
10
11# Print the result
12print(result)
13
14# Example output :
15# [{'label': 'pozitif', 'score': 0.9998408555984497}]
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "msamilim/electra-turkish-sentiment-optuna-hpo"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
8def predict_sentiment(texts):
9 inputs = tokenizer(texts, return_tensors="pt", truncation=True, padding=True, max_length=512)
10 with torch.no_grad():
11 outputs = model(**inputs)
12 probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
13 id2label = { 0: "Negatif", 1: "Nötr", 2: "Pozitif"}
14 return [id2label[p] for p in torch.argmax(probabilities, dim=-1).tolist()]
15
16texts = [
17 "Güzel ürün, tavsiye ederim kullanılır.",
18 "Ürün çok güzel ve kaliteli. Maalesef yüzüme uymadığı için iade etmek zorunda kaldım.",
19 "Keşke aldıktan sonra indirime girmeseydi.",
20 "Daha soluk ve mat yapısı var beğenmedim .",
21]
22
23for text, sentiment in zip(texts, predict_sentiment(texts)):
24 print(f"Text: {text}\nSentiment: {sentiment}\n")
25
26# Example output :
27# Text: Güzel ürün, tavsiye ederim kullanılır.
28# Sentiment: Pozitif
29# Text: Ürün çok güzel ve kaliteli. Maalesef yüzüme uymadığı için iade etmek zorunda kaldım.
30# Sentiment: Pozitif
31# Text: Keşke aldıktan sonra indirime girmeseydi.
32# Sentiment: Negatif
33# Text: Daha soluk ve mat yapısı var beğenmedim .
34# Sentiment: Negatif
35
36
37