nmmursit commited on
Commit
ab61984
·
verified ·
1 Parent(s): b0e3f56

Upload complete model with all files

Browse files
README.md ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ task_categories:
4
+ - sentence-similarity
5
+ language:
6
+ - tr
7
+ tags:
8
+ - dataset
9
+ - sentence-similarity
10
+ - tr
11
+ - turkish
12
+ - ms-marco
13
+ - contrastive-learning
14
+ size_categories:
15
+ - 1K<n<10K
16
+ ---
17
+
18
+ # MS MARCO Turkish Triplets Dataset
19
+
20
+ ## Dataset Description
21
+
22
+ Turkish version of the original MS MARCO dataset. This dataset contains query-passage triplets prepared specifically for contrastive learning tasks in Turkish language. This dataset is formatted from [parsak/msmarco-tr](https://huggingface.co/datasets/parsak/msmarco-tr) for triplet-based contrastive learning.
23
+
24
+ ## Dataset Source
25
+
26
+ **Source**: This dataset is formatted from [parsak/msmarco-tr](https://huggingface.co/datasets/parsak/msmarco-tr), which is based on the original MS MARCO dataset.
27
+
28
+ ## Dataset Structure
29
+
30
+ ### Data Fields
31
+
32
+ - **query_text**: Query text in Turkish
33
+ - **pos_text**: Positive passage text in Turkish
34
+ - **neg_text**: Negative passage text in Turkish
35
+
36
+ ### Data Splits
37
+
38
+ This dataset contains the following splits:
39
+ - **train**: Training data
40
+
41
+ ## Usage
42
+
43
+ ```python
44
+ from datasets import load_dataset
45
+
46
+ # Load the dataset
47
+ dataset = load_dataset("newmindai/ms-marco-turkish-triplets")
48
+
49
+ # Access training data
50
+ train_data = dataset['train']
51
+
52
+ # Example usage
53
+ for example in train_data:
54
+ query = example['query_text']
55
+ positive = example['pos_text']
56
+ negative = example['neg_text']
57
+ print(f"Query: {query}")
58
+ print(f"Positive: {positive}")
59
+ print(f"Negative: {negative}")
60
+ break
61
+ ```
62
+
63
+ ## Recommended Loss Functions
64
+
65
+ This dataset is optimized for the following loss functions:
66
+
67
+ - **MultipleNegativesRankingLoss**
68
+ - **CachedMultipleNegativesRankingLoss**
69
+ - **TripletLoss**
70
+
71
+ ### Loss Function Details
72
+
73
+ #### MultipleNegativesRankingLoss (MNR)
74
+ **Purpose**: Bring similar examples closer while pushing different examples apart. Used when you only have positive pairs (anchor, positive) and want to derive negatives from within the batch.
75
+
76
+ **Mathematical Formula**:
77
+ ```
78
+ L = - (1/N) * Σ log(exp(s(ai, pi) * scale) / Σ exp(s(ai, pj) * scale))
79
+ ```
80
+
81
+ Where:
82
+ - `s(ai, pj)`: similarity function (e.g., cosine similarity)
83
+ - `scale`: temperature coefficient
84
+ - `N`: batch size
85
+
86
+ **Logic**: Maximizes the probability of the correct positive example for each anchor. Other positives in the batch act as negatives ("in-batch negatives"). Larger batches provide more negative examples, leading to better separation.
87
+
88
+ #### CachedMultipleNegativesRankingLoss
89
+ **Purpose**: Same mathematical principle as MNR but with higher memory efficiency.
90
+
91
+ **Key Difference**: Used when large batches cannot fit directly into GPU memory. Pre-caches embeddings and then calculates losses, allowing for "virtually" larger in-batch negatives.
92
+
93
+ **Formula**: Same as MNR, only the computation method differs (mini-batch caching).
94
+
95
+ #### TripletLoss
96
+ **Purpose**: Bring anchor-positive pairs closer while pushing anchor-negative pairs apart by a specific margin.
97
+
98
+ **Mathematical Formula**:
99
+ ```
100
+ L = max(0, d(a, p) - d(a, n) + m)
101
+ ```
102
+
103
+ Where:
104
+ - `d(·, ·)`: distance function (e.g., Euclidean, 1 - cosine)
105
+ - `m`: margin (safety interval)
106
+
107
+ **Logic**: If the negative is already far enough → loss = 0. If the negative is too close to the positive → loss > 0 (penalty).
108
+
109
+ ### Usage Example with Sentence Transformers
110
+
111
+ ```python
112
+ from sentence_transformers import SentenceTransformer, losses, InputExample
113
+ from datasets import load_dataset
114
+
115
+ # Load dataset
116
+ dataset = load_dataset("newmindai/ms-marco-turkish-triplets")
117
+
118
+ # Initialize model
119
+ model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
120
+
121
+ # Prepare training examples
122
+ train_examples = []
123
+ for example in dataset['train']:
124
+ train_examples.append(InputExample(texts=[example['query_text'], example['pos_text']], label=1))
125
+ train_examples.append(InputExample(texts=[example['query_text'], example['neg_text']], label=0))
126
+
127
+ # Initialize loss function
128
+ train_loss = losses.MultipleNegativesRankingLoss(model)
129
+
130
+ # Train the model
131
+ model.fit(
132
+ train_objectives=[(train_examples, train_loss)],
133
+ epochs=1,
134
+ warmup_steps=100
135
+ )
136
+ ```
137
+
138
+ ### Usage Example with TripletLoss
139
+
140
+ ```python
141
+ from sentence_transformers import SentenceTransformer, losses, InputExample
142
+
143
+ # Prepare triplet examples
144
+ train_examples = []
145
+ for example in dataset['train']:
146
+ train_examples.append(InputExample(
147
+ texts=[example['query_text'], example['pos_text'], example['neg_text']]
148
+ ))
149
+
150
+ # Initialize triplet loss
151
+ train_loss = losses.TripletLoss(model)
152
+
153
+ # Train the model
154
+ model.fit(
155
+ train_objectives=[(train_examples, train_loss)],
156
+ epochs=1,
157
+ warmup_steps=100
158
+ )
159
+ ```
160
+
161
+ ## Dataset Statistics
162
+
163
+ - **Language**: tr (Turkish)
164
+ - **Task**: sentence-similarity
165
+ - **Source**: [parsak/msmarco-tr](https://huggingface.co/datasets/parsak/msmarco-tr) (based on original MS MARCO dataset)
166
+ - **Format**: Query-Passage Triplets
167
+ - **Use Case**: Contrastive Learning, Sentence Embeddings
168
+
169
+ ## Performance Tips
170
+
171
+ 1. **Batch Size**: Use batch sizes between 16-32 for optimal performance
172
+ 2. **Learning Rate**: Start with 2e-5 and adjust based on validation performance
173
+ 3. **Epochs**: 1-3 epochs are usually sufficient for fine-tuning
174
+ 4. **Warmup**: Use 10% warmup steps for stable training
175
+
176
+ ## Citation
177
+
178
+ ```bibtex
179
+ @dataset{ms-marco-turkish-triplets,
180
+ title={MS MARCO Turkish Triplets Dataset},
181
+ author={NewMind AI},
182
+ year={2024},
183
+ language={Turkish},
184
+ source={parsak/msmarco-tr (https://huggingface.co/datasets/parsak/msmarco-tr)},
185
+ url={https://huggingface.co/datasets/newmindai/ms-marco-turkish-triplets}
186
+ }
187
+ ```
188
+
189
+ ## License
190
+
191
+ This dataset is released under the Apache 2.0 License.
192
+
193
+ ## Contact
194
+
195
+ For questions or issues regarding this dataset, please contact NewMind AI.
196
+
197
+ ## Related Datasets
198
+
199
+ - [parsak/msmarco-tr](https://huggingface.co/datasets/parsak/msmarco-tr) - Source dataset used to create this formatted triplet version
200
+ - [MS MARCO NLI Triplets](https://huggingface.co/datasets/newmindai/ms-marco-nli-triplets)
201
+ - [MS MARCO Multiple Negatives](https://huggingface.co/datasets/newmindai/ms-marco-multiple-negatives)
data/train-00000-of-00002.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d1c575bad7ddf88a612984313d7b77cb493032dc1da472ffda025a39d7746438
3
+ size 139728878
data/train-00001-of-00002.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:77271035cf21c3139827c9ce1b412933aae43b5c5b0445b8c57c4d452e46d474
3
+ size 139042981