Initial upload of sarcasm-detector
Browse files- .gitattributes +0 -1
- README.md +71 -0
- config.json +27 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer_config.json +16 -0
- training_args.bin +3 -0
- vocab.txt +0 -0
.gitattributes
CHANGED
|
@@ -25,7 +25,6 @@
|
|
| 25 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
*.wasm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 25 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 28 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
*.wasm filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: "en"
|
| 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 |
+
# English Sarcasm Detector
|
| 12 |
+
|
| 13 |
+
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.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
<b>Labels</b>:
|
| 17 |
+
0 -> Not Sarcastic;
|
| 18 |
+
1 -> Sarcastic
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
## Source Data
|
| 22 |
+
|
| 23 |
+
Datasets:
|
| 24 |
+
- English language data: [Kaggle: News Headlines Dataset For Sarcasm Detection](https://www.kaggle.com/datasets/rmisra/news-headlines-dataset-for-sarcasm-detection).
|
| 25 |
+
|
| 26 |
+
## Training Dataset
|
| 27 |
+
- [helinivan/sarcasm_headlines_multilingual](https://huggingface.co/datasets/helinivan/sarcasm_headlines_multilingual)
|
| 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/english-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=256, 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.9337034225463867}
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## Performance
|
| 66 |
+
| Model-Name | F1 | Precision | Recall | Accuracy
|
| 67 |
+
| ------------- |:-------------| -----| -----| ----|
|
| 68 |
+
| [helinivan/english-sarcasm-detector ](https://huggingface.co/helinivan/english-sarcasm-detector)| **92.38** | 92.75 | 92.38 | 92.42
|
| 69 |
+
| [helinivan/italian-sarcasm-detector ](https://huggingface.co/helinivan/italian-sarcasm-detector) | 88.26 | 87.66 | 89.66 | 88.69
|
| 70 |
+
| [helinivan/multilingual-sarcasm-detector ](https://huggingface.co/helinivan/multilingual-sarcasm-detector) | 87.23 | 88.65 | 86.33 | 88.30
|
| 71 |
+
| [helinivan/dutch-sarcasm-detector ](https://huggingface.co/helinivan/dutch-sarcasm-detector) | 83.02 | 84.27 | 82.01 | 86.81
|
config.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "bert-base-uncased",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"BertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"classifier_dropout": null,
|
| 8 |
+
"gradient_checkpointing": false,
|
| 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 |
+
"position_embedding_type": "absolute",
|
| 21 |
+
"problem_type": "single_label_classification",
|
| 22 |
+
"torch_dtype": "float32",
|
| 23 |
+
"transformers_version": "4.24.0",
|
| 24 |
+
"type_vocab_size": 2,
|
| 25 |
+
"use_cache": true,
|
| 26 |
+
"vocab_size": 30522
|
| 27 |
+
}
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:93827e574975e434a95b6b5b9c9ffbae9132f863a0dc467b89121e88f72f1fe2
|
| 3 |
+
size 438006125
|
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-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:f964b93090dcfc704c2bc0c2a87b6992d5ef9f462e37dd6e4e2969c383cf0284
|
| 3 |
+
size 3311
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|