AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

AIML <learn> tag in Program O
 
 

Hi everyone.

I am using Program O to build a chatbot. As I am testing the supported tags, I noticed that the learn tag is not working properly or I am not using it correctly. Can someone please help.

<category>
<
pattern>_</pattern
<
template>
<
think>
 <
set name="star"><star /></set>
 <
set name="response1"><response index "1" /></set>
 <
set name="response2"><response index "2" /></set>
 <
condition>
  <
li name="response2" value="OK, what should I have said">
  <
set name="badanswer-newresp"><request index "1" /></set>
  </
li>
 </
condition>
</
think>
<
condition>
<
li name="response1" value="OK, what should I have said"></li>
<
li name="star" value="no">I'll try to remember to respond, "<get name="badanswer-newresp" />" when you say, "<get name="badanswer-input" />" 
<learn>
 <category>
 <pattern>
  <eval><uppercase><get name="badanswer-input" /></uppercase></eval>
 </pattern>
 <template>
  <eval><get name="badanswer-newresp" /></eval>
 </template>
 </category>
</learn>
<think><set name="topic">learning new answers</set></think>
</li>
<li name="star" value="yes">I'
ll try to remember to respond"<get name="badanswer-newresp" />" when you say"<get name="badanswer-input" />" if I have just said "<get name="badanswer-that-full" />" 
<learn>
 <
category>
 <
pattern>
  <eval><
uppercase><get name="badanswer-input" /></uppercase></eval>
 </
pattern>
 <
that>
  <eval><
uppercase><get name="badanswer-that" /></uppercase></eval>
 </
that>
 <
template>
 <eval><
get name="badanswer-newresp" /></eval>
 </
template>
 </
category>
</
learn>
<
think><set name="topic">learning new answers</set></think>
</
li>
<
li>Yes or No?</li>
</
condition>
</
template>
</
category
 

 
  [ # 1 ]

Hi, Laureen, and welcome to chatbots.org! smile

I’ve taken the liberty of wrapping your AIML code in [code] tags, so that the code will format properly. The forum software dislikes certain tags (<pattern> being among them), so whenever you need to post AIML (or any other code, really) it’s best to use [code][/code] to contain it. It’s far better than just pasting stuff and hoping for the best. wink

Ok, let’s address your issue. First of, some questions:

1.) Which version of Program O are you using, and on which server OS?
2.) Could you post a transcript of what’s going on? That will help a lot.

Aside from that, I do see one problem that will plague you continually, and that’s the use of the underscore wildcard in a pattern that has no other means of filtering the input. This:

<pattern>_</pattern

