File size: 2,543 Bytes
3d6ad07
 
 
 
 
 
 
 
 
 
 
 
e811c99
3d6ad07
 
b0d7cc2
 
 
 
 
1d99ed7
3d6ad07
 
b3e66ec
3d6ad07
1d99ed7
 
 
f6d0624
72d2fea
3d6ad07
 
 
 
 
 
 
 
 
 
 
72d2fea
3d6ad07
 
 
 
 
 
 
7bbcd80
3d6ad07
 
 
 
 
 
 
 
 
 
 
7bbcd80
3d6ad07
 
 
 
 
5cda127
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
language: "en"
tags:
- bert
- sarcasm-detection
- text-classification
widget:
- text: "CIA Realizes It's Been Using Black Highlighters All These Years."
---

# English Sarcasm Detector

English Sarcasm Detector is a text classification model built to detect sarcasm from news article titles. It is fine-tuned on [bert-base-uncased](https://huggingface.co./bert-base-uncased) and the training data consists of ready-made dataset available on Kaggle.


<b>Labels</b>: 
0 -> Not Sarcastic;
1 -> Sarcastic


## Source Data

Datasets:
- English language data: [Kaggle: News Headlines Dataset For Sarcasm Detection](https://www.kaggle.com/datasets/rmisra/news-headlines-dataset-for-sarcasm-detection).

## Training Dataset
- [helinivan/sarcasm_headlines_multilingual](https://huggingface.co./datasets/helinivan/sarcasm_headlines_multilingual)

## Codebase:
- Git Repo: [Official repository](https://github.com/helinivan/multilingual-sarcasm-detector).

---

## Example of classification

```python
from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer
import string

def preprocess_data(text: str) -> str:
   return text.lower().translate(str.maketrans("", "", string.punctuation)).strip()

MODEL_PATH = "helinivan/english-sarcasm-detector"

tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH)

text = "CIA Realizes It's Been Using Black Highlighters All These Years."
tokenized_text = tokenizer([preprocess_data(text)], padding=True, truncation=True, max_length=256, return_tensors="pt")
output = model(**tokenized_text)
probs = output.logits.softmax(dim=-1).tolist()[0]
confidence = max(probs)
prediction = probs.index(confidence)
results = {"is_sarcastic": prediction, "confidence": confidence}

```

Output: 

```
{'is_sarcastic': 1, 'confidence': 0.9337034225463867}
```

## Performance
| Model-Name | F1 | Precision | Recall | Accuracy 
| ------------- |:-------------| -----| -----| ----| 
| [helinivan/english-sarcasm-detector ](https://huggingface.co./helinivan/english-sarcasm-detector)| **92.38** | 92.75 | 92.38 | 92.42
| [helinivan/italian-sarcasm-detector ](https://huggingface.co./helinivan/italian-sarcasm-detector) | 88.26 | 87.66 | 89.66 | 88.69
| [helinivan/multilingual-sarcasm-detector ](https://huggingface.co./helinivan/multilingual-sarcasm-detector) | 87.23 | 88.65 | 86.33 | 88.30
| [helinivan/dutch-sarcasm-detector ](https://huggingface.co./helinivan/dutch-sarcasm-detector) | 83.02 | 84.27 | 82.01 | 86.81