{"id":2162,"date":"2020-10-11T14:32:08","date_gmt":"2020-10-11T09:02:08","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2162"},"modified":"2020-10-11T14:32:08","modified_gmt":"2020-10-11T09:02:08","slug":"template-based-text-generation-part-2","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2020\/10\/11\/template-based-text-generation-part-2\/","title":{"rendered":"Template-based Text Generation &#8211; Part 2"},"content":{"rendered":"<p>In my <a href=\"https:\/\/www.rangakrish.com\/index.php\/2020\/09\/28\/template-based-text-generation\/\" target=\"_blank\" rel=\"noopener noreferrer\"><em><strong>previous article<\/strong><\/em><\/a>, I showed how <em><strong>\u201ciLangGen\u201d<\/strong><\/em> framework facilitates text generation using templates. I talked about the various <em><strong>\u201cpatterns\u201d<\/strong><\/em> that can be used in a template. However, in that article, I did not go into the details of the <em><strong>\u201cEmbedded Template\u201d<\/strong><\/em> pattern. That is the focus of today\u2019s article.<\/p>\n<h4>Embedded Template<\/h4>\n<p>This pattern allows us to instantiate and embed another template in the current template. The format is:<\/p>\n<p><em><strong>{{ &lt; another-template.txt par1 par2 par3 }}<\/strong><\/em><\/p>\n<p>As you can see, optional parameters can be passed to the template and used as part of the instantiation process.<\/p>\n<p>The idea of embedded templates is appealing because it allows us to define reusable template fragments and compose them, as needed, to form a larger template.<\/p>\n<p>Take a look at the following template:<\/p>\n<figure id=\"attachment_2163\" aria-describedby=\"caption-attachment-2163\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2163\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/10\/11\/template-based-text-generation-part-2\/main-template\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template.jpg\" data-orig-size=\"686,313\" 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;1602352311&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=\"Main Template\" data-image-description=\"&lt;p&gt;Main Template&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Main Template&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template.jpg\" class=\"wp-image-2163\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template.jpg?resize=500%2C228&#038;ssl=1\" alt=\"Main Template\" width=\"500\" height=\"228\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template.jpg?resize=300%2C137&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template.jpg?w=686&amp;ssl=1 686w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2163\" class=\"wp-caption-text\"><strong>Main Template<\/strong><\/figcaption><\/figure>\n<p>Here, we have a reference to an embedded template file <em><strong>\u201ccpp-for-loop.txt\u201d<\/strong><\/em> along with 4 parameters. When the template processor sees this reference, it attempts to instantiate it using the passed context (when embedding templates, there should be no cycles).<\/p>\n<p>Here is the referenced template:<\/p>\n<figure id=\"attachment_2164\" aria-describedby=\"caption-attachment-2164\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2164\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/10\/11\/template-based-text-generation-part-2\/forloop\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop.jpg\" data-orig-size=\"778,403\" 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;1602352184&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=\"Embedded Template &amp;#8211; For Loop\" data-image-description=\"&lt;p&gt;Embedded Template &amp;#8211; For Loop&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Embedded Template &amp;#8211; For Loop&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop.jpg\" class=\"wp-image-2164\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop.jpg?resize=500%2C259&#038;ssl=1\" alt=\"Embedded Template - For Loop\" width=\"500\" height=\"259\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop.jpg?resize=300%2C155&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop.jpg?resize=768%2C398&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop.jpg?w=778&amp;ssl=1 778w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2164\" class=\"wp-caption-text\"><strong>Embedded Template &#8211; For Loop<\/strong><\/figcaption><\/figure>\n<p>We have a code section that defines a <em><strong>Lisp<\/strong><\/em> function, followed by the text template. You will notice that this corresponds to a <em><strong>C++ \u201cfor\u201d<\/strong><\/em> loop. What is interesting is that we use several patterns in this template in order to give a concrete syntax after instantiation. The patterns of the form <em><strong>\u201c{{$1}}&#8221;<\/strong><\/em> refer to the parameters passed from the main template. If you have read the earlier article, you will also notice that I have omitted the special marker <em><strong>\u201c!\u201d<\/strong><\/em> used to refer to the contextual parameter. Instead of <em><strong>\u201c{{! $1}}\u201d<\/strong><\/em>, I have used <em><strong>\u201c{{$1}}\u201d<\/strong><\/em>. This is a permitted shortcut.<\/p>\n<p>There is also a call to a <em><strong>Lisp<\/strong><\/em> function <em><strong>\u201cget-delta\u201d<\/strong><\/em> inside the <em><strong>\u201cfor\u201d<\/strong><\/em> loop. This function, as we mentioned earlier, is defined in the <em><strong>\u201ccode\u201d<\/strong><\/em> block.<\/p>\n<p>Let us look at the actual output produced by the template processor:<\/p>\n<figure id=\"attachment_2165\" aria-describedby=\"caption-attachment-2165\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run1.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2165\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/10\/11\/template-based-text-generation-part-2\/run1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run1.jpg\" data-orig-size=\"772,252\" 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;1602352510&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=\"Instantiated Output\" data-image-description=\"&lt;p&gt;Instantiated Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Instantiated Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run1.jpg\" class=\"wp-image-2165\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run1.jpg?resize=500%2C163&#038;ssl=1\" alt=\"Instantiated Output\" width=\"500\" height=\"163\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run1.jpg?resize=300%2C98&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run1.jpg?resize=768%2C251&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run1.jpg?w=772&amp;ssl=1 772w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2165\" class=\"wp-caption-text\"><strong>Instantiated Output<\/strong><\/figcaption><\/figure>\n<p>This shows how the different parameters passed from the main template are used inside the embedded template.<\/p>\n<p>What happens if we instantiate again?<\/p>\n<figure id=\"attachment_2166\" aria-describedby=\"caption-attachment-2166\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2166\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/10\/11\/template-based-text-generation-part-2\/run2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run2.jpg\" data-orig-size=\"769,262\" 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;1602352558&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=\"Another Instantiation\" data-image-description=\"&lt;p&gt;Another Instantiation&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Another Instantiation&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run2.jpg\" class=\"wp-image-2166\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run2.jpg?resize=500%2C170&#038;ssl=1\" alt=\"Another Instantiation\" width=\"500\" height=\"170\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run2.jpg?resize=300%2C102&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run2.jpg?w=769&amp;ssl=1 769w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2166\" class=\"wp-caption-text\"><strong>Another Instantiation<\/strong><\/figcaption><\/figure>\n<p>Because the <em><strong>Lisp<\/strong><\/em> function uses a random number, you can see that the <em><strong>RHS<\/strong><\/em> of the assignment has changed this time.<\/p>\n<p>Let us try to make the <em><strong>\u201cfor\u201d<\/strong><\/em> template more interesting, by using <em><strong>grammar-based<\/strong><\/em> generation. Here is the enhanced template:<\/p>\n<figure id=\"attachment_2167\" aria-describedby=\"caption-attachment-2167\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2167\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/10\/11\/template-based-text-generation-part-2\/forloop2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop2.jpg\" data-orig-size=\"798,746\" 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;1602407636&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=\"Using Grammar\" data-image-description=\"&lt;p&gt;Using Grammar&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Using Grammar&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop2.jpg\" class=\"wp-image-2167\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop2.jpg?resize=500%2C467&#038;ssl=1\" alt=\"Using Grammar\" width=\"500\" height=\"467\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop2.jpg?resize=300%2C280&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop2.jpg?resize=768%2C718&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/forloop2.jpg?w=798&amp;ssl=1 798w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2167\" class=\"wp-caption-text\"><strong>Using Grammar<\/strong><\/figcaption><\/figure>\n<p>Inside the <em><strong>\u201cfor\u201d<\/strong><\/em> template, I am using a <em><strong>\u201cgrammar\u201d<\/strong><\/em> pattern. It refers to a grammar named <em><strong>\u201cTest\u201d<\/strong><\/em> and a start node called <em><strong>\u201cstmt\u201d<\/strong><\/em>. The grammar itself is defined in a separate <em><strong>\u201ccode\u201d<\/strong><\/em> block (I have left the <em><strong>Lisp<\/strong><\/em> function code block undisturbed, although it is not used in this example). What really happens is that when the template processor encounters the grammar pattern, it invokes <em><strong>\u201ciLanGen\u201d<\/strong><\/em> to generate a <em><strong>\u201cstatement\u201d<\/strong><\/em> and substitutes it in the text.<\/p>\n<p>Since the above <em><strong>\u201cfor\u201d<\/strong><\/em> template uses only 3 parameters $<em><strong>1, $2 <\/strong><\/em>and<em><strong> $3,<\/strong><\/em> there is no need to pass the fourth parameter from the main template. Here is the modified main template:<\/p>\n<figure id=\"attachment_2168\" aria-describedby=\"caption-attachment-2168\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2168\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/10\/11\/template-based-text-generation-part-2\/main-template2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template2.jpg\" data-orig-size=\"754,311\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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=\"Updated Main Template\" data-image-description=\"&lt;p&gt;Updated Main Template&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Updated Main Template&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template2.jpg\" class=\"wp-image-2168\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template2.jpg?resize=500%2C206&#038;ssl=1\" alt=\"Updated Main Template\" width=\"500\" height=\"206\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template2.jpg?resize=300%2C124&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template2.jpg?w=754&amp;ssl=1 754w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2168\" class=\"wp-caption-text\"><strong>Updated Main Template<\/strong><\/figcaption><\/figure>\n<p>OK, what happens when we run the template processor this time?<\/p>\n<figure id=\"attachment_2169\" aria-describedby=\"caption-attachment-2169\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2169\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/10\/11\/template-based-text-generation-part-2\/run3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run3.jpg\" data-orig-size=\"828,251\" 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;1602407727&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=\"Template Instantiation\" data-image-description=\"&lt;p&gt;Template Instantiation&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Template Instantiation&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run3.jpg\" class=\"wp-image-2169\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run3.jpg?resize=500%2C152&#038;ssl=1\" alt=\"Template Instantiation\" width=\"500\" height=\"152\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run3.jpg?resize=300%2C91&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run3.jpg?resize=768%2C233&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run3.jpg?w=828&amp;ssl=1 828w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2169\" class=\"wp-caption-text\"><strong>Template Instantiation<\/strong><\/figcaption><\/figure>\n<p>Let us run it one more time:<\/p>\n<figure id=\"attachment_2170\" aria-describedby=\"caption-attachment-2170\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run4.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2170\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/10\/11\/template-based-text-generation-part-2\/run4\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run4.jpg\" data-orig-size=\"802,253\" 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;1602407762&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=\"Another Run\" data-image-description=\"&lt;p&gt;Another Run&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Another Run&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run4.jpg\" class=\"wp-image-2170\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run4.jpg?resize=500%2C158&#038;ssl=1\" alt=\"Another Run\" width=\"500\" height=\"158\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run4.jpg?resize=300%2C95&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run4.jpg?resize=768%2C242&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run4.jpg?resize=800%2C253&amp;ssl=1 800w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/run4.jpg?w=802&amp;ssl=1 802w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2170\" class=\"wp-caption-text\"><strong>Another Run<\/strong><\/figcaption><\/figure>\n<p>We get a slightly different output this time.<\/p>\n<p>Using a grammar pattern gives us greater power and hence we can generate text with better variations. Theoretically, it is possible to generate the entire <em><strong>\u201cfor\u201d<\/strong><\/em> loop using only grammar pattern, but using a textual <em><strong>\u201ctemplate\u201d<\/strong><\/em> along with the grammar pattern makes it more manageable, and is a trade-off.<\/p>\n<p>This completes the discussion on template-based text generation. Hope you find this idea interesting. If I make further enhancements to the template processor, I will be glad to share the updates with you.<\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my previous article, I showed how \u201ciLangGen\u201d framework facilitates text generation using templates. I talked about the various \u201cpatterns\u201d that can be used in a template. However, in that article, I did not go into the details of the \u201cEmbedded Template\u201d pattern. That is the focus of today\u2019s article. Embedded Template This pattern allows [&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,19,108],"class_list":["post-2162","post","type-post","status-publish","format-standard","hentry","category-lisp","category-natural-language-processing","category-programming","tag-ilanggen","tag-lisp","tag-text-generation"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-yS","jetpack-related-posts":[{"id":2152,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/09\/28\/template-based-text-generation\/","url_meta":{"origin":2162,"position":0},"title":"Template-Based Text Generation","author":"admin","date":"September 28, 2020","format":false,"excerpt":"I had written earlier about natural language generation\u00a0using my iLangGen framework. I used a \"template\" text file which was instantiated dynamically based on predefined \"grammars\" and external data. The sample application I show-cased demonstrated its utility and versatility. Today I would like to touch upon a few other \"pattern\" elements\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Template File","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/09\/Template-300x195.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/09\/Template-300x195.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/09\/Template-300x195.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":2162,"position":1},"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":2668,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/01\/23\/template-mixins-in-d-programming-language\/","url_meta":{"origin":2162,"position":2},"title":"Template Mixins in D Programming Language","author":"admin","date":"January 23, 2022","format":false,"excerpt":"When I heard the name Mixin\u00a0for the first time in the context of Dlang, I imagined it would be something similar to the mixins\u00a0of Common Lisp, but I was completely wrong!\u00a0 Mixins are a very interesting feature of D language. They allow code to be \"injected\" into the source at\u2026","rel":"","context":"In &quot;D Language&quot;","block_context":{"text":"D Language","link":"https:\/\/www.rangakrish.com\/index.php\/category\/d-language\/"},"img":{"alt_text":"Simple Template Mixin","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/01\/Defn-300x98.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1410,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/27\/generating-poetry-using-ilanggen\/","url_meta":{"origin":2162,"position":3},"title":"Generating Poetry Using iLangGen","author":"admin","date":"January 27, 2019","format":false,"excerpt":"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 \"poetry\". Be warned, however, that the\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Sample Output 2","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Output2.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":575,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/08\/06\/text-generation-using-ilanggen-framework\/","url_meta":{"origin":2162,"position":4},"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":739,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/12\/17\/c17-constexpr-if\/","url_meta":{"origin":2162,"position":5},"title":"C++17: constexpr if","author":"admin","date":"December 17, 2017","format":false,"excerpt":"constexpr if is another nice little feature in C++17, which significantly simplifies the way we code, especially in the context of templates. In this article, I will briefly talk about this feature and look at some examples. constexpr if is a variant of the standard if statement we have had\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Example1","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/12\/Example1-1.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2162","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=2162"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2162\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}