gal-lardo commited on
Commit
1fbc1a0
·
verified ·
1 Parent(s): ed07278

Upload BERT-RTE-LinearClassifier for EEE 486/586 Assignment

Browse files
Files changed (6) hide show
  1. README.md +74 -0
  2. config.json +39 -0
  3. pytorch_model.bin +3 -0
  4. special_tokens_map.json +7 -0
  5. tokenizer_config.json +58 -0
  6. vocab.txt +0 -0
README.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ datasets:
5
+ - glue/rte
6
+ tags:
7
+ - text-classification
8
+ - glue
9
+ - bert
10
+ - recognizing textual entailment
11
+ - assignment
12
+ metrics:
13
+ - accuracy
14
+ ---
15
+
16
+ # BERT-RTE Linear Classifier for EEE 486/586 Assignment
17
+
18
+ This model is a fine-tuned version of `bert-base-uncased` on the RTE (Recognizing Textual Entailment) task from the GLUE benchmark. It was developed as part of the EEE 486/586 Statistical Foundations of Natural Language Processing course assignment.
19
+
20
+ ## Model Architecture
21
+
22
+ Unlike the standard BERT classification approach, this model implements a custom architecture:
23
+
24
+ - Uses BERT base model as the encoder for feature extraction
25
+ - Replaces the standard single linear classification head with **multiple linear layers**:
26
+ - First expansion layer: hidden_size → hidden_size*2
27
+ - Intermediate layer with ReLU activation and dropout
28
+ - Final classification layer
29
+ - Uses label smoothing of 0.1 in the loss function for better generalization
30
+
31
+ ## Performance
32
+
33
+ The model achieves **70.40%** accuracy on the RTE validation set, with the following training dynamics:
34
+ - Best validation accuracy: 70.40% (epoch 3)
35
+ - Final validation accuracy: 69.68% (with early stopping)
36
+
37
+ ## Hyperparameters
38
+
39
+ The model was optimized using Optuna hyperparameter search:
40
+
41
+ | Hyperparameter | Value |
42
+ |----------------|-------|
43
+ | Learning rate | 1.72e-05 |
44
+ | Max sequence length | 128 |
45
+ | Dropout rate | 0.2 |
46
+ | Hidden size multiplier | 2 |
47
+ | Weight decay | 0.04 |
48
+ | Batch size | 16 |
49
+ | Training epochs | 6 (+2 for final model) |
50
+
51
+ ## Usage
52
+
53
+ This model can be used for textual entailment classification (determining whether one text logically follows from another):
54
+
55
+ ```python
56
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
57
+
58
+ # Load model and tokenizer
59
+ tokenizer = AutoTokenizer.from_pretrained("gal-lardo/BERT-RTE-LinearClassifier")
60
+ model = AutoModelForSequenceClassification.from_pretrained("gal-lardo/BERT-RTE-LinearClassifier")
61
+
62
+ # Prepare input texts
63
+ premise = "The woman is sleeping on the couch."
64
+ hypothesis = "There is a woman resting."
65
+
66
+ # Tokenize and predict
67
+ inputs = tokenizer(premise, hypothesis, return_tensors="pt", padding=True, truncation=True)
68
+ outputs = model(**inputs)
69
+ prediction = outputs.logits.argmax(-1).item()
70
+
71
+ # Convert prediction to label
72
+ label = "entailment" if prediction == 1 else "not_entailment"
73
+ print(f"Prediction: {label}")
74
+ ```
config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": 0.2,
7
+ "custom_params": {
8
+ "batch_size": 16,
9
+ "hidden_size_multiplier": 2,
10
+ "learning_rate": 1.7166350301570613e-05,
11
+ "max_sequence_length": 128,
12
+ "weight_decay": 0.04
13
+ },
14
+ "gradient_checkpointing": false,
15
+ "hidden_act": "gelu",
16
+ "hidden_dropout_prob": 0.1,
17
+ "hidden_size": 768,
18
+ "id2label": {
19
+ "0": "not_entailment",
20
+ "1": "entailment"
21
+ },
22
+ "initializer_range": 0.02,
23
+ "intermediate_size": 3072,
24
+ "label2id": {
25
+ "entailment": 1,
26
+ "not_entailment": 0
27
+ },
28
+ "layer_norm_eps": 1e-12,
29
+ "max_position_embeddings": 512,
30
+ "model_type": "bert",
31
+ "num_attention_heads": 12,
32
+ "num_hidden_layers": 12,
33
+ "pad_token_id": 0,
34
+ "position_embedding_type": "absolute",
35
+ "transformers_version": "4.50.3",
36
+ "type_vocab_size": 2,
37
+ "use_cache": true,
38
+ "vocab_size": 30522
39
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3861415043fdcb6fa8f2c6a7a2810b8f5c2191001fefa5164f5b1673c9d42789
3
+ size 442743563
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_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 512,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "BertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff