{"id":944,"date":"2019-08-15T22:58:03","date_gmt":"2019-08-15T22:58:03","guid":{"rendered":"http:\/\/ai.intelligentonlinetools.com\/ml\/?p=944"},"modified":"2019-10-12T19:54:59","modified_gmt":"2019-10-12T19:54:59","slug":"running-r-package-pomdp-from-python","status":"publish","type":"post","link":"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/","title":{"rendered":"Running R Package POMDP from Python"},"content":{"rendered":"<div class=\"ndxud69ef6d64ab1d2\" ><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<!-- Text analytics techniques 728_90 horizontal top -->\n<ins class=\"adsbygoogle\"\n     style=\"display:inline-block;width:728px;height:90px\"\n     data-ad-client=\"ca-pub-3416618249440971\"\n     data-ad-slot=\"2926649501\"><\/ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/div><style type=\"text\/css\">\r\n.ndxud69ef6d64ab1d2 {\r\nmargin: 5px; padding: 0px;\r\n}\r\n@media screen and (min-width: 1201px) {\r\n.ndxud69ef6d64ab1d2 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 993px) and (max-width: 1200px) {\r\n.ndxud69ef6d64ab1d2 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 769px) and (max-width: 992px) {\r\n.ndxud69ef6d64ab1d2 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 768px) and (max-width: 768px) {\r\n.ndxud69ef6d64ab1d2 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (max-width: 767px) {\r\n.ndxud69ef6d64ab1d2 {\r\ndisplay: block;\r\n}\r\n}\r\n<\/style>\r\n<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-content\/uploads\/2019\/08\/python_r.png\" alt=\"python R\" width=\"303\" height=\"95\" class=\"aligncenter size-full wp-image-958\" srcset=\"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-content\/uploads\/2019\/08\/python_r.png 303w, http:\/\/ai.intelligentonlinetools.com\/ml\/wp-content\/uploads\/2019\/08\/python_r-300x94.png 300w\" sizes=\"(max-width: 303px) 100vw, 303px\" \/><\/p>\n<p>Chatbots are now used in many applications for different purposes. The popularity of this type widget can be estimated from this fact:<br \/>\nAs of August 2019, search results on Google for the following keywords:<\/p>\n<li> chatbot &#8211; Volume: 246,000 searches per month and found 32,700,000 results <\/li>\n<li>neural net &#8211; Volume 3600 searches per month and  127,000,000 results <\/li>\n<p>One of the key components of chatbot architecture is Dialog Management. In order to incorporate some degree of uncertainty in classifying intents and entities, partially observable Markov decision process (POMDP) algorithm was proposed for building chatbots with Dialog Management. [1],[2]<\/p>\n<p>How can we run POMDP?  There is a package in R for this. <\/p>\n<p>But what if we want run from python?  One of the way could be call R from python. Here is how it can be done.<\/p>\n<p>First we need to create R program. For running POMDP in R we need first download and install (only one time). We also need set working directory (if it is different than default) and specify pdf file name &#8211; this is where the R<br \/>\nscript will output charts and diagrams. See below lines for this:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nr = getOption(&quot;repos&quot;)\r\nr[&quot;CRAN&quot;] = &quot;http:\/\/cran.us.r-project.org&quot;\r\noptions(repos = r)\r\n\r\nsetwd (&quot;C:\/\/Users\/\/username\/\/Documents&quot;)\r\n\r\n## the below line need to be run only first time and it must be run with admin priv.\r\n##install.packages(&quot;pomdp&quot;)\r\nlibrary(&quot;pomdp&quot;)\r\npdf('rplot123.pdf')\r\n<\/pre>\n<p>Now we can continue with our R program. Documentation for POMDP [3] has R code for tiger problem, that we can insert here.<\/p>\n<h2>Running POMDP R Package from Python<\/h2>\n<p>Now we need to create python script that will call R script. In addition to calling the R program, python will also display output from running R program. This is possible because when we call R program, we save output within txt file.  So the python script will save output into file and also output on screen. <\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# -*- coding: utf-8 -*-\r\nimport os\r\n\r\n\r\nos.system('&quot;C:\\\\Program Files\\\\R\\\\R-3.4.3\\\\bin\\\\Rscript&quot; C:\\\\Users\\\\username\\\\POMDP_R\\\\r_example.r &gt; C:\\\\Users\\\\username\\\\output_file_ex.txt')\r\n\r\nwith open('output_file_ex.txt', 'r') as reader:\r\n             print(reader.read())\r\n<\/pre>\n<p>Now we can run R package POMDP or any other R program from python and start build advanced chatbot dialog system.<\/p>\n<p><strong>References<\/strong><br \/>\n1. <a href=\"https:\/\/tutorials.botsfloor.com\/dialog-management-799c20a39aad\" target=\"_blank\">Dialog management<\/a><br \/>\n2. <a href=\"https:\/\/scholar.uwindsor.ca\/cgi\/viewcontent.cgi?article=8732&#038;context=etd\" target=\"_blank\">An Improved Approach of Intention Discovery with Machine Learning for POMDP-based Dialogue Management<\/a><br \/>\n3. <a href=\"https:\/\/cran.r-project.org\/web\/packages\/pomdp\/vignettes\/POMDP.pdf\" target=\"_blank\">POMDP: Introduction to Partially Observable Markov Decision Processes<\/a><\/p>\n<div class=\"sewtk69ef6d64ab200\" ><center>\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<!-- Text analytics techniques link ads horizontal Medium after content -->\n<ins class=\"adsbygoogle\"\n     style=\"display:inline-block;width:468px;height:15px\"\n     data-ad-client=\"ca-pub-3416618249440971\"\n     data-ad-slot=\"5765984772\"><\/ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-3416618249440971\"\n     data-ad-slot=\"3903486841\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<\/center><\/div><style type=\"text\/css\">\r\n.sewtk69ef6d64ab200 {\r\nmargin: 5px; padding: 0px;\r\n}\r\n@media screen and (min-width: 1201px) {\r\n.sewtk69ef6d64ab200 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 993px) and (max-width: 1200px) {\r\n.sewtk69ef6d64ab200 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 769px) and (max-width: 992px) {\r\n.sewtk69ef6d64ab200 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 768px) and (max-width: 768px) {\r\n.sewtk69ef6d64ab200 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (max-width: 767px) {\r\n.sewtk69ef6d64ab200 {\r\ndisplay: block;\r\n}\r\n}\r\n<\/style>\r\n","protected":false},"excerpt":{"rendered":"<p>Chatbots are now used in many applications for different purposes. The popularity of this type widget can be estimated from this fact: As of August 2019, search results on Google for the following keywords: chatbot &#8211; Volume: 246,000 searches per month and found 32,700,000 results neural net &#8211; Volume 3600 searches per month and 127,000,000 &#8230; <a title=\"Running R Package POMDP from Python\" class=\"read-more\" href=\"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/\" aria-label=\"More on Running R Package POMDP from Python\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[47],"tags":[75,73,74],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Running R Package POMDP from Python - Text Analytics Techniques<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Running R Package POMDP from Python - Text Analytics Techniques\" \/>\n<meta property=\"og:description\" content=\"Chatbots are now used in many applications for different purposes. The popularity of this type widget can be estimated from this fact: As of August 2019, search results on Google for the following keywords: chatbot &#8211; Volume: 246,000 searches per month and found 32,700,000 results neural net &#8211; Volume 3600 searches per month and 127,000,000 ... Read more\" \/>\n<meta property=\"og:url\" content=\"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Text Analytics Techniques\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-15T22:58:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-10-12T19:54:59+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-content\/uploads\/2019\/08\/python_r.png\" \/>\n<meta name=\"author\" content=\"owygs156\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"owygs156\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/\",\"url\":\"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/\",\"name\":\"Running R Package POMDP from Python - Text Analytics Techniques\",\"isPartOf\":{\"@id\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/#website\"},\"datePublished\":\"2019-08-15T22:58:03+00:00\",\"dateModified\":\"2019-10-12T19:54:59+00:00\",\"author\":{\"@id\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/#\/schema\/person\/832f10562faaa1c7ed668c1ab4388857\"},\"breadcrumb\":{\"@id\":\"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Running R Package POMDP from Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/#website\",\"url\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/\",\"name\":\"Text Analytics Techniques\",\"description\":\"Text Analytics Techniques\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/#\/schema\/person\/832f10562faaa1c7ed668c1ab4388857\",\"name\":\"owygs156\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g\",\"caption\":\"owygs156\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Running R Package POMDP from Python - Text Analytics Techniques","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/","og_locale":"en_US","og_type":"article","og_title":"Running R Package POMDP from Python - Text Analytics Techniques","og_description":"Chatbots are now used in many applications for different purposes. The popularity of this type widget can be estimated from this fact: As of August 2019, search results on Google for the following keywords: chatbot &#8211; Volume: 246,000 searches per month and found 32,700,000 results neural net &#8211; Volume 3600 searches per month and 127,000,000 ... Read more","og_url":"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/","og_site_name":"Text Analytics Techniques","article_published_time":"2019-08-15T22:58:03+00:00","article_modified_time":"2019-10-12T19:54:59+00:00","og_image":[{"url":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-content\/uploads\/2019\/08\/python_r.png"}],"author":"owygs156","twitter_card":"summary_large_image","twitter_misc":{"Written by":"owygs156","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/","url":"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/","name":"Running R Package POMDP from Python - Text Analytics Techniques","isPartOf":{"@id":"https:\/\/ai.intelligentonlinetools.com\/ml\/#website"},"datePublished":"2019-08-15T22:58:03+00:00","dateModified":"2019-10-12T19:54:59+00:00","author":{"@id":"https:\/\/ai.intelligentonlinetools.com\/ml\/#\/schema\/person\/832f10562faaa1c7ed668c1ab4388857"},"breadcrumb":{"@id":"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/ai.intelligentonlinetools.com\/ml\/running-r-package-pomdp-from-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ai.intelligentonlinetools.com\/ml\/"},{"@type":"ListItem","position":2,"name":"Running R Package POMDP from Python"}]},{"@type":"WebSite","@id":"https:\/\/ai.intelligentonlinetools.com\/ml\/#website","url":"https:\/\/ai.intelligentonlinetools.com\/ml\/","name":"Text Analytics Techniques","description":"Text Analytics Techniques","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ai.intelligentonlinetools.com\/ml\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ai.intelligentonlinetools.com\/ml\/#\/schema\/person\/832f10562faaa1c7ed668c1ab4388857","name":"owygs156","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ai.intelligentonlinetools.com\/ml\/#\/schema\/person\/image\/","url":"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g","contentUrl":"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g","caption":"owygs156"}}]}},"_links":{"self":[{"href":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/posts\/944"}],"collection":[{"href":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/comments?post=944"}],"version-history":[{"count":22,"href":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/posts\/944\/revisions"}],"predecessor-version":[{"id":975,"href":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/posts\/944\/revisions\/975"}],"wp:attachment":[{"href":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/media?parent=944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/categories?post=944"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/tags?post=944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}