EphAsad commited on
Commit
103195f
·
verified ·
1 Parent(s): 0f1a4fc

Upload 5 files

Browse files
Files changed (5) hide show
  1. README.md +389 -3
  2. config.json +15 -0
  3. full_checkpoint.pt +3 -0
  4. tokenizer.json +0 -0
  5. tokenizer_config.json +16 -0
README.md CHANGED
@@ -1,3 +1,389 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ tags:
6
+ - sentence-transformers
7
+ - sentence-embeddings
8
+ - multi-task-learning
9
+ - reinforcement-learning
10
+ - semantic-similarity
11
+ - nli
12
+ - paraphrase-detection
13
+ datasets:
14
+ - sentence-transformers/stsb
15
+ - nyu-mll/multi_nli
16
+ - quora
17
+ - google-research-datasets/paws
18
+ - nyu-mll/glue
19
+ pipeline_tag: sentence-similarity
20
+ base_model: sentence-transformers/all-MiniLM-L6-v2
21
+ model-index:
22
+ - name: FireDevourerEmbedder-RL-v3.6
23
+ results:
24
+ - task:
25
+ type: semantic-similarity
26
+ name: Semantic Textual Similarity
27
+ dataset:
28
+ type: sentence-transformers/stsb
29
+ name: STS-B
30
+ metrics:
31
+ - type: pearson_spearman_avg
32
+ value: 0.3366
33
+ - task:
34
+ type: natural-language-inference
35
+ name: Natural Language Inference
36
+ dataset:
37
+ type: nyu-mll/multi_nli
38
+ name: MultiNLI
39
+ metrics:
40
+ - type: accuracy
41
+ value: 0.7465
42
+ - task:
43
+ type: text-classification
44
+ name: Question Duplicate Detection
45
+ dataset:
46
+ type: quora
47
+ name: QQP
48
+ metrics:
49
+ - type: accuracy
50
+ value: 0.8636
51
+ - task:
52
+ type: text-classification
53
+ name: Paraphrase Detection
54
+ dataset:
55
+ type: google-research-datasets/paws
56
+ name: PAWS
57
+ metrics:
58
+ - type: accuracy
59
+ value: 0.8459
60
+ - task:
61
+ type: text-classification
62
+ name: Paraphrase Detection
63
+ dataset:
64
+ type: nyu-mll/glue
65
+ name: MRPC
66
+ metrics:
67
+ - type: accuracy
68
+ value: 0.7744
69
+ ---
70
+
71
+ # FireDevourerEmbedder-RL-v3.6
72
+
73
+ A multi-task sentence embedding model that uses **Reinforcement Learning** to dynamically optimize task weights during training. The model learns to balance multiple NLU tasks simultaneously, producing robust sentence embeddings suitable for semantic similarity, natural language inference, and paraphrase detection.
74
+
75
+ ## Key Innovation
76
+
77
+ FireDevourerEmbedder introduces an **RL-based adaptive task weighting system** that automatically adjusts the importance of each training task based on validation performance. Instead of using fixed task weights, a policy network learns optimal weight distributions during training, leading to better overall performance across diverse NLU benchmarks.
78
+
79
+ ## Why Multi-Task? Information-Dense Embeddings
80
+
81
+ The core philosophy behind FireDevourerEmbedder is that **multi-task learning creates richer, more information-dense embeddings** than single-task approaches.
82
+
83
+ By training with multiple task heads simultaneously, the shared encoder is forced to learn representations that capture:
84
+
85
+ | Dimension | Learned From | What It Captures |
86
+ |-----------|--------------|------------------|
87
+ | **Semantic Similarity** | STS-B | Fine-grained meaning overlap |
88
+ | **Logical Relationships** | MultiNLI | Entailment, contradiction, neutrality |
89
+ | **Question Semantics** | QQP | Intent and duplicate detection |
90
+ | **Adversarial Patterns** | PAWS | Word-order sensitivity, paraphrase robustness |
91
+ | **Domain Awareness** | All datasets | Context-appropriate representations |
92
+
93
+ This results in embeddings that are:
94
+ - **More robust** - trained to handle diverse linguistic phenomena
95
+ - **More transferable** - generalize better to unseen tasks
96
+ - **More informative** - each dimension of the embedding vector carries meaningful semantic signal
97
+
98
+ Unlike single-task embedders that optimize for one objective, FireDevourerEmbedder's embeddings simultaneously encode multiple facets of meaning, making them suitable for a wide range of downstream applications without fine-tuning.
99
+
100
+ ## Model Details
101
+
102
+ | Property | Value |
103
+ |----------|-------|
104
+ | **Base Model** | [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) |
105
+ | **Hidden Size** | 384 |
106
+ | **Version** | v3.6 |
107
+ | **Training Steps** | 80,000 |
108
+ | **Total Parameters** | ~22M |
109
+
110
+ ## Architecture
111
+
112
+ The model consists of a shared BERT encoder with task-specific output heads:
113
+
114
+ ```
115
+ Input Sentence(s)
116
+
117
+
118
+ ┌─────────────────────────┐
119
+ │ MiniLM-L6-v2 Encoder │
120
+ │ (384-dim output) │
121
+ └─────────────────────────┘
122
+
123
+
124
+ Mean Pooling
125
+
126
+ ├──► STS Head (384→1) ──► Similarity Score [0,1]
127
+ ├──► NLI Head (384→3) ──► [Contradiction, Neutral, Entailment]
128
+ ├──► QQP Head (384→2) ──► [Not Duplicate, Duplicate]
129
+ ├──► PAWS Head (384→2) ──► [Not Paraphrase, Paraphrase]
130
+ └──► Domain Head (384→5) ──► [General, Entailment, Questions, Adversarial, News]
131
+ ```
132
+
133
+ ## Performance
134
+
135
+ | Task | Dataset | Metric | Score |
136
+ |------|---------|--------|-------|
137
+ | Question Duplicate Detection | QQP | Accuracy + F1 | **0.8636** |
138
+ | Paraphrase Detection | PAWS | Accuracy + F1 | **0.8459** |
139
+ | Paraphrase Detection | MRPC | Accuracy + F1 | **0.7744** |
140
+ | Natural Language Inference | MultiNLI | Accuracy + F1 | **0.7465** |
141
+ | Semantic Textual Similarity | STS-B | Pearson/Spearman | **0.3366** |
142
+ | | | **Average** | **0.7134** |
143
+
144
+ ## Training Details
145
+
146
+ ### Datasets
147
+
148
+ The model was trained on 5 balanced datasets with 100,000 samples each (500,000 total):
149
+
150
+ | Dataset | Task Type | Domain | Samples |
151
+ |---------|-----------|--------|---------|
152
+ | [STS-B](https://huggingface.co/datasets/sentence-transformers/stsb) | Semantic Similarity | General | 100,000 |
153
+ | [MultiNLI](https://huggingface.co/datasets/nyu-mll/multi_nli) | Natural Language Inference | Entailment | 100,000 |
154
+ | [QQP](https://huggingface.co/datasets/quora) | Duplicate Question Detection | Questions | 100,000 |
155
+ | [PAWS](https://huggingface.co/datasets/google-research-datasets/paws) | Paraphrase Detection | Adversarial | 100,000 |
156
+ | [MRPC](https://huggingface.co/datasets/nyu-mll/glue) | Paraphrase Detection | News | 100,000 |
157
+
158
+ ### Data Augmentation Strategy
159
+
160
+ To prevent training bias, all datasets were balanced to exactly **100,000 samples** each:
161
+
162
+ | Dataset | Original Size | Augmentation Method |
163
+ |---------|---------------|---------------------|
164
+ | STS-B | ~8,600 | Repetition (~12x) + pair swapping |
165
+ | MultiNLI | ~433,000 | Subsampling |
166
+ | QQP | ~400,000 | Subsampling |
167
+ | PAWS | ~49,000 | Repetition (~2x) + pair swapping |
168
+ | MRPC | ~3,600 | Repetition (~10x, capped) + pair swapping |
169
+
170
+ **Why this matters:**
171
+ - Without balancing, larger datasets (QQP, MultiNLI) would dominate training
172
+ - Smaller but valuable datasets (MRPC, STS-B) would be underrepresented
173
+ - Equal representation ensures the model learns equally from all task types
174
+
175
+ **Augmentation techniques:**
176
+ - **Repetition**: Smaller datasets repeated up to 10x maximum to prevent memorization
177
+ - **Sentence pair swapping**: For symmetric tasks, (A, B) pairs also trained as (B, A)
178
+
179
+ ### Training Configuration
180
+
181
+ | Parameter | Value |
182
+ |-----------|-------|
183
+ | Epochs | 3 |
184
+ | Batch Size | 16 |
185
+ | Learning Rate | 2e-5 |
186
+ | Total Steps | 93,750 |
187
+ | Warmup Steps | 9,375 (10%) |
188
+ | Evaluation Frequency | Every 10,000 steps |
189
+ | Early Stopping | 3 consecutive decreases |
190
+ | Training Time | 3.29 hours |
191
+
192
+ ### RL Weight Adaptation System
193
+
194
+ The model uses a policy network to dynamically adjust task weights during training:
195
+
196
+ | Parameter | Value |
197
+ |-----------|-------|
198
+ | RL Learning Rate | 0.001 |
199
+ | State Dimension | 6 (5 task scores + average) |
200
+ | Action Dimension | 5 (weight deltas) |
201
+ | Hidden Dimension | 32 |
202
+ | Delta Scale | ±5% per update |
203
+ | Update Frequency | Every 10,000 steps |
204
+
205
+ **Weight Evolution During Training:**
206
+
207
+ | Task | Initial Weight | Final Weight | Change |
208
+ |------|---------------|--------------|--------|
209
+ | STS | 0.250 | 0.282 | +0.032 |
210
+ | NLI | 0.300 | 0.337 | +0.037 |
211
+ | QQP | 0.200 | 0.063 | -0.137 |
212
+ | PAWS | 0.150 | 0.173 | +0.023 |
213
+ | MRPC | 0.100 | 0.145 | +0.045 |
214
+
215
+ The RL system learned to reduce QQP weight (already high-performing) while increasing weights for harder tasks.
216
+
217
+ ## Training Progress
218
+
219
+ | Version | Step | Average Score | Best Task | Improvement |
220
+ |---------|------|---------------|-----------|-------------|
221
+ | v3.1 | 10,000 | 0.6133 | QQP (0.8093) | +0.6133 |
222
+ | v3.2 | 20,000 | 0.6430 | QQP (0.8351) | +0.0297 |
223
+ | v3.3 | 30,000 | 0.6813 | QQP (0.8391) | +0.0383 |
224
+ | v3.4 | 40,000 | 0.6925 | QQP (0.8527) | +0.0111 |
225
+ | v3.5 | 50,000 | 0.7099 | QQP (0.8579) | +0.0175 |
226
+ | **v3.6** | **80,000** | **0.7134** | **QQP (0.8636)** | **+0.0035** |
227
+
228
+ ## Usage
229
+
230
+ ### Installation
231
+
232
+ ```bash
233
+ pip install torch transformers
234
+ ```
235
+
236
+ ### Loading the Model
237
+
238
+ ```python
239
+ import torch
240
+ from transformers import AutoTokenizer, AutoModel
241
+
242
+ # Load tokenizer and base model
243
+ tokenizer = AutoTokenizer.from_pretrained("path/to/FireDevourerEmbedder-RL-v3.6")
244
+ base_model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
245
+
246
+ # Load checkpoint
247
+ checkpoint = torch.load("path/to/FireDevourerEmbedder-RL-v3.6/full_checkpoint.pt")
248
+
249
+ # Load model weights (you'll need to reconstruct the full model class)
250
+ # See the training script for the complete FireDevourerEmbedder class definition
251
+ ```
252
+
253
+ ### Computing Embeddings
254
+
255
+ ```python
256
+ def mean_pooling(model_output, attention_mask):
257
+ """Apply mean pooling to get sentence embeddings."""
258
+ token_embeddings = model_output[0]
259
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
260
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
261
+
262
+ def get_embedding(text, model, tokenizer):
263
+ """Get sentence embedding for a single text."""
264
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
265
+ with torch.no_grad():
266
+ outputs = model(**inputs)
267
+ return mean_pooling(outputs, inputs["attention_mask"])
268
+
269
+ # Example
270
+ embedding = get_embedding("This is a sample sentence.", model, tokenizer)
271
+ print(f"Embedding shape: {embedding.shape}") # [1, 384]
272
+ ```
273
+
274
+ ### Computing Similarity
275
+
276
+ ```python
277
+ from torch.nn.functional import cosine_similarity
278
+
279
+ sentence1 = "A man is eating pizza"
280
+ sentence2 = "A person is eating food"
281
+
282
+ emb1 = get_embedding(sentence1, model, tokenizer)
283
+ emb2 = get_embedding(sentence2, model, tokenizer)
284
+
285
+ similarity = cosine_similarity(emb1, emb2)
286
+ print(f"Similarity: {similarity.item():.4f}") # ~0.9448
287
+ ```
288
+
289
+ ### Task-Specific Predictions
290
+
291
+ ```python
292
+ # After loading the full model with task heads:
293
+
294
+ def predict_nli(sentence1, sentence2, model, tokenizer):
295
+ """Predict entailment relationship."""
296
+ # Get embeddings for both sentences
297
+ emb1 = get_embedding(sentence1, model, tokenizer)
298
+ emb2 = get_embedding(sentence2, model, tokenizer)
299
+
300
+ # Combine embeddings (concatenate with element-wise difference and product)
301
+ combined = torch.cat([emb1, emb2, torch.abs(emb1 - emb2), emb1 * emb2], dim=-1)
302
+
303
+ # Pass through NLI head
304
+ logits = model.nli_head(combined)
305
+ prediction = torch.argmax(logits, dim=-1)
306
+
307
+ labels = ["Contradiction", "Neutral", "Entailment"]
308
+ return labels[prediction.item()]
309
+
310
+ # Example
311
+ result = predict_nli("It's raining outside", "The weather is sunny", model, tokenizer)
312
+ print(f"NLI Prediction: {result}") # Contradiction
313
+ ```
314
+
315
+ ## Evaluation Results
316
+
317
+ ### Test Suite Statistics (20 diverse test cases)
318
+
319
+ **Cosine Similarity:**
320
+ | Statistic | Value |
321
+ |-----------|-------|
322
+ | Mean | 0.8001 |
323
+ | Std | 0.1562 |
324
+ | Min | 0.3139 |
325
+ | Max | 0.9831 |
326
+ | Median | 0.8149 |
327
+
328
+ **STS Score:**
329
+ | Statistic | Value |
330
+ |-----------|-------|
331
+ | Mean | 0.5672 |
332
+ | Std | 0.2270 |
333
+ | Min | 0.0182 |
334
+ | Max | 0.9468 |
335
+ | Median | 0.5788 |
336
+
337
+ ### Example Predictions
338
+
339
+ | Sentence 1 | Sentence 2 | Cosine Sim | NLI | Domain |
340
+ |------------|------------|------------|-----|--------|
341
+ | "A man is eating pizza" | "A person is eating food" | 0.9448 | Entailment | General |
342
+ | "It's raining outside" | "The weather is sunny" | 0.7124 | Contradiction | Entailment |
343
+ | "How do I learn Python?" | "What's the best way to learn Python?" | 0.8915 | Entailment | Questions |
344
+ | "The quick brown fox jumps..." | "A fast brown fox leaps..." | 0.7837 | Entailment | General |
345
+
346
+ ## Intended Use
347
+
348
+ ### Best Use Cases
349
+ - **Semantic Search**: Finding similar documents or passages
350
+ - **Duplicate Detection**: Identifying duplicate questions or content
351
+ - **Paraphrase Mining**: Finding paraphrased text pairs
352
+ - **Clustering**: Grouping similar sentences or documents
353
+ - **Natural Language Inference**: Determining textual entailment
354
+
355
+ ### Limitations
356
+ - **STS-B Performance**: The model shows lower performance on fine-grained semantic similarity regression (0.3366). For tasks requiring precise similarity scores, consider using dedicated STS models.
357
+ - **English Only**: Trained exclusively on English data.
358
+ - **Max Length**: 512 tokens maximum input length.
359
+ - **Adversarial Robustness**: While trained on PAWS adversarial data, performance on novel adversarial examples may vary.
360
+
361
+ ## Training Loss Progression
362
+
363
+ | Epoch | STS Loss | NLI Loss | QQP Loss | PAWS Loss | MRPC Loss | Domain Loss | Total Loss |
364
+ |-------|----------|----------|----------|-----------|-----------|-------------|------------|
365
+ | 1 | 0.0073 | 0.2508 | 0.0742 | 0.0966 | 0.0287 | 0.0529 | 0.4977 |
366
+ | 2 | 0.0038 | 0.1970 | 0.0430 | 0.0638 | 0.0025 | 0.0196 | 0.3211 |
367
+ | 3 | 0.0031 | 0.1822 | 0.0221 | 0.0479 | 0.0009 | 0.0141 | 0.2631 |
368
+
369
+ ## Citation
370
+
371
+ If you use this model in your research, please cite:
372
+
373
+ ```bibtex
374
+ @misc{firedevourerembedder2025,
375
+ author = {Asad, Zain},
376
+ title = {FireDevourerEmbedder: Multi-Task Sentence Embeddings with RL-Adaptive Task Weighting},
377
+ year = {2025},
378
+ publisher = {Hugging Face},
379
+ url = {https://huggingface.co/zainasad/FireDevourerEmbedder-RL-v3.6}
380
+ }
381
+ ```
382
+
383
+ ## Author
384
+
385
+ **Zain Asad**
386
+
387
+ ## License
388
+
389
+ MIT License
config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "FireDevourerEmbedder",
3
+ "base_model": "sentence-transformers/all-MiniLM-L6-v2",
4
+ "hidden_size": 384,
5
+ "num_domains": 5,
6
+ "version": "v3.6",
7
+ "all_scores": {
8
+ "sts": 0.3365603044681801,
9
+ "nli": 0.7465245776963085,
10
+ "qqp": 0.8635770412127299,
11
+ "paws": 0.8459381311612224,
12
+ "mrpc": 0.7744121028246376,
13
+ "average": 0.7134024314726156
14
+ }
15
+ }
full_checkpoint.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3b3b5f57ca1c72ba35752e1331f585ea3a5959ad893b0af3092e1f3ddd617b21
3
+ size 90930450
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "cls_token": "[CLS]",
4
+ "do_basic_tokenize": true,
5
+ "do_lower_case": true,
6
+ "is_local": false,
7
+ "mask_token": "[MASK]",
8
+ "model_max_length": 512,
9
+ "never_split": null,
10
+ "pad_token": "[PAD]",
11
+ "sep_token": "[SEP]",
12
+ "strip_accents": null,
13
+ "tokenize_chinese_chars": true,
14
+ "tokenizer_class": "BertTokenizer",
15
+ "unk_token": "[UNK]"
16
+ }