Upload 8 files
Browse files- README.md +130 -0
- config.json +37 -0
- model.safetensors +3 -0
- special_tokens_map.json +37 -0
- tokenizer.json +0 -0
- tokenizer_config.json +64 -0
- training_args.bin +3 -0
- vocab.txt +0 -0
README.md
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# all-MiniLM-L6-v2-nli
|
13 |
+
|
14 |
+
- **Base Model:** [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
|
15 |
+
- **Task:** Natural Language Inference (NLI)
|
16 |
+
- **Framework:** Hugging Face Transformers, Sentence Transformers
|
17 |
+
|
18 |
+
all-MiniLM-L6-v2-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 [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) for improved performance on NLI tasks.
|
19 |
+
|
20 |
+
## Intended Use
|
21 |
+
all-MiniLM-L6-v2-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 |
+
all-MiniLM-L6-v2-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.7183
|
33 |
+
- Precision: 0.72
|
34 |
+
- Recall: 0.72
|
35 |
+
- F1-score: 0.72
|
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:** 64
|
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/all-MiniLM-L6-v2-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/all-MiniLM-L6-v2-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 |
+
all-MiniLM-L6-v2-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 |
+
all-MiniLM-L6-v2-nli offers a robust solution for NLI tasks, enhancing [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)'s capabilities with straightforward integration into existing frameworks. It aids developers in building intelligent applications that require nuanced language understanding.
|
130 |
+
|
config.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "sentence-transformers/all-MiniLM-L6-v2",
|
3 |
+
"architectures": [
|
4 |
+
"BertForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"gradient_checkpointing": false,
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.1,
|
11 |
+
"hidden_size": 384,
|
12 |
+
"id2label": {
|
13 |
+
"0": "LABEL_0",
|
14 |
+
"1": "LABEL_1",
|
15 |
+
"2": "LABEL_2"
|
16 |
+
},
|
17 |
+
"initializer_range": 0.02,
|
18 |
+
"intermediate_size": 1536,
|
19 |
+
"label2id": {
|
20 |
+
"LABEL_0": 0,
|
21 |
+
"LABEL_1": 1,
|
22 |
+
"LABEL_2": 2
|
23 |
+
},
|
24 |
+
"layer_norm_eps": 1e-12,
|
25 |
+
"max_position_embeddings": 512,
|
26 |
+
"model_type": "bert",
|
27 |
+
"num_attention_heads": 12,
|
28 |
+
"num_hidden_layers": 6,
|
29 |
+
"pad_token_id": 0,
|
30 |
+
"position_embedding_type": "absolute",
|
31 |
+
"problem_type": "single_label_classification",
|
32 |
+
"torch_dtype": "float32",
|
33 |
+
"transformers_version": "4.44.2",
|
34 |
+
"type_vocab_size": 2,
|
35 |
+
"use_cache": true,
|
36 |
+
"vocab_size": 30522
|
37 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a088dcd6cef8740031d9d63d7b47f3a7ad71e61da231b2a72a5a1cfa91b00602
|
3 |
+
size 90869492
|
special_tokens_map.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": {
|
3 |
+
"content": "[CLS]",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": false,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"mask_token": {
|
10 |
+
"content": "[MASK]",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"pad_token": {
|
17 |
+
"content": "[PAD]",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": false,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": false
|
22 |
+
},
|
23 |
+
"sep_token": {
|
24 |
+
"content": "[SEP]",
|
25 |
+
"lstrip": false,
|
26 |
+
"normalized": false,
|
27 |
+
"rstrip": false,
|
28 |
+
"single_word": false
|
29 |
+
},
|
30 |
+
"unk_token": {
|
31 |
+
"content": "[UNK]",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": false,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false
|
36 |
+
}
|
37 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
"max_length": 128,
|
50 |
+
"model_max_length": 512,
|
51 |
+
"never_split": null,
|
52 |
+
"pad_to_multiple_of": null,
|
53 |
+
"pad_token": "[PAD]",
|
54 |
+
"pad_token_type_id": 0,
|
55 |
+
"padding_side": "right",
|
56 |
+
"sep_token": "[SEP]",
|
57 |
+
"stride": 0,
|
58 |
+
"strip_accents": null,
|
59 |
+
"tokenize_chinese_chars": true,
|
60 |
+
"tokenizer_class": "BertTokenizer",
|
61 |
+
"truncation_side": "right",
|
62 |
+
"truncation_strategy": "longest_first",
|
63 |
+
"unk_token": "[UNK]"
|
64 |
+
}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:842fada25c53a9ac391d53cf3fc82429dc2b9b51ce5a7c5109b3d15c96ed49c5
|
3 |
+
size 5240
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|