anpmts commited on
Commit
50739f9
·
verified ·
1 Parent(s): 73632a8

Upload sentiment classifier trained on Amazon Reviews

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: multilingual
3
+ license: apache-2.0
4
+ tags:
5
+ - sentiment-analysis
6
+ - text-classification
7
+ - xlm-roberta
8
+ - amazon-reviews
9
+ datasets:
10
+ - amazon-reviews
11
+ metrics:
12
+ - accuracy
13
+ model-index:
14
+ - name: anpmts/sentiment-classifier
15
+ results:
16
+ - task:
17
+ type: text-classification
18
+ name: Sentiment Analysis
19
+ dataset:
20
+ type: amazon-reviews
21
+ name: Amazon Reviews
22
+ metrics:
23
+ - type: accuracy
24
+ value: 0.924
25
+ name: Validation Accuracy
26
+ ---
27
+
28
+ # Sentiment Classifier - XLM-RoBERTa
29
+
30
+ This is a sentiment classification model fine-tuned on Amazon Reviews dataset.
31
+
32
+ ## Model Description
33
+
34
+ - **Base Model**: xlm-roberta-base
35
+ - **Task**: Binary Sentiment Classification (negative/positive)
36
+ - **Languages**: Multilingual (100+ languages)
37
+ - **Parameters**: 278M
38
+
39
+ ## Training Data
40
+
41
+ - **Dataset**: Amazon Reviews (Kaggle)
42
+ - **Training Samples**: 8,500
43
+ - **Validation Samples**: 1,500
44
+ - **Test Samples**: 5,000
45
+
46
+ ## Performance
47
+
48
+ | Metric | Value |
49
+ |--------|-------|
50
+ | Validation Accuracy | 92.4% |
51
+ | Training Accuracy | 85.4% |
52
+ | Validation Loss | 0.179 |
53
+
54
+ ## Training Details
55
+
56
+ - **Epochs**: 10
57
+ - **Batch Size**: 16
58
+ - **Learning Rate**: 2e-5
59
+ - **Mixed Precision**: FP16
60
+ - **Optimizer**: AdamW
61
+ - **Scheduler**: Linear Warmup + Cosine Decay
62
+
63
+ ## Usage
64
+
65
+ ```python
66
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
67
+ import torch
68
+
69
+ # Load model and tokenizer
70
+ model_name = "anpmts/sentiment-classifier"
71
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
72
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
73
+
74
+ # Prepare input
75
+ text = "This product is amazing! Highly recommend."
76
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=256)
77
+
78
+ # Get prediction
79
+ with torch.no_grad():
80
+ outputs = model(**inputs)
81
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
82
+ sentiment = torch.argmax(predictions, dim=-1)
83
+
84
+ # Map to label
85
+ labels = ["negative", "neutral", "positive"]
86
+ print(f"Sentiment: {labels[sentiment.item()]}")
87
+ print(f"Confidence: {predictions[0][sentiment].item():.2%}")
88
+ ```
89
+
90
+ ## Training Metrics Over Epochs
91
+
92
+ | Epoch | Train Loss | Val Loss | Val Acc |
93
+ |-------|-----------|----------|---------|
94
+ | 1 | 0.639 | 0.613 | 49.5% |
95
+ | 5 | 0.551 | 0.455 | 68.9% |
96
+ | 10 | 0.270 | 0.179 | 92.4% |
97
+
98
+ ## Citation
99
+
100
+ If you use this model, please cite:
101
+
102
+ ```
103
+ @misc{sentiment-classifier-xlm-roberta,
104
+ author = {TrustShop},
105
+ title = {Sentiment Classifier - XLM-RoBERTa},
106
+ year = {2025},
107
+ publisher = {HuggingFace},
108
+ url = {https://huggingface.co/anpmts/sentiment-classifier}
109
+ }
110
+ ```
111
+
112
+ ## License
113
+
114
+ Apache 2.0
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "SentimentClassifier"
4
+ ],
5
+ "dropout": 0.1,
6
+ "hidden_size": 768,
7
+ "id2label": {
8
+ "0": "LABEL_0",
9
+ "1": "LABEL_1",
10
+ "2": "LABEL_2"
11
+ },
12
+ "label2id": {
13
+ "LABEL_0": 0,
14
+ "LABEL_1": 1,
15
+ "LABEL_2": 2
16
+ },
17
+ "loss_weights": {
18
+ "classification": 0.7,
19
+ "regression": 0.3
20
+ },
21
+ "model_type": "sentiment-classifier",
22
+ "pretrained_model": "xlm-roberta-base",
23
+ "torch_dtype": "float32",
24
+ "transformers_version": "4.40.2"
25
+ }
label_mappings.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "label_to_id": {
3
+ "negative": 0,
4
+ "neutral": 1,
5
+ "positive": 2
6
+ },
7
+ "id_to_label": {
8
+ "0": "negative",
9
+ "1": "neutral",
10
+ "2": "positive"
11
+ }
12
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2995c0d64ef46001f404d8cfdf891f65e5b9f198d8ae794e549d3f74f9279a0
3
+ size 1113391228
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a56def25aa40facc030ea8b0b87f3688e4b3c39eb8b45d5702b3a1300fe2a20
3
+ size 17082734
tokenizer_config.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "250001": {
36
+ "content": "<mask>",
37
+ "lstrip": true,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "<s>",
45
+ "clean_up_tokenization_spaces": true,
46
+ "cls_token": "<s>",
47
+ "eos_token": "</s>",
48
+ "mask_token": "<mask>",
49
+ "model_max_length": 512,
50
+ "pad_token": "<pad>",
51
+ "sep_token": "</s>",
52
+ "tokenizer_class": "XLMRobertaTokenizer",
53
+ "unk_token": "<unk>"
54
+ }