Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
base_model:
|
4 |
+
- bhadresh-savani/distilbert-base-uncased-emotion
|
5 |
+
---
|
6 |
+
|
7 |
+
# bhadresh-ft-enc
|
8 |
+
|
9 |
+
Fine-tuned version of [`bhadresh-savani/distilbert-base-uncased-emotion`](https://huggingface.co/bhadresh-savani/distilbert-base-uncased-emotion) on a mix of clean and imperceptibly perturbed emotion classification data. This model is designed to improve robustness against character-level adversarial attacks while retaining high accuracy on clean text.
|
10 |
+
|
11 |
+
# Modified encoder architecture
|
12 |
+
|
13 |
+
6 new Transformer layers were added, bringing the total to 12. The final layer of hidden token embeddings are re-aggregated into "word" embeddings by using the groupings created by the tokenizer. The [CLS] embedding is also passed into the new Transformer block. The final output [CLS] embedding is used for classification.
|
14 |
+
A contrastive loss (cosine similarity) between the final [CLS] embeddings generated by clean and perturbed inputs is also added during training.
|
15 |
+
|
16 |
+
Accuracy on [`vlwk/emotion-perturbed`](https://huggingface.co/datasets/vlwk/emotion-perturbed) improves by 2% on perturbation budget 1 to 5 and over 10% over the original model.
|
17 |
+
|
18 |
+
## Model Description
|
19 |
+
|
20 |
+
- **Base model**: `distilbert-base-uncased-emotion`
|
21 |
+
- **Fine-tuning data**: [`vlwk/emotion-perturbed`](https://huggingface.co/datasets/vlwk/emotion-perturbed): lean and perturbed emotion classification inputs (perturbation types: homoglyphs, deletions, reorderings, invisible characters), perturbation budget 1 to 5.
|
22 |
+
|
23 |
+
- **Training epochs**: 3
|
24 |
+
- **Batch size**: 16
|
25 |
+
- **Learning rate**: 2e-5
|
26 |
+
- **Validation split**: 10%
|
27 |
+
|
28 |
+
## Intended Use
|
29 |
+
|
30 |
+
This model is intended for robust emotion classification under adversarial character-level noise. It is particularly useful for evaluating or defending against imperceptible text perturbations.
|
31 |
+
|
32 |
+
## Usage
|
33 |
+
|
34 |
+
```python
|
35 |
+
from transformers import DistilBertTokenizerFast, DistilBertForSequenceClassification
|
36 |
+
|
37 |
+
tokenizer = DistilBertTokenizerFast.from_pretrained("vlwk/bhadresh-ft-enc")
|
38 |
+
model = DistilBertForSequenceClassification.from_pretrained("vlwk/bhadresh-ft-enc")
|
39 |
+
|
40 |
+
inputs = tokenizer("I'm feeling great today!", return_tensors="pt")
|
41 |
+
outputs = model(**inputs)
|
42 |
+
predicted_class = outputs.logits.argmax(-1).item()
|