agentlans commited on
Commit
5bb7923
·
verified ·
1 Parent(s): a7d53dc

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +130 -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
+ # snowflake-arctic-embed-s-nli
13
+
14
+ - **Base Model:** [Snowflake/snowflake-arctic-embed-s](https://huggingface.co/Snowflake/snowflake-arctic-embed-s)
15
+ - **Task:** Natural Language Inference (NLI)
16
+ - **Framework:** Hugging Face Transformers, Sentence Transformers
17
+
18
+ snowflake-arctic-embed-s-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 [Snowflake/snowflake-arctic-embed-s](https://huggingface.co/Snowflake/snowflake-arctic-embed-s) for improved performance on NLI tasks.
19
+
20
+ ## Intended Use
21
+ snowflake-arctic-embed-s-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
+ snowflake-arctic-embed-s-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.7745
33
+ - Precision: 0.78
34
+ - Recall: 0.77
35
+ - F1-score: 0.77
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 = "snowflake-arctic-embed-s-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 = "snowflake-arctic-embed-s-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
+ snowflake-arctic-embed-s-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
+ snowflake-arctic-embed-s-nli offers a robust solution for NLI tasks, enhancing [Snowflake/snowflake-arctic-embed-s](https://huggingface.co/Snowflake/snowflake-arctic-embed-s)'s capabilities with straightforward integration into existing frameworks. It aids developers in building intelligent applications that require nuanced language understanding.
130
+