File size: 4,325 Bytes
cce5c90
9106abb
 
cce5c90
 
 
9106abb
6df081a
 
 
9106abb
 
 
 
 
 
 
 
 
 
 
 
 
cce5c90
 
 
 
 
 
 
20a3a8e
cce5c90
6d45229
cce5c90
 
 
20a3a8e
 
 
 
cce5c90
 
 
20a3a8e
 
 
cce5c90
 
 
 
 
 
 
ecbd3b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20a3a8e
cce5c90
 
 
 
 
 
 
 
 
6d45229
 
 
 
 
 
 
 
 
 
 
cce5c90
 
 
 
 
 
 
6d45229
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
---
language:
- ar
license: apache-2.0
tags:
- generated_from_trainer
base_model: google-bert/bert-base-multilingual-uncased
datasets:
- labr
widget:
- text: كتاب يستحق القراءة
  example_title: مثال 1
- text: ما عجبني بنوب
  example_title: مثال 2
- text: لم يعجبني أبدا
  example_title: مثال 3
- text: أنصح وبشدة قراءة الكتاب خصوصا لمن لديه اهتمام في العلوم الاجتماعية
  example_title: مثال 4
- text: ماشي حالو بعطيه 4 من 10
  example_title: مثال 5
model-index:
- name: Arabic-Book-Review-Sentiment-Assessment
  results: []
---

<!-- This model card has been generated automatically according to the information the Trainer had access to. You
should probably proofread and complete it, then remove this comment. -->

# Arabic-Book-Review-Sentiment-Assessment

This model is a fine-tuned version of [google-bert/bert-base-multilingual-uncased](https://huggingface.co/google-bert/bert-base-multilingual-uncased) on [labr](https://huggingface.co/datasets/labr) dataset.
It achieves the following results on the evaluation set:
- Loss: 1.5290

## Model description

The purpose of this model is to analyze Arabic review texts and predict the appropriate rating for them, based on the sentiment and content of the review. 
This can be particularly useful in tasks such as sentiment analysis, customer feedback analysis, or any application where understanding the sentiment conveyed in an Arabic textual review is important.



## Intended uses & limitations

While the model performs well with formal Arabic text (Examples 1, 3, and 4), it may struggle with slang or informal language, occasionally assigning higher ratings than expected (Example 2). 
Additionally, the model is not capable of interpreting verbally given ratings (Example 5). 
Users should be aware of these limitations and provide context-appropriate input for optimal performance.

## Training and evaluation data

More information needed

## Training procedure

```
import torch
from datasets import load_dataset
from transformers import (
  AutoModelForSequenceClassification,
  AutoTokenizer,
  DataCollatorWithPadding,
  TrainingArguments,
  Trainer
)


device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

labr = load_dataset("labr")

labels = {0,1,2,3,4}
target_names = [
    "Poor",
    "Fair",
    "Good",
    "Very Good",
    "Excellent"
]

id2label = {idx: label for idx, label in enumerate(target_names)}
label2id = {label: idx for idx, label in enumerate(target_names)}


BERT_MODEL = "google-bert/bert-base-multilingual-uncased"

model = AutoModelForSequenceClassification.from_pretrained(BERT_MODEL, num_labels = len(id2label))
tokenizer = AutoTokenizer.from_pretrained(BERT_MODEL)

model.to(device)


def preprocess_function(examples):
    return tokenizer(examples["text"], truncation=True)

tokenized_labr = labr.map(preprocess_function, batched=True)


data_collator = DataCollatorWithPadding(tokenizer=tokenizer)

training_args = TrainingArguments(
    output_dir="Arabic-Book-Review-Sentiment-Assessment",
    learning_rate=2e-5,
    per_device_train_batch_size=8,
    per_device_eval_batch_size=8,
    num_train_epochs=1,
    weight_decay=0.01,
    push_to_hub=True
)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=tokenized_labr["train"],
    eval_dataset=tokenized_labr["test"],
    tokenizer=tokenizer,
    data_collator=data_collator,
)

trainer.train()

trainer.evaluate(tokenized_labr["test"])
```

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 2e-05
- train_batch_size: 8
- eval_batch_size: 8
- seed: 42
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- num_epochs: 5

### Training results

| Training Loss | Epoch | Step | Validation Loss |
|:-------------:|:-----:|:----:|:---------------:|
| 1.0459        | 1.0   | 1470 | 1.5290          |
| 0.7622        | 2.0   | 2940 | 1.6278          |
| 0.8204        | 3.0   | 4410 | 1.5341          |
| 0.6592        | 4.0   | 5880 | 1.8030          |
| 0.4976        | 5.0   | 7350 | 1.9638          |


### Framework versions

- Transformers 4.39.1
- Pytorch 2.2.1+cu121
- Datasets 2.18.0
- Tokenizers 0.15.2