without either a <topic> or <that> to help discard unwanted patterns will end up creating an endless loop of the same response, even when using <srai> tags, because the underscore wildcard matches literally everything, even over a direct match. the underscore wildcard should never be used by itself for exactly this reason. My first suggestion for now is to change that underscore to a star, and see if that resolves the issue. If it does, great! a simple re-think of the pattern should do wonders. If you STILL get the same issue, then we can dig deeper.

 

 
  [ # 2 ]

Thank you very much for the reply Mr. Dave smile

Well, unfortunately, it didn’t solve the problem. I will post the full code maybe you could spot the error.

But first, to answer your questions, I am using Program O version 2.6.4 on my local WAMP server.

<aiml versi>
<
category>
<
pattern>BAD ANSWER</pattern>
<
template>
<
think>
 <
set name="badanswer-input"><input index="2" /></set>
 <
set name="badanswer-that"><that index="2,1" /></set>
 <
set name="badanswer-that-full"><that index="2,*" /></set>
 <
set name="topic">badanswer-prelim</set>
</
think>
Would you like to teach me a new answer to "<get name="badanswer-input"/>"?
</
template>
</
category>

<
topic name="BADANSWER-PRELIM">

<
category>
<
pattern>_</pattern>
<
template>
<
think><set name="star"><star /></set></think>
<
condition>
<
li name="star" value="yes">
 
OKwhat should I have said?<think><set name="topic">learning new answers</set></think>
</
li>
<
li name="star" value="no">
 
OKlet's forget it then.<think><set name="topic">learning new answers</set></think>
</li>
<li>Yes or No?</li>
</condition>
</template>
</category>

<category>
<pattern>_ _</pattern>
<template><sr /></template>
</category>

</topic>


<category>
<pattern>*</pattern>
<that>OK WHAT SHOULD I HAVE SAID</that>
<template>
"<set name="badanswer-newresp"><input index="1" /></set>..."?
<condition>
<li name="badanswer-that" value="*">
 <think><set name="topic">BADANSWER</set></think>
 Does this depend on me having just said, "<get name="badanswer-that-full" />"?
</li>
<li>
 <think><set name="topic">BADANSWER2</set></think>
 Do you want me to remember that?
</li>
</condition>
</template>
</category>

<category>
<pattern>_ _</pattern>
<that>OK WHAT SHOULD I HAVE SAID</that>
<template><sr /></template>
</category>


<topic name="BADANSWER">

<category>
<pattern>*</pattern>
<template>
<think>
 <set name="star"><star /></set>
 <set name="response1"><response index = "1" /></set>
 <set name="response2"><response index = "2" /></set>
 <condition>
  <li name="response2" value="OK, what should I have said">
  <set name="badanswer-newresp"><request index = "1" /></set>
  </li>
 </condition>
</think>
<condition>
<li name="response1" value="OK, what should I have said"></li>
<li name="star" value="no">I'
ll try to remember to respond"<get name="badanswer-newresp" />" when you say"<get name="badanswer-input" />"
<learn>
 <
category>
 <
pattern>
  <eval><
uppercase><get name="badanswer-input" /></uppercase></eval>
 </
pattern>
 <
template>
  <eval><
get name="badanswer-newresp" /></eval>
 </
template>
 </
category>
</
learn>
<
think><set name="topic">learning new answers</set></think>
</
li>
<
li name="star" value="yes">I'll try to remember to respond, "<get name="badanswer-newresp" />" when you say, "<get name="badanswer-input" />" if I have just said "<get name="badanswer-that-full" />"
<learn>
 <category>
 <pattern>
  <eval><uppercase><get name="badanswer-input" /></uppercase></eval>
 </pattern>
 <that>
  <eval><uppercase><get name="badanswer-that" /></uppercase></eval>
 </that>
 <template>
 <eval><get name="badanswer-newresp" /></eval>
 </template>
 </category>
</learn>
<think><set name="topic">learning new answers</set></think>
</li>
<li>Yes or No?</li>
</condition>
</template>
</category>

<category>
<pattern>_ _</pattern>
<template><sr /></template>
</category>

</topic>

<topic name="BADANSWER2">

<category>
<pattern>_</pattern>
<template>
<think>
 <set name="star"><star /></set>
 <set name="response1"><response index = "1" /></set>
 <set name="response2"><response index = "2" /></set>
 <condition>
  <li name="response2" value="OK, what should I have said">
  <set name="badanswer-newresp"><request index = "1" /></set>
  </li>
 </condition>
</think>
<condition>
<li name="response1" value="OK, what should I have said"></li>
<li name="star" value="yes">Fine. I'
ll try to remember to respond"<get name="badanswer-newresp" />" when you say"<get name="badanswer-input" />"
<learn>
 <
category>
 <
pattern>
  <eval><
uppercase><get name="badanswer-input" /></uppercase></eval>
 </
pattern>
 <
template>
  <eval><
get name="badanswer-newresp" /></eval>
 </
template>
 </
category>
</
learn>
<
think><set name="topic">learning new answers</set></think>
</
li>
<
li name="star" value="no">OKlet's forget it then.
<think><set name="topic">learning new answers</set></think>
</li>
<li>Yes or No?</li>
</condition>
</template>
</category>

<category>
<pattern>_ _</pattern>
<template><sr /></template>
</category>

</topic> 

I would honestly appreciate any help you could give me. Thank you so much in advance smile

 

 
  [ # 3 ]

Given that you’re using WAMP, I’m guessing you’re either using Windows 8, or possibly 10. I have a virtual machine for Win8, and my development server is Win10, so I can test either fairly easily. I’ll create a new chatbot using the AIML categories you’ve posted above and see what I can see.

It would still be helpful if I could see not only the transcripts from your tests, but also what you expected in those tests that you didn’t see.

 

 
  [ # 4 ]

I’ve created a new bot (Laureen) and put in only the AIML file that you posted (with some minor structuring changes), and of course saying “Hello”  returned the default “no response found” message, as expected, so I typed in “Bad answer”, and got the expected response. however, things went south from there, and I think I see why. Sadly, I have deadlines to meet this weekend, so I don’t have time right now to investigate further. But I’ve taken notes, and will revisit this mid-week next, and should have some suggestions at that point.

 

 
  [ # 5 ]

I expect the transcript to be something like this:

User: Hello
Bot: ‘error message’
User: bad answer
Bot: Would you like to teach me a new answer to “hello”
User: yes
Bot:OK, what should I have said?
User: hey
Bot: ” hey…”? Do you want me to remember that?
User: I’ll try to remember to respond hey when you say hello

When the User asks again hello the bot replies with hey for the current user session.

Thank you very much smile please take all the time you need. Good luck in everything you have to do.
Looking forward to hearing from you again smile

 

 
  [ # 6 ]

Welcome Laureen.

I tried similar code on pandorabots playground that does not use the _ underscore and only uses the * star once.  Please see the sample code below on how I used the * star in conjunction with the <that> tag to avoid either always trapping the input or an endless loop.  Let us know if it works for you in program O and good luck!

<?xml version="1.0" encoding="UTF-8"?>
<aiml>
<!-- 
version attribute removed in the AIML tag to appease the forum software Dave -->

<
category>
    <
pattern>bad answer</pattern>
    <
template>
    <
think>
    <
set name="badanswer-input"><input index="2" /></set>
    </
think>
    
Would you like to teach me a new answer for <get name="badanswer-input"/>?</template>
</
category>

<
category>
    <
pattern>yes</pattern>
    <
that>Would you like to teach me a new answer for *</that>
    <
template>Okwhat should I have said?</template>
</
category>

<
category>
    <
pattern>no</pattern>
    <
that>Would you like to teach me a new answer</that>
    <
template>Okforget it then.</template>
</
category>

<
category>
    <
pattern>yes</pattern>
    <
that>Would you like to teach me a new answer?</that>
    <
template>Okwhat should I have said?</template>
</
category>

<
category>
    <
pattern>*</pattern>
    <
that>Okwhat should I have said</that>
    <
template><think>
    <
learn>
        <
category>
            <
pattern>
                <eval><
uppercase><get name="badanswer-input" /></uppercase></eval>
            </
pattern>
            <
template>
                <eval><
star/></eval>
            </
template>
        </
category>
    </
learn>
    </
think>
    
I will try to remember that.
    </
template>
</
category>

</
aiml

 

 

 
  [ # 7 ]

Thanks for that, Alaric.

For some reason, the forum software doesn’t like the VERSION attribute within the <aiml> tag, and always shortens it to “versi”, with no value, so I took the liberty of simply removing it from your code, so that copy/paste operations won’t create invalid XML. Program O is very picky about any uploaded AIML, and absolutely requires valid XML before it will add AIML files to the database. I’ve run into this exact problem before, and it’s frustrating, so I took steps to prevent it. I hope you don’t mind. smile

 

 
  [ # 8 ]

Thank you very much Mr. Alaric Schenck.

But that didn’t work :( I get the error message when I reply to “Ok, what should I have said? “

 

 
  [ # 9 ]

Laureen, can you post your input and I can try to recreate the error.  The code works on Pandorabots.  I would try to enter a simple response of a few words to test at first.  Do not include any punctuation in your response and see if it accepts a simple response.  Do you get an error each time if you try several different questions and responses?

Dave, can you test using Program O? (Thanks for fixing the version attribute in my posted code.)

 

 
  [ # 10 ]

I’ve tested it already, and it fails, but work and school deadlines prevent me from looking into why it fails right now. Later this week I’ll have more time, but for now there’s not much I can do.

 

 
  [ # 11 ]

It works when the original input does not have a question mark.  I tried a few things but I am not really sure why trying to learn a pattern with a question mark is an issue.  In Pandorabots there are two files “denormal” and “normal” where punctuation is converted to text and back again.  In my case the question mark is being replaced with a space and getting rid of it.  I have also tried converting it to the word “questionmark” and updating the patterns but there were still issues with it successfully remembering the correction and being able to answer correctly once the correct response was entered and “learned”.  You will just have to experiment some more and improve the code.  Try inputs without any punctuation first.  Once those work then try inputs and responses with punctuation such as commas and question marks.  Review how program O handles punctuation and how it is represented in AIML as there may be substitutions being made.

 

 
  [ # 12 ]

I haven’t had the time to make a thorough investigation into the AIML code involved, so I can’t make any judgments yet. I’m hoping that by Tuesday I’ll have enough time to do so. It’s on my calendar for then.

 

 
  [ # 13 ]

Hi Laureen,
I encountered the same issue. I tried Alaric’s code, but that didn’t work. So I change the code a bit and now it works! I am not sure if you still need it, but here is the code:

<?xml version="1.0" encoding="UTF-8"?>
<aiml>
  <
category>
    <
pattern>BAD ANSWER</pattern>
    <
template><think><set name="badanswer-input"><input index="2"/></set></think>    Would you like to teach me a new answer for <get name="badanswer-input"/>?</template>
  </
category>
  <
category>
    <
pattern>_</pattern>
    <
that>OK WHAT SHOULD I HAVE SAID</that>
    <
template><think><learn><category><pattern><eval><uppercase><get name="badanswer-input"/></uppercase></eval></pattern><template><eval><star/></eval></template></category></learn></think>    I will try to remember that.</template>
  </
category>
  <
category>
    <
pattern>YES</pattern>
    <
that>Would you like to teach me a new answer for *</that>
    <
template>Okwhat should I have said?</template>
  </
category>
  <
category>
    <
pattern>NO</pattern>
    <
that>Would you like to teach me a new answer</that>
    <
template>Okforget it then.</template>
  </
category>
  <
category>
    <
pattern>YES</pattern>
    <
that>WOULD YOU LIKE TO TEACH ME A NEW ANSWER</that>
    <
template>Okwhat should I have said?</template>
  </
category>
</
aiml
 

 
  login or register to react