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..

Implementing topics successfully - recursion errors abound!
 
 

Hello everyone!

I’m actually new to the forum. I’ve hit a wall in terms of my development of the “Katbot”, as I affectionately refer to her. I began my programming by starting out with simple, preliminary stuff. I also have been going through the tutorial and implementing things on the go until I have a grasp on things. However, when I got to “topic” that’s when my troubles began. I tried to implement a sample topic regarding movies. The initiation of my topic and the bots response was appropriate enough, but then I get the “too much recursion in AIML” response. Now, I’ve become aware through the forum that this means I have an infinite loop in my code, but I don’t know where or how and I really need help understanding how to fix it and understanding <topic> as a concept so as not to repeat my mistakes. Here is my code in the file called “movies”.

<?xml version="1.0" encoding="UTF-8"?>
<aiml versi>
  
 <
category>
      <
pattern>Can we talk about movies?</pattern>
      <
template>Are you a fan of <set name="topic">movies</set>?</template>
  </
category>
  
  <
category>
      <
pattern>LET US DISCUSS MOVIES</pattern>
      <
template>Yes <set name="topic">movies</set></template>  
   </
category>
   <
topic name="movies">
      <
category>
         <
pattern> * </pattern>
         <
template>Watching good movie refreshes our minds.</template>
      </
category>
      <
category>
         <
patternI LIKE WATCHING COMEDY! </pattern>
         <
template>I like comedy movies too.</template>
      </
category>
   </
topic>  
   
<
category>
<
pattern> * MOVIES </pattern>
<
template>What kind of movies do you like? </template>
</
category>

<
category>
<
pattern>*ACTION*</pattern>
<
that>WHAT KIND OF MOVIES DO YOU LIKE</that>
<
template>I personally prefer martial arts movies myself.</template>
</
category>

<
category>
<
pattern>*COMEDY*</pattern>
<
that>WHAT KIND OF MOVIES DO YOU LIKE</that>
<
template>Then you should check out the Money Pit on Netflix with Tom Hanks and Shelley Long.</template>
</
category>

</
aiml


Here is a couple sample interactions…

 

Me: Let’s discuss movies.
Katbot: Yes movies.
Me: I like watching comedy!
Katbot: I didn’t know that. (ultimate default category)

 

Me: Let’s discuss movies.
Katbot: Yes movies.
Me: What kind of movies do you like?
Katbot: Too much recursion in AIML.*

*as a side note - I did a trace to see it matching cases in the “safereduction3” file*

 

If anyone could be so kind as to walk me through what I’m doing wrong I’d greatly appreciate your assistance. I can take snapshots if necessary. Thank you so much!

 

