i-timur commited on
Commit
55e8e98
·
verified ·
1 Parent(s): 2902d8a

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ tags:
5
+ - sentiment-analysis
6
+ - text-classification
7
+ - bert
8
+ - sst2
9
+ - transformers
10
+ datasets:
11
+ - glue
12
+ metrics:
13
+ - accuracy
14
+ - f1
15
+ - precision
16
+ - recall
17
+ pipeline_tag: text-classification
18
+ ---
19
+
20
+ # Fine-tuned BERT for Sentiment Analysis on SST-2
21
+
22
+ This model is a **fine-tuned version of BERT (`bert-base-uncased`)** specifically designed for **binary sentiment classification** of English text, achieving state-of-the-art performance on the Stanford Sentiment Treebank v2 (SST-2) benchmark.
23
+
24
+ ## Model Description
25
+
26
+ The model was created to demonstrate the practical application of **transfer learning** in Natural Language Processing (NLP). While the base BERT model has a deep understanding of general English language structure, it was not originally trained to detect sentiment. This fine-tuning process adapts BERT's powerful contextual embeddings to the specialized task of determining whether a given sentence expresses a **positive** or **negative** opinion.
27
+
28
+ ### Key Technical Details
29
+ * **Architecture:** BERT-base-uncased with a sequence classification head (2 output neurons).
30
+ * **Training Approach:** The pre-trained BERT layers were gently tuned while the newly added classification layer was trained from scratch over 3 epochs.
31
+ * **Framework:** PyTorch with the Hugging Face Transformers library.
32
+
33
+ ## Intended Use & Limitations
34
+
35
+ ### ✅ Intended Use
36
+ This model is optimal for classifying the sentiment of **short English texts**, particularly:
37
+ * Movie or product reviews
38
+ * Social media posts (opinions)
39
+ * Customer feedback snippets
40
+
41
+ ### ⚠️ Limitations
42
+ * **Domain Specificity:** Performance may degrade on texts far outside the movie review domain (e.g., technical, financial, or medical jargon).
43
+ * **Binary Scope:** It is designed for positive/negative classification and does not detect neutral sentiment or more complex emotions.
44
+ * **Language:** Works only with English text.
45
+
46
+ ## Training Data
47
+
48
+ The model was fine-tuned on the **Stanford Sentiment Treebank v2 (SST-2)** dataset from the GLUE benchmark.
49
+
50
+ | Dataset Split | Number of Examples |
51
+ | :--- | :--- |
52
+ | **Training** | 67,349 |
53
+ | **Validation** | 872 |
54
+ | **Test** | 1,821 |
55
+
56
+ **Example from the dataset:**
57
+ * **Sentence:** *"contains no wit , only labored gags"*
58
+ * **Label:** `0` (Negative)
59
+
60
+ ## Training Procedure & Hyperparameters
61
+
62
+ The model was trained for **3 epochs** using the following configuration:
63
+
64
+ | Hyperparameter | Value |
65
+ | :--- | :--- |
66
+ | **Learning Rate** | 2e-5 |
67
+ | **Batch Size** | 16 |
68
+ | **Optimizer** | AdamW |
69
+ | **Weight Decay** | 0.01 |
70
+ | **Warmup Steps** | 0 |
71
+ | **Max Sequence Length** | 128 |
72
+
73
+ The training leveraged the Hugging Face `Trainer` API for efficient optimization and evaluation.
74
+
75
+ ## Evaluation Results
76
+
77
+ The model's performance was evaluated on the SST-2 **validation set**, yielding the following metrics:
78
+
79
+ ### 📊 Overall Performance
80
+ | Metric | Score |
81
+ | :--- | :--- |
82
+ | **Accuracy** | **92.55%** |
83
+ | **F1-Score (Macro Avg)** | **0.93** |
84
+ | **Precision (Negative)** | 0.93 |
85
+ | **Recall (Positive)** | 0.94 |
86
+
87
+ ### 📈 Training Progress
88
+ | Epoch | Training Loss | Validation Loss | Validation Accuracy |
89
+ | :--- | :--- | :--- | :--- |
90
+ | 1 | 0.1760 | 0.2400 | 92.43% |
91
+ | 2 | 0.1240 | 0.3320 | 91.63% |
92
+ | 3 | **0.0704** | **0.3400** | **92.55%** |
93
+
94
+ ### Confusion Matrix (Validation Set, n=872)
95
+ | | Predicted Negative | Predicted Positive |
96
+ | :--- | :---: | :---: |
97
+ | **Actual Negative** | **391** (TN) | 37 (FP) |
98
+ | **Actual Positive** | 27 (FN) | **417** (TP) |
99
+
100
+ ## Live Inference Examples
101
+
102
+ The model correctly classifies clear examples and shows nuanced understanding of ambiguous text:
103
+
104
+ | Input Sentence | Predicted Label | Confidence (Negative, Positive) |
105
+ | :--- | :--- | :--- |
106
+ | *"The movie was fantastic!"* | **Positive** | [0.0002, 0.9998] |
107
+ | *"I hated every minute of this film."* | **Negative** | [0.9994, 0.0006] |
108
+ | *"It was okay, nothing special."* | **Positive** | [0.4308, 0.5692] |
109
+
110
+ *Note: The third example shows low confidence, appropriately reflecting the neutral sentiment of the input.*
111
+
112
+ ## Conclusion
113
+
114
+ This project successfully demonstrates how **transfer learning** with a foundation model like BERT can efficiently create a high-performance, specialized classifier. With minimal training time and data, the fine-tuned model achieves competitive results on a standard NLP benchmark, making it suitable for real-world sentiment analysis applications.
115
+
116
+ ---
117
+ *Model card generated using best practices from the [Hugging Face Model Card Guidebook](https://huggingface.co/docs/hub/model-cards).*
config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "dtype": "float32",
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "id2label": {
13
+ "0": "negative",
14
+ "1": "positive"
15
+ },
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 3072,
18
+ "label2id": {
19
+ "negative": 0,
20
+ "positive": 1
21
+ },
22
+ "layer_norm_eps": 1e-12,
23
+ "max_position_embeddings": 512,
24
+ "model_type": "bert",
25
+ "num_attention_heads": 12,
26
+ "num_hidden_layers": 12,
27
+ "pad_token_id": 0,
28
+ "position_embedding_type": "absolute",
29
+ "problem_type": "single_label_classification",
30
+ "transformers_version": "4.57.3",
31
+ "type_vocab_size": 2,
32
+ "use_cache": true,
33
+ "vocab_size": 30522
34
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aef0ffb596aefbef130424a3b9b3c4276d3a16d62eeb09706a77c1bab427cbf2
3
+ size 437958648
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": false,
45
+ "cls_token": "[CLS]",
46
+ "do_lower_case": true,
47
+ "extra_special_tokens": {},
48
+ "mask_token": "[MASK]",
49
+ "model_max_length": 512,
50
+ "pad_token": "[PAD]",
51
+ "sep_token": "[SEP]",
52
+ "strip_accents": null,
53
+ "tokenize_chinese_chars": true,
54
+ "tokenizer_class": "BertTokenizer",
55
+ "unk_token": "[UNK]"
56
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bfb7ae18e386369f751c5808ed9a9704f57a9f9600bc4ea5aa7a31eaedf8b1d1
3
+ size 5841
vocab.txt ADDED
The diff for this file is too large to render. See raw diff