Fanar-2-Diwan specializes in generating classical Arabic poetry adhering to the strict metrical patterns (
Buhur
), rhyme schemes (
Qafiyah
), and prosodic rules (
Arud
) established by al-Farahidi. Trained on
118K high-quality poems
with complete metadata (meter, rhyme, topic, era, poet), Fanar-2-Diwan achieves the
highest fluency score (6.88/10)
among all evaluated models and demonstrates strong performance across poeticness, meaning, and coherence metrics.
We have published a
report
with all the details regarding Fanar 2.0 GenAI platform. We also provide a
chat interface
, mobile apps for
iOS
and
Android
, and
API access
to our models and the GenAI platform (request access
here
).
Arabic poetry represents a culturally significant literary tradition governed by well-defined structural constraints:
Metrical Patterns (البحور - Buhur):
Categorized by al-Farahidi, 16 classical meters define rhythmic structure through specific patterns of long and short syllables. Common meters include:
الطويل
(Al-Taweel) - The Long
البسيط
(Al-Baseet) - The Simple
الكامل
(Al-Kamel) - The Complete
الوافر
(Al-Wafir) - The Abundant
الرمل
(Al-Ramal) - The ''Ramal''
Prosodic Rules (عروض - Arud):
Governs syllable patterns, ensuring adherence to metrical feet across hemistichs (half-verses).
Rhyme Scheme (قافية - Qaafiyah):
Strict rhyme requirements where all verses typically end with the same rhyme letter and pattern.
Data
Continual Pretraining
The base model of Fanar-2-Diwan was continually pretrained using
47 million words
of Arabic literary texts to specialize it in classical Arabic prose and poetic language, strengthen understanding of classical Arabic vocabulary, literary expressions, and rhetorical devices.
Data Sources:
adab.com
adabworld.com
Other literature-focused websites
Fine-tuning
Data Sources:
126K poems crawled from AlDiwan.net
Only 76% had complete metadata initially
Poets having more 10 poems in AlDiwan are considered in this version
The expected values for
meter
,
topic
,
era
,
poet_id
, and
rhyme_letter
are found in the file
poem_generation_metadata.py
The input text of
Hemistich1
and
Hemistich2
should be provided without diacritics.
Example:
فيا ليت الشباب يعود يوما [الوافر][دين][العباسي][poet_273] فأخبره بما صنع المشيب [ب]
poet_273
refers to
ابو العتاهية
in this example.
Poetry Example
Below is an example of a poem generated by Fanar-2-Diwan given the following metadata and the first verse:
العصر: العثماني
الشاعر: الأمير الصنعاني
الموضوع: رومانسية
البحر: الكامل
القافية: ع
لا والغرام وما تجن الأضلع .. من مهجة بيد الهوى تتقطع
ودموع عيني في هواك غزيرة .. وعلى جفوني من جفونك تدمع
يا أيها الرشأ الذي قلبي له .. في كل جارحة متيم مصرع
إن لم تكن لي منك يا رشأ الحمى .. عين فأنت لكل صب موجع
لولاك ما ذاب الفؤاد ولا غدا .. للعاشقين جميعهم يتضعضع
ما كنت أعلم أن حبك قاتلي .. حتى رميت بسهم لحاظك فأصعصع
إني لأعجب كيف تصبر عاشقا .. عن حبه وهو الكئيب الموجع
كيف التصبر عن حبيب قلبه .. بفؤادي أبدا عليه موزع
لم أنس ليلة زارني متلثما .. متبسما والدمع منه ينبعق
وبكى فظننته بدرا طالعا .. أو غصن بان نابتا يتفتقع
Human Evaluation Scores for the example: Poeticness=6, Meaning=5, Coherence=7, Fluency=6.
Getting Started
(Tested on Python 3.11.2 and 3.13.5,
transformers
v4.51.3 and
arabert
v1.0.1)
from transformers import AutoTokenizer, AutoModelForCausalLM
defprocess_poem_output(tokenizer, outputs):
generated_poem = tokenizer.decode(outputs[0], skip_special_tokens=False)
first_verse = generated_poem.splitlines()[0]
qafiya = first_verse[first_verse.rfind('[') + 1:first_verse.rfind(']')].strip()
trimmed_string = generated_poem[:generated_poem.rfind(f'[{qafiya}]') + len(f'[{qafiya}]')]
cleaned_lines = [line.split('[')[0].strip() + '\t' + line.split('[')[-2].split(']')[-1].strip() for line in trimmed_string.splitlines()]
return'\n'.join(cleaned_lines)
model_name = "QCRI/Fanar-2-Diwan"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", trust_remote_code=True)
# Metadata-driven prompt# Format: Hemistich1 [meter][topic][era][poet] Hemistich2 [rhyme_letter]
prompt = "على أي حال لليالي أعاتب[الطويل][الدول][حزن][poet_1196]وأي صروف للزمان أغالب[ب]"# poet_1196 is ابن خلدون# Mamluk era (العصر المملوكي) is mapped to Countries era (عصر الدول والممالك)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_length=256,
num_beams=5,
top_p=0.92,
do_sample=True,
repetition_penalty=3.0,
no_repeat_ngram_size = 6,
early_stopping=True)
print(process_poem_output(tokenizer, outputs))
Sample generated poem:
على أي حال لليالي أعاتب .. وأي صروف للزمان أغالب
إذا لم يكن لي في الخطوب معول .. فإن خطوب الدهر لا شك غالب
أعلل نفسي بالمنى وهي ضلة .. وأكتمها ما قد جنته النوائب
وما أنا إلا كالزناد مضاءه .. له بين أحناء الضلوع مضارب
ولولا الهوى ما ذقت طعم مرارة .. ولا سقيت كأسا من الحب شارب
سقى الله أكناف الحمى كل غادية .. من المزن أو صوب الحيا وهو ساكب
وعهدي بهاتيك المعاهد جنة .. تظل بها الأرواح فيها ترائب
فيا حبذا تلك المعاهد والحمى .. ويا حبذا تلك المنازل والربى
وحبذا تلك الطلول وإن نأت .. بها غربة الدار التي هي آيب
وماذا عسى يجدي التذكر والهوى .. يعبر عما في الضمير الكاتب
لقد كنت أخشى أن يطول بعادنا .. فأصبحت أخشى أن يطول النوى
Evaluation
Human Evaluation (Expert Linguists)
Two expert Arabic linguists independently rated
50 poems
(5 eras) on a 0-10 scale across four criteria:
Model
Poeticness
Meaning
Coherence
Fluency
Fanar-Diwan
4.81 ± 1.57
4.83 ± 1.14
5.52 ± 1.27
6.88 ± 1.12
GPT-4o
5.73 ± 1.81
5.52 ± 1.30
6.31 ± 1.39
6.25 ± 1.06
GPT-4o-mini
1.70 ± 0.76
3.70 ± 1.15
3.92 ± 1.08
3.82 ± 1.16
Fanar-27B
0.77 ± 1.13
2.74 ± 1.22
3.45 ± 1.70
5.06 ± 1.41
Fanar-9B
0.08 ± 0.35
2.21 ± 1.17
2.83 ± 1.43
4.12 ± 1.65
ALLaM-7B
0.50 ± 0.97
0.50 ± 0.74
0.54 ± 0.85
1.44 ± 1.44
Jais-13B
0.06 ± 0.24
0.52 ± 0.82
0.67 ± 1.08
1.88 ± 2.13
Key Findings:
Fanar-Diwan achieves highest fluency
(6.88), even surpassing GPT-4o (6.25)
Competitive with GPT-4o on meaning (4.83 vs 5.52) and coherence (5.52 vs 6.31)
Fanar-2-Diwan is built for classical Arabic poetry generation adhering to traditional prosodic rules, educational applications teaching Arabic prosody (Arud) and metrics (Buhur), cultural preservation of classical Arabic poetic traditions, literary research on computational poetry generation, creative writing assistance, and poetry completion and variation generation.
Strengths:
The model adheres to classical metrical patterns (Buhur) and rhyme schemes (Qafiya), generates culturally appropriate content, achieves the best fluency among evaluated models (6.88/10).
Limitations:
Poetry quality varies (averaging ~5/10 on poeticness), and the model may produce semantically weak verses. Meter detection in training data had lower accuracy, and the model cannot fully match human poet creativity or produce modern/non-classical forms.
Ethical Considerations:
Always disclose AI-generated content and provide attribution when publishing. Poetry generated by this model may touch on sensitive cultural and religious themes and should be treated with appropriate respect. The model is excellent for learning and creative assistance, but is not a replacement for human poets. Individual poem quality varies, and human review is recommended before publication. This model should not be used for plagiarism, misrepresenting cultural or religious content, commercial purposes without proper attribution, high-stakes literary competitions without disclosure, professional literary publications without review, or religious and ceremonial contexts requiring perfect metrical accuracy.
The output generated by this model is not considered a statement of QCRI, HBKU, Qatar Foundation, MCIT, or any other organization or individual.
Fanar Platform
While Fanar-2-27B-Instruct is a powerful standalone model, it is part of the broader
Fanar Platform
—an integrated Arabic-centric multimodal AI ecosystem that provides enhanced capabilities and continuous updates. The platform includes:
Core Capabilities:
Text Generation
: Multiple conversational models optimized for different tasks
Speech (Aura)
: Speech-to-text (short-form and long-form) and text-to-speech synthesis with Arabic dialect support and bilingual Arabic-English capabilities
Image Understanding (Oryx-IVU)
: Vision-language model for culturally-grounded image and video understanding including Arabic calligraphy recognition
Image Generation (Oryx-IG)
: Culturally-aligned text-to-image generation trained on taxonomy-driven data across 23,000+ cultural search terms
Machine Translation (FanarShaheen)
: High-quality bilingual Arabic↔English translation across diverse domains (e.g., news, STEM, and medical)
Fanar-Sadiq
: Multi-agent Islamic question-answering system with 9 specialized tools (Fiqh reasoning, Quran/Hadith retrieval, zakat/inheritance calculation, prayer times, and Hijri calendar). Deployed in production on
IslamWeb
and
IslamOnline
platforms.
Safety & Moderation
: Fanar-Guard and culturally-informed content filtering trained on 468K annotated Arabic-English safety examples
Access Points:
Fanar Chat
: Web conversational interface integrating all modalities
iOS
and
Android
apps
: Mobile apps for on-the-go access to the Fanar Platform
Fanar API
: Programmatic access to models and specialized capabilities
The Fanar Platform continuously evolves with model updates, new capabilities, and improved safety mechanisms. For production deployments requiring the latest features, multimodal integration, cross-model orchestration, and ongoing support, we recommend using the
Fanar Platform
rather than the standalone models published here.
Citation
If you use Fanar-2-Diwan or the Fanar 2.0 GenAI platform in your research or applications, please cite:
@misc{fanarteam2026fanar20arabicgenerative,
title={Fanar 2.0: Arabic Generative AI Stack},
author={FANAR TEAM and Ummar Abbas and Mohammad Shahmeer Ahmad and Minhaj Ahmad and Abdulaziz Al-Homaid and Anas Al-Nuaimi and Enes Altinisik and Ehsaneddin Asgari and Sanjay Chawla and Shammur Chowdhury and Fahim Dalvi and Kareem Darwish and Nadir Durrani and Mohamed Elfeky and Ahmed Elmagarmid and Mohamed Eltabakh and Asim Ersoy and Masoomali Fatehkia and Mohammed Qusay Hashim and Majd Hawasly and Mohamed Hefeeda and Mus'ab Husaini and Keivin Isufaj and Soon-Gyo Jung and Houssam Lachemat and Ji Kim Lucas and Abubakr Mohamed and Tasnim Mohiuddin and Basel Mousi and Hamdy Mubarak and Ahmad Musleh and Mourad Ouzzani and Amin Sadeghi and Husrev Taha Sencar and Mohammed Shinoy and Omar Sinan and Yifan Zhang},
year={2026},
eprint={2603.16397},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2603.16397},
}
Fanar-2-Diwan huggingface.co is an AI model on huggingface.co that provides Fanar-2-Diwan's model effect (), which can be used instantly with this QCRI Fanar-2-Diwan model. huggingface.co supports a free trial of the Fanar-2-Diwan model, and also provides paid use of the Fanar-2-Diwan. Support call Fanar-2-Diwan model through api, including Node.js, Python, http.
Fanar-2-Diwan huggingface.co is an online trial and call api platform, which integrates Fanar-2-Diwan's modeling effects, including api services, and provides a free online trial of Fanar-2-Diwan, you can try Fanar-2-Diwan online for free by clicking the link below.
QCRI Fanar-2-Diwan online free url in huggingface.co:
Fanar-2-Diwan is an open source model from GitHub that offers a free installation service, and any user can find Fanar-2-Diwan on GitHub to install. At the same time, huggingface.co provides the effect of Fanar-2-Diwan install, users can directly use Fanar-2-Diwan installed effect in huggingface.co for debugging and trial. It also supports api for free installation.