Official repository for UAlberta at SemEval-2026 Task 9: Detecting Multilingual, Multicultural and Multievent Online Polarization
This repo contains our systems for the POLAR shared task, covering:
- Subtask 1 – Binary polarization / hate detection
- Subtask 2 – Multi-label hate types (5 labels)
- Subtask 3 – Multi-label hate manifestations (6 labels)
We implement and compare:
- A reproduced BERT baseline (organizers’ starter system)
- Strong encoder models (DeBERTa-v3, XLM-R) with MT-based multilingual support
- Cross-validated and calibrated models with focal loss
- A Qwen2.5-7B few-shot LLM baseline
- Qwen-based data augmentation (paraphrasing)
- Final ensembles of DeBERTa and XLM-R
.
├── BERT-baseline/ # Organizer-style BERT baseline (all subtasks)
├── method/ # Single-run DeBERTa & XLM-R systems (no CV)
├── method2/ # CV + calibration (DeBERTa+MT, XLM-R+MT)
├── method3/ # Qwen augmentation + CV + calibration
├── llm-baseline/ # Qwen2.5-7B LLM few-shot baseline & utilities
└── README.md # This file
At a high level:
- BERT-baseline/ – Reproduces the official BERT baseline using the shared-task data.
- method/ – First improved systems: single-run DeBERTa and XLM-R, with optional MT (for non-English) and simple ensembling.
- method2/ – Adds K-fold cross-validation, focal loss, temperature scaling + threshold calibration, and ensembling.
- method3/ – Uses Qwen2.5-7B to paraphrase labeled data and train CV models on the augmented corpus.
- llm-baseline/ – Few-shot prompting of Qwen2.5-7B for all three subtasks (no fine-tuning).
All training and inference are implemented as Jupyter notebooks; you can run them interactively or convert them to scripts.
Tested with:
- Python 3.10+/3.11+
- CUDA GPU (recommended) for fine-tuning and Qwen2.5-7B
Create a fresh environment (example with conda):
conda create -n polar python=3.10
conda activate polarInstall dependencies (minimal set):
pip install \
torch \
transformers \
accelerate \
datasets \
sentencepiece \
scikit-learn \
pandas \
numpy \
tqdm \
bitsandbytesIf you plan to use the notebooks directly:
pip install jupyterNote:
- Make sure your PyTorch install is GPU-enabled (e.g., via
pip install torch --index-url https://download.pytorch.org/whl/cu121or the recommended command from pytorch.org).- For Qwen2.5-7B, a GPU with ≥ 16 GB VRAM is strongly recommended; for CPU-only, inference will be very slow.
We assume the official POLAR data is available under a directory like:
dev_phase/
subtask1/
train/
eng.csv
...
dev/
eng.csv
...
subtask2/
train/
eng.csv
...
dev/
eng.csv
...
subtask3/
train/
eng.csv
...
dev/
eng.csv
...
Each train CSV typically contains:
id– unique example IDtext– post text- Subtask 1:
polarization(0/1) - Subtask 2: 5 binary columns for hate types
- Subtask 3: 6 binary columns for hate manifestations
Each dev CSV contains:
id,text(no labels)
For Method 3 (augmentation), we create a similar directory:
dev_phase_aug/
subtask1/...
subtask2/...
subtask3/...
where each train file contains both original and Qwen-paraphrased examples (same label schema).
Where to put data: Place
dev_phase/(and eventuallydev_phase_aug/) at the repo root or update theBASEvariable inside notebooks to point to your data directory.
Most notebooks will create and/or expect:
-
cache/– for:- MT outputs (translated text → English)
- Saved model logits and probabilities
- Qwen predictions for LLM baselines
-
submissions/– for:- Final CSVs formatted for Codabench / shared-task submission
You can safely delete and regenerate cache/ and submissions/, but keep a copy of any submitted runs you care about.
Below is a quick guide to the main workflows. All paths are relative to the repo root.
Notebook: BERT-baseline/starter.ipynb
Steps:
-
Open the notebook in Jupyter:
jupyter notebook BERT-baseline/starter.ipynb
-
Set:
BASE = "../dev_phase"LANG = "eng"(or another language if supported)
-
Run all cells. The notebook:
- Loads the data for each subtask
- Trains a BERT model (or models) on the train split
- Evaluates on an internal validation split
- Writes predictions for the official
devset to CSV undersubmissions/BERT-baseline/
This reproduces the official-style baseline.
Main notebooks (per encoder):
method/deberta_train_all_tasks.ipynbmethod/xlmr_train_all_tasks.ipynbmethod/ensemble_all_tasks.ipynb
a. DeBERTa single-run
-
Open
method/deberta_train_all_tasks.ipynb. -
Set configuration cells (near the top), e.g.:
BASE = "../dev_phase"LANG = "eng"EN_MODEL = "microsoft/deberta-v3-base"MAX_LEN,EPOCHS,LR, etc.
-
Run all cells:
-
For Subtask 1:
- Train a binary classifier on
text_en(English or translated) - Apply temperature scaling + a global threshold
- Train a binary classifier on
-
For Subtasks 2 & 3:
- Train multi-label classifiers
- Fit per-label thresholds on validation data
-
Save dev predictions and thresholds to
cache/andsubmissions/method/deberta/.
-
b. XLM-R single-run
Repeat the same steps with:
method/xlmr_train_all_tasks.ipynbMODEL_NAME = "xlm-roberta-base"
c. Ensemble (DeBERTa + XLM-R)
-
Open
method/ensemble_all_tasks.ipynb. -
Make sure paths to both models’ cached predictions are correct.
-
Run all cells:
- Loads probabilities from DeBERTa and XLM-R
- Averages them
- Applies thresholds
- Writes ensemble predictions to
submissions/method/ensemble/.
Main notebooks:
method2/deberta_mt_cv_train_all_tasks.ipynbmethod2/xlmr_cv_train_all_tasks.ipynbmethod2/ensemble_cv_xlmr_deberta.ipynb
This method adds:
- K-fold CV (typically K = 3)
- Focal loss for multi-label tasks
- Temperature scaling and threshold search using OOF logits
- Ensembling across folds and across encoders
a. DeBERTa+MT CV
-
Open
method2/deberta_mt_cv_train_all_tasks.ipynb. -
Set:
BASE = "../dev_phase"LANG = "eng"(or a non-English language with MT configured)N_FOLDS,MAX_LEN,EPOCHS, etc.
-
Run all cells:
-
For each fold:
- Train on K−1 folds, validate on 1 fold
- Store OOF logits and labels
-
Fit temperature and thresholds using OOF data
-
Generate calibrated dev predictions
-
Save to
cache/deberta_cv/andsubmissions/method2/deberta_cv/.
-
b. XLM-R CV
Repeat with method2/xlmr_cv_train_all_tasks.ipynb.
c. CV ensemble (DeBERTa + XLM-R)
-
Open
method2/ensemble_cv_xlmr_deberta.ipynb. -
Run all cells:
- Loads calibrated probabilities from both CV runs
- Averages them
- Applies calibrated thresholds
- Writes final CSVs to
submissions/method2/ensemble/.
Main notebooks:
method3/qwen_data_augmentation.ipynbmethod3/deberta_mt_cv_train_all_tasks.ipynbmethod3/xlmr_cv_train_all_tasks.ipynbmethod3/ensemble_cv_xlmr_deberta.ipynb
a. Qwen paraphrase augmentation
-
Open
method3/qwen_data_augmentation.ipynb. -
Configure Qwen:
MODEL_NAME = "Qwen/Qwen2.5-7B-Instruct"- Set device (GPU recommended).
-
Run all cells:
-
For each labeled train example in
dev_phase/:- Prompt Qwen to paraphrase the text without changing the label
-
Write augmented CSVs under
../dev_phase_aug/mirroring the original directory structure.
-
b. CV training on augmented data
-
Open
method3/deberta_mt_cv_train_all_tasks.ipynbandmethod3/xlmr_cv_train_all_tasks.ipynb. -
Set:
BASE = "../dev_phase_aug"- Other hyperparameters as desired.
-
Run all cells to train CV models on the augmented corpus and generate calibrated dev predictions.
c. Final ensemble
-
Open
method3/ensemble_cv_xlmr_deberta.ipynb. -
Run all cells to:
- Average DeBERTa and XLM-R calibrated probabilities
- Apply thresholds
- Save final CSVs to
submissions/method3/ensemble/.
This is our strongest configuration (MT + augmentation + CV + calibration + ensemble).
Main notebooks:
llm-baseline/qwen2p5_multilingual_llm.ipynbllm-baseline/qwen_fewshot_predictions.ipynb
Workflow:
-
Open
llm-baseline/qwen2p5_multilingual_llm.ipynb. -
Configure:
MODEL_NAME = "Qwen/Qwen2.5-7B-Instruct"LANGand data paths
-
Run:
- Builds prompts for each subtask
- Calls Qwen in an instruction-following setup
- Parses outputs into labels (0/1 vectors)
- Caches raw outputs and parsed predictions under
cache/qwen/.
-
Optionally, use
qwen_fewshot_predictions.ipynbto:- Inspect predictions
- Convert to submission CSV format in
submissions/llm-baseline/.
-
Most notebooks expose:
SEEDorRANDOM_SEEDN_FOLDS,EPOCHS,BATCH_TRAIN_GPU, etc.
-
For full reproducibility:
- Fix seeds in all relevant libraries (
random,numpy,torch). - Use a single GPU and avoid non-deterministic CuDNN settings where possible.
- Fix seeds in all relevant libraries (
-
Some variability is expected due to GPU kernels and data loader ordering.