Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: "multilingual"
|
| 3 |
+
tags:
|
| 4 |
+
- bert
|
| 5 |
+
- sarcasm-detection
|
| 6 |
+
- text-classification
|
| 7 |
+
widget:
|
| 8 |
+
- text: "CIA Realizes It's Been Using Black Highlighters All These Years."
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Multilingual Sarcasm Detector
|
| 12 |
+
|
| 13 |
+
Multilingual Sarcasm Detector is a text classification model built to detect sarcasm from news article titles. It is fine-tuned on bert-multilingual uncased and the training data consists of ready-made datasets available on Kaggle as well scraped data from multiple newspapers in English, Dutch and Italian.
|
| 14 |
+
|
| 15 |
+
## Metrics:
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
## Training Data
|
| 19 |
+
|
| 20 |
+
Datasets:
|
| 21 |
+
- English language data: [Kaggle: News Headlines Dataset For Sarcasm Detection]([https://www.kaggle.com/datasets/rmisra/news-headlines-dataset-for-sarcasm-detection]).
|
| 22 |
+
- Dutch non-sarcastic data: [Kaggle: Dutch News Articles]([https://www.kaggle.com/datasets/maxscheijen/dutch-news-articles])
|
| 23 |
+
|
| 24 |
+
Scraped data:
|
| 25 |
+
- Dutch sarcastic news from [De Speld]([https://speld.nl])
|
| 26 |
+
- Italian non-sarcastic news from [Il Giornale]([https://www.ilgiornale.it])
|
| 27 |
+
- Italian sarcastic news from [Lercio]([https://www.lercio.it])
|
| 28 |
+
|
| 29 |
+
Codebase:
|
| 30 |
+
- Git Repo: [Official repository]([https://github.com/helinivan/multilingual-sarcasm-detector]).
|
| 31 |
+
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
## Example of classification
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
from transformers import AutoModelForSequenceClassification
|
| 38 |
+
from transformers import AutoTokenizer
|
| 39 |
+
import string
|
| 40 |
+
|
| 41 |
+
def preprocess_data(text: str) -> str:
|
| 42 |
+
return text.lower().translate(str.maketrans("", "", string.punctuation)).strip()
|
| 43 |
+
|
| 44 |
+
MODEL_PATH = "helinivan/multilingual-sarcasm-detector"
|
| 45 |
+
|
| 46 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
| 47 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH)
|
| 48 |
+
|
| 49 |
+
text = "CIA Realizes It's Been Using Black Highlighters All These Years."
|
| 50 |
+
tokenized_text = tokenizer([preprocess_data(text)], padding=True, truncation=True, max_length=512, return_tensors="pt")
|
| 51 |
+
output = model(**tokenized_text)
|
| 52 |
+
probs = output.logits.softmax(dim=-1).tolist()[0]
|
| 53 |
+
confidence = max(probs)
|
| 54 |
+
prediction = probs.index(confidence)
|
| 55 |
+
results = {"is_sarcastic": prediction, "confidence": confidence}
|
| 56 |
+
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
Output:
|
| 60 |
+
|
| 61 |
+
```
|
| 62 |
+
{'is_sarcastic': 1, 'confidence': 0.9999909400939941}
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## Performance
|
| 66 |
+
| Model-Name | F1 | Precision | Recall | Accuracy
|
| 67 |
+
| ------------- |:-------------| -----| -----| ----|
|
| 68 |
+
| helinivan/multilingual-sarcasm-detector | 90.91 | 91.51 | 90.44 | 91.55
|