AI Zone Admin Forum Add your forum
Writing a bot from scratch
 
 

Hi there,

I was just wondering, are there any other massochists like myself out there that write their bot starting with… nothing at all.
Especially with all these premade bots out there (e.g Pandorabots) is there really a need to write a bot’s core from scratch? You can just register “your own” bot and start with the process of training it.

My personal preference goes to writing one from scratch in any programming language, even though this is alot more time consuming.
I can say this from experience, when I wrote my very first bot with I believe was Jbasic, I had more fun writing the bot than talking to it. Simply because I already knew how it would respond.

 

 
  [ # 1 ]

Hi, you might want to check out the AIML Superbot at http://alicebot.org/superbot.html

Even if you are using another language besides AIML, the Superbot is a good starting point to construct an original bot.

Without telling your bot what to say, we can tell you the top 10,000 most likely things it will be asked.

 

 
  [ # 2 ]

hi Rich,

Why don’t you create a YouTube video: ‘Your first chatbot in 5 steps’ (or 7 or 9, but never 6 and 4; marketing thing wink )

 

 
  [ # 3 ]

Thanks Richard,
but Im not looking for a bot creation program. I’m currently writing one myself, using Java and several 3rd party APIs such as tts, voice recognition, swing components, etc.
Though I am interested in the english aiml set, it seems to have everything its supposed to have. If possible I’d like to use it for my bot and include it with an open source distribution. Could you point me to the license of the aiml sets?


P.S There seems to be a dead link at your site, the one that points to the standard-aiml (@http://www.virtualitas.net).

 

 
  [ # 4 ]
Roy van Berkum - May 7, 2010:

Hi there,

I was just wondering, are there any other massochists like myself out there that write their bot starting with… nothing at all.
. . .
My personal preference goes to writing one from scratch in any programming language, even though this is alot more time consuming.
I can say this from experience, when I wrote my very first bot with I believe was Jbasic, I had more fun writing the bot than talking to it. Simply because I already knew how it would respond.

Hi Roy,
I’m a ‘massochist’!  I’m starting my own project from scratch. Have you actually started any design work at the moment?  It’s amazing…if you sit down and think this problem through, that there are an incredible number of issues that must be worked out before a simple chat bot can emerge.

I hope to see you and maybe others start from scratch. It’s one way of coming to appreciate what guys like Richard and others have done to advance this field.

Regards,
Chuck

 

 
  [ # 5 ]

How much do you like programming?  What will you use your chatbot for (what are its ‘functional requirements’) ?  If you love programming as much as I do, and dream of winning the Loebner Prize with your bot, then there is absolutely no question you must embark upon your own design!  If you want a general purpose bot that can answer basic questions, then probably some existing architectures may provide for that.  For your own bot design, let me suggest using dynamic languages (‘scripting languages’) like Perl, Python, etc for your initial proof of concept.    Languages like C, C++ and Java are great – but not for the initial experimentation.  Once you have developed an algorithm that works, then think of moving to efficient, strictly typed languages.  You don’t want to be worried about heap memory management and data types when you are experimenting.

My bot is currently 100% Perl code – I find it is extremely flexible language, allowing me to do whatever I want, how I want, and make changes very quickly and easily.  I am close to completing all the necessarily algorithms and will probably convert it to C++ or perhaps Java next year.  I want to first complete the engine and start filling its knowledge base first though.

 

 
  [ # 6 ]

Hi Victor,
I worked with PERL several years ago (about 8) when I built a very small search engine. I really liked its ability to work with strings and pattern matching.

How long have you been working on this project?  Do you read about the designs of others in solving all of the chatbot problems? Does this influence your thinking? Or are you a ‘free spirit’ and code your own designs?

I began thinking about a chatbot nearly 10 years ago.  I read a few AI books when I was teaching robotics to some high school students.  I’ve done a few small related projects but nothing substantial.

Regards,
Chuck

 

 
  [ # 7 ]

@Chuck: sorrry for my PERL-newbee question. I’m an experienced programmer, but I’ve never seen PERL before. What is what you like about the ability with strings and pattern matching? Can you give an example?

 

 
  [ # 8 ]

Well, it depends on what you mean about “this” project.  Since I was about 16 years old I have been pursuing AI research.    I’m almost 40, so I’ve been at it for a bit.  ALL my approaches and algorithms have been my own ideas.  My very first chat bots, back in 1985 at age 14 were of the “Eliza” level, and, later on, as I learned to program better, and in better languages like C, C++, java, perl, pascal, etc, I have thought of better ideas.  I later re-coded my chatbot to use templates, like AIML.  I quickly realized that was much too restricting.  My current incarnation of my chatbot has no templates, the input is absolutely free form - only limited by the permutations of english grammar!   

The number of parse trees in even a simple sentence is quite high, and CPU usage goes through the roof in a lot of cases.  I’ve developed a way for the system to choose the best parse tree based on knowledge of words, which I call properties.    One of the reasons I asked about your system and how many CPU cores is because my code will HAVE TO make use of at least 4 processors in order to give a result in any reasonable about of time.  I am fully convinced that the human mind must be a “massively parallel” system. 

My chatbot, in just the last few months is now able to understand a sentence like “While I was in Africa I shot an elephant in my pajamas”, and actually know, based on the fact that “I” is probably a person, and that people wear pajamas and elephant is an animal, and thus probably doesn’t wear pajamas, and therefore knows to assume that it was “I” that was in pajamas and not the elephant !

  So, this particular “algorithm” of my 25 + year project was started in Feb ‘09.    Before that, I tried many failed attempts.  Well, not really failures, I “ruled out” all those ideas and gained knowledge in the process. 
About one month ago my bot know every English grammatical rule, and was able to parse very complex sentence in completely free form.  However, sentences longer than about 20 words took extremely long times (sometimes 60 to 90 seconds long with CPU ‘pegged’ at 100%).

I had to go back to the drawing board and re-write the engine.  I have redesigned it and made many optimizations, but I won’t know just how much faster the new engine is until I re-write a lot of the grammar rules—the new engine requires the grammar rules to be re-written since the API was changed.    By “grammar rule”  I mean something like saying “A sentence is a subject followed by a predicate”, that is one possible grammar rule.  Another would be “a predicate is a verb followed by an object”.

Each grammar rule is a snippet of Perl code, which links into, or ‘plugs into’ the main code.    A complex 25 word input took over a minute with old engine, I am very hopeful that with the new engine, when I have re-wrote all grammar rules of it, and try that same 25 word input, that it will be much faster to process.

I was considering re-writing the code in C, but I think I want to pursue more of the “pure research” and hammer out the ‘proof of concept’ first.  Besides, another way to speed it up is make it run on an 8 core cpu system, which is what I am also seriously considering.  Luckily, I don’t think it will be too difficult to fork out multiple processes and have them work on different groups of parse trees at a time. 

@Erwin - Perl is absolutely great for strings .. here is an example…  it validates if your postal code is valid (I’m in Canada, a postal code is an alpha-character, followed by digit, followed by alpha, then space, then digit, then alpha, then digit)

my $postal_code = “K0J 1B0”;
if($postal_code =~ m/^[a-z]\d[a-z]\s\d[a-z]\d$/i) { print “postal code valid\n”; } else { print “postal code INVALID!\n”; }

the code above says the variable $postal_code must be :

            any character that is a-z
            then single digit (\d)
            then a character a-z
            then digit (\d)
            then a space ( \s )
            then digit (\d)
            then character a-z
            then digit
  the ^ means start of line,  $ means end of line.

if you change $postal_code to say “K0J 1BC” it will state it is invalid, since the “C” won’t match \d (digit).

 

 
  [ # 9 ]
Erwin Van Lun - Jun 1, 2010:

@Chuck: sorrry for my PERL-newbee question. I’m an experienced programmer, but I’ve never seen PERL before. What is what you like about the ability with strings and pattern matching? Can you give an example?

The whole PMLS (PetaMem Language Server) is implemented in Perl. Contrary to popular belief, we have eliminated some C++ code from it to make it faster.

Therefore, the PMLS Discourse Engine is also implemented in Perl. And yes, the regular expressions available in Perl 5.10 alone beat other formalisms (such as AIML grin) hands down.

As Perl is a higher-order language allowing to create and interpret code at runtime, there will be no porting to C++/Java/Whatever as this would rob our engine of many of its essential features.

Richard

 

 
  [ # 10 ]
Victor Shulist - Jun 2, 2010:

my $postal_code = “K0J 1B0”;
if($postal_code =~ m/^[a-z]\d[a-z]\s\d[a-z]\d$/i) { print “postal code valid\n”; } else { print “postal code INVALID!\n”; }

Isn’t that just a regular expression? What languages don’t accept regex these days???

What would be actually awesome is an API function somewhere like

is_postal_code (codecountry, (state), strict falsewhich return truefalse, or a postal code which is probably right

But that’s a separate thread actually grin

@Richard: thanks for your clarification!

 

 
  [ # 11 ]

Sure, but it is the ease at which you write the syntax.  In one built in operator “m” for match, or s for substitute.  With VB.net for example you have to create a Regex object, and other objects, a big pain.  I like just having that ‘m’, or ‘s’ operator with =~ to do the regex right there.

Also, hash variables in perl are very quiick and easy to work with, and yes, other languages like VB have them as well, but again, you have to instantiate a bunch of objects.  With perl it’s just:

$country{‘Victor’} = ‘Canada’;

print $country{‘Victor’};  prints “Canada”

In VB I have to create a bunch of objects.  With Perl the hash is a built in datatype.  You can also handle hashes of hashes of hashes very easy if you want.    Also, Perl has the list variable - a built in datatype (VB has arrays, again objects). 

Lists :
      push @names,‘Bob’;  push @names,‘Alice’, push @names,‘Sam’;

      foreach my $name (sort @namees) { print $name; }
      # output is :  Alice, Bob, Sam
      simple, fast list (aka ‘array’) definition, population, and sorting

Also, Perl is supported by the open source community and has 10’s of thousands of already written modules to do everything from sending emails, to logic programming, to accesing the web, webservices, database access you name it.

When I am experimenting with a new algorithm, I want easy, built-in, simple programming constructs.  I don’t want to spend 1/2 my time creating and dealing with a big unnecessarily complex object library and instantiating 3 objects just to do pattern matching and substitution operations.

For your API, you could use:

sub is_postal_code
{
  my $code = shift;
  if($code =~ m/^[a-z]\d[a-z]\s\d[a-z]\d$/i)
  {
      return 1;  # it -is- a valid code
  }
  else
  {
      return 0; # it is -not- a valid code
  }
}

I’m not sure what you mean by “or a postal code which is probably right.”.  Are you talking about returning a fuzzy logic value?

Another handy feature of Perl I find is symbolic variables.

my $var_name = ‘name’;

$$var_name = ‘bob’;

In the above, it is not the variable ‘var_name’ that was set to ‘bob’, but instead it was the same as saying:

            $name = ‘bob’

why is this handy?  serialization is one obvious use.

Another very handy routine in Perl I use alot is eval() - yes, I know Javascript has it also.  Perl can write its own Perl code and evaluate it on the fly.  This relates to what Richard said.  I know that Microsoft .Net languages -can- do this , but it is complex and involves all kinds of objects again.  Perl eval ... simple,  eval(”$a =5; $b = 3; print $a*$b”);

I guess it is also a preference thing as well, and the fact that I have done so much Perl coding over the last few years, but I find for prototyping, it is my language of choice—for me it has all the best features all in one dynamic language.

 

 
  [ # 12 ]
Erwin Van Lun - Jun 3, 2010:
Victor Shulist - Jun 2, 2010:

my $postal_code = “K0J 1B0”;
if($postal_code =~ m/^[a-z]\d[a-z]\s\d[a-z]\d$/i) { print “postal code valid\n”; } else { print “postal code INVALID!\n”; }k

Isn’t that just a regular expression?

It is. And a bad one. wink See below.

Erwin Van Lun - Jun 3, 2010:

What languages don’t accept regex these days???

I assume that is a rhetorical question. The answer would be very different from what you think, though. Because it would be something like “perl and a very few others”. Java, .NET, C, C++ etc. not being among them. Remember: You asked “What languages”, not “What libraries, todays programming languages use,...”.

Erwin Van Lun - Jun 3, 2010:

What would be actually awesome is an API function somewhere like

is_postal_code (codecountry, (state), strict falsewhich return truefalse, or a postal code which is probably right

But that’s a separate thread actually grin

Yes, because from the AI programmers point of view, that would not only be not awesome, but plain wrong. You do not want to teach machines new tricks by programming statically tons of APIs. You want them to operate on input data, which provides knowledge about the world and perform semantic inference on that data.

Which brings me to the bad regex Victor provided.

From Wikipedia:

No postal code includes the letters D, F, I, O, Q, or U, as the OCR equipment used in automated sorting could easily confuse them with other letters and digits[citation needed], especially when they are rendered as cursive handwriting. The letters W and Z are used, but are not currently used as the first letter.

Which means Victors code would validate W1D 1O1 as correct. My poke at this problem would be:

sub cpc_first {
    
return <<'END';
0061 0063
0065
0067 0068
006A 006E
0070
0072 0074
0076
0078
007A
END
}

sub cpc {
    
return <<'END';
0061 0063
0065
0067 0068
006A 006E
0070
0072 0074
0076 007A
END
}

my $cpc 
"a1a 1a1";

if (
$cpc =~ m{\A\p{cpc_first}\d\p{cpc}\s\d\p{cpc}\d\z}xmsi{
    
print "valid\n";
}
else {
    
print "invalid\n";

tadaaa.


Richard

 

 
  [ # 13 ]

Ok, fair point.  My posting was of course just to give Erwin an idea of Perl syntax and Perl’s other uses, which was his original question, rather than an actual ‘production code’  postal code checker, a very quick sample… but that is good feedback.

I very much agree with your statement regarding not simply feeding an AI program hard-coded subroutines, but rather it reason semantically on information, that is, I believe also, the heart of AI research.  My bot, for example, will have no such concept as ‘data type’, there will be no “date” type, no “time type, no “number” type, all will be strings and it will infer what to do with that data based on it’s knowledge base.

When a AI program can do the following we will have reached TRUE machine intelligence:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User: A valid postal code is : letter, number, letter, number, letter, number

Computer: OK

User: is K0J1B0 a valid postal code?

Computer: Yes

User: is W1D1O1 ?

Computer : Yes

User: Oh, by the way no postal code includes the letters D, F, I, O, Q, or U, as the OCR equipment used in automated sorting could easily confuse them with other letters and digits[citation needed], especially when they are rendered as cursive handwriting. The letters W and Z are used, but are not currently used as the first letter.

Computer: I see, so W1D 1O1 is not valid.

User: really? why not?

Computer: it starts with a W.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So teaching it, not by providing massive amounts of hard-coded routines in programming languages, but teaching it incrementally in natural language.

What is really needed is, take statements in natural language, have it have the intelligence to then self program the perl/java/c/whatever logic itself.  Then, based on feedback (like ‘by the way, W cannot begin a postal code), have it have the intelligence to actually update its code based on that natural language).

Yes, there can be other ways to be intelligence than natural language processing, but the above would most certainly be one proof of intelligence.

 

 
  [ # 14 ]

Victor,

Victor Shulist - Jun 4, 2010:

Ok, fair point.  My posting was of course just to give Erwin an idea of Perl syntax and Perl’s other uses…

well your posting was of course just Perl advocacy. wink
Which is ok, but when it is done, it should be done right.

It is hard to explain/make clear the merits of a programming language if your examples show no clear benefit compared to other languages. Even more so to someone who is foreign to that language, because even most Perl programmers do not really know what they’re “holding in their hands”. In that context I recommend reading the “Higher Order Perl” Book. It’s freely available now. http://hop.perl.plover.com/

Regular expression to reverse all words that are longer than 5 characters in a string - but only if the current time stamp in seconds since the epoch is an odd number?

string =~ s{(\w+)}{(length $&& time() % 2) ? reverse $: $1}xmsge;

nah... I meant

string 
=~ s{(\w{6,})}{time() % reverse $: $1}xmsge

Now do that ye stinkin’ C# gonzos. :-D (I hope the humor weighs more than the insult, sorry otherwise)

Of course we do not need to elaborate on the tiresome “my language is better than yours”, because probably all of us know that every language has it’s benefits in a given application scenario, same way as every tool has it’s application.

You wouldn’t mow your lawn with grippers - would you? I wouldn’t write an office-suite in Perl also, but it is clearly beyond my comprehension (and imagination) how someone can try to tackle AI problems with a non-interpreted language. Sure - they write their own interpreters in JAVA, .NET and the like. But then again they probably also perform self-flagellation in their cellars every night. :-D

I very much agree with your statement regarding not simply feeding an AI program hard-coded subroutines, but rather it reason semantically on information, that is, I believe also, the heart of AI research.  My bot, for example, will have no such concept as ‘data type’, there will be no “date” type, no “time type, no “number” type, all will be strings and it will infer what to do with that data based on it’s knowledge base.

I think true machine intelligence would be if a machine would understand the intended(!) semantics of this quote. Because I do, OTOH I could now start picking on that and show how full of unpreciseness, contradictions and ambiguities it is.

So I would also be careful with things like that:

When a AI program can do the following we will have reached TRUE machine intelligence:
...

because from the example provided, the machine that could solve this (as the general case - not hardcoded) would not only show true machine intelligence, but also true machine clairvoyance. :-D

So teaching it, not by providing massive amounts of hard-coded routines in programming languages, but teaching it incrementally in natural language.

Which brings us to the topic of knowledge representation. What do you use if I might ask?
Because from what I’ve read so far, you probably (hopefully) have left the evolutionary
step of predicate-logic behind already.

 

Richard

 

 
  [ # 15 ]

@Richard:
Thanks for your clarification, makes sense.

will have no such concept as ‘data type’, there will be no “date” type, no “time type, no “number” type

That’s interesting. Because these things are made up by humans. We have to learn about it in school. It’s structured data by definition. It’s not something like gender, or species, or color, which are biological and could also be recognised by obversing.

Numbers and time are basic elements of mathematics. Would you consider to have all mathetical equations in strings?

Erwin
ps I’ve split your private contest idea to another thread, it’s a separate discussion.

 

 1 2 3 >  Last ›
1 of 4
 
  login or register to react