Sentence Similarity
sentence-transformers
Safetensors
English
bert
feature-extraction
sts
embeddings
symmetric-augmentation
fine-tuned
text-embeddings-inference
Instructions to use blueprint-ai/SymSTS-MiniLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use blueprint-ai/SymSTS-MiniLM with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("blueprint-ai/SymSTS-MiniLM") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,630 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cd "/run/media/yahya/HARD DISK 4/go/output/minilm-sts-dominator-v3"
|
| 2 |
+
|
| 3 |
+
cat > README.md << 'READMEEOF'
|
| 4 |
---
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
license: apache-2.0
|
| 8 |
+
library_name: sentence-transformers
|
| 9 |
+
tags:
|
| 10 |
+
- sentence-transformers
|
| 11 |
+
- sentence-similarity
|
| 12 |
+
- feature-extraction
|
| 13 |
+
- sts
|
| 14 |
+
- embeddings
|
| 15 |
+
- symmetric-augmentation
|
| 16 |
+
- fine-tuned
|
| 17 |
+
base_model: sentence-transformers/all-MiniLM-L6-v2
|
| 18 |
+
pipeline_tag: sentence-similarity
|
| 19 |
+
datasets:
|
| 20 |
+
- mteb/stsbenchmark-sts
|
| 21 |
+
- mteb/sts12-sts
|
| 22 |
+
metrics:
|
| 23 |
+
- spearmanr
|
| 24 |
---
|
| 25 |
+
|
| 26 |
+
<h1 align="center">SymSTS-MiniLM-L6</h1>
|
| 27 |
+
|
| 28 |
+
<p align="center">
|
| 29 |
+
<strong>Symmetrically Augmented MiniLM for Semantic Textual Similarity</strong>
|
| 30 |
+
</p>
|
| 31 |
+
|
| 32 |
+
<p align="center">
|
| 33 |
+
<img src="https://img.shields.io/badge/Parameters-22.7M-blue" alt="params"/>
|
| 34 |
+
<img src="https://img.shields.io/badge/Embedding--Dim-384-orange" alt="dim"/>
|
| 35 |
+
<img src="https://img.shields.io/badge/Max--Seq--Len-256-yellow" alt="seqlen"/>
|
| 36 |
+
<img src="https://img.shields.io/badge/License-Apache--2.0-green" alt="license"/>
|
| 37 |
+
<img src="https://img.shields.io/badge/STS--Avg--Spearman-0.8205-brightgreen" alt="score"/>
|
| 38 |
+
</p>
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
## 1. What This Model Is
|
| 43 |
+
|
| 44 |
+
SymSTS-MiniLM-L6 is a fine-tuned version of
|
| 45 |
+
[sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2),
|
| 46 |
+
specialized for **Semantic Textual Similarity (STS)**.
|
| 47 |
+
|
| 48 |
+
The key idea behind this model is **symmetric data augmentation**. During training, every sentence
|
| 49 |
+
pair `(A, B, score)` is duplicated as `(B, A, score)`. This forces the model to learn that
|
| 50 |
+
similarity is bidirectional: `similarity(A, B) = similarity(B, A)`. This simple technique
|
| 51 |
+
produces consistent gains across all historical STS benchmarks.
|
| 52 |
+
|
| 53 |
+
The model has **22.7 million parameters**, runs fast on CPU, and fits comfortably on consumer GPUs.
|
| 54 |
+
|
| 55 |
+
> **This is NOT a general-purpose embedding model.**
|
| 56 |
+
> It is built for one job: measuring how similar two sentences are in meaning.
|
| 57 |
+
> It is not optimized for document retrieval, classification, or multilingual tasks.
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## 2. Model Architecture
|
| 62 |
+
|
| 63 |
+
<table>
|
| 64 |
+
<tr><th>Property</th><th>Value</th></tr>
|
| 65 |
+
<tr><td>Base Architecture</td><td>MiniLM (6-layer Transformer encoder)</td></tr>
|
| 66 |
+
<tr><td>Total Parameters</td><td>22.7 M</td></tr>
|
| 67 |
+
<tr><td>Hidden Dimension</td><td>384</td></tr>
|
| 68 |
+
<tr><td>Output Embedding Dimension</td><td>384</td></tr>
|
| 69 |
+
<tr><td>Max Sequence Length</td><td>256 tokens</td></tr>
|
| 70 |
+
<tr><td>Pooling Strategy</td><td>Mean Pooling</td></tr>
|
| 71 |
+
<tr><td>Normalization</td><td>L2-normalized embeddings</td></tr>
|
| 72 |
+
<tr><td>Similarity Function</td><td>Cosine Similarity</td></tr>
|
| 73 |
+
</table>
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## 3. Intended Use
|
| 78 |
+
|
| 79 |
+
<table>
|
| 80 |
+
<tr>
|
| 81 |
+
<th>Good For</th>
|
| 82 |
+
<th>Not Built For</th>
|
| 83 |
+
</tr>
|
| 84 |
+
<tr>
|
| 85 |
+
<td>Semantic similarity scoring between two sentences</td>
|
| 86 |
+
<td>Document retrieval or search ranking over large corpora</td>
|
| 87 |
+
</tr>
|
| 88 |
+
<tr>
|
| 89 |
+
<td>Paraphrase and duplicate question detection</td>
|
| 90 |
+
<td>Sentiment analysis or text classification</td>
|
| 91 |
+
</tr>
|
| 92 |
+
<tr>
|
| 93 |
+
<td>Small-scale text clustering by meaning</td>
|
| 94 |
+
<td>Zero-shot classification</td>
|
| 95 |
+
</tr>
|
| 96 |
+
<tr>
|
| 97 |
+
<td>FAQ matching and chatbot intent matching</td>
|
| 98 |
+
<td>Multilingual or cross-lingual tasks</td>
|
| 99 |
+
</tr>
|
| 100 |
+
<tr>
|
| 101 |
+
<td>Sentence-level deduplication pipelines</td>
|
| 102 |
+
<td>Long-document embedding beyond 256 tokens</td>
|
| 103 |
+
</tr>
|
| 104 |
+
</table>
|
| 105 |
+
|
| 106 |
+
---
|
| 107 |
+
|
| 108 |
+
## 4. Benchmark Results
|
| 109 |
+
|
| 110 |
+
All scores are **Spearman rank correlation** measured locally using the
|
| 111 |
+
[MTEB](https://github.com/embeddings-benchmark/mteb) library on official test splits.
|
| 112 |
+
|
| 113 |
+
### 4.1 STS Results vs Base Model
|
| 114 |
+
|
| 115 |
+
<table>
|
| 116 |
+
<tr>
|
| 117 |
+
<th>Task</th>
|
| 118 |
+
<th>Base MiniLM-L6-v2</th>
|
| 119 |
+
<th>SymSTS-MiniLM-L6 (Ours)</th>
|
| 120 |
+
<th>Difference</th>
|
| 121 |
+
</tr>
|
| 122 |
+
<tr><td>STS12</td><td>0.7237</td><td><strong>0.7873</strong></td><td>+0.0636</td></tr>
|
| 123 |
+
<tr><td>STS13</td><td>0.8060</td><td><strong>0.8290</strong></td><td>+0.0230</td></tr>
|
| 124 |
+
<tr><td>STS14</td><td>0.7559</td><td><strong>0.8186</strong></td><td>+0.0627</td></tr>
|
| 125 |
+
<tr><td>STS15</td><td>0.8539</td><td><strong>0.8758</strong></td><td>+0.0219</td></tr>
|
| 126 |
+
<tr><td>STS16</td><td>0.7899</td><td><strong>0.8152</strong></td><td>+0.0253</td></tr>
|
| 127 |
+
<tr><td>STSBenchmark</td><td>0.8203</td><td><strong>0.8407</strong></td><td>+0.0204</td></tr>
|
| 128 |
+
<tr><td>SICK-R</td><td>0.7758</td><td><strong>0.7772</strong></td><td>+0.0013</td></tr>
|
| 129 |
+
<tr>
|
| 130 |
+
<td><strong>Average</strong></td>
|
| 131 |
+
<td><strong>0.7894</strong></td>
|
| 132 |
+
<td><strong>0.8205</strong></td>
|
| 133 |
+
<td><strong>+0.0312</strong></td>
|
| 134 |
+
</tr>
|
| 135 |
+
</table>
|
| 136 |
+
|
| 137 |
+
### 4.2 Honest Comparison Against Other Models
|
| 138 |
+
|
| 139 |
+
Scores for external models are approximate, taken from the MTEB leaderboard and published
|
| 140 |
+
model cards. Our scores are measured locally. We include models that outperform ours
|
| 141 |
+
for full transparency.
|
| 142 |
+
|
| 143 |
+
<table>
|
| 144 |
+
<tr>
|
| 145 |
+
<th>Model</th>
|
| 146 |
+
<th>Params</th>
|
| 147 |
+
<th>STS-B Spearman</th>
|
| 148 |
+
<th>STS Avg (approx)</th>
|
| 149 |
+
<th>vs SymSTS</th>
|
| 150 |
+
</tr>
|
| 151 |
+
<tr>
|
| 152 |
+
<td><strong>SymSTS-MiniLM-L6 (Ours)</strong></td>
|
| 153 |
+
<td>22.7M</td>
|
| 154 |
+
<td><strong>0.8407</strong></td>
|
| 155 |
+
<td><strong>0.8205</strong></td>
|
| 156 |
+
<td>--</td>
|
| 157 |
+
</tr>
|
| 158 |
+
<tr>
|
| 159 |
+
<td>all-MiniLM-L6-v2</td>
|
| 160 |
+
<td>22.7M</td>
|
| 161 |
+
<td>0.8203</td>
|
| 162 |
+
<td>0.7894</td>
|
| 163 |
+
<td>SymSTS wins</td>
|
| 164 |
+
</tr>
|
| 165 |
+
<tr>
|
| 166 |
+
<td>all-MiniLM-L12-v2</td>
|
| 167 |
+
<td>33M</td>
|
| 168 |
+
<td>~0.835</td>
|
| 169 |
+
<td>~0.805</td>
|
| 170 |
+
<td>SymSTS wins</td>
|
| 171 |
+
</tr>
|
| 172 |
+
<tr>
|
| 173 |
+
<td>all-mpnet-base-v2</td>
|
| 174 |
+
<td>109M</td>
|
| 175 |
+
<td>~0.835</td>
|
| 176 |
+
<td>~0.810</td>
|
| 177 |
+
<td>SymSTS wins</td>
|
| 178 |
+
</tr>
|
| 179 |
+
<tr>
|
| 180 |
+
<td>bge-small-en-v1.5</td>
|
| 181 |
+
<td>33M</td>
|
| 182 |
+
<td>~0.815</td>
|
| 183 |
+
<td>~0.800</td>
|
| 184 |
+
<td>SymSTS wins</td>
|
| 185 |
+
</tr>
|
| 186 |
+
<tr>
|
| 187 |
+
<td>e5-small-v2</td>
|
| 188 |
+
<td>33M</td>
|
| 189 |
+
<td>~0.820</td>
|
| 190 |
+
<td>~0.805</td>
|
| 191 |
+
<td>SymSTS wins</td>
|
| 192 |
+
</tr>
|
| 193 |
+
<tr>
|
| 194 |
+
<td>gte-small</td>
|
| 195 |
+
<td>33M</td>
|
| 196 |
+
<td>~0.840</td>
|
| 197 |
+
<td>~0.815</td>
|
| 198 |
+
<td>Comparable</td>
|
| 199 |
+
</tr>
|
| 200 |
+
<tr>
|
| 201 |
+
<td>bge-base-en-v1.5</td>
|
| 202 |
+
<td>110M</td>
|
| 203 |
+
<td>~0.855</td>
|
| 204 |
+
<td>~0.835</td>
|
| 205 |
+
<td>They win</td>
|
| 206 |
+
</tr>
|
| 207 |
+
<tr>
|
| 208 |
+
<td>gte-base</td>
|
| 209 |
+
<td>110M</td>
|
| 210 |
+
<td>~0.855</td>
|
| 211 |
+
<td>~0.840</td>
|
| 212 |
+
<td>They win</td>
|
| 213 |
+
</tr>
|
| 214 |
+
<tr>
|
| 215 |
+
<td>nomic-embed-text-v1.5</td>
|
| 216 |
+
<td>137M</td>
|
| 217 |
+
<td>~0.865</td>
|
| 218 |
+
<td>~0.845</td>
|
| 219 |
+
<td>They win</td>
|
| 220 |
+
</tr>
|
| 221 |
+
<tr>
|
| 222 |
+
<td>jina-embeddings-v3</td>
|
| 223 |
+
<td>570M</td>
|
| 224 |
+
<td>~0.870</td>
|
| 225 |
+
<td>~0.855</td>
|
| 226 |
+
<td>They win</td>
|
| 227 |
+
</tr>
|
| 228 |
+
<tr>
|
| 229 |
+
<td>e5-mistral-7b-instruct</td>
|
| 230 |
+
<td>7B</td>
|
| 231 |
+
<td>~0.880</td>
|
| 232 |
+
<td>~0.860</td>
|
| 233 |
+
<td>They win</td>
|
| 234 |
+
</tr>
|
| 235 |
+
</table>
|
| 236 |
+
|
| 237 |
+
**Summary:** SymSTS-MiniLM-L6 outperforms all models at or below 33M parameters and several
|
| 238 |
+
models up to 109M parameters on STS tasks. It is outperformed by larger base-architecture
|
| 239 |
+
models (110M+) and LLM-based embeddings, which is expected given the parameter gap.
|
| 240 |
+
|
| 241 |
+
---
|
| 242 |
+
|
| 243 |
+
## 5. Training Details
|
| 244 |
+
|
| 245 |
+
### 5.1 Loss Function
|
| 246 |
+
|
| 247 |
+
`CosineSimilarityLoss` — minimizes the mean squared error between the predicted cosine
|
| 248 |
+
similarity and the human-annotated similarity score.
|
| 249 |
+
|
| 250 |
+
### 5.2 Symmetric Data Augmentation
|
| 251 |
+
|
| 252 |
+
For every training pair:
|
| 253 |
+
Original: (Sentence_A, Sentence_B, score)
|
| 254 |
+
Augmented: (Sentence_B, Sentence_A, score)
|
| 255 |
+
|
| 256 |
+
Both are included. This doubles the effective dataset and enforces bidirectional similarity.
|
| 257 |
+
|
| 258 |
+
### 5.3 Hyperparameters
|
| 259 |
+
|
| 260 |
+
<table>
|
| 261 |
+
<tr><th>Hyperparameter</th><th>Value</th></tr>
|
| 262 |
+
<tr><td>Learning Rate</td><td>1e-5</td></tr>
|
| 263 |
+
<tr><td>Batch Size</td><td>16</td></tr>
|
| 264 |
+
<tr><td>Epochs</td><td>2</td></tr>
|
| 265 |
+
<tr><td>Warmup</td><td>10% of total steps</td></tr>
|
| 266 |
+
<tr><td>Weight Decay</td><td>0.01</td></tr>
|
| 267 |
+
<tr><td>Optimizer</td><td>AdamW</td></tr>
|
| 268 |
+
<tr><td>Precision</td><td>FP16 (mixed precision)</td></tr>
|
| 269 |
+
<tr><td>Random Seed</td><td>42</td></tr>
|
| 270 |
+
<tr><td>Hardware</td><td>NVIDIA GeForce GTX 1660 SUPER (6 GB VRAM)</td></tr>
|
| 271 |
+
</table>
|
| 272 |
+
|
| 273 |
+
---
|
| 274 |
+
|
| 275 |
+
## 6. Training Data
|
| 276 |
+
|
| 277 |
+
The model was fine-tuned on the **train** splits of the following datasets.
|
| 278 |
+
STS13 through STS16 and SICK-R were **not** used during training. They are held-out
|
| 279 |
+
evaluation benchmarks only.
|
| 280 |
+
|
| 281 |
+
<table>
|
| 282 |
+
<tr>
|
| 283 |
+
<th>Dataset</th>
|
| 284 |
+
<th>Source</th>
|
| 285 |
+
<th>Original Pairs</th>
|
| 286 |
+
<th>After Augmentation</th>
|
| 287 |
+
<th>License</th>
|
| 288 |
+
</tr>
|
| 289 |
+
<tr>
|
| 290 |
+
<td>STS Benchmark (train)</td>
|
| 291 |
+
<td>SemEval-2017 Task 1</td>
|
| 292 |
+
<td>5,749</td>
|
| 293 |
+
<td>11,498</td>
|
| 294 |
+
<td>Research use</td>
|
| 295 |
+
</tr>
|
| 296 |
+
<tr>
|
| 297 |
+
<td>STS12 (train)</td>
|
| 298 |
+
<td>SemEval-2012 Task 6</td>
|
| 299 |
+
<td>2,234</td>
|
| 300 |
+
<td>4,468</td>
|
| 301 |
+
<td>Research use</td>
|
| 302 |
+
</tr>
|
| 303 |
+
<tr>
|
| 304 |
+
<td><strong>Total</strong></td>
|
| 305 |
+
<td></td>
|
| 306 |
+
<td><strong>7,983</strong></td>
|
| 307 |
+
<td><strong>15,966</strong></td>
|
| 308 |
+
<td></td>
|
| 309 |
+
</tr>
|
| 310 |
+
</table>
|
| 311 |
+
|
| 312 |
+
The raw dataset files are **not** redistributed in this repository.
|
| 313 |
+
Only the fine-tuned model weights are provided.
|
| 314 |
+
|
| 315 |
+
---
|
| 316 |
+
|
| 317 |
+
## 7. Usage
|
| 318 |
+
|
| 319 |
+
```python
|
| 320 |
+
from sentence_transformers import SentenceTransformer, util
|
| 321 |
+
|
| 322 |
+
model = SentenceTransformer("YOUR_USERNAME/symsts-minilm-l6")
|
| 323 |
+
|
| 324 |
+
sentences = [
|
| 325 |
+
"The cat sits on the mat.",
|
| 326 |
+
"A feline is resting on the rug.",
|
| 327 |
+
"The stock market crashed today."
|
| 328 |
+
]
|
| 329 |
+
|
| 330 |
+
embeddings = model.encode(sentences, normalize_embeddings=True)
|
| 331 |
+
|
| 332 |
+
sim_01 = util.cos_sim(embeddings[0], embeddings[1]).item()
|
| 333 |
+
sim_02 = util.cos_sim(embeddings[0], embeddings[2]).item()
|
| 334 |
+
|
| 335 |
+
print(f"Cat vs Feline: {sim_01:.4f}")
|
| 336 |
+
print(f"Cat vs Stocks: {sim_02:.4f}")
|
| 337 |
+
#8. Full Training Code
|
| 338 |
+
This is the exact script used to train SymSTS-MiniLM-L6.
|
| 339 |
+
import warnings
|
| 340 |
+
warnings.filterwarnings("ignore")
|
| 341 |
+
|
| 342 |
+
import os
|
| 343 |
+
import torch
|
| 344 |
+
from datasets import load_dataset, Dataset
|
| 345 |
+
|
| 346 |
+
from sentence_transformers import (
|
| 347 |
+
SentenceTransformer,
|
| 348 |
+
SentenceTransformerTrainer,
|
| 349 |
+
SentenceTransformerTrainingArguments,
|
| 350 |
+
InputExample,
|
| 351 |
+
)
|
| 352 |
+
from sentence_transformers.losses import CosineSimilarityLoss
|
| 353 |
+
from sentence_transformers.evaluation import EmbeddingSimilarityEvaluator
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
# =============================================================
|
| 357 |
+
# Configuration
|
| 358 |
+
# =============================================================
|
| 359 |
+
BASE_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
|
| 360 |
+
OUTPUT_DIR = "./output/symsts-minilm-l6"
|
| 361 |
+
RUNS_DIR = "./output/runs-symsts-minilm-l6"
|
| 362 |
+
MAX_SEQ_LEN = 256
|
| 363 |
+
BATCH_SIZE = 16
|
| 364 |
+
LEARNING_RATE = 1e-5
|
| 365 |
+
EPOCHS = 2
|
| 366 |
+
|
| 367 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 368 |
+
print(f"Device: {device}")
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
# =============================================================
|
| 372 |
+
# Helpers
|
| 373 |
+
# =============================================================
|
| 374 |
+
def clean_text(text):
|
| 375 |
+
if text is None:
|
| 376 |
+
return ""
|
| 377 |
+
return " ".join(str(text).strip().split())
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
def get_main_score(result):
|
| 381 |
+
if isinstance(result, dict):
|
| 382 |
+
for key, value in result.items():
|
| 383 |
+
if "spearman_cosine" in key:
|
| 384 |
+
try: return float(value)
|
| 385 |
+
except Exception: pass
|
| 386 |
+
for key, value in result.items():
|
| 387 |
+
if "spearman" in key:
|
| 388 |
+
try: return float(value)
|
| 389 |
+
except Exception: pass
|
| 390 |
+
for value in result.values():
|
| 391 |
+
try: return float(value)
|
| 392 |
+
except Exception: pass
|
| 393 |
+
try: return float(result)
|
| 394 |
+
except Exception: return 0.0
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
# =============================================================
|
| 398 |
+
# 1. Load Base Model
|
| 399 |
+
# =============================================================
|
| 400 |
+
print("Loading base model...")
|
| 401 |
+
student = SentenceTransformer(BASE_MODEL, device=device)
|
| 402 |
+
student.max_seq_length = MAX_SEQ_LEN
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
# =============================================================
|
| 406 |
+
# 2. Load STS Training Data with Symmetric Augmentation
|
| 407 |
+
# =============================================================
|
| 408 |
+
print("Loading STS training data...")
|
| 409 |
+
|
| 410 |
+
sources = [
|
| 411 |
+
("mteb/stsbenchmark-sts", "train"),
|
| 412 |
+
("mteb/sts12-sts", "train"),
|
| 413 |
+
]
|
| 414 |
+
|
| 415 |
+
sentence1_list = []
|
| 416 |
+
sentence2_list = []
|
| 417 |
+
label_list = []
|
| 418 |
+
seen_pairs = set()
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
def add_pair(s1, s2, score):
|
| 422 |
+
s1 = clean_text(s1)
|
| 423 |
+
s2 = clean_text(s2)
|
| 424 |
+
if not s1 or not s2:
|
| 425 |
+
return
|
| 426 |
+
|
| 427 |
+
key = tuple(sorted((s1.lower(), s2.lower())))
|
| 428 |
+
if key in seen_pairs:
|
| 429 |
+
return
|
| 430 |
+
seen_pairs.add(key)
|
| 431 |
+
|
| 432 |
+
# Forward
|
| 433 |
+
sentence1_list.append(s1)
|
| 434 |
+
sentence2_list.append(s2)
|
| 435 |
+
label_list.append(score)
|
| 436 |
+
|
| 437 |
+
# Reverse (Symmetric Augmentation)
|
| 438 |
+
if s1.lower() != s2.lower():
|
| 439 |
+
sentence1_list.append(s2)
|
| 440 |
+
sentence2_list.append(s1)
|
| 441 |
+
label_list.append(score)
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
for dataset_name, split in sources:
|
| 445 |
+
try:
|
| 446 |
+
ds = load_dataset(dataset_name, split=split)
|
| 447 |
+
count = 0
|
| 448 |
+
for row in ds:
|
| 449 |
+
s1 = row.get("sentence1")
|
| 450 |
+
s2 = row.get("sentence2")
|
| 451 |
+
score = row.get("score", 0.0)
|
| 452 |
+
try:
|
| 453 |
+
score = float(score)
|
| 454 |
+
except Exception:
|
| 455 |
+
continue
|
| 456 |
+
if score > 1.0:
|
| 457 |
+
score = score / 5.0
|
| 458 |
+
score = max(0.0, min(1.0, score))
|
| 459 |
+
add_pair(s1, s2, score)
|
| 460 |
+
count += 1
|
| 461 |
+
print(f" Loaded {count} original pairs from {dataset_name}")
|
| 462 |
+
except Exception as e:
|
| 463 |
+
print(f" Skipping {dataset_name}: {e}")
|
| 464 |
+
|
| 465 |
+
print(f"Unique pairs: {len(seen_pairs)}")
|
| 466 |
+
print(f"Total augmented rows: {len(sentence1_list)}")
|
| 467 |
+
|
| 468 |
+
train_dataset = Dataset.from_dict({
|
| 469 |
+
"sentence1": sentence1_list,
|
| 470 |
+
"sentence2": sentence2_list,
|
| 471 |
+
"label": label_list,
|
| 472 |
+
})
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
# =============================================================
|
| 476 |
+
# 3. STS-B Test Evaluator
|
| 477 |
+
# =============================================================
|
| 478 |
+
print("Loading STS-B test evaluator...")
|
| 479 |
+
|
| 480 |
+
sts_test = load_dataset("mteb/stsbenchmark-sts", split="test")
|
| 481 |
+
eval_examples = []
|
| 482 |
+
for row in sts_test:
|
| 483 |
+
s1 = clean_text(row.get("sentence1"))
|
| 484 |
+
s2 = clean_text(row.get("sentence2"))
|
| 485 |
+
score = float(row.get("score", 0.0)) / 5.0
|
| 486 |
+
eval_examples.append(InputExample(texts=[s1, s2], label=score))
|
| 487 |
+
|
| 488 |
+
evaluator = EmbeddingSimilarityEvaluator.from_input_examples(
|
| 489 |
+
eval_examples,
|
| 490 |
+
name="sts-b-test",
|
| 491 |
+
)
|
| 492 |
+
|
| 493 |
+
base_score = get_main_score(evaluator(student))
|
| 494 |
+
print(f"Base model STS-B score: {base_score:.4f}")
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
# =============================================================
|
| 498 |
+
# 4. Train
|
| 499 |
+
# =============================================================
|
| 500 |
+
print("Training SymSTS-MiniLM-L6...")
|
| 501 |
+
|
| 502 |
+
train_loss = CosineSimilarityLoss(model=student)
|
| 503 |
+
|
| 504 |
+
training_args = SentenceTransformerTrainingArguments(
|
| 505 |
+
output_dir = RUNS_DIR,
|
| 506 |
+
num_train_epochs = EPOCHS,
|
| 507 |
+
per_device_train_batch_size = BATCH_SIZE,
|
| 508 |
+
per_device_eval_batch_size = BATCH_SIZE,
|
| 509 |
+
learning_rate = LEARNING_RATE,
|
| 510 |
+
warmup_steps = 0.1,
|
| 511 |
+
weight_decay = 0.01,
|
| 512 |
+
fp16 = torch.cuda.is_available(),
|
| 513 |
+
bf16 = False,
|
| 514 |
+
logging_steps = 50,
|
| 515 |
+
save_strategy = "no",
|
| 516 |
+
eval_strategy = "epoch",
|
| 517 |
+
dataloader_num_workers = 0,
|
| 518 |
+
report_to = "none",
|
| 519 |
+
remove_unused_columns = False,
|
| 520 |
+
seed = 42,
|
| 521 |
+
)
|
| 522 |
+
|
| 523 |
+
trainer = SentenceTransformerTrainer(
|
| 524 |
+
model = student,
|
| 525 |
+
args = training_args,
|
| 526 |
+
train_dataset = train_dataset,
|
| 527 |
+
loss = train_loss,
|
| 528 |
+
evaluator = evaluator,
|
| 529 |
+
)
|
| 530 |
+
|
| 531 |
+
trainer.train()
|
| 532 |
+
|
| 533 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 534 |
+
try:
|
| 535 |
+
trainer.save_model(OUTPUT_DIR)
|
| 536 |
+
except Exception:
|
| 537 |
+
student.save_pretrained(OUTPUT_DIR)
|
| 538 |
+
|
| 539 |
+
print(f"Model saved to: {OUTPUT_DIR}")
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
# =============================================================
|
| 543 |
+
# 5. Final Evaluation
|
| 544 |
+
# =============================================================
|
| 545 |
+
final_score = get_main_score(evaluator(student))
|
| 546 |
+
|
| 547 |
+
print("=" * 50)
|
| 548 |
+
print(f"Base model STS-B: {base_score:.4f}")
|
| 549 |
+
print(f"SymSTS STS-B: {final_score:.4f}")
|
| 550 |
+
print(f"Improvement: {final_score - base_score:+.4f}")
|
| 551 |
+
print("=" * 50)
|
| 552 |
+
|
| 553 |
+
#9. Evaluation Code
|
| 554 |
+
This is the script used to produce the benchmark tables above.
|
| 555 |
+
import warnings
|
| 556 |
+
warnings.filterwarnings("ignore")
|
| 557 |
+
|
| 558 |
+
import os, json, glob, mteb
|
| 559 |
+
from sentence_transformers import SentenceTransformer
|
| 560 |
+
|
| 561 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 562 |
+
|
| 563 |
+
TASKS = [
|
| 564 |
+
"STS12", "STS13", "STS14", "STS15",
|
| 565 |
+
"STS16", "STSBenchmark", "SICK-R",
|
| 566 |
+
]
|
| 567 |
+
|
| 568 |
+
def get_scores(model_path, out_dir):
|
| 569 |
+
model = SentenceTransformer(model_path)
|
| 570 |
+
tasks = mteb.get_tasks(tasks=TASKS)
|
| 571 |
+
evaluation = mteb.MTEB(tasks=tasks)
|
| 572 |
+
evaluation.run(model, output_folder=out_dir, verbosity=0)
|
| 573 |
+
|
| 574 |
+
scores = {}
|
| 575 |
+
for task_name in TASKS:
|
| 576 |
+
files = glob.glob(f"{out_dir}/**/*{task_name}*.json", recursive=True)
|
| 577 |
+
if files:
|
| 578 |
+
with open(files[0]) as f:
|
| 579 |
+
d = json.load(f)
|
| 580 |
+
if "scores" in d and "test" in d["scores"]:
|
| 581 |
+
scores[task_name] = d["scores"]["test"][0].get("main_score", 0.0)
|
| 582 |
+
return scores
|
| 583 |
+
|
| 584 |
+
base = get_scores("sentence-transformers/all-MiniLM-L6-v2", "./mteb_base")
|
| 585 |
+
ours = get_scores("./output/symsts-minilm-l6", "./mteb_ours")
|
| 586 |
+
|
| 587 |
+
print(f"{'Task':<16} {'Base':>8} {'Ours':>8} {'Diff':>8}")
|
| 588 |
+
print("-" * 44)
|
| 589 |
+
for t in TASKS:
|
| 590 |
+
b = base.get(t, 0)
|
| 591 |
+
o = ours.get(t, 0)
|
| 592 |
+
print(f"{t:<16} {b:>8.4f} {o:>8.4f} {o-b:>+8.4f}")
|
| 593 |
+
10. Limitations
|
| 594 |
+
Trained on a small curated dataset (~16,000 augmented pairs). May not generalize well
|
| 595 |
+
to domains far from the STS benchmark distribution (news, forums, headlines, image captions).
|
| 596 |
+
Symmetric augmentation assumes similarity is perfectly symmetric. This is generally true
|
| 597 |
+
for semantic similarity but may not hold for all retrieval scenarios.
|
| 598 |
+
Inherits biases from the base MiniLM architecture and SemEval training data, which is
|
| 599 |
+
predominantly English, web-sourced text.
|
| 600 |
+
Should not be used as the sole decision-making system in high-stakes applications
|
| 601 |
+
without human oversight.
|
| 602 |
+
11. License
|
| 603 |
+
This fine-tuned model is released under the Apache 2.0 License, consistent with the
|
| 604 |
+
license of the base model
|
| 605 |
+
sentence-transformers/all-MiniLM-L6-v2.
|
| 606 |
+
The training datasets (STS Benchmark, STS12) are released for research and evaluation
|
| 607 |
+
purposes by their respective authors. The raw dataset files are not redistributed here.
|
| 608 |
+
12. Credits and Citations
|
| 609 |
+
Base Model:
|
| 610 |
+
Nils Reimers and Iryna Gurevych.
|
| 611 |
+
"Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks."
|
| 612 |
+
Proceedings of EMNLP 2019.
|
| 613 |
+
Model Card
|
| 614 |
+
STS Benchmark:
|
| 615 |
+
Daniel Cer, Mona Diab, Eneko Agirre, Inigo Lopez-Gazpio, Lucia Specia.
|
| 616 |
+
"SemEval-2017 Task 1: Semantic Textual Similarity Multilingual and Crosslingual Focused Evaluation."
|
| 617 |
+
Proceedings of SemEval-2017.
|
| 618 |
+
STS12:
|
| 619 |
+
Eneko Agirre, Daniel Cer, Mona Diab, Inigo Lopez-Gazpio, Lucia Specia.
|
| 620 |
+
"SemEval-2012 Task 6: A Pilot on Semantic Textual Similarity."
|
| 621 |
+
Proceedings of *SEM 2012.
|
| 622 |
+
Evaluation Framework:
|
| 623 |
+
MTEB: Massive Text Embedding Benchmark
|
| 624 |
+
13. Contact
|
| 625 |
+
For questions, bug reports, or collaboration inquiries:
|
| 626 |
+
Email: [YOUR_EMAIL_HERE]
|
| 627 |
+
<p align="center">
|
| 628 |
+
<sub>Trained on consumer hardware. No datacenter required.</sub>
|
| 629 |
+
</p>
|
| 630 |
+
|