|
--- |
|
language: "multilingual" |
|
tags: |
|
- bert |
|
- sarcasm-detection |
|
- text-classification |
|
widget: |
|
- text: "Gli Usa a un passo dalla recessione" |
|
- text: "CIA Realizes It's Been Using Black Highlighters All These Years." |
|
- text: "We deden een man een nacht in een vat met cola en nu is hij dood" |
|
--- |
|
|
|
# Multilingual Sarcasm Detector |
|
|
|
Multilingual Sarcasm Detector is a text classification model built to detect sarcasm from news article titles. It is fine-tuned on [bert-base-multilingual-uncased](https://huggingface.co/bert-base-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. |
|
|
|
|
|
<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). |
|
- Dutch non-sarcastic data: [Kaggle: Dutch News Articles](https://www.kaggle.com/datasets/maxscheijen/dutch-news-articles) |
|
|
|
Scraped data: |
|
- Dutch sarcastic news from [De Speld](https://speld.nl) |
|
- Italian non-sarcastic news from [Il Giornale](https://www.ilgiornale.it) |
|
- Italian sarcastic news from [Lercio](https://www.lercio.it) |
|
|
|
## 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/multilingual-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.9374828934669495} |
|
``` |
|
|
|
## 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 |