File size: 3,464 Bytes
dda1843
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---

language: tr
tags:
- sentiment-analysis
- turkish
- bert
- text-classification
license: apache-2.0
datasets:
- winvoker/turkish-sentiment-analysis-dataset
- WhiteAngelss/Turkce-Duygu-Analizi-Dataset
metrics:
- accuracy
- f1
- precision
- recall
---


# Turkish Sentiment Analysis Model

A fine-tuned BERT model for Turkish sentiment analysis, trained on a combined dataset of 439,384 labeled Turkish sentences.

## Model Details

- **Base Model:** `dbmdz/bert-base-turkish-cased`
- **Task:** Text Classification (Sentiment Analysis)
- **Language:** Turkish
- **Labels:** positive, negative, neutral

## Training Data

The model was trained on a combination of two high-quality Turkish sentiment datasets:
- `winvoker/turkish-sentiment-analysis-dataset` (440,641 samples)
- `WhiteAngelss/Turkce-Duygu-Analizi-Dataset` (440,641 samples)

After deduplication and preprocessing, the final training set consisted of:
- **Training:** 351,507 samples
- **Validation:** 43,938 samples
- **Test:** 43,939 samples

### Label Distribution

- **Positive:** 234,957 (53.5%)
- **Neutral:** 153,809 (35.0%)
- **Negative:** 50,618 (11.5%)

## Training

- **Epochs:** 3
- **Learning Rate:** 2e-5
- **Batch Size:** 16
- **Max Length:** 128
- **Optimizer:** AdamW

## Usage

```python

from transformers import AutoTokenizer, AutoModelForSequenceClassification

import torch



# Load model and tokenizer

model_name = "codealchemist01/turkish-sentiment-analysis"

tokenizer = AutoTokenizer.from_pretrained(model_name)

model = AutoModelForSequenceClassification.from_pretrained(model_name)



# Example text

text = "Bu ürün gerçekten harika!"



# Tokenize

inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)



# Predict

with torch.no_grad():

    outputs = model(**inputs)

    predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)

    predicted_label_id = predictions.argmax().item()



# Map to label

id2label = {0: "negative", 1: "neutral", 2: "positive"}

predicted_label = id2label[predicted_label_id]

confidence = predictions[0][predicted_label_id].item()



print(f"Label: {predicted_label}")

print(f"Confidence: {confidence:.4f}")

```

## Performance

Evaluation metrics on the test set (43,939 samples):

- **Accuracy:** 97.45%
- **Weighted F1:** 97.42%
- **Weighted Precision:** 97.41%
- **Weighted Recall:** 97.45%

### Per-Class Performance

| Class    | Precision | Recall | F1-Score | Support |
|----------|-----------|--------|----------|---------|
| Negative | 91.42%    | 86.69% | 88.99%   | 5,062   |
| Neutral  | 99.79%    | 99.96% | 99.87%   | 15,381  |
| Positive | 97.15%    | 98.12% | 97.63%   | 23,496  |

**Note:** Negative class has lower performance due to class imbalance (only 11.5% of the dataset). The model performs excellently on neutral and positive classes.

## Limitations

- The model may not perform well on very short texts (< 3 words)
- Performance may vary across different domains (social media, news, reviews)
- Class imbalance may affect performance on minority classes (negative)

## Citation

If you use this model, please cite:

```bibtex

@misc{turkish-sentiment-analysis,

  title={Turkish Sentiment Analysis Model},

  author={codealchemist01},

  year={2024},

  howpublished={\url{https://huggingface.co/codealchemist01/turkish-sentiment-analysis}}

}

```

## License

Apache 2.0