---
title: "A Contextual Word Embedding for Arabic — Elgabry 2021"
description: "This shared-task paper tackles sarcasm detection in Arabic tweets."
authors: ["Hazem Elgabry", "Shimaa Attia", "Ahmed Abdel-Rahman", "Ahmed Abdel-Ate", "Sandra Girgis"]
year: 2021
venue: "Proceedings of the Sixth Arabic Natural Language Processing Workshop"
source: "https://aclanthology.org/2021.wanlp-1.43/"
licence: "CC BY 4.0 (ACL Anthology)"
licence_url: "https://creativecommons.org/licenses/by/4.0/"
summary_licence: "Elamur Cosmic License"
canonical: "https://research.elamur.ai/free/en/papers/elgabry-2021-contextual-word-embedding-arabic-sarcasm/"
---
[Elamur Research](https://md.research.elamur.ai/free/en/) · [this page in HTML](https://research.elamur.ai/free/en/papers/elgabry-2021-contextual-word-embedding-arabic-sarcasm/)

[home](https://md.research.elamur.ai/free/en/) / [papers](https://md.research.elamur.ai/free/en/papers/) / [2021](https://md.research.elamur.ai/free/en/papers/2021/) / A Contextual Word Embedding for Arabic Sarcasm Detection with Random Forests

# A Contextual Word Embedding for Arabic Sarcasm Detection with Random Forests

**Authors:** Hazem Elgabry, Shimaa Attia, Ahmed Abdel-Rahman, Ahmed Abdel-Ate, Sandra Girgis · **Year:** 2021 · **Venue:** Proceedings of the Sixth Arabic Natural Language Processing Workshop · **Licence:** [CC BY 4.0 (ACL Anthology)](https://creativecommons.org/licenses/by/4.0/)

**Links:** [Publisher's page](https://aclanthology.org/2021.wanlp-1.43/) · [PDF](https://aclanthology.org/2021.wanlp-1.43.pdf) · [OpenAlex](https://openalex.org/W3153999212)

**Citations:** 13 citations (openalex-snapshot · 2026-10-14) · [3](#cited-by) in our library, of the 140884 papers whose bibliographies we read

## Summary
This shared-task paper tackles sarcasm detection in Arabic tweets. Arabic suffers from small and skewed datasets, weak preprocessing tools, and strong dialect variation. The authors train on ArSarcasm-V2 (12548 tweets, about 17% sarcastic) and balance the classes by duplicating sarcastic tweets and dropping some non-sarcastic ones. They clean the tweets with regular expressions and replace emojis with Arabic names taken from a translated Kaggle emoji list. Each tweet then goes through AraBERT-base to obtain contextual token vectors. Stop words and affix sub-tokens are removed only after encoding, and the remaining vectors are averaged into a 768-dimensional tweet vector. A default scikit-learn random forest classifies these vectors.

On the official unseen test set the system reached 0.5189 F1-sarcastic and 0.7533 accuracy, clearly above a TF-IDF variant (0.41 F1-sarcastic). The authors also admit that their internal 0.93 score was inflated, because they augmented the data before splitting it. The paper is mainly useful as a simple contextual-embedding baseline and as a cautionary note on evaluation leakage.

## Key points
- Data: ArSarcasm-V2 with sarcasm, sentiment (POS/NEG/NEU) and dialect labels (MSA, Gulf, Egypt, Levant, Magreb). The 10380 non-sarcastic vs 2168 sarcastic tweets were rebalanced to 6018 per class, 12036 in total.
- Representation: AraBERT base configuration (L=12, H=768, A=12, 110M parameters). Token embeddings are mean-pooled into a 768-feature sentence vector.
- Classifier: a random forest with default settings (100 estimators, unlimited depth, Gini criterion). Tweets left empty after cleaning are labelled non-sarcastic by default.
- Official results: F1-sarcastic 0.5189, accuracy 0.7533, macro-F1 0.6765, precision 0.6858, recall 0.6700.
- TF-IDF comparison: F1-sarcastic 0.41, accuracy 0.73, macro-F1 0.62, recall only 0.34.
- The internal 80/20 validation gave 0.93 F1 for both classes. This was an artefact of duplicated tweets leaking into the validation split.

## Interesting ideas
- Encode the full, untouched text first, then filter stop words and affixes from the contextual output, so that small function words still shape the context of their neighbours. — For Mova (tokens): keep every token, including negators and particles, through tagging and lemmatization, and apply any filtering only to downstream views, never to the input of contextual models.
- The WordPiece tokenizer's prefix/suffix markers are reused as a cheap stemmer for dialect forms that no rule-based stemmer covers. — For Mova (tokens): subword segmentation from gparse's tokenizer could suggest candidate affix splits for unknown or nonstandard English words, to be checked against the morphology rules.
- Oversampling by duplication before the train/validation split leaks copies into validation and makes a weak model look excellent. The paper shows this failure openly. — For Mova (learn): always split by source item before any augmentation or silver-data expansion, and add a duplicate-overlap check as a standing negative control in evaluation.
- Emojis are replaced by their names in the target language, turning opaque symbols into words the encoder understands. — For Mova (tokens): map emoji and emoticons to lexical tokens with lemmas, so later stages can treat them as evaluative words rather than noise.
- Sarcasm is treated as a labelled property of the whole utterance and scored on the sarcastic class specifically, not on overall accuracy. — For Mova (frames): when evaluating the irony component in prag, report F1 on the ironic class separately, since accuracy hides poor recall on a rare phenomenon.

*Our summary of the paper, in our own words — not its text. The work belongs to its authors; read it at the links above.*

Fields: [Linguistics & languages](https://md.research.elamur.ai/free/en/shelves/linguistics/)

## Cited by

Cited by

3 papers of our library cite it (of the 140884 whose bibliographies we read); 1 of them have a page here, 2 not yet.

- [Overview of the WANLP 2021 Shared Task on Sarcasm and Sentiment Detection in Arabic](https://md.research.elamur.ai/free/en/papers/farha-2021-overview-wanlp-2021-shared-task/)

## Cite

The paper itself, not this page. BibTeX from the library's record of the work.

```bibtex
@inproceedings{elgabry2021contextual,
  title = {{A Contextual Word Embedding for Arabic Sarcasm Detection with Random Forests}},
  author = {Elgabry, Hazem and Attia, Shimaa and Abdel-Rahman, Ahmed and Abdel-Ate, Ahmed and Girgis, Sandra},
  booktitle = {Proceedings of the Sixth Arabic Natural Language Processing Workshop},
  year = {2021},
  url = {https://aclanthology.org/2021.wanlp-1.43/}
}
```

- [← previous A Context-Dependent Gated Module for Incorporating Symbolic Semantics into Event Coreference Resolution](https://md.research.elamur.ai/free/en/papers/lai-2021-context-dependent-gated-module-incorporating/)
- [next → A Dataset of Information-Seeking Questions and Answers Anchored in Research Papers](https://md.research.elamur.ai/free/en/papers/dasigi-2021-dataset-information-seeking-questions-answers/)
- [↑ back to papers of 2021](https://md.research.elamur.ai/free/en/papers/2021/)

## References

1 references, 0 of them with a card of ours. ↗ leads to the work, «find» searches for one we have no id for yet.

1. Liu, P., Chen, W., Ou, G., Wang, T., Yang, D. and Lei, K., 2014, June. Sarcasm detection in social media based on imbalanced classification. In International [find](https://scholar.google.com/scholar?q=Liu%2C+P%2E%2C+Chen%2C+W%2E%2C+Ou%2C+G%2E%2C+Wang%2C+T%2E%2C+Yang%2C+D%2E+and+Lei%2C+K%2E%2C+2014%2C+June%2E+Sarcasm+detection+in+social+media+based+on+imbalanced+classification%2E+In+International)
