Generating Classical Arabic Poetry using Pre-trained Models
Paper · 2022 · Maryam ElOraby, Mohamed Abdelgaber, Nehal Elkaref et al.
Summary
The paper asks whether general pre-trained transformers can absorb the formal rules of classical Arabic verse (meter, i.e. al-'arūd, and rhyme, al-qafiya) from data alone. Earlier systems instead built these constraints in by hand. The authors merged the ashaar and Arabic Poetry Dataset collections and scraped al-diwan to fill gaps and add a rhyme field. They kept only poems from pre-modern eras with strict prosody and restricted the corpus to 15 of the 16 canonical meters. On this data they fine-tuned two architectures:
- a BERTShared encoder-decoder, warm-started from CAMelBERT-CA;
- the 6B-parameter decoder-only GPT-J.
Each model was conditioned once on a meter prompt and once on a topic prompt. An automatic check measured meter adherence, and expert human raters scored rhyme consistency, fluency and coherence. Raters found BERTShared output somewhat more fluent and coherent, while GPT-J kept rhyme noticeably better. The work suggests that off-the-shelf models capture some poetic structure without explicit constraint machinery.
Key points
- Corpus: ashaar (HuggingFace), the Kaggle Arabic Poetry Dataset and al-diwan scraping, totalling about 18K poems.
- Eras include Abbasid, Umayyad, Andalusian, Mamluk, Ottoman, Ayubi and Pre-Islamic.
- Labels cover 17 topics, with al-T.awīl, al-Kāmil, al-Basīt. and al-Wāfir the dominant meters.
- BERTShared design: encoder and decoder share parameters, which halves memory.
- The WordPiece tokenizer was extended with two tokens, one splitting hemistichs and one marking verse starts.
- Poems were chunked into 23-verse pieces, with a 512-token output limit.
- BERTShared training and decoding: batch size 16, Adam at 5e-5 with 3k warm-up steps, on a T4 GPU in Colab.
- Generation used beam search with multinomial sampling, capped at 130 tokens.
- The meter experiment used a 15,000-poem sample with an 85/15 split.
- GPT-J: decoded with top-p sampling and trained on TPUs from Google TRC. It was only fine-tuned, not pre-trained, which the authors call suboptimal.
- Data cleanup and limitations:
- Poems rhyming on a short vowel were relabelled with the matching long vowel.
- The catch-all topics "generic" and "short" were dropped for topic prompting.
- The authors acknowledge unverifiable topic labels and evaluator fatigue across many meters.
Interesting ideas
- I1. Encoding the verse layout with dedicated separator tokens lets a generic model learn hemistich and verse boundaries without architectural changes.
- I2. Collapsing phonetically identical variants (short vowel vs. long vowel rhyme) into one canonical label prevents spurious class splits in the data.
- I3. Removing uninformative catch-all labels ("generic", "short") keeps the conditioning signal meaningful, even though it costs data.
- I4. Evaluation is split between an automatic test for the hard formal constraint (meter) and human judgement for soft qualities (fluency, coherence).
- I5. Warm-starting both halves of an encoder-decoder from one domain-matched checkpoint with shared weights gives a cheap seq2seq model.
For Mova
How these ideas could serve Mova, our small open language model — its files, stages and tests:
- I1 (back): when realizing text from the meaning graph, explicit boundary tokens for clauses and sentences could make the structure of generated output controllable and checkable.
- I2 (tokens): mapping spelling variants such as colour/color to a canonical form before lemmatization would keep morphology tables and counts consistent.
- I3 (learn): when building silver data, examples whose label is a vague default could be excluded so that witness agreement reflects real distinctions.
- I4 (back): the text → graph → text compressor could be scored by an automatic structural round-trip check, with human or LLM review kept only for naturalness.
- I5 (back): a translation or regeneration model through the meta-world could reuse one shared encoder checkpoint to fit modest GPU memory.
Institutions
Fields, topics and concepts
📚 Shelves 5The field of science this work belongs to (OpenAlex fields).Computer Science · 18,614 worksArtificial Intelligence · 17,965 worksArts and Humanities · 17,450 worksLanguage and Linguistics · 17,296 worksComputer Vision and Pattern Recognition · 3,486 works
🧭 Topics 1Research subjects and languages the work is about.Semitic languages · 3,066 works
Cite
Cite as Maryam ElOraby, Mohamed Abdelgaber, Nehal Elkaref and Mervat Abu-Elkheir. 2022. Generating Classical Arabic Poetry using Pre-trained Models. Proceedings of the Seventh Arabic Natural Language Processing Workshop (WANLP).
@inproceedings{eloraby2022generating,
title = {{Generating Classical Arabic Poetry using Pre-trained Models}},
author = {Maryam ElOraby, Mohamed Abdelgaber, Nehal Elkaref and Mervat Abu-Elkheir},
booktitle = {Proceedings of the Seventh Arabic Natural Language Processing Workshop (WANLP)},
year = {2022},
doi = {10.18653/v1/2022.wanlp-1.6},
url = {https://doi.org/10.18653/v1/2022.wanlp-1.6}
}References
- Zaid Alyafeai, Maged Saeed AlShaibani, Mustafa Ghaleb, and Irfan Ahmad. 2021. Evaluating various tokenizers for arabic text classification. CoRR, abs/2106.07540. ↗
- Mike Lewis, Yinhan Liu, Naman Goyal, Marjan Ghazvininejad, Abdelrahman Mohamed, Omer Levy, Veselin Stoyanov, and Luke Zettlemoyer. 2020. BART: Denoising sequence-to-sequence pre-training for natural language generation, translation, and comprehension. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 7871–7880.
- Zaid Alyafeai, Maged Saeed AlShaibani, and Omar Hammad. 2022. Qawafi: Arabic poetry analysis using deep learning and knowledge based methods. https://github.com/ARBML/qawafi. ↗
- Mohamed El Ghaly Beheitt and Moez Ben Haj Hmida. 2022. Automatic arabic poem generation with gpt-2. In Proceedings of the 14th International Conference on Agents and Artificial Intelligence (ICAART 2022), volume 2, pages 366–374. find
- Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. 2019. Roberta: A robustly optimized bert pretraining approach. arXiv preprint arXiv:1907.11692. ↗
- Sid Black, Leo Gao, Phil Wang, Connor Leahy, and Stella Biderman. 2021. GPT-Neo: Large Thang Luong, Hieu Pham, and Christopher D. Manning. 2015. Effective approaches to attention-based neural machine translation. In Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing, pages 1412–1421. Association for Computational Linguistics.
- Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. 2019. Language models are unsupervised multitask learners. OpenAI blog, 1(8):9. find
- Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. 2020. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of Machine Learning Research, 21(140):1–67. ↗
- Sascha Rothe, Shashi Narayan, and Aliaksei Severyn. 2020. Leveraging Pre-trained Checkpoints for Sequence Generation Tasks. Transactions of the Association for Computational Linguistics, 8:264–280. ↗
- Tim Van de Cruys. 2020. Automatic poetry generation from prosaic text. In Proceedings of the 58th annual meeting of the association for computational linguistics, pages 2471–2480. find
- Ben Wang and Aran Komatsuzaki. 2021. GPT-J-6B: A 6 Billion Parameter Autoregressive Language Model. https://github.com/kingoflolz/ mesh-transformer-jax. ↗
- Rui Yan. 2016. i, poet: Automatic poetry composition through recurrent neural networks with iterative polishing schema. In Proceedings of the Twenty-Fifth International Joint Conference on Artificial Intelligence, pages 2238––2244. find
- Jingqing Zhang, Yao Zhao, Mohammad Saleh, and Peter Liu. 2020. PEGASUS: Pre-training with extracted gap-sentences for abstractive summarization. In Proceedings of the 37th International Conference on Machine Learning, volume 119, pages 11328–11339. ↗
- Xingxing Zhang and Mirella Lapata. 2014. Chinese poetry generation with recurrent neural networks. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP), pages 670–680.
Updated
This page in Markdown → https://md.research.elamur.ai/free/en/papers/eloraby-2022-generating-classical-arabic-poetry-pre/