Sarcasm detection LoRA adapter for British English (en-UK)
A 4-bit QLoRA adapter that turns google/gemma-2-2b into a binary sarcasm classifier for British English text (Google reviews and Reddit posts).
It is one of three variety-specific adapters (British, Australian, Indian English) that share a single base model and can be swapped at request time.
- Try it: run the Gradio demo locally on a CUDA GPU with
python src/app.pyfrom the GitHub repo - Code and full study: github.com/mohammadabdalaziz241/cross-variety-sentiment-sarcasm
- Sibling adapters: en-UK · en-AU · en-IN
Results
Test-set results for this adapter (seed 123, the uploaded checkpoint), evaluated on each English variety:
| Test variety | Macro-F1 | Sarcastic-class F1 | Accuracy |
|---|---|---|---|
| en-UK (British English) (in-variety) | 0.737 | 0.506 | 0.939 |
| en-AU (Australian English) | 0.541 | 0.248 | 0.727 |
| en-IN (Indian English) | 0.617 | 0.283 | 0.907 |
Across two seeds, the in-variety Macro-F1 is 0.719 ± 0.025, compared with 0.702 for full RoBERTa-base fine-tuning on the same split.
Strong in-variety performance; the sarcastic class is rare in the British test split (53 examples), so per-class F1 is noisy.
Efficiency: about 0.4% of parameters trained (6.4M of 1.6B), and the adapter is about 25 MB on disk, against roughly 500 MB for a full RoBERTa checkpoint. Measured single-example GPU latency was about 39 ms with the 4-bit base.
How to use
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True, bnb_4bit_compute_dtype=torch.float16)
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")
base = AutoModelForSequenceClassification.from_pretrained(
"google/gemma-2-2b", num_labels=2, quantization_config=bnb,
torch_dtype=torch.float16, device_map="auto")
base.config.pad_token_id = tokenizer.pad_token_id
model = PeftModel.from_pretrained(base, "Mohammadeeu20/besstie-sarcasm-gemma2b-lora-en-uk").eval()
inputs = tokenizer("Oh brilliant, another delayed train.", return_tensors="pt").to(model.device)
with torch.inference_mode():
p_sarcastic = model(**inputs).logits.float().softmax(-1)[0, 1].item()
print(f"P(sarcastic) = {p_sarcastic:.3f}")
Label 1 = sarcastic, label 0 = not sarcastic. Gemma is a gated model, so accept its licence on Hugging Face and log in before loading.
Training details
- Data: surrey-nlp/BESSTIE-CW-26, en-UK training split only
- Base model: google/gemma-2-2b loaded in 4-bit NF4 with double quantisation (QLoRA)
- LoRA: r = 16, alpha = 32, dropout = 0.05, targets q_proj, k_proj, v_proj, o_proj; sequence-classification head
- Optimisation: 4 epochs, learning rate 2e-4, effective batch size 16, warm-up 10%, weight decay 0.01, paged AdamW 8-bit, class-weighted cross-entropy
- Selection: best epoch by validation Macro-F1; max sequence length 384 tokens
Limitations
- Sarcasm is rare and subjective; the minority-class F1 is the number to watch, not accuracy.
- Adapters over-specialise to their own variety: cross-variety transfer is clearly weaker (see the table).
- Trained on short reviews and Reddit posts; other domains are untested.
- Research prototype, not intended for moderation or other high-stakes decisions.
Context
Built as part of a team project for the COMM061 Natural Language Processing module at the University of Surrey (2026). Author of this release: Mohammad Abdalaziz.