ZyroGod commited on
Commit
cbfee93
·
verified ·
1 Parent(s): ba3c8af

Upload fine-tuned DistilBERT sentiment classifier (Run-2)

Browse files
Files changed (6) hide show
  1. README.md +134 -0
  2. config.json +37 -0
  3. confusion_matrix.png +0 -0
  4. model.safetensors +3 -0
  5. tokenizer.json +0 -0
  6. tokenizer_config.json +19 -0
README.md ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ tags:
6
+ - text-classification
7
+ - sentiment-analysis
8
+ - distilbert
9
+ - pytorch
10
+ - transformers
11
+ - cardiffnlp
12
+ - twitter
13
+ datasets:
14
+ - cardiffnlp/tweet_sentiment_multilingual
15
+ metrics:
16
+ - accuracy
17
+ - f1
18
+ pipeline_tag: text-classification
19
+ model-index:
20
+ - name: ZyroGod/distilbert-sentiment-classifier
21
+ results:
22
+ - task:
23
+ type: text-classification
24
+ name: Sentiment Analysis
25
+ dataset:
26
+ name: cardiffnlp/tweet_sentiment_multilingual (English)
27
+ type: cardiffnlp/tweet_sentiment_multilingual
28
+ args: english
29
+ metrics:
30
+ - name: Test Accuracy
31
+ type: accuracy
32
+ value: 0.6690
33
+ - name: Test Macro F1
34
+ type: f1
35
+ value: 0.6651
36
+ - name: Test Weighted F1
37
+ type: f1
38
+ value: 0.6651
39
+ ---
40
+
41
+ # DistilBERT Sentiment Classifier (Run-2 Champion)
42
+
43
+ Fine-tuned [distilbert-base-uncased](https://huggingface.co/distilbert-base-uncased) for 3-class sentiment classification (`negative`, `neutral`, `positive`) on the English subset of the [cardiffnlp/tweet_sentiment_multilingual](https://huggingface.co/datasets/cardiffnlp/tweet_sentiment_multilingual) dataset.
44
+
45
+ Trained with hardware optimizations designed for a **4GB VRAM NVIDIA GeForce RTX 3050 Laptop GPU**, including FP16 Tensor Core mixed precision and CUDA-fused AdamW (`adamw_torch_fused`).
46
+
47
+ ---
48
+
49
+ ## Benchmark Results (Test Set: 870 Unseen Samples)
50
+
51
+ | Metric | Score | Notes |
52
+ | :--- | :--- | :--- |
53
+ | **Accuracy** | **66.90%** | +1.04% over 3-epoch baseline |
54
+ | **Macro F1** | **66.51%** | Balanced across all 3 classes |
55
+ | **Weighted F1** | **66.51%** | Metric used for checkpoint selection |
56
+ | **Negative F1 / Recall** | **72.98% / 82.41%** | Robust detection of complaints & negative sentiment |
57
+ | **Positive F1 / Precision** | **73.70% / 79.60%** | High precision when flagging positive sentiment |
58
+ | **Neutral F1 / Recall** | **52.84% / 49.66%** | Weakest class; neutral is often confused with its neighbors |
59
+ | **Severe Polarity Inversion** | **3.56%** | Low confusion between opposing sentiments (31/870 samples) |
60
+
61
+
62
+ ### Confusion Matrix
63
+ ![Confusion Matrix](confusion_matrix.png)
64
+
65
+ ---
66
+
67
+ ## Training Configuration & Hyperparameters
68
+
69
+ - **Base Architecture:** `distilbert-base-uncased` (66.95M parameters)
70
+ - **Epochs:** 10 (Champion run with best model selection)
71
+ - **Learning Rate:** 2.0e-5 (Linear warmup & decay)
72
+ - **Per-Device Batch Size:** 16
73
+ - **Gradient Accumulation Steps:** 2 (Effective Batch Size = 32)
74
+ - **Precision:** Mixed Precision FP16 (AMP)
75
+ - **Optimizer:** `adamw_torch_fused` (Weight Decay = 0.01)
76
+ - **Hardware Footprint:** Peak reserved VRAM of 1,456.0 MB (~1.42 GB / 36.4% utilization)
77
+
78
+ ---
79
+
80
+ ## Quickstart & Usage
81
+
82
+ ### Option 1: Hugging Face Pipeline (Simplest)
83
+
84
+ ```python
85
+ from transformers import pipeline
86
+
87
+ # Load pipeline directly from Hugging Face Hub
88
+ classifier = pipeline("sentiment-analysis", model="ZyroGod/distilbert-sentiment-classifier")
89
+
90
+ # Run inference
91
+ sample_text = "I absolutely love this product! Best purchase ever!"
92
+ prediction = classifier(sample_text)
93
+ print(prediction)
94
+ # Output: [{'label': 'positive', 'score': 0.7588}]
95
+ ```
96
+
97
+ ### Option 2: PyTorch AutoModel & AutoTokenizer
98
+
99
+ ```python
100
+ import torch
101
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
102
+
103
+ model_name = "ZyroGod/distilbert-sentiment-classifier"
104
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
105
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
106
+ model.eval()
107
+
108
+ text = "Amazing customer service and quick resolution!"
109
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
110
+
111
+ with torch.no_grad():
112
+ outputs = model(**inputs)
113
+ probs = torch.softmax(outputs.logits, dim=-1)[0]
114
+
115
+ id2label = model.config.id2label
116
+ for idx, prob in enumerate(probs):
117
+ print(f"{id2label[idx]:<10s}: {prob.item():.2%}")
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Label Mapping
123
+
124
+ | Label ID | Sentiment Class |
125
+ | :--- | :--- |
126
+ | `0` | `negative` |
127
+ | `1` | `neutral` |
128
+ | `2` | `positive` |
129
+
130
+ ---
131
+
132
+ ## License
133
+
134
+ This model is open-sourced under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation": "gelu",
3
+ "architectures": [
4
+ "DistilBertForSequenceClassification"
5
+ ],
6
+ "attention_dropout": 0.1,
7
+ "bos_token_id": null,
8
+ "dim": 768,
9
+ "dropout": 0.1,
10
+ "dtype": "float32",
11
+ "eos_token_id": null,
12
+ "hidden_dim": 3072,
13
+ "id2label": {
14
+ "0": "negative",
15
+ "1": "neutral",
16
+ "2": "positive"
17
+ },
18
+ "initializer_range": 0.02,
19
+ "label2id": {
20
+ "negative": 0,
21
+ "neutral": 1,
22
+ "positive": 2
23
+ },
24
+ "max_position_embeddings": 512,
25
+ "model_type": "distilbert",
26
+ "n_heads": 12,
27
+ "n_layers": 6,
28
+ "pad_token_id": 0,
29
+ "problem_type": "single_label_classification",
30
+ "qa_dropout": 0.1,
31
+ "seq_classif_dropout": 0.2,
32
+ "sinusoidal_pos_embds": false,
33
+ "tie_weights_": true,
34
+ "tie_word_embeddings": true,
35
+ "transformers_version": "5.17.0",
36
+ "vocab_size": 30522
37
+ }
confusion_matrix.png ADDED
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e47cecf72866c174d5f1104b6b85a0e1c5f0e24523ab787d3d97b13c3521e113
3
+ size 267835644
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "cls_token": "[CLS]",
4
+ "do_lower_case": true,
5
+ "is_local": true,
6
+ "local_files_only": false,
7
+ "mask_token": "[MASK]",
8
+ "max_length": 128,
9
+ "model_max_length": 128,
10
+ "pad_token": "[PAD]",
11
+ "sep_token": "[SEP]",
12
+ "stride": 0,
13
+ "strip_accents": null,
14
+ "tokenize_chinese_chars": true,
15
+ "tokenizer_class": "BertTokenizer",
16
+ "truncation_side": "right",
17
+ "truncation_strategy": "longest_first",
18
+ "unk_token": "[UNK]"
19
+ }