Katherine

 

 

 

 
  [ # 1 ]

Hi, Kat, and welcome to chatbots.org! smile (I hope you don’t mind me calling you Kat)

I’ve taken the liberty of surrounding your AIML code with [ code ] tags, so as to make it easier to read (if the code isn’t surrounded by those tags, some of the AIML “disappears”).

Generally speaking, the <topic> tag by itself won’t cause the “infinite loop” that you’re experiencing. More often than not, it also requires an <srai> tag to also be involved, but I don’t see any of those tags in evidence within the code you’ve posted. Given the error message you’re reporting (“Too much recursion in AIML”), I’m assuming that you’re using Pandorabots for the chatbot platform? If not, I’d be interesting in knowing which platform you’re using. I know it’s not Program O because I never put in such an error message into the script. cheese

As far as the AIML itself is concerned, I only see a couple of things that are out of order, but nothing that in and of itself would cause the recursion issue you’re having. I’ll go over what I see first, then we can tackle the recursion issue, ok?

First off, in the very first AIML category you have there, you have a question mark in the <pattern> tag. This is a complete no-no. None of the pattern-side tags in AIML tags (<pattern>, <that> or <topic>) can have punctuation of any sort. Only letters, numbers or wildcards ( _ or * in AIML 1.0, and _, *, $ and ^ {I think} in AIML 2.0) are allowed in any of those tags. the only exception to this is within the <pattern> tag you’re allowed to use <bot> and/or <set> tags. this isn’t the source of the recursion issue, but it will cause unexpected results that would be tough to properly trace.

Secondly, I don’t see any “breakout” category within your posted code. this means that the chatbot will only talk about movies once it enters that topic, which is another sort of “infinite loop”, but not the sort that the bot will tell you about. Most often, a breakout category will have a “star” wildcard ( * ) in the <pattern>, and most often, no <that> pattern (or the same wildcard in that tag), and the output of the template will <set> the topic to either another topic, or to blank. Here’s an example of a couple of breakout categories:

<topic name="movies">
  <
category>
    <
pattern>*</pattern>
    <
template>
      <
think><set name="topic"></set></think>
      <!-- 
This sets the topic to an empty value -->
      <!-- 
The rest of the chatbot response would go here. -->
    </
template>
  </
category>

  <
category>
    <
pattern>LET S TALK ABOUT *</pattern>
    <
template>
      
CertainlyWe can talk about <set name="topic"><star /></set>! 
      <!-- 
againthis sets the topicbut now to the value of <star /> -->
    </
template>
  </
category>

  <!-- 
More categories about movies go here -->
</
topic

There are other ways to break out of a topic, but these two examples are the most common.


Ok, now for the recursion issue. Since you’ve already performed at least one trace, would you be willing to post the results of that trace (or another one) here, so we could examine it? It would help us to guide you toward finding the cause so that it can be corrected.

 

 
  [ # 2 ]

Hi Kat,

Welcome aboard

1 - As Dave says, remove all punctuation from that and pattern tags
2 - Wildcards need to be separated from the main body by spaces, so *COMEDY* becomes * COMEDY *

 

 
  [ # 3 ]

You’re going to hate me once I post the trace. It’s incredibly long!!! D: I thank you both for your replies. I went ahead and made those changes you mentioned, so now my code resembles the following. By the way, yes I am using the pandorabots platform to make this.

<?xml version="1.0" encoding="UTF-8"?>
<aiml>
  
  
  <
category>
      <
pattern>Can we talk about movies</pattern>
      <
template>Are you a fan of <set name="topic">movies</set>?</template>
  </
category>
  
  <
category>
      <
pattern>LET US DISCUSS MOVIES</pattern>
      <
template>Yes <set name="topic">movies</set></template>  
   </
category>
   <
topic name="movies">
      <
category>
         <
pattern> * </pattern>
         <
template>Watching good movie refreshes our minds.</template>
      </
category>
      <
category>
         <
patternI LIKE WATCHING COMEDY! </pattern>
         <
template>I like comedy movies too.</template>
      </
category>
   </
topic>  
   
   
   
   
   <
category>
<
pattern> * MOVIES </pattern>
<
template>What kind of movies do you like? </template>
</
category>

<
category>
<
pattern> * ACTION * </pattern>
<
that>WHAT KIND OF MOVIES DO YOU LIKE</that>
<
template>I personally prefer martial arts movies myself.</template>
</
category>

<
category>
<
pattern> * COMEDY * </pattern>
<
that>WHAT KIND OF MOVIES DO YOU LIKE</that>
<
template>Then you should check out the Money Pit on Netflix with Tom Hanks and Shelley Long.</template>
</
category>

<
topic name="movies">
  <
category>
    <
pattern>*</pattern>
    <
template>
      <
think><set name="topic"></set></think>
      <!-- 
This sets the topic to an empty value -->
      <!-- 
The rest of the chatbot response would go here. -->
      <
random>
          <
li>I see.</li>
          <
li>Roger that.</li>
      </
random>
    </
template>
  </
category>

  <
category>
    <
pattern>LET S TALK ABOUT *</pattern>
    <
template>
      
CertainlyWe can talk about <set name="topic"><star /></set>! 
      <!-- 
againthis sets the topicbut now to the value of <star /> -->
    </
template>
  </
category>

  <!-- 
More categories about movies go here -->
</
topic

  
  
  
  
</
aiml

Seriously, Kat. Please surround your AIML code with [ code ] tags (no spaces). It makes the code SO MUCH easier to read. - Dave

Now, for the dreaded trace…. the case test results from the following exchange.

Me: Let’s talk about movies.
Bot: Yes movies.
Me: What kind of movies do you like?
Bot: Too much recursion in AIML.


Attached is a notepad file with the trace results…

File Attachments
trace_results.txt  (File Size: 71KB - Downloads: 56)
 

 
  [ # 4 ]

Do you have this category in safereductions4.aiml?

<category>
<
pattern>WHAT IS YOUR MOVIE</pattern>
<
template><srai>what is your favorite movie</srai></template>
</
category

This will loop until it crashes with a too much recursion error.
You need to add a category like so:

<category>
<
pattern>WHAT IS YOUR FAVORITE MOVIE</pattern>
<
template>(Whatever you want the bot to say)</template>
</
category
 

 
  [ # 5 ]

Yup! Without a specific category to cover WHAT IS YOUR FAVORITE MOVIE, you’ll get a recursion error every time that question comes up.

BTW, Kat, I’ve edited your most recent post to surround the AIML code with [code][/code] tags. If you post AIML code without those code tags, the <pattern> tags won’t show up at all. The only reason why it does now is because I know how to “cheat”, and convince the forum software to display it. If you’re interested, it’s as simple as replacing < with &lt; smile

 

 
  login or register to react