Views
No views yet
headline: The text content to classifyis_sarcastic: Binary label (1 for sarcastic, 0 for non-sarcastic)| Epoch | Training Loss | Validation Loss | Accuracy |
|---|---|---|---|
| 1 | 0.2048 | 0.1821 | 92.96% |
| 2 | 0.1138 | 0.2792 | 91.01% |
| 3 | 0.0586 | 0.2372 | 93.86% |
pip install transformers datasets evaluate scikit-learn torch1from transformers import pipeline
2import torch
3
4# Load the trained model
5classifier = pipeline("text-classification",
6 model="./sarcasm_model",
7 tokenizer="./sarcasm_model")
8
9# Test examples
10test_inputs = [
11 "I'm absolutely thrilled to be stuck in traffic again.",
12 "The weather is nice and sunny today.",
13 "Oh great, another email from the boss with more tasks."
14]
15
16for sentence in test_inputs:
17 result = classifier(sentence)[0]
18 label = "Sarcastic" if result["label"] == "LABEL_1" else "Not Sarcastic"
19 print(f"'{sentence}' → {label} (Confidence: {result['score']:.2f})")1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model = AutoModelForSequenceClassification.from_pretrained("./sarcasm_model")
6tokenizer = AutoTokenizer.from_pretrained("./sarcasm_model")
7
8# Tokenize input
9text = "Oh wonderful, another Monday morning!"
10inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
11
12# Inference
13with torch.no_grad():
14 outputs = model(**inputs)
15 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
16 predicted_class = outputs.logits.argmax(dim=1).item()
17
18label_mapping = {0: "Not Sarcastic", 1: "Sarcastic"}
19confidence = predictions[0][predicted_class].item()
20print(f"Prediction: {label_mapping[predicted_class]} (Confidence: {confidence:.2f})")bert-base-uncasedsarcasm-detection/
├── sarcasm_model/ # Main fine-tuned model
│ ├── config.json
│ ├── model.safetensors
│ ├── tokenizer_config.json
│ ├── special_tokens_map.json
│ ├── vocab.txt
│ └── tokenizer.json
├── quantized-model/ # Float16 quantized version
│ ├── config.json
│ ├── model.safetensors
│ └── tokenizer files...
├── logs/ # Training logs
├── sarcasm-detection.ipynb # Training notebook
└── README.md # This file1# Load quantized model (Float16)
2quantized_model = AutoModelForSequenceClassification.from_pretrained("./quantized-model")
3quantized_model = quantized_model.to(dtype=torch.float16)1@misc{sarcasm_detection_bert,
2 title={BERT-based Sarcasm Detection for Headlines},
3 author={Your Name},
4 year={2025},
5 note={Fine-tuned BERT model for binary sarcasm classification}
6}