{"id":1410,"date":"2019-01-27T07:37:19","date_gmt":"2019-01-27T02:07:19","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=1410"},"modified":"2019-01-27T07:41:54","modified_gmt":"2019-01-27T02:11:54","slug":"generating-poetry-using-ilanggen","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/","title":{"rendered":"Generating Poetry Using iLangGen"},"content":{"rendered":"<p>In an earlier <a href=\"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/08\/natural-language-generation\/\" target=\"_blank\" rel=\"noopener\"><em><strong>article<\/strong><\/em><\/a>, I wrote about using <em><strong>iLangGen<\/strong><\/em> to generate natural language text. <em><strong>iLangGen<\/strong><\/em> is a powerful text generation library that I have been working on over the years. Today, I would like to show how we can use that library to generate &#8220;<em><strong>poetry<\/strong><\/em>&#8220;. Be warned, however, that the generated poem is devoid of meaning and coherence, similar to what I had <a href=\"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/16\/generating-poetry-using-rita\/\" target=\"_blank\" rel=\"noopener\"><em><strong>generated<\/strong><\/em><\/a>\u00a0with the <em><strong>RiTa<\/strong><\/em> library. The idea is to show the kind of interesting things that one can do with <em><strong>iLangGen<\/strong><\/em>.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>First, we need to get words with interesting patterns and properties, for example, &#8220;<em><strong>adjectives<\/strong><\/em>&#8221; that end in &#8220;<em><strong>ate<\/strong><\/em>&#8220;, or &#8220;<em><strong>verbs<\/strong><\/em>&#8221; with 4 syllables, and so on. For this I use my <a href=\"https:\/\/www.rangakrish.com\/index.php\/2018\/03\/11\/kangaroo-words\/\" target=\"_blank\" rel=\"noopener\"><em><strong>iLexicon<\/strong><\/em><\/a>\u00a0as backend.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Here is how we set up the words to use:<\/p>\n<figure id=\"attachment_1412\" aria-describedby=\"caption-attachment-1412\" style=\"width: 605px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/WordLists.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"1412\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/wordlists\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/WordLists.jpg\" data-orig-size=\"605,395\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1548511420&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Defining Word Lists\" data-image-description=\"&lt;p&gt;Defining Word Lists&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Defining Word Lists&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/WordLists.jpg\" class=\"size-full wp-image-1412\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/WordLists.jpg?resize=605%2C395&#038;ssl=1\" alt=\"Defining Word Lists\" width=\"605\" height=\"395\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/WordLists.jpg?w=605&amp;ssl=1 605w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/WordLists.jpg?resize=300%2C196&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/WordLists.jpg?resize=140%2C90&amp;ssl=1 140w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/a><figcaption id=\"caption-attachment-1412\" class=\"wp-caption-text\"><strong>Defining Word Lists<\/strong><\/figcaption><\/figure>\n<p>The <em><strong>LHS<\/strong><\/em> is a variable that gets bound to the evaluated expression on the <em><strong>RHS<\/strong><\/em>.<\/p>\n<p>The next step is to define one or more <em><strong>grammars<\/strong><\/em> that control the generation process. Here is a simple version of &#8220;<em><strong>Verb Phrase<\/strong><\/em>&#8220;:<\/p>\n<figure id=\"attachment_1413\" aria-describedby=\"caption-attachment-1413\" style=\"width: 575px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/VerbPhrase.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"1413\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/verbphrase\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/VerbPhrase.jpg\" data-orig-size=\"575,413\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1548511865&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Grammar for Verb Phrase\" data-image-description=\"&lt;p&gt;Grammar for Verb Phrase&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Grammar for Verb Phrase&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/VerbPhrase.jpg\" class=\"size-full wp-image-1413\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/VerbPhrase.jpg?resize=575%2C413&#038;ssl=1\" alt=\"Grammar for Verb Phrase\" width=\"575\" height=\"413\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/VerbPhrase.jpg?w=575&amp;ssl=1 575w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/VerbPhrase.jpg?resize=300%2C215&amp;ssl=1 300w\" sizes=\"(max-width: 575px) 100vw, 575px\" \/><\/a><figcaption id=\"caption-attachment-1413\" class=\"wp-caption-text\"><strong>Grammar for Verb Phrase<\/strong><\/figcaption><\/figure>\n<p>You will notice that in some of the productions, the <em><strong>RHS<\/strong><\/em> involves invoking a function to dynamically fetch a word from the word list. For instance, the production with &#8220;<em><strong>adjective<\/strong><\/em>&#8221; as the <em><strong>LHS<\/strong><\/em> gets a random adjective from our word list.<\/p>\n<p>The last production in &#8220;<em><strong>VerbPhrase<\/strong><\/em>&#8221; defines a &#8220;<em><strong>word separator<\/strong><\/em>&#8220;, which is itself defined in another grammar called &#8220;<em><strong>Utils<\/strong><\/em>&#8220;. This ability to reference productions in other grammars is an example of grammar re-use in <em><strong>iLangGen<\/strong><\/em> and allows us to develop complex grammars. I have described the features of <em><strong>iLangGen<\/strong><\/em> in a series of articles earlier (August 2017). Here is the simple &#8220;<em><strong>Utils<\/strong><\/em>&#8221; grammar:<\/p>\n<figure id=\"attachment_1415\" aria-describedby=\"caption-attachment-1415\" style=\"width: 201px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Utils.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"1415\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/utils\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Utils.jpg\" data-orig-size=\"201,48\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1548512484&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Grammar: Utils\" data-image-description=\"&lt;p&gt;Grammar: Utils&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Grammar: Utils&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Utils.jpg\" class=\"size-full wp-image-1415\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Utils.jpg?resize=201%2C48&#038;ssl=1\" alt=\"Grammar: Utils\" width=\"201\" height=\"48\" \/><\/a><figcaption id=\"caption-attachment-1415\" class=\"wp-caption-text\"><strong>Grammar: Utils<\/strong><\/figcaption><\/figure>\n<p>To make the generated poem look more realistic, we define a few more grammars:<\/p>\n<figure id=\"attachment_1416\" aria-describedby=\"caption-attachment-1416\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/MoreGrammars.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1416\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/moregrammars\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/MoreGrammars.jpg\" data-orig-size=\"530,668\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1548512564&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"More Grammars\" data-image-description=\"&lt;p&gt;More Grammars&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;More Grammars&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/MoreGrammars.jpg\" class=\"size-full wp-image-1416\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/MoreGrammars.jpg?resize=530%2C668&#038;ssl=1\" alt=\"More Grammars\" width=\"530\" height=\"668\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/MoreGrammars.jpg?w=530&amp;ssl=1 530w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/MoreGrammars.jpg?resize=238%2C300&amp;ssl=1 238w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/a><figcaption id=\"caption-attachment-1416\" class=\"wp-caption-text\"><strong>More Grammars<\/strong><\/figcaption><\/figure>\n<p>To add further variety, let us define two grammars to generate simple &#8220;<em><strong>why<\/strong><\/em>&#8221; and &#8220;<em><strong>who<\/strong><\/em>&#8221; questions:<\/p>\n<figure id=\"attachment_1417\" aria-describedby=\"caption-attachment-1417\" style=\"width: 501px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Questions.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1417\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/questions\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Questions.jpg\" data-orig-size=\"501,129\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1548512769&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Grammars for Questions\" data-image-description=\"&lt;p&gt;Grammars for Questions&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Grammars for Questions&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Questions.jpg\" class=\"size-full wp-image-1417\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Questions.jpg?resize=501%2C129&#038;ssl=1\" alt=\"Grammars for Questions\" width=\"501\" height=\"129\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Questions.jpg?w=501&amp;ssl=1 501w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Questions.jpg?resize=300%2C77&amp;ssl=1 300w\" sizes=\"(max-width: 501px) 100vw, 501px\" \/><\/a><figcaption id=\"caption-attachment-1417\" class=\"wp-caption-text\"><strong>Grammars for Questions<\/strong><\/figcaption><\/figure>\n<p>The third step in the generation strategy is to define &#8220;<em><strong>sentence patterns<\/strong><\/em>&#8220;. Each line (or sentence) in the poem is generated using this pattern. The pattern itself refers to a grammar and one or more non-terminals in that grammar. The generator synthesizes a line of the poem from the referenced grammar, randomly choosing a non-terminal from the list. Here is how we define the patterns:<\/p>\n<figure id=\"attachment_1418\" aria-describedby=\"caption-attachment-1418\" style=\"width: 478px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Patterns.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1418\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/patterns\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Patterns.jpg\" data-orig-size=\"478,111\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1548513330&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Defining Sentence Patterns\" data-image-description=\"&lt;p&gt;Defining Sentence Patterns&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Defining Sentence Patterns&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Patterns.jpg\" class=\"size-full wp-image-1418\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Patterns.jpg?resize=478%2C111&#038;ssl=1\" alt=\"Defining Sentence Patterns\" width=\"478\" height=\"111\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Patterns.jpg?w=478&amp;ssl=1 478w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Patterns.jpg?resize=300%2C70&amp;ssl=1 300w\" sizes=\"(max-width: 478px) 100vw, 478px\" \/><\/a><figcaption id=\"caption-attachment-1418\" class=\"wp-caption-text\"><strong>Defining Sentence Patterns<\/strong><\/figcaption><\/figure>\n<p>When the generator decides to generate a line according to &#8220;<em><strong>pat3<\/strong><\/em>&#8220;, for instance, it will use &#8220;<em><strong>AdjPhrase<\/strong><\/em>&#8221; grammar and one of its non-terminals &#8220;<em><strong>phrase3<\/strong><\/em>&#8220;,<span class=\"Apple-converted-space\">\u00a0 <\/span>&#8220;<em><strong>phrase5<\/strong><\/em>&#8220;,<span class=\"Apple-converted-space\">\u00a0 <\/span>or &#8220;<em><strong>phrase6<\/strong><\/em>&#8221; at random.<\/p>\n<p>Finally, to generate a poem, we use the &#8220;<em><strong>generate-poem<\/strong><\/em>&#8221; function, supplying a list of patterns. Here is a sample output:<\/p>\n<figure id=\"attachment_1420\" aria-describedby=\"caption-attachment-1420\" style=\"width: 411px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1420\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/output1-3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output1.jpg\" data-orig-size=\"411,202\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1548513978&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Sample Output 1\" data-image-description=\"&lt;p&gt;Sample Output 1&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Sample Output 1&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output1.jpg\" class=\"size-full wp-image-1420\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output1.jpg?resize=411%2C202&#038;ssl=1\" alt=\"Sample Output 1\" width=\"411\" height=\"202\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output1.jpg?w=411&amp;ssl=1 411w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output1.jpg?resize=300%2C147&amp;ssl=1 300w\" sizes=\"(max-width: 411px) 100vw, 411px\" \/><\/a><figcaption id=\"caption-attachment-1420\" class=\"wp-caption-text\"><strong>Sample Output 1<\/strong><\/figcaption><\/figure>\n<p>Each group of patterns defines a &#8220;<em><strong>stanza<\/strong><\/em>&#8221; or &#8220;<em><strong>para<\/strong><\/em>&#8220;.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>If we execute the function again, passing the same set of arguments as patterns, we are guaranteed to get a new poem. The text is not repeated!<\/p>\n<figure id=\"attachment_1421\" aria-describedby=\"caption-attachment-1421\" style=\"width: 403px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1421\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/output2-3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output2.jpg\" data-orig-size=\"403,204\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1548514092&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Sample Output 2\" data-image-description=\"&lt;p&gt;Sample Output 2&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Sample Output 2&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output2.jpg\" class=\"size-full wp-image-1421\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output2.jpg?resize=403%2C204&#038;ssl=1\" alt=\"Sample Output 2\" width=\"403\" height=\"204\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output2.jpg?w=403&amp;ssl=1 403w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output2.jpg?resize=300%2C152&amp;ssl=1 300w\" sizes=\"(max-width: 403px) 100vw, 403px\" \/><\/a><figcaption id=\"caption-attachment-1421\" class=\"wp-caption-text\"><strong>Sample Output 2<\/strong><\/figcaption><\/figure>\n<p>Here is a simpler version using just the pattern &#8220;<em><strong>pat1<\/strong><\/em>&#8220;:<\/p>\n<figure id=\"attachment_1422\" aria-describedby=\"caption-attachment-1422\" style=\"width: 412px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1422\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/output3-3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output3.jpg\" data-orig-size=\"412,99\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1548514191&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"With a Single Pattern\" data-image-description=\"&lt;p&gt;With a Single Pattern&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;With a Single Pattern&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output3.jpg\" class=\"size-full wp-image-1422\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output3.jpg?resize=412%2C99&#038;ssl=1\" alt=\"With a Single Pattern\" width=\"412\" height=\"99\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output3.jpg?w=412&amp;ssl=1 412w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output3.jpg?resize=300%2C72&amp;ssl=1 300w\" sizes=\"(max-width: 412px) 100vw, 412px\" \/><\/a><figcaption id=\"caption-attachment-1422\" class=\"wp-caption-text\"><strong>With a Single Pattern<\/strong><\/figcaption><\/figure>\n<p>As you can see, generating text of arbitrary nature, including poems, is possible with <em><strong>iLangGen<\/strong><\/em>. Of course, to get acceptable quality, considerable effort needs to be put in in terms of the grammar and choice of words. For example, take a look at &#8220;<em><strong>Sent<\/strong><\/em>&#8221; grammar. It is used in &#8220;<em><strong>pat6<\/strong><\/em>&#8221; and is capable of generating sentences that <em><strong>rhyme<\/strong><\/em>\u00a0by using words that end in &#8220;<em><strong>ate<\/strong><\/em>&#8220;. For this, the generator is ably assisted by the other core component, &#8220;<em><strong>iLexicon<\/strong><\/em>&#8220;.<\/p>\n<p>Hope you enjoyed reading this post. Have a nice weekend.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In an earlier article, I wrote about using iLangGen to generate natural language text. iLangGen is a powerful text generation library that I have been working on over the years. Today, I would like to show how we can use that library to generate &#8220;poetry&#8220;. Be warned, however, that the generated poem is devoid of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18,107,17],"tags":[109,130,174,173],"class_list":["post-1410","post","type-post","status-publish","format-standard","hentry","category-lisp","category-natural-language-processing","category-programming","tag-ilanggen","tag-ilexicon","tag-natural-language-processing","tag-poetry-generation"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-mK","jetpack-related-posts":[{"id":575,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/08\/06\/text-generation-using-ilanggen-framework\/","url_meta":{"origin":1410,"position":0},"title":"Text Generation Using iLangGen Framework","author":"admin","date":"August 6, 2017","format":false,"excerpt":"The two primary areas in Natural Language processing are Natural Language Understanding and Natural Language Generation. The former is concerned with processing and making sense of natural language text, whereas the latter is concerned with synthesizing text, possibly from some deep representation. Both are fascinating and at the same time,\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"iLangGen Grammar","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/08\/Blog1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/08\/Blog1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/08\/Blog1.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1309,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/16\/generating-poetry-using-rita\/","url_meta":{"origin":1410,"position":1},"title":"Generating Poetry Using RiTa","author":"admin","date":"December 16, 2018","format":false,"excerpt":"A few days ago, I came across a nice library called RiTa, which is described as a software toolkit for computational literature. Its two major features are text analysis and text generation.\u00a0 The text analysis module parses given text to extract sentences, tokens, POS, stresses, and phonemes. There is also\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Terminal Session","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/12\/Terminal.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":585,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/08\/18\/repetition-in-grammar-rules\/","url_meta":{"origin":1410,"position":2},"title":"Repetition in Grammar Rules","author":"admin","date":"August 18, 2017","format":false,"excerpt":"Many times, we need to repeatedly generate an element, or in general, have a way to control the number times one or more elements get generated. iLangGen supports all the standard cases: - Zero or once - Zero or more times (unbounded) - Zero or more times (bounded) - One\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Zero or Once","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/08\/Optional.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/08\/Optional.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/08\/Optional.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1659,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/04\/generating-poetry-in-prolog\/","url_meta":{"origin":1410,"position":3},"title":"Generating Poetry in Prolog","author":"admin","date":"August 4, 2019","format":false,"excerpt":"In an earlier article, I showed how we can generate poetry (with limitations, of course!) using my iLangGen framework. That implementation (in Lisp) made use of iLexicon, a large dictionary of English words, which I have been building over the years. I subsequently ported iLexicon to Prolog and it now\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Generation Logic","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/Code3.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/Code3.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/Code3.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":884,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/08\/natural-language-generation\/","url_meta":{"origin":1410,"position":4},"title":"Natural Language Generation","author":"admin","date":"April 8, 2018","format":false,"excerpt":"I had written a series of posts on my iLangGen framework last year. It aims to provide a flexible and expressive approach for building natural language generation systems. In today's post, I would like to describe a concrete example of how iLangGen can be used for generating natural language text\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Overall Approach","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/overall-1.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":637,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/09\/27\/composition-of-grammars\/","url_meta":{"origin":1410,"position":5},"title":"Composition of Grammars","author":"admin","date":"September 27, 2017","format":false,"excerpt":"In the last post, we saw how iLangGen text generation framework supports reuse of grammars through inheritance, akin to object-oriented languages. The good news is that we can achieve reuse through composition as well. The following is a simple grammar, nothing fancy to elaborate. Here is the output when you\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Simple Grammar","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/09\/G1.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=1410"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1410\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=1410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=1410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=1410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}