Trying RNN based character models on Persian poetry
After reading the famous and amazing blog post “ Unreasonable effectiveness of recurrent neural networks “ I decided to try to build a character model on Persian poems.
For this trial, I chose “The Book of Kings” (Shahnameh), which is a long epic poem written by the Persian poet Ferdowsi around 1000 CE. Shahnameh is the national epic of Greater Iran. Consisting of some 50,000 “distichs” or couplets (two-line verses), Shahnameh is also the world’s longest epic poem written by a single poet.
Verses in Shahnameh have two important properties:
- Every verse has two rhyming lines
- All lines have the same rhythm. In more technical terms Persian poetry is quantitative, and the metrical patterns are made of long, short and overlong syllables. Shahnameh particularly uses a pattern in the form “u — — u — — u — — u -” where u stands for short and dash stands for long patterns. For instance, each line, from rhythm perspective will sound like this: “you don’t care, I don’t care, we don’t care, at all” (Ta tan tan, Ta tan tan, Ta tan tan, Ta tan)
I trained a three-layer LSTM models in Tensorflow with 400 cells on each layer and generated new text based on this model., The result was very interesting and as unreasonable as it should be. The model learned to generate verses (two lines) with correct words, rhyme, and rhythm with a decent grammar and almost no mistake like this:
روان را به دانش به کار آوری
به توران به خواب اندر آرد سری
If you can read Persian feel free to check some of the results which I posted on darbare.com. Also included one example here:
ادامه داستان
سواران گردنکشان دسته دید
خردمند را او بدان خسته دیدسکندر نگه کرد پس پهلوان
به بدخواه شد شاد و روشن روانسپاه اندر آمد به پیش سوار
خردمند و شایستهی کارزاربفرمود تا بنده آگاه دید
چنین تا بر شاه ایران کشیدنهادند چیزی که پوشیده بود
جهان را درم داد و دینار بودسران افسر از گوهر شاهوار
نخست آفرین کرد بر کردگارچو بهرام بشنید گریان شدند
وزان جایگه شاد و خندان شدندبفرمود تا ناسزا بنگرید
یکی باد سرد از جگر برکشیدشب تیره چون رستم او را بدید
سپهدار پیران به هامون کشیددمان تا فراز آمد اندر کمان
برو بر نکرد ایچ پیدا زبانبران تیغ زهر آب داده به دست
به هاماوران داد جویان به دستسیاوش چو بشنید شاه جهان
که آمد میان کهان و مهانعنان برگرفتند یکسر به من
بخواند آگهی بر سر انجمنچنین داد پاسخ که از مهتران
خداوند شمشیر و گرز گرانروان را به دانش به کار آوری
به توران به خواب اندر آرد سریبه گرد اندر آرد بهنگام کار
درختی چنان خسته در کارزار
Originally published at https://www.linkedin.com. on January 16, 2018