CoolFace
Modelpublic

hasancanbiyik/euphemism-detector-multilingual

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes12downloads
Model Card

Euphemism Detector — Multilingual

Fine-tuned XLM-RoBERTa-base for euphemism disambiguation across 7 languages. Given a sentence with a marked phrase, the model predicts whether the phrase is used euphemistically (e.g., "passed away" meaning death) or literally (e.g., "the ball passed away from the goalkeeper").

Live demo: HuggingFace Spaces

GitHub: hasancanbiyik/euphemism-detector


Model Description

Euphemisms are context-dependent — the same phrase can be euphemistic in one context and literal in another. This model detects that distinction by learning contextual signals around Potentially Euphemistic Terms (PETs), which are marked with special [PET_BOUNDARY] tokens in the input.

The model was fine-tuned on 19,490 labeled examples across 7 languages, with class-weighted loss to handle label imbalance, fp16 mixed-precision training, and early stopping.

Training Languages

LanguageExamplesEuph/Lit RatioMacro-F1
English3,0981.5:10.800
Turkish2,4361.5:10.760
Chinese (Mandarin)3,2112.2:10.834
Spanish2,9522.0:10.828
Yoruba2,5981.9:10.840
Polish2,4391.0:10.810
Ukrainian2,7763.3:10.777
Overall19,4900.808

Zero-Shot Cross-Lingual Transfer

The model was evaluated on 22 unseen languages across 12 language families using curated minimal-pair benchmarks (synthetic, LLM-generated — see Limitations). Results demonstrate broad cross-lingual transfer, with 15/22 languages exceeding 0.70 macro-F1 and 7 exceeding 0.85.

LanguageFamilyF1n
PortugueseRomance0.90611
IndonesianAustronesian0.89910
SwedishGermanic0.89910
HebrewSemitic0.89910
DanishGermanic0.8839
HindiIndo-Aryan0.8629
GermanGermanic0.84414
ItalianRomance0.82912
KoreanKoreanic0.80410
HungarianUralic0.80010
RomanianRomance0.8009
ArabicSemitic0.79210
ArmenianArmenian0.7334
FrenchRomance0.70814
VietnameseAustroasiatic0.69710
DutchGermanic0.69710
JapaneseJaponic0.69411
CzechSlavic0.67010
RussianSlavic0.67010
GreekHellenic0.60010
SwahiliBantu0.60010
FinnishUralic0.5509

Key finding: Transfer strength correlates more with euphemistic semantic category than with language family alone. Appearance euphemisms (F1: 1.00) and death euphemisms (F1: 0.79) transfer best across all language families. Strong transfer was observed to typologically distant languages (Arabic/Semitic: 0.79, Korean/Koreanic: 0.80, Indonesian/Austronesian: 0.90), while some typologically close languages showed weaker transfer (Czech/Slavic: 0.67 despite Polish and Ukrainian in training).


How to Use

Input Format

The model expects input text with [PET_BOUNDARY] tokens marking the potentially euphemistic term:

My grandmother [PET_BOUNDARY]passed away[PET_BOUNDARY] last Tuesday.

Python

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import torch.nn.functional as F

model_name = "hasancanbiyik/euphemism-detector-multilingual"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
model.eval()

text = "My grandmother [PET_BOUNDARY]passed away[PET_BOUNDARY] last Tuesday."
inputs = tokenizer(text, return_tensors="pt", max_length=256, truncation=True)

with torch.no_grad():
    outputs = model(**inputs)
    probs = F.softmax(outputs.logits, dim=1).squeeze()

print(f"Euphemistic: {probs[1].item():.1%}")
print(f"Literal:     {probs[0].item():.1%}")
# Output: Euphemistic: 95.2%, Literal: 4.8%

API (via deployed Space)

bash
curl -X POST https://hasancanbiyik-euphemism-detector.hf.space/predict \
  -H "Content-Type: application/json" \
  -d '{"sentence": "He was let go from the company.", "phrase": "let go"}'

Batch Prediction

The deployed API supports CSV batch prediction:

bash
curl -X POST https://hasancanbiyik-euphemism-detector.hf.space/batch/predict \
  -F "file=@examples.csv"

CSV format: sentence,phrase columns.


Training Details

Training Procedure

  • Base model: xlm-roberta-base (Conneau et al., 2020)
  • Task: Binary classification (euphemistic vs. literal)
  • Special tokens: [PET_BOUNDARY] added to vocabulary (vocab size: 250,003)
  • Loss: Cross-entropy with class weights (literal: 1.392, euphemistic: 0.780)
  • Optimizer: AdamW
  • Learning rate: 1e-5
  • Batch size: 32
  • Max epochs: 30 (early stopped at epoch 15)
  • Early stopping patience: 5 (on validation macro-F1)
  • Mixed precision: fp16
  • Max sequence length: 256 tokens
  • Train/Val/Test split: 80/10/10, stratified by language and label

Data Preprocessing

Seven datasets in three different schemas were unified into a single training format:

  • English, Chinese, Spanish, Yoruba: Already in text,label format with [PET_BOUNDARY] markers
  • Turkish: Required [PET BOUNDARY][PET_BOUNDARY] normalization
  • Polish: Three-column context format (left/sentence/right) with separate PET column — required concatenation and PET boundary insertion; 58 unrecoverable rows dropped
  • Ukrainian: Angle bracket <PET> markers converted to [PET_BOUNDARY]; emojis stripped; "war" category downsampled from 4,743 to 500 to prevent category dominance

Behavioral Testing

A 26-test behavioral QA suite validates model robustness:

  • Known euphemistic/literal pairs: 12 tests (all pass)
  • Negation robustness: 2 tests (expected failure — negation context overwhelms euphemistic signal; documented as known limitation)
  • Boundary token edge cases: 4 tests (all pass)
  • Cross-lingual consistency: 2 tests (all pass)
  • Confidence calibration: 2 tests (all pass)
  • Surface invariance (case, punctuation, whitespace): 4 tests (all pass)

Result: 23 passed, 3 xfail (documented limitations)


Limitations

  • Zero-shot evaluation uses synthetic test data: The 22-language cross-lingual benchmark was curated using LLM-generated examples (Gemini), not native-speaker-validated data. Distributional overlap between the evaluation data and XLM-R's pretraining corpus may inflate zero-shot performance estimates. Native-speaker validation is required before deployment claims can be made for unseen languages.
  • Small zero-shot sample sizes: 9–14 examples per unseen language. Per-language F1 scores have wide confidence intervals and should be interpreted as preliminary estimates.
  • Negation sensitivity: The model tends to classify negated euphemisms as literal (e.g., "He didn't pass away"). Negation provides strong literal-context signals that overwhelm the euphemistic sense of the marked phrase.
  • Ukrainian class imbalance: Ukrainian data has a 3.3:1 euphemistic/literal ratio even after downsampling, which may affect per-language calibration.
  • Culture-specific euphemisms: The model performs best on universal euphemistic categories (death, appearance) and may underperform on culture-specific euphemisms without cross-lingual parallels in the training data.
  • Low-frequency PETs: Rare or archaic euphemisms (e.g., "powder her nose") may be classified with low confidence or incorrectly.

Research Context

This model was developed as part of ongoing NLP research on cross-lingual euphemism detection:

  • Biyik, H. C., Barak, L., Peng, J., & Feldman, A. (2026). When Semantic Overlap Is Not Enough: Cross-Lingual Euphemism Transfer Between Turkish and English. SIGTURK at EACL 2026, Rabat, Morocco. arXiv:2602.16957
  • Biyik, H. C., Lee, P., & Feldman, A. (2024). Turkish Delights: A Dataset on Turkish Euphemisms. SIGTURK at ACL 2024, Bangkok, Thailand. arXiv:2407.13040
  • Lee, P., et al. (2024). MEDs for PETs: Multilingual Euphemism Disambiguation for Potentially Euphemistic Terms. Findings of EACL 2024. ACL Anthology

The zero-shot cross-lingual evaluation extends Section 6 ("Future Work") of Lee et al. (2024), which called for testing additional languages from diverse language families.


Citation

bibtex
@inproceedings{biyik2026semantic,
  title={When Semantic Overlap Is Not Enough: Cross-Lingual Euphemism Transfer Between Turkish and English},
  author={Biyik, Hasan Can and Barak, Libby and Peng, Jing and Feldman, Anna},
  booktitle={Proceedings of SIGTURK at EACL 2026},
  year={2026},
  address={Rabat, Morocco}
}

License

MIT