AI Zone Admin Forum Add your forum
JAIL (TM) (JavaScript Artificial Intelligence Language)
 
 

On JAIL: Would it be possible to start a separate thread on this?

JAIL(TM) (Javascript Artificial Intelligent Language) was a framework that I invented to explore AI and chatbots. It has worked extremely well, allowing flexibility and portability that I could not have achieved with other frameworks. It also has benefited from recent advances in JavaScript interpreter/compiler technology enabling speed that I would not have originally thought possible.

What was the reason why you created JAIL (what was lacking)


When I started the process I was looking for something that would be able to run both on the web and on my desktop. There was less choice in Bot web hosting than there is now. Additionally, I was more interested in a distributed processing model than having a web host run a CGI program that would degrade as more users accessed it.

Although AIML looked interesting it had 2 limitation. First, I would have to build my own interpreter. Secondly, I felt that using XML added to much overhead to the brain if I wanted to download it into a target device. This is the same discussion that web developers have regarding XML VS Json. JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write.

There had already been some simplistic chabots created with JavaScript that acted as a proof of concept for me. There were also many more examples on the web of functionality that I wanted to add.

JavaScript already had many of the functions that I needed, and ran on all the platforms I was interested in. All I needed to add was the enhanced AI features. I could package the AI in an efficient form and download it with minimum overhead and signal to noise ratio. It handles strings and regular expressions extremely well and I used that as the foundation for the AI.

can it be compared to something, how to use it in practice, where to download stuff etc?

Web developers will recognize the use of frameworks to make their jobs easier. Examples include; 10 promising JavaScript Frameworks (http://sixrevisions.com/javascript/promising_javascript_frameworks/)

In practice I use JAIL for developing Skynet-AI and for prototyping new AI functionality (some of which may never be integrated into a chatbot).

AI & Chatbot developers would most liken JAIL to AIML. AIML on a web site is usually interpreted on the host server, JAIL is downloaded to the browser and run on the client.

To Compare:

AIML: XML based mark-up
<category>ARE YOU * BED</pattern>
<template>I like sleeping in bed.</template></category>

JAIL: Regular Expressions and enhanced string interpreter
/ARE YOU .+ BED/i,
“I like sleeping in bed.”,

 

 

 
  [ # 1 ]

AIML: XML based mark-up
<category>ARE YOU * BED</pattern>
<template>I like sleeping in bed.</template></category>

JAIL: Regular Expressions and enhanced string interpreter
/ARE YOU .+ BED/i,
“I like sleeping in bed.”,

 

There is a reason AIML uses a simpler pattern matching mechanism than regular expressions: most people, that is most people who would write all the responses for a bot, have no idea what regular expressions are.  Just trying to explain to an English major the concept of a “wildcard” alone is impossibly difficult. 

The example also illustrates a benefit of XML: Strings do not need to be quoted.  The concept of a *markup* language means that the basic element is raw, unmarked text.  One can think of AIML as a language in which the print statement is implicit.  If the response itself contains quote marks, they would have to escaped in a language with quoted strings.

Compare:

<category>

WHAT DID EINSTEIN SAY
</pattern>
<template>He said, “Time is Money”.</template>
</category>

and

/WHAT DID EINSTEIN SAY/i,
“He said, \“Time is Money\”.”,

 

 
  [ # 2 ]

<category>

EINSTEIN ACTUALLY SAID: “I am absolutely convinced that no wealth in the world can help humanity forward, even in the hands of the most devoted worker. The example of great and pure individuals is the only thing that can lead us to noble thoughts and deeds. Money only appeals to selfishness and irresistibly invites abuse. Can anyone imagine Moses, Jesus or Ghandi armed with the money-bags of Carnegie?”
</pattern>
<template>And he also said “The most precious things in life are note those one gets for money.”</template>
</category>

 

 
  [ # 3 ]

The example also illustrates a benefit of XML

There are pros and cons of using XML vs other alternatives. For example:
JSON: The Fat-Free Alternative to XML (http://www.json.org/xml.html)


For Novices
The simple choice for novice JAIL users would be between the following:

/WHAT DID EINSTEIN SAY/i,

“He said“Time is Money”.,//Escape the quotes

'He said, “Time is Money".'//Change the outside quotes from double to single

“He said'Time is Money'.//Change the inside quotes from double to single-OK in many cases 

In most cases though, I would not expect a novice to be working with the raw data. Most users would benefit from some kind of editor for their system. I have created a variety of tools to help eliminate those types of issues. In the simplest form a novice could use a text editor or a spreadsheet to provide input in the following form:

<INPUT><TAB><OUTPUT>
This example would end up as:
WHAT DID EINSTEIN SAY<TAB>He said, “Time is Money”.

The <TAB> would be the tab button in a word processor, or just moving to the next column in a spreadsheet. In reality this is the most compressed form for simple patterns. Only the tab and line return are extra in the pattern/response. The patterns can be stored as a TSV file that any word processor or spreadsheet can save as.

JavaScript has a function that can escape all of the text input the same way it does for URLs. In practice, I automatically append the slashes and the regular expression tags and can escape the text responses during input conversion.

There is a reason AIML uses a simpler pattern matching mechanism than regular expressions: most people, that is most people who would write all the responses for a bot, have no idea what regular expressions are.  Just trying to explain to an English major the concept of a “wildcard” alone is impossibly difficult.

I agree, I was looking for something more powerful that “power users” could use in its raw form. I felt I could do much more with access to advanced pattern matching capabilities. Regular Expressions can also be much simpler and less verbose for those who don’t know XML.

In my first example I made a mistake:

<category>
<
pattern>   ----->For well formed XML I think <patternwas missing
WHAT DID EINSTEIN SAY
</pattern>
<
template>He said“Time is Money”.</template>
</
category

This type of error or a typo in the XML is common for me when I am entering raw XML and requires extra proof reading. In “raw” XML I am as apt to make a mistake in the XML as in the actual pattern or response.


If you compare the size of a input/response in the 3 formats you get:

TSV file 2 characters per input/response (tab character and return character)
Raw RegEx/Response 7 characters per input/response (//i,"",)
AIML  61 characters per input/response
(<category><pattern></pattern><template></template></category>) 

Since I actually download the “Brain” and the “interpreter” to the client, this becomes important. Even running on a server it can add up.

For Power Users
Of course the real power of JAIL comes across when you want to use its advanced features, either for pattern matching on input or expanded functionality in replies.

Today,  many Javascript/Web developers are now familiar with Regular Expressions and there are some tools that make it much easier to test and build RegEx patterns. For example:
http://gskinner.com/RegExr/


The input example:

<category>
<
pattern>
WHAT DID EINSTEIN SAY
</pattern

Could be easily expanded and enhanced with minimal extra coding:

/(WHAT DID (EINSTEIN|NEWTONSAY)/i,
"[RegExp.$2]? Wasn't he a scientist?[Search(RegExp.$1)]"

This is a simple regex that looks for either “EINSTEIN or NEWTON”.
It will reply either:
Einstein? Wasn’t he a scientist?
Newton? Wasn’t he a scientist?
and it also initiates a web search for “WHAT DID EINSTEIN SAY” or WHAT DID NEWTON SAY”.

You can find examples in action by talking with Skynet-AI at http://www.tinyurl.com/Skynet-AI

Try variations of the phrase: “What color is the red truck?”

Try math, or search for people, topics and images, or ask it to define something.

 

 

 

 

 

 
  [ # 4 ]

USER:is an ant bigger than Rigel?
AI: I have not experienced an ant bigger than enough to form an opinion. Are you preoccupied with Rigel things?
USER:an ant is smaller than Rigel
AI: OK. What else would you classify as smaller than Rigel?
USER:is an ant smaller than Rigel?
AI: Yes, you said, an ant is smaller than Rigel.
USER:an ant is an insect
AI: OK. What other things are an insect?
USER:is an insect smaller than Rigel?
AI: I have not experienced an insect smaller than enough to form an opinion. Are you preoccupied with Rigel things?

—-

After some tweaking, my logicagent (zip) can do:

> is an ant bigger than Rigel?
I have no knowledge that an ant is bigger than Rigel.

> an ant is smaller than Rigel
Okay, an ant is smaller than Rigel.

> is an ant smaller than Rigel?
Yes, an ant is smaller than Rigel.

> an ant = an insect
Okay, an ant = an insect.

> is an insect smaller than Rigel?
Yes, an insect is smaller than Rigel.

> why is an insect smaller than Rigel?
an insect is smaller than Rigel because: an insect = an ant, and an ant is smaller than rigel

 

 
  [ # 5 ]

It’s not as though no one ever thought of adding disjunctive patterns to AIML.  We could just as easily have expanded the pattern language to include an “or” operation like “EINSTEIN|NEWTON”.  Or even simpler, as has been suggested before, the ability to list multiple patterns per category:

<category>
WHAT DID EINSTEIN SAY</pattern>
WHAT DID NEWTON SAY</pattern>
<template>....

In fact many bot languages include disjunctive patterns as a feature.

Early on however I realized that there was a scaling problem with disjunctive patterns.  If the bot has a pattern “A or B” and then 10,000 categories later the botmaster adds “B or C”, and the input is B, which category is activated?  The interpreter would have rules of course saying which takes priority, but the botmaster may forget the earlier pattern (or it was written by someone else perhaps) and expect the new response for the input B, then be surprised to get the earlier response.  Fixing that becomes a tedious editing process of revising old categories (or rules, or whatever).

The one pattern-per-category principle of AIML avoids the scaling problem because you always know, when you add a new pattern, which response to expect. 

AIML handles the equivalent of disjunctive patterns with <srai>

<category>
WHAT DID NEWTON SAY</pattern>
<template><srai>WHAT DID EINSTEIN SAY</srai></template>
</category>

Which means, “saying WHAT DID NEWTON SAY is the same as saying WHAT DID EINSTEIN SAY”.

More characters are needed to write a category, yes, but we have tools, such as AIML spreadsheet editors, that reduce the need for typing <category>, , <template> over and over again.

 

 

 
  [ # 6 ]

For some reason all my leading <pattern> tags from the previous post were removed, perhaps in due to not using <code> tags.

 

 
  [ # 7 ]

@Richard: can you please send me the text you’ve posted, so I can check the issue with the pattern tag.

Tx! erwin

 

 
  [ # 8 ]

Thanks Robert,
Your logic agent is interesting and focuses on an area that I am also exploring. I noticed from your web site that you also make extensive use of regular expressions. wink

The on-line Skynet-AI implementation only handles dynamically learned “direct” relationships.

As I am sure you are aware, the dialog you had, represents “transitivity”, the ability to deduce “indirect” relationships from a set of direct relationships.
Transitivity (http://tim.oreilly.com/pub/gl/53)

The classic example of this is:
Socrates is a man.
All men are mortal.
Is Socrates mortal?

In fact, someone had that conversation with Skynet-AI earlier this week:

“USER:who is socrates?
BOT: Let me see if I have a record on file. “//shows the wiki page on socrates
“USER:is socrates mortal?
BOT: I have not talked about socrates enough to know. Are you interested in mortal things?”
“USER:socrates is a man
BOT: OK. Tell me about some other things that are a man?”
“USER:aristotle is a man
BOT: Would I be human if I had a soul?”
“USER:all men are mortal
BOT: OK. Are all men really mortal?”
“USER:is socrates mortal?
BOT: Well, you told me, socrates is a man.”
“USER:is a man mortal?
BOT: I have not experienced a man enough to know. Are you interested in mortal things?”
“USER:interesting
BOT: Humans fascinate me also.”
I have not implemented indirect logic (Transitivity) so far. I am exploring the difference between storing the direct relationships and then trying to draw an inference about an indirect relationship vs dynamically looking for relationships.

In addition, I am looking at allowing a Skynet-AI user to do a bulk load of his assertions and patterns. I have been waiting until HTML 5 is more widespread. It has new capabilities for user storage. If I go with the direct storage method I need to add a few storage management features. In the mean time I may let people select a local file to upload/parse.

Your example where;
> an ant = an insect
Okay, an ant = an insect.

implies that they are identical. I think that breaks down because although all ants are insects, not all insects are ants.

If I substitute different items into your example you will see what I mean.

> is a man bigger than a car?
I have no knowledge that a man is bigger than a car.

> a man is smaller than a car
Okay, a man is smaller than a car.

> is a man smaller than a car?
Yes, a man is smaller than a car.

> a man = a mammal
Okay, a man = a mammal.

> is a mammal smaller than a car?
Yes, a mammal is smaller than a car.

> why is a mammal smaller than a car?
a mammal is smaller than a car because: a mammal = a man and a man is smaller than a car

If I asked it about a whale and told it a whale is a mammal wouldn’t it reply that a whale is smaller than a car?

One of the things I am also looking at is how to handle/store exceptions to the rule.
If ALL (SOMETHING) ARE (SOMETHING)
This is a quick method to cover the general case. But for an individual case this might not be true.

 

 
  [ # 9 ]

More characters are needed to write a category, yes, but we have tools, such as AIML spreadsheet editors, that reduce the need for typing <category>, , <template> over and over again.

Richard, I understand. Your tools have allowed many people and organizations to create some of the best on-line entities around. I am simply trying to contrast the JAIL approach.

I was concerned not only with the number of characters needed to write a category, but also if you had many categories, and wanted to download the AI on start-up, what overhead it would induce.

10,000 empty categories in each of the formats would be about:

TSV file 20K
JAIL RegEx
/Response 70K
AIML  
61 610K 

On a dial-up line (used to be modems, today it is cell phones), this was overhead I did not want to add to the downloads.

It’s not as though no one ever thought of adding disjunctive patterns to AIML.  We could just as easily have expanded the pattern language to include an “or” operation like “EINSTEIN|NEWTON”.  Or even simpler, as has been suggested before, the ability to list multiple patterns per category:

I have found that being able to use disjunctive/multiple patterns has significantly increased the capability of JAIL and dramatically reduced the number of unique categories that need to be created, possibly by a factor of 10:1. If I identify a pattern which should link to an already existing response, I simply add it to an existing category instead of creating an new unique category and response (template).

Early on however I realized that there was a scaling problem with disjunctive patterns.  If the bot has a pattern “A or B” and then 10,000 categories later the botmaster adds “B or C”, and the input is B, which category is activated?  The interpreter would have rules of course saying which takes priority, but the botmaster may forget the earlier pattern (or it was written by someone else perhaps) and expect the new response for the input B, then be surprised to get the earlier response. Fixing that becomes a tedious editing process of revising old categories (or rules, or whatever).

With many fewer categories, I have found scaling is much easier. In many cases the AI can be reduced to a single manageable file that can easily be loaded into a spreadsheet. For an expert, it is small enough to edit directly.

The interpreter enables easy priority management and selective parsing, speeding performance. It also eliminates problematic “recursion” bugs that can be difficult to troubleshoot.

 

 

 
  [ # 10 ]

The other feature that JAIL was designed for is speed.
Skynet-AI is parsing at an average rate of 350,000 categories per second on a single CPU Windows XP running @2.66ghz w/512MB of RAM.

 

 
  [ # 11 ]

The interpreter would have rules of course saying which takes priority, but the botmaster may forget the earlier pattern (or it was written by someone else perhaps) and expect the new response for the input B, then be surprised to get the earlier response.  Fixing that becomes a tedious editing process of revising old categories (or rules, or whatever).

Perhaps some debuggers attached to the interpreter might help in this area? As you mention, the interpreter should have a fairly good idea which patterns it evaluates. If you present this info to the designers through some proper debuggers, such problems might be simpler to solve.

 

 
  [ # 12 ]
Jan Bogaerts - Jan 1, 2011:

Perhaps some debuggers attached to the interpreter might help in this area? As you mention, the interpreter should have a fairly good idea which patterns it evaluates. If you present this info to the designers through some proper debuggers, such problems might be simpler to solve.

You are right Jan. When I use Skynet-AI in “DEBUG” mode, I can list the pattern number, pattern and response time. This is especially useful when the AI uses selective branching so that you can trace the route to the response.

USER:hi
AI
You have successfully logged-in.
712 - /^(hello|hib|whassup|(good )?(morning|afternoon|evening))/i

Response time
:3 milliseconds

This pattern is also a good example of “category compression” that I talked about.
It has reduced what would have been 9 categories down to 1.

 

 
  [ # 13 ]

http://code.google.com/p/mindforth/wiki/JsAiManual
is where I have just published a JSAI Mind User Manual
for the JavaScript tutorial artificial intelligence at
http://www.scn.org/~mentifex/AiMind.html for MSIE.

 

 
  [ # 14 ]

Arthur,
It is interesting to see the differences in our approaches while both using JavaScript as a foundation for AI.

In your case, it looks like you have tried to emulate some of the biological processes and adapt them to the computer.

I took the opposite approach. I tried to think about what things computers can do really well and bridge natural language to them. You can test my work with JAIL on Skynet-AI.

Early in the process I made some key design decisions.

  1. - The AI would think in English
  2. - Alternative inputs (voice, foreign languages) can be transformed into English as a separate process
  3. - The AI would work via concepts not grammar
  4. - The AI would test concepts against the input vs splitting the input and looking up word meanings and grammar
  5. - Speed/Size and Ease of programming were high priority
 

 
  [ # 15 ]

Merlin wrote:
> Arthur,
> It is interesting to see the differences in our approaches
> while both using JavaScript as a foundation for AI.
>
> In your case, it looks like you have tried to emulate some
> of the biological processes and adapt them to the computer.

Yes, MindForth and AiMind are implementations of a theory.

> I took the opposite approach. I tried to think about
> what things computers can do really well and bridge
> natural language to them. You can test my work with
> JAIL on Skynet-AI.

Just now as “Mentifex” I have conversed with
http://home.comcast.net/~chatterbot/bots/AI/Skynet/
and I entered some of the same input as I use with
http://www.scn.org/~mentifex/AiMind.html for MSIE.

>
> Early in the process I made some key design decisions.
>
> - The AI would think in English
> - Alternative inputs (voice, foreign languages) can
> be transformed into English as a separate process

I can anticipate such speech recognition, but the
foreign languages might present difficulties.

> - The AI would work via concepts not grammar

MindForth and the JavaScript AiMind also use
concepts, with grammar coming in to govern the
interactions among concepts and the generation
of thought by means of spreading activation.

> - The AI would test concepts against the input vs
> splitting the input and looking up word meanings and grammar

Apparently we do the same thing. The JSAI Mind matches
English word-inputs against known words and either
reactivates an “OldConcept” or creates a “NewConcept”
for an unknown word. The auditory recognition module
AudRecog can detect noun-stems and other morphemes by
using differential activation on streaming phonemes.

> - Speed/Size and Ease of programming were high priority

I was surprised to see the speed of you responses
and the variety of outside resources that were
adduced in direct response to my various queries.

I can see that it would be possible to enter
a set of identical exploratory inputs to both
Skynet and to the JavaScript AiMind, and to
compare the “understanding” shown by the responses.

My software does not give such elaborate responses
as yours, or such non-sequitur jumps as I saw with
Skynet, because the software only associates from
conceptualized vocabulary items to similar items.

Thanks for sharing the ideas on JavaScript AI.

Arthur

 

1 of 4
1
 
  login or register to react