anpmts commited on
Commit
ec49d62
·
verified ·
1 Parent(s): e915c1f

Model save

Browse files
.gitattributes CHANGED
@@ -34,3 +34,4 @@ saved_model/**/* 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
 
 
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
37
+ final_model/tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,160 +1,81 @@
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**: Sentiment Classification (negative/neutral/positive)
36
- - **Architecture**: Sequence Classification (single-head)
37
- - **Languages**: Multilingual (100+ languages)
38
- - **Parameters**: 278M
39
 
40
- ## Training Data
41
 
42
- - **Dataset**: Amazon Reviews (Kaggle)
43
- - **Training Samples**: 8,500
44
- - **Validation Samples**: 1,500
45
- - **Test Samples**: 5,000
46
 
47
- ## Performance
48
 
49
- | Metric | Value |
50
- |--------|-------|
51
- | Validation Accuracy | 92.4% |
52
- | Training Accuracy | 85.4% |
53
- | Validation Loss | 0.179 |
54
 
55
- ## Training Details
56
 
57
- - **Epochs**: 10
58
- - **Batch Size**: 16
59
- - **Learning Rate**: 2e-5
60
- - **Mixed Precision**: FP16
61
- - **Optimizer**: AdamW
62
- - **Scheduler**: Linear Warmup + Cosine Decay
63
 
64
- ## Usage
65
 
66
- ### Option 1: Using AutoModelForSequenceClassification (Recommended)
 
 
 
 
 
 
 
 
67
 
68
- First, make sure the custom model is registered by installing from this repository:
69
 
70
- ```python
71
- # If loading from HuggingFace Hub, you need to install trust_remote_code
72
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
73
- import torch
 
 
 
 
 
 
74
 
75
- # Load model and tokenizer
76
- model_name = "anpmts/sentiment-classifier"
77
- tokenizer = AutoTokenizer.from_pretrained(model_name)
78
- model = AutoModelForSequenceClassification.from_pretrained(
79
- model_name,
80
- trust_remote_code=True # Required for custom models
81
- )
82
 
83
- # Prepare input
84
- text = "This product is amazing! Highly recommend."
85
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=256)
86
 
87
- # Get prediction
88
- with torch.no_grad():
89
- outputs = model(**inputs)
90
- predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
91
- sentiment = torch.argmax(predictions, dim=-1)
92
-
93
- # Map to label
94
- labels = ["negative", "neutral", "positive"]
95
- print(f"Sentiment: {labels[sentiment.item()]}")
96
- print(f"Confidence: {predictions[0][sentiment].item():.2%}")
97
- ```
98
-
99
- ### Option 2: Using Pipeline (Easiest)
100
-
101
- ```python
102
- from transformers import pipeline
103
-
104
- # Load sentiment analysis pipeline
105
- classifier = pipeline(
106
- "text-classification",
107
- model="anpmts/sentiment-classifier",
108
- trust_remote_code=True
109
- )
110
-
111
- # Predict
112
- result = classifier("This product is amazing! Highly recommend.")
113
- print(result)
114
- # Output: [{'label': 'positive', 'score': 0.96}]
115
- ```
116
-
117
- ### Option 3: Direct Model Loading
118
-
119
- ```python
120
- from transformers import AutoTokenizer
121
- import torch
122
-
123
- # You need to have the model code available locally
124
- from src.models import SentimentClassifier
125
-
126
- model = SentimentClassifier.from_pretrained("anpmts/sentiment-classifier")
127
- tokenizer = AutoTokenizer.from_pretrained("anpmts/sentiment-classifier")
128
-
129
- # Inference
130
- text = "This product is amazing!"
131
- inputs = tokenizer(text, return_tensors="pt", max_length=256, truncation=True, padding=True)
132
- outputs = model(**inputs)
133
- predictions = torch.softmax(outputs["logits"], dim=-1)
134
- ```
135
-
136
- ## Training Metrics Over Epochs
137
-
138
- | Epoch | Train Loss | Val Loss | Val Acc |
139
- |-------|-----------|----------|---------|
140
- | 1 | 0.639 | 0.613 | 49.5% |
141
- | 5 | 0.551 | 0.455 | 68.9% |
142
- | 10 | 0.270 | 0.179 | 92.4% |
143
-
144
- ## Citation
145
-
146
- If you use this model, please cite:
147
-
148
- ```
149
- @misc{sentiment-classifier-xlm-roberta,
150
- author = {TrustShop},
151
- title = {Sentiment Classifier - XLM-RoBERTa},
152
- year = {2025},
153
- publisher = {HuggingFace},
154
- url = {https://huggingface.co/anpmts/sentiment-classifier}
155
- }
156
- ```
157
-
158
- ## License
159
-
160
- Apache 2.0
 
1
  ---
 
 
2
  tags:
3
+ - generated_from_trainer
 
 
 
 
 
4
  metrics:
5
  - accuracy
6
+ - precision
7
+ - recall
8
+ - f1
9
  model-index:
10
+ - name: sentiment-classifier
11
+ results: []
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
+ <!-- This model card has been generated automatically according to the information the Trainer had access to. You
15
+ should probably proofread and complete it, then remove this comment. -->
16
 
17
+ # sentiment-classifier
18
 
19
+ This model is a fine-tuned version of [](https://huggingface.co/) on the None dataset.
20
+ It achieves the following results on the evaluation set:
21
+ - Loss: 0.6947
22
+ - Accuracy: 0.4901
23
+ - Precision: 0.2402
24
+ - Recall: 0.4901
25
+ - F1: 0.3224
26
+ - F1 Macro: 0.3289
27
+ - F1 Negative: 0.0
28
+ - Precision Negative: 0.0
29
+ - Recall Negative: 0.0
30
+ - Support Negative: 900
31
+ - F1 Neutral: 0.6578
32
+ - Precision Neutral: 0.4901
33
+ - Recall Neutral: 1.0
34
+ - Support Neutral: 865
35
 
36
+ ## Model description
 
 
 
 
37
 
38
+ More information needed
39
 
40
+ ## Intended uses & limitations
 
 
 
41
 
42
+ More information needed
43
 
44
+ ## Training and evaluation data
 
 
 
 
45
 
46
+ More information needed
47
 
48
+ ## Training procedure
 
 
 
 
 
49
 
50
+ ### Training hyperparameters
51
 
52
+ The following hyperparameters were used during training:
53
+ - learning_rate: 2e-05
54
+ - train_batch_size: 256
55
+ - eval_batch_size: 256
56
+ - seed: 42
57
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
58
+ - lr_scheduler_type: cosine
59
+ - lr_scheduler_warmup_ratio: 0.1
60
+ - num_epochs: 10
61
 
62
+ ### Training results
63
 
64
+ | Training Loss | Epoch | Step | Validation Loss | Accuracy | Precision | Recall | F1 | F1 Macro | F1 Negative | Precision Negative | Recall Negative | Support Negative | F1 Neutral | Precision Neutral | Recall Neutral | Support Neutral |
65
+ |:-------------:|:-----:|:----:|:---------------:|:--------:|:---------:|:------:|:------:|:--------:|:-----------:|:------------------:|:---------------:|:----------------:|:----------:|:-----------------:|:--------------:|:---------------:|
66
+ | 1.1656 | 1.0 | 33 | 0.7228 | 0.5099 | 0.2600 | 0.5099 | 0.3444 | 0.3377 | 0.6754 | 0.5099 | 1.0 | 900 | 0.0 | 0.0 | 0.0 | 865 |
67
+ | 0.8474 | 2.0 | 66 | 0.7003 | 0.4901 | 0.2402 | 0.4901 | 0.3224 | 0.3289 | 0.0 | 0.0 | 0.0 | 900 | 0.6578 | 0.4901 | 1.0 | 865 |
68
+ | 0.8033 | 3.0 | 99 | 0.8336 | 0.4901 | 0.2402 | 0.4901 | 0.3224 | 0.3289 | 0.0 | 0.0 | 0.0 | 900 | 0.6578 | 0.4901 | 1.0 | 865 |
69
+ | 0.7789 | 4.0 | 132 | 0.7006 | 0.5099 | 0.2600 | 0.5099 | 0.3444 | 0.3377 | 0.6754 | 0.5099 | 1.0 | 900 | 0.0 | 0.0 | 0.0 | 865 |
70
+ | 0.7639 | 5.0 | 165 | 0.6940 | 0.4901 | 0.2402 | 0.4901 | 0.3224 | 0.3289 | 0.0 | 0.0 | 0.0 | 900 | 0.6578 | 0.4901 | 1.0 | 865 |
71
+ | 0.7385 | 6.0 | 198 | 0.6946 | 0.4901 | 0.2402 | 0.4901 | 0.3224 | 0.3289 | 0.0 | 0.0 | 0.0 | 900 | 0.6578 | 0.4901 | 1.0 | 865 |
72
+ | 0.7299 | 7.0 | 231 | 0.6961 | 0.4901 | 0.2402 | 0.4901 | 0.3224 | 0.3289 | 0.0 | 0.0 | 0.0 | 900 | 0.6578 | 0.4901 | 1.0 | 865 |
73
+ | 0.7287 | 8.0 | 264 | 0.6943 | 0.4901 | 0.2402 | 0.4901 | 0.3224 | 0.3289 | 0.0 | 0.0 | 0.0 | 900 | 0.6578 | 0.4901 | 1.0 | 865 |
74
 
 
 
 
 
 
 
 
75
 
76
+ ### Framework versions
 
 
77
 
78
+ - Transformers 4.40.2
79
+ - Pytorch 2.9.0+cu128
80
+ - Datasets 2.18.0
81
+ - Tokenizers 0.19.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
all_results.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 8.0,
3
+ "eval_accuracy": 0.49008498583569404,
4
+ "eval_f1": 0.3223752948653044,
5
+ "eval_f1_macro": 0.3288973384030418,
6
+ "eval_f1_negative": 0.0,
7
+ "eval_f1_neutral": 0.6577946768060836,
8
+ "eval_loss": 0.6946861743927002,
9
+ "eval_precision": 0.24018329334157243,
10
+ "eval_precision_negative": 0.0,
11
+ "eval_precision_neutral": 0.49008498583569404,
12
+ "eval_recall": 0.49008498583569404,
13
+ "eval_recall_negative": 0.0,
14
+ "eval_recall_neutral": 1.0,
15
+ "eval_runtime": 0.7012,
16
+ "eval_samples_per_second": 2517.135,
17
+ "eval_steps_per_second": 9.983,
18
+ "eval_support_negative": 900,
19
+ "eval_support_neutral": 865,
20
+ "test_accuracy": 0.502,
21
+ "test_f1": 0.33555792276964047,
22
+ "test_f1_macro": 0.33422103861517977,
23
+ "test_f1_negative": 0.0,
24
+ "test_f1_neutral": 0.6684420772303595,
25
+ "test_loss": 0.6933125257492065,
26
+ "test_precision": 0.252004,
27
+ "test_precision_negative": 0.0,
28
+ "test_precision_neutral": 0.502,
29
+ "test_recall": 0.502,
30
+ "test_recall_negative": 0.0,
31
+ "test_recall_neutral": 1.0,
32
+ "test_runtime": 0.352,
33
+ "test_samples_per_second": 2840.874,
34
+ "test_steps_per_second": 11.363,
35
+ "test_support_negative": 498,
36
+ "test_support_neutral": 502,
37
+ "total_flos": 67710593593440.0,
38
+ "train_loss": 0.838070989558191,
39
+ "train_runtime": 136.8755,
40
+ "train_samples_per_second": 601.642,
41
+ "train_steps_per_second": 2.411
42
+ }
config.json CHANGED
@@ -20,6 +20,6 @@
20
  },
21
  "model_type": "sentiment-classifier",
22
  "pretrained_model": "xlm-roberta-base",
23
- "torch_dtype": "float32",
24
  "transformers_version": "4.40.2"
25
  }
 
20
  },
21
  "model_type": "sentiment-classifier",
22
  "pretrained_model": "xlm-roberta-base",
23
+ "torch_dtype": "bfloat16",
24
  "transformers_version": "4.40.2"
25
  }
eval_results.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 8.0,
3
+ "eval_accuracy": 0.49008498583569404,
4
+ "eval_f1": 0.3223752948653044,
5
+ "eval_f1_macro": 0.3288973384030418,
6
+ "eval_f1_negative": 0.0,
7
+ "eval_f1_neutral": 0.6577946768060836,
8
+ "eval_loss": 0.6946861743927002,
9
+ "eval_precision": 0.24018329334157243,
10
+ "eval_precision_negative": 0.0,
11
+ "eval_precision_neutral": 0.49008498583569404,
12
+ "eval_recall": 0.49008498583569404,
13
+ "eval_recall_negative": 0.0,
14
+ "eval_recall_neutral": 1.0,
15
+ "eval_runtime": 0.7012,
16
+ "eval_samples_per_second": 2517.135,
17
+ "eval_steps_per_second": 9.983,
18
+ "eval_support_negative": 900,
19
+ "eval_support_neutral": 865
20
+ }
final_model/config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "SentimentClassifier"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "configuration_sentiment.SentimentClassifierConfig",
7
+ "AutoModelForSequenceClassification": "sentiment_classifier.SentimentClassifier"
8
+ },
9
+ "dropout": 0.1,
10
+ "hidden_size": 768,
11
+ "id2label": {
12
+ "0": "negative",
13
+ "1": "neutral",
14
+ "2": "positive"
15
+ },
16
+ "label2id": {
17
+ "negative": 0,
18
+ "neutral": 1,
19
+ "positive": 2
20
+ },
21
+ "model_type": "sentiment-classifier",
22
+ "pretrained_model": "xlm-roberta-base",
23
+ "torch_dtype": "bfloat16",
24
+ "transformers_version": "4.40.2"
25
+ }
final_model/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:345950cfc5b7ef657aecf0810dd83f8e29a5b3dc99780869c74d0b2f67b37952
3
+ size 556116300
final_model/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
+ }
final_model/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d0091a328b3441d754e481db5a390d7f3b8dabc6016869fd13ba350d23ddc4cd
3
+ size 17082832
final_model/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
+ }
final_model/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2c0d15bb147b64e7c599e439ac472043fc63dd0a41b956d951ef81d1e2239993
3
+ size 5457
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:92ecd57cf94586c75fa3535e22d0eb6ba86d72aa62223dbe93c116d58994f6dc
3
- size 1112208144
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:345950cfc5b7ef657aecf0810dd83f8e29a5b3dc99780869c74d0b2f67b37952
3
+ size 556116300
test_results.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 8.0,
3
+ "test_accuracy": 0.502,
4
+ "test_f1": 0.33555792276964047,
5
+ "test_f1_macro": 0.33422103861517977,
6
+ "test_f1_negative": 0.0,
7
+ "test_f1_neutral": 0.6684420772303595,
8
+ "test_loss": 0.6933125257492065,
9
+ "test_precision": 0.252004,
10
+ "test_precision_negative": 0.0,
11
+ "test_precision_neutral": 0.502,
12
+ "test_recall": 0.502,
13
+ "test_recall_negative": 0.0,
14
+ "test_recall_neutral": 1.0,
15
+ "test_runtime": 0.352,
16
+ "test_samples_per_second": 2840.874,
17
+ "test_steps_per_second": 11.363,
18
+ "test_support_negative": 498,
19
+ "test_support_neutral": 502
20
+ }
train_results.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 8.0,
3
+ "total_flos": 67710593593440.0,
4
+ "train_loss": 0.838070989558191,
5
+ "train_runtime": 136.8755,
6
+ "train_samples_per_second": 601.642,
7
+ "train_steps_per_second": 2.411
8
+ }