EphAsad commited on
Commit
502da85
·
verified ·
1 Parent(s): 06e7987

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +347 -0
README.md ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ## Model Details
80
+
81
+ | Property | Value |
82
+ |----------|-------|
83
+ | **Base Model** | [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) |
84
+ | **Hidden Size** | 384 |
85
+ | **Version** | v3.6 |
86
+ | **Training Steps** | 80,000 |
87
+ | **Total Parameters** | ~22M |
88
+
89
+ ## Architecture
90
+
91
+ The model consists of a shared BERT encoder with task-specific output heads:
92
+
93
+ ```
94
+ Input Sentence(s)
95
+
96
+
97
+ ┌─────────────────────────┐
98
+ │ MiniLM-L6-v2 Encoder │
99
+ │ (384-dim output) │
100
+ └─────────────────────────┘
101
+
102
+
103
+ Mean Pooling
104
+
105
+ ├──► STS Head (384→1) ──► Similarity Score [0,1]
106
+ ├──► NLI Head (384→3) ──► [Contradiction, Neutral, Entailment]
107
+ ├──► QQP Head (384→2) ──► [Not Duplicate, Duplicate]
108
+ ├──► PAWS Head (384→2) ──► [Not Paraphrase, Paraphrase]
109
+ └──► Domain Head (384→5) ──► [General, Entailment, Questions, Adversarial, News]
110
+ ```
111
+
112
+ ## Performance
113
+
114
+ | Task | Dataset | Metric | Score |
115
+ |------|---------|--------|-------|
116
+ | Question Duplicate Detection | QQP | Accuracy + F1 | **0.8636** |
117
+ | Paraphrase Detection | PAWS | Accuracy + F1 | **0.8459** |
118
+ | Paraphrase Detection | MRPC | Accuracy + F1 | **0.7744** |
119
+ | Natural Language Inference | MultiNLI | Accuracy + F1 | **0.7465** |
120
+ | Semantic Textual Similarity | STS-B | Pearson/Spearman | **0.3366** |
121
+ | | | **Average** | **0.7134** |
122
+
123
+ ## Training Details
124
+
125
+ ### Datasets
126
+
127
+ The model was trained on 5 balanced datasets with 100,000 samples each (500,000 total):
128
+
129
+ | Dataset | Task Type | Domain | Samples |
130
+ |---------|-----------|--------|---------|
131
+ | [STS-B](https://huggingface.co/datasets/sentence-transformers/stsb) | Semantic Similarity | General | 100,000 |
132
+ | [MultiNLI](https://huggingface.co/datasets/nyu-mll/multi_nli) | Natural Language Inference | Entailment | 100,000 |
133
+ | [QQP](https://huggingface.co/datasets/quora) | Duplicate Question Detection | Questions | 100,000 |
134
+ | [PAWS](https://huggingface.co/datasets/google-research-datasets/paws) | Paraphrase Detection | Adversarial | 100,000 |
135
+ | [MRPC](https://huggingface.co/datasets/nyu-mll/glue) | Paraphrase Detection | News | 100,000 |
136
+
137
+ ### Training Configuration
138
+
139
+ | Parameter | Value |
140
+ |-----------|-------|
141
+ | Epochs | 3 |
142
+ | Batch Size | 16 |
143
+ | Learning Rate | 2e-5 |
144
+ | Total Steps | 93,750 |
145
+ | Warmup Steps | 9,375 (10%) |
146
+ | Evaluation Frequency | Every 10,000 steps |
147
+ | Early Stopping | 3 consecutive decreases |
148
+ | Training Time | 3.29 hours |
149
+
150
+ ### RL Weight Adaptation System
151
+
152
+ The model uses a policy network to dynamically adjust task weights during training:
153
+
154
+ | Parameter | Value |
155
+ |-----------|-------|
156
+ | RL Learning Rate | 0.001 |
157
+ | State Dimension | 6 (5 task scores + average) |
158
+ | Action Dimension | 5 (weight deltas) |
159
+ | Hidden Dimension | 32 |
160
+ | Delta Scale | ±5% per update |
161
+ | Update Frequency | Every 10,000 steps |
162
+
163
+ **Weight Evolution During Training:**
164
+
165
+ | Task | Initial Weight | Final Weight | Change |
166
+ |------|---------------|--------------|--------|
167
+ | STS | 0.250 | 0.282 | +0.032 |
168
+ | NLI | 0.300 | 0.337 | +0.037 |
169
+ | QQP | 0.200 | 0.063 | -0.137 |
170
+ | PAWS | 0.150 | 0.173 | +0.023 |
171
+ | MRPC | 0.100 | 0.145 | +0.045 |
172
+
173
+ The RL system learned to reduce QQP weight (already high-performing) while increasing weights for harder tasks.
174
+
175
+ ## Training Progress
176
+
177
+ | Version | Step | Average Score | Best Task | Improvement |
178
+ |---------|------|---------------|-----------|-------------|
179
+ | v3.1 | 10,000 | 0.6133 | QQP (0.8093) | +0.6133 |
180
+ | v3.2 | 20,000 | 0.6430 | QQP (0.8351) | +0.0297 |
181
+ | v3.3 | 30,000 | 0.6813 | QQP (0.8391) | +0.0383 |
182
+ | v3.4 | 40,000 | 0.6925 | QQP (0.8527) | +0.0111 |
183
+ | v3.5 | 50,000 | 0.7099 | QQP (0.8579) | +0.0175 |
184
+ | **v3.6** | **80,000** | **0.7134** | **QQP (0.8636)** | **+0.0035** |
185
+
186
+ ## Usage
187
+
188
+ ### Installation
189
+
190
+ ```bash
191
+ pip install torch transformers
192
+ ```
193
+
194
+ ### Loading the Model
195
+
196
+ ```python
197
+ import torch
198
+ from transformers import AutoTokenizer, AutoModel
199
+
200
+ # Load tokenizer and base model
201
+ tokenizer = AutoTokenizer.from_pretrained("path/to/FireDevourerEmbedder-RL-v3.6")
202
+ base_model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
203
+
204
+ # Load checkpoint
205
+ checkpoint = torch.load("path/to/FireDevourerEmbedder-RL-v3.6/full_checkpoint.pt")
206
+
207
+ # Load model weights (you'll need to reconstruct the full model class)
208
+ # See the training script for the complete FireDevourerEmbedder class definition
209
+ ```
210
+
211
+ ### Computing Embeddings
212
+
213
+ ```python
214
+ def mean_pooling(model_output, attention_mask):
215
+ """Apply mean pooling to get sentence embeddings."""
216
+ token_embeddings = model_output[0]
217
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
218
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
219
+
220
+ def get_embedding(text, model, tokenizer):
221
+ """Get sentence embedding for a single text."""
222
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
223
+ with torch.no_grad():
224
+ outputs = model(**inputs)
225
+ return mean_pooling(outputs, inputs["attention_mask"])
226
+
227
+ # Example
228
+ embedding = get_embedding("This is a sample sentence.", model, tokenizer)
229
+ print(f"Embedding shape: {embedding.shape}") # [1, 384]
230
+ ```
231
+
232
+ ### Computing Similarity
233
+
234
+ ```python
235
+ from torch.nn.functional import cosine_similarity
236
+
237
+ sentence1 = "A man is eating pizza"
238
+ sentence2 = "A person is eating food"
239
+
240
+ emb1 = get_embedding(sentence1, model, tokenizer)
241
+ emb2 = get_embedding(sentence2, model, tokenizer)
242
+
243
+ similarity = cosine_similarity(emb1, emb2)
244
+ print(f"Similarity: {similarity.item():.4f}") # ~0.9448
245
+ ```
246
+
247
+ ### Task-Specific Predictions
248
+
249
+ ```python
250
+ # After loading the full model with task heads:
251
+
252
+ def predict_nli(sentence1, sentence2, model, tokenizer):
253
+ """Predict entailment relationship."""
254
+ # Get embeddings for both sentences
255
+ emb1 = get_embedding(sentence1, model, tokenizer)
256
+ emb2 = get_embedding(sentence2, model, tokenizer)
257
+
258
+ # Combine embeddings (concatenate with element-wise difference and product)
259
+ combined = torch.cat([emb1, emb2, torch.abs(emb1 - emb2), emb1 * emb2], dim=-1)
260
+
261
+ # Pass through NLI head
262
+ logits = model.nli_head(combined)
263
+ prediction = torch.argmax(logits, dim=-1)
264
+
265
+ labels = ["Contradiction", "Neutral", "Entailment"]
266
+ return labels[prediction.item()]
267
+
268
+ # Example
269
+ result = predict_nli("It's raining outside", "The weather is sunny", model, tokenizer)
270
+ print(f"NLI Prediction: {result}") # Contradiction
271
+ ```
272
+
273
+ ## Evaluation Results
274
+
275
+ ### Test Suite Statistics (20 diverse test cases)
276
+
277
+ **Cosine Similarity:**
278
+ | Statistic | Value |
279
+ |-----------|-------|
280
+ | Mean | 0.8001 |
281
+ | Std | 0.1562 |
282
+ | Min | 0.3139 |
283
+ | Max | 0.9831 |
284
+ | Median | 0.8149 |
285
+
286
+ **STS Score:**
287
+ | Statistic | Value |
288
+ |-----------|-------|
289
+ | Mean | 0.5672 |
290
+ | Std | 0.2270 |
291
+ | Min | 0.0182 |
292
+ | Max | 0.9468 |
293
+ | Median | 0.5788 |
294
+
295
+ ### Example Predictions
296
+
297
+ | Sentence 1 | Sentence 2 | Cosine Sim | NLI | Domain |
298
+ |------------|------------|------------|-----|--------|
299
+ | "A man is eating pizza" | "A person is eating food" | 0.9448 | Entailment | General |
300
+ | "It's raining outside" | "The weather is sunny" | 0.7124 | Contradiction | Entailment |
301
+ | "How do I learn Python?" | "What's the best way to learn Python?" | 0.8915 | Entailment | Questions |
302
+ | "The quick brown fox jumps..." | "A fast brown fox leaps..." | 0.7837 | Entailment | General |
303
+
304
+ ## Intended Use
305
+
306
+ ### Best Use Cases
307
+ - **Semantic Search**: Finding similar documents or passages
308
+ - **Duplicate Detection**: Identifying duplicate questions or content
309
+ - **Paraphrase Mining**: Finding paraphrased text pairs
310
+ - **Clustering**: Grouping similar sentences or documents
311
+ - **Natural Language Inference**: Determining textual entailment
312
+
313
+ ### Limitations
314
+ - **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.
315
+ - **English Only**: Trained exclusively on English data.
316
+ - **Max Length**: 512 tokens maximum input length.
317
+ - **Adversarial Robustness**: While trained on PAWS adversarial data, performance on novel adversarial examples may vary.
318
+
319
+ ## Training Loss Progression
320
+
321
+ | Epoch | STS Loss | NLI Loss | QQP Loss | PAWS Loss | MRPC Loss | Domain Loss | Total Loss |
322
+ |-------|----------|----------|----------|-----------|-----------|-------------|------------|
323
+ | 1 | 0.0073 | 0.2508 | 0.0742 | 0.0966 | 0.0287 | 0.0529 | 0.4977 |
324
+ | 2 | 0.0038 | 0.1970 | 0.0430 | 0.0638 | 0.0025 | 0.0196 | 0.3211 |
325
+ | 3 | 0.0031 | 0.1822 | 0.0221 | 0.0479 | 0.0009 | 0.0141 | 0.2631 |
326
+
327
+ ## Citation
328
+
329
+ If you use this model in your research, please cite:
330
+
331
+ ```bibtex
332
+ @misc{firedevourerembedder2025,
333
+ author = {Asad, Zain},
334
+ title = {FireDevourerEmbedder: Multi-Task Sentence Embeddings with RL-Adaptive Task Weighting},
335
+ year = {2025},
336
+ publisher = {Hugging Face},
337
+ url = {https://huggingface.co/zainasad/FireDevourerEmbedder-RL-v3.6}
338
+ }
339
+ ```
340
+
341
+ ## Author
342
+
343
+ **Zain Asad**
344
+
345
+ ## License
346
+
347
+ MIT License