helinivan commited on
Commit
6146e12
1 Parent(s): 1d3e3d1

Upload 6 files

Browse files

---
language: "multilingual"
tags:
- bert
- sarcasm-detection
- text-classification
widget:
- text: "CIA Realizes It's Been Using Black Highlighters All These Years."
---

# 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-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.

## Metrics:


## Training 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])

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=512, 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.9999909400939941}
```

## Performance
| Model-Name | F1 | Precision | Recall | Accuracy
| ------------- |:-------------| -----| -----| ----|
| helinivan/multilingual-sarcasm-detector | 90.91 | 91.51 | 90.44 | 91.55

config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "bert-base-multilingual-uncased",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "directionality": "bidi",
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "bert",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 0,
20
+ "pooler_fc_size": 768,
21
+ "pooler_num_attention_heads": 12,
22
+ "pooler_num_fc_layers": 3,
23
+ "pooler_size_per_head": 128,
24
+ "pooler_type": "first_token_transform",
25
+ "position_embedding_type": "absolute",
26
+ "problem_type": "single_label_classification",
27
+ "torch_dtype": "float32",
28
+ "transformers_version": "4.24.0",
29
+ "type_vocab_size": 2,
30
+ "use_cache": true,
31
+ "vocab_size": 105879
32
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6b9491e390a49b708740debec4e8440b1cc6bdd8343cf4477e8c6f3255437e4
3
+ size 669502829
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "do_basic_tokenize": true,
4
+ "do_lower_case": true,
5
+ "mask_token": "[MASK]",
6
+ "model_max_length": 512,
7
+ "name_or_path": "bert-base-multilingual-uncased",
8
+ "never_split": null,
9
+ "pad_token": "[PAD]",
10
+ "sep_token": "[SEP]",
11
+ "special_tokens_map_file": null,
12
+ "strip_accents": null,
13
+ "tokenize_chinese_chars": true,
14
+ "tokenizer_class": "BertTokenizer",
15
+ "unk_token": "[UNK]"
16
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c89f74038f8f083be59130b4ff3cd0ced0598628c86ceb6bdf86522b33f217d0
3
+ size 3375
vocab.txt ADDED
The diff for this file is too large to render. See raw diff