agentlans commited on
Commit
5f910da
1 Parent(s): 69ef222

Upload 8 files

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