--- 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 and the training data consists of ready-made dataset available on Kaggle. ## 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]). 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=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.9997416138648987} ``` ## Performance | Model-Name | F1 | Precision | Recall | Accuracy | ------------- |:-------------| -----| -----| ----| | helinivan/english-sarcasm-detector | 94.48 | 94.46 | 94.51 | 94.48 | helinivan/multilingual-sarcasm-detector | 90.91 | 91.51 | 90.44 | 91.55