helinivan's picture
Create README.md
50058f1
|
raw
history blame
2.31 kB
metadata
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:

Scraped data:

Codebase:


Example of classification

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