agentlans commited on
Commit
a0387db
1 Parent(s): 9f7d5ef

Upload 8 files

Browse files
README.md CHANGED
@@ -1,3 +1,134 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ tags:
5
+ - natural-language-inference
6
+ - sentence-transformers
7
+ - transformers
8
+ - nlp
9
+ - model-card
10
+ ---
11
+
12
+ # TinyBERT\_General\_4L\_312D-nli
13
+
14
+ > [!CAUTION]
15
+ > This model has poor Natural Language Inference (NLI) performance probably due to its small size. For research and experimental use only.
16
+
17
+ - **Base Model:** [huawei-noah/TinyBERT_General_4L_312D](https://huggingface.co/huawei-noah/TinyBERT_General_4L_312D)
18
+ - **Task:** Natural Language Inference (NLI)
19
+ - **Framework:** Hugging Face Transformers, Sentence Transformers
20
+
21
+ TinyBERT\_General\_4L\_312D-nli is a fine-tuned NLI model that classifies the relationship between pairs of sentences into three categories: entailment, neutral, and contradiction. It enhances the capabilities of [huawei-noah/TinyBERT_General_4L_312D](https://huggingface.co/huawei-noah/TinyBERT_General_4L_312D) for improved performance on NLI tasks.
22
+
23
+ ## Intended Use
24
+ TinyBERT\_General\_4L\_312D-nli is ideal for research applications requiring understanding of logical relationships between sentences, including:
25
+
26
+ - Semantic textual similarity
27
+ - Question answering
28
+ - Dialogue systems
29
+ - Content moderation
30
+
31
+ ## Performance
32
+ TinyBERT\_General\_4L\_312D-nli was trained on the [sentence-transformers/all-nli](https://huggingface.co/datasets/sentence-transformers/all-nli) dataset, achieving better than random results in sentence pair classification.
33
+
34
+ Performance on the MNLI matched validation set:
35
+ - Accuracy: 0.5911
36
+ - Precision: 0.68
37
+ - Recall: 0.60
38
+ - F1-score: 0.58
39
+
40
+ ## Training details
41
+
42
+ <details>
43
+ <summary><strong>Training Details</strong></summary>
44
+
45
+ - **Dataset:**
46
+ - Used [sentence-transformers/all-nli](https://huggingface.co/datasets/sentence-transformers/all-nli).
47
+
48
+ - **Sampling:**
49
+ - 100 000 training samples and 10 000 evaluation samples.
50
+
51
+ - **Fine-tuning Process:**
52
+ - Custom Python script with adaptive precision training (bfloat16).
53
+ - Early stopping based on evaluation loss.
54
+
55
+ - **Hyperparameters:**
56
+ - **Learning Rate:** 2e-5
57
+ - **Batch Size:** 32
58
+ - **Optimizer:** AdamW (weight decay: 0.01)
59
+ - **Training Duration:** Up to 10 epochs
60
+
61
+ </details>
62
+
63
+ <details>
64
+ <summary><strong>Reproducibility</strong></summary>
65
+
66
+ To ensure reproducibility:
67
+ - Fixed random seed: 42
68
+ - Environment:
69
+ - Python: 3.10.12
70
+ - PyTorch: 2.5.1
71
+ - Transformers: 4.44.2
72
+
73
+ </details>
74
+
75
+ ## Usage Instructions
76
+
77
+ ## Using Sentence Transformers
78
+ ```python
79
+ from sentence_transformers import CrossEncoder
80
+
81
+ model_name = "agentlans/TinyBERT_General_4L_312D-nli"
82
+ model = CrossEncoder(model_name)
83
+ scores = model.predict(
84
+ [
85
+ ("A man is eating pizza", "A man eats something"),
86
+ (
87
+ "A black race car starts up in front of a crowd of people.",
88
+ "A man is driving down a lonely road.",
89
+ ),
90
+ ]
91
+ )
92
+
93
+ label_mapping = ["entailment", "neutral", "contradiction"]
94
+ labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
95
+ print(labels)
96
+ ```
97
+
98
+ ## Using Transformers Library
99
+ ```python
100
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
101
+ import torch
102
+
103
+ model_name = "agentlans/TinyBERT_General_4L_312D-nli"
104
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
105
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
106
+
107
+ features = tokenizer(
108
+ [
109
+ "A man is eating pizza",
110
+ "A black race car starts up in front of a crowd of people.",
111
+ ],
112
+ ["A man eats something", "A man is driving down a lonely road."],
113
+ padding=True,
114
+ truncation=True,
115
+ return_tensors="pt",
116
+ )
117
+
118
+ model.eval()
119
+ with torch.no_grad():
120
+ scores = model(**features).logits
121
+ label_mapping = ["entailment", "neutral", "contradiction"]
122
+ labels = [label_mapping[score_max] for score_max in scores.argmax(dim=1)]
123
+ print(labels)
124
+ ```
125
+
126
+ ## Limitations and Ethical Considerations
127
+ TinyBERT\_General\_4L\_312D-nli may reflect biases present in the training data. Users should evaluate its performance in specific contexts to ensure fairness and accuracy.
128
+
129
+ More importantly, this model has poor performance on the NLI task.
130
+
131
+ ## Conclusion
132
+ TinyBERT\_General\_4L\_312D-nli is a model for NLI tasks, enhancing [huawei-noah/TinyBERT_General_4L_312D](https://huggingface.co/huawei-noah/TinyBERT_General_4L_312D)'s capabilities with straightforward integration into existing frameworks. It aids developers in building intelligent applications that require nuanced language understanding.
133
+
134
+
config.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "huawei-noah/TinyBERT_General_4L_312D",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "cell": {},
8
+ "classifier_dropout": null,
9
+ "emb_size": 312,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 312,
13
+ "id2label": {
14
+ "0": "LABEL_0",
15
+ "1": "LABEL_1",
16
+ "2": "LABEL_2"
17
+ },
18
+ "initializer_range": 0.02,
19
+ "intermediate_size": 1200,
20
+ "label2id": {
21
+ "LABEL_0": 0,
22
+ "LABEL_1": 1,
23
+ "LABEL_2": 2
24
+ },
25
+ "layer_norm_eps": 1e-12,
26
+ "max_position_embeddings": 512,
27
+ "model_type": "bert",
28
+ "num_attention_heads": 12,
29
+ "num_hidden_layers": 4,
30
+ "pad_token_id": 0,
31
+ "position_embedding_type": "absolute",
32
+ "pre_trained": "",
33
+ "problem_type": "single_label_classification",
34
+ "structure": [],
35
+ "torch_dtype": "float32",
36
+ "transformers_version": "4.44.2",
37
+ "type_vocab_size": 2,
38
+ "use_cache": true,
39
+ "vocab_size": 30522
40
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5aed6b738288e55cf1e5c4e57318557da82901091e536488c0af0c9285812879
3
+ size 57413060
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,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "mask_token": "[MASK]",
49
+ "model_max_length": 1000000000000000019884624838656,
50
+ "never_split": null,
51
+ "pad_token": "[PAD]",
52
+ "sep_token": "[SEP]",
53
+ "strip_accents": null,
54
+ "tokenize_chinese_chars": true,
55
+ "tokenizer_class": "BertTokenizer",
56
+ "unk_token": "[UNK]"
57
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:10be73be1914ba8d91cb46bea6405f702a2bd3e8b16d0e147d2e36c69daf1b49
3
+ size 5240
vocab.txt ADDED
The diff for this file is too large to render. See raw diff