Showing posts with label Eliza Chatbot. Show all posts
Showing posts with label Eliza Chatbot. Show all posts

Sunday, November 05, 2017

Towards the esoterically-programmed chatbot

Gary Larson has this famous cartoon:



It might as well be labelled, 'What chatbots hear'.

I type something profound to the chatbot, and this is what the program gets:
"I     *!@      +^%    £")#     owl      +=&£."
Plainly no amount of inference is going to reconstruct that. However, a gossipy chatbot has only to keep the conversation going .. .



An Eliza-type program uses patterns such as:
"I tokens* owl tokens*"  => "How interested are you in owls?"
where the response is bland enough to match most owl-related utterances.

If the chatbot can recognise a little more, perhaps put some syntactic structure to it, then we could do a semantically-informed best match to the noisy user input using a metric over the space of semantic structures (I'm thinking something like situation semantics, or more likely an extensible, data-populated semantic net).

It might be tempting to map everything into a vector space but that's way too much gratuitous (and irrelevant) structure: like doing logic programming using arithmetic over Gödel numbering. To save us from that was why God invented compilers.

---

I'd like to play with some of these ideas, restart my stalled chatbot programme. But I'm lazy, I don't want to do low-level coding, I want a really high-level language which lets me get straight into the problem space. And this brings me - via consideration of Lisp and Haskell - back to Prolog.

As I wrote a couple of years ago,
"First, Prolog. Its supporters always touted it as a higher-level language than Lisp - though I always found Lisp more congenial, I like to set up data structures and manipulate them explicitly. With Prolog you define relationships between things and the miraculous powers of unification and depth-first search with backtracking pull magical rabbits out of hats. The Eliza program in Prolog can be read in its entirety on one screen, ditto for the blocks world planning system.

This procedural power is the result of enormously complex recursive structures built at execution time by the Prolog system. It frequently defies one's powers of abstraction, short-term memory and inference to visualise what's actually going on. I know you're meant to read and understand the programs declaratively, but in reality you don't get too far without a consideration of what actually happens at run-time.

Still, the power to write ridiculously-powerful programs in just a few lines of code is addictive. It reminds me of the first time I fired the General-Purpose Machine Gun (GPMG). I was good with the Lee-Enfield rifle and prided myself on my accuracy; the GPMG just bounced around and hosed the target. So much power and so little control!"
---

Oh, and here's Eliza in Prolog (as modified to represent our deceased pet, Shadow) from the Sterling and Shapiro book, 'The Art of Prolog', (chapter 14):
shadow :-
write('Hello, I am Shadow. Miaow!'),
nl,write('Please type your thoughts and press return.'),
nl,write('To finish type bye'),nl,
read_word_list(Input),shadow(Input),!.

shadow([bye]) :- reply(['Goodbye, miaow!']).

shadow(Input) :-
pattern(Stimulus,Response),
match(Stimulus,Dictionary,Input),
match(Response,Dictionary,Output),
reply(Output),
read_word_list(Input1),
!,shadow(Input1).

match([Word|Pattern],Dictionary,[Word|Target]) :-
atom(Word),
match(Pattern,Dictionary,Target).

match([N|Pattern],Dictionary,Target) :-
integer(N),
append(LeftTarget,RightTarget,Target),
lookup(N,Dictionary,LeftTarget),
match(Pattern,Dictionary,RightTarget).

match([],_,[]).


reply([Head|Tail]) :- write(Head), write(' '),reply(Tail).

reply([]) :- nl.

lookup(Key,[(Key,Value)|_],Value).

lookup(Key,[(Key1,_)|Dict],Value) :- Key \= Key1,lookup(Key,Dict,Value).

There are some lower-level functions (and the relevant patterns) defined elsewhere, but this is the gist of it. Pretty clear, wouldn't you say?


Amazon link

I used to think it was just me, but I read somewhere of the despair of computer science students at Edinburgh university at the sheer intellectual difficulty of writing (and even understanding) non-trivial programs in Prolog. It would seem there's a high IQ-cutoff just to use the language at all.

This reminds me of Marain, the language of the Culture, where those dialects used by the Minds were simply beyond the intellectual capacities of humans. And while we're on that case, let me remind you of a real-world counterpart: Malbolge.
"... invented by Ben Olmstead in 1998 and named after the eighth circle of hell in Dante's Inferno. "Malbolge was specifically designed to be almost impossible to use, via a counter-intuitive 'crazy operation', base-three arithmetic, and self-altering code." *

In fact the author of Malbolge was unable himself to write a program in it.

In the end it required an AI system to write the first program, using a form of 'best-first' search in the space of all possible programs.

Here is the "Hello World!" program in Malbolge.
(=<`#9]~6ZY32Vx/4Rs+0No-&Jk)"Fh}|Bcy?`=*z]Kw%oG4UUS0/@-ejc(:'8dc
---

* Malbolge design trivia.
After each instruction is executed, the guilty instruction gets encrypted so that it won't do the same thing next time, unless a jump just happened. Right after a jump, Malbolge will encrypt the innocent instruction just prior to the one it jumped to instead."
Of course, with artificial neural networks and deep learning, we're already away with the fairies as far as esoteric programming is concerned.

As for me, I've re-installed SWI-Prolog. Time to get up to speed with programming in logic again - so hard to think with, yet so much more compact than Lisp.

Sunday, February 12, 2017

Chatbots: conversation as AI planning

I just love those YouTube videos of Internet-connected dolls. They're Wifi-linked to IBM's Watson, or some similar AI-in-the-cloud.

You'd think that the conversation would be scintillating - insofar as talking to a small child might have its moments.

But no, in the clip the adorable child is always shown asking the doll, "How far away is the Moon?" and the doll shows its conversational prowess by reciting Wikipedia.

Surely we can do better.

It's good to recall that we converse in order to achieve objectives. Sometime those objectives are indeed objective - as when we wonder how far away is the Moon.

Most of the time, though, the objectives are more about our more basic human desires. The need for sympathy, approbation, bonding against a third party, humiliation and revenge.

Oh dear, I've been listening to Cersei Lannister again..

Cersei and Margaery

Conversation is composed of speech acts directed towards goals, the goals often being the alteration of emotional states. Real-life chat is therefore very dependent on the accurate reading of emotional cues: facial expressions, tone of voice or other body language. No wonder email and WhatsApp chats go awry so often.

This suggests that a chatbot (a better Eliza) should treat conversation as an AI planning task.*

Naturally I'm not the first to realise that - this 1980 article - but it's the next place to go.

This relatively recent Stanford review - Conversational Agents - is quite illuminating (PDF slides).

---

Call me an old GOFAI-nostalgic but bottom-up number-crunching the stats is subject to diminishing returns as we move to higher cognitive tasks. Which is why I'm less than impressed by the tedious Google Assistant in Allo.

---

* I mean like GPS. Most conversational chatbots - like Google Assistant - cope with the extreme difficulties of unrestricted natural language input by giving a series of response-text buttons for the user to select ("Tell me a joke").

In a formalised conversational model, the chatbot should treat the conversation as a two-person game-tree. The opponent (user) has a choice of possible conversational rejoinders ('moves') which the program has a chance of understanding, and which propel the conversation forward in some direction.

Best to look at the planner conversation 'speech-act' rule-base and list the possible responses (need a way to flag input-variables) so as to guide the user.

Example:

Chatbot>: "What's your brother's name?

[I understand best:
   1. <first-name>
   2. <first-name> <second-name>
   3. <name> but we call him <nickname>
   4. I don't have a brother.
   5. Could we move on to another topic?
You can enter the response number if there's no information to give.]

User>:  Jimmie.

Friday, February 10, 2017

So this is where we are .. Doctor

CL-USER 1 > (eliza +eliza-rules-extended+)
Hello, I am your doctor. Please type bye to finish.

Please type your first name then return>  Clare

SPEAK> Hi there.

(HI CLARE - PLEASE STATE YOUR PROBLEM.)
SPEAK> I think a lot about the cat.

(DO YOU FEEL  STRONGLY ABOUT DISCUSSING SUCH THINGS?)
SPEAK> Yes, I dream about Shadow.

(HOW DO YOU FEEL ABOUT SHADOW IN REALITY?)
SPEAK> I dreamed he was playing in the garden.

(HAVE YOU DREAMED HE WAS PLAYING IN THE GARDEN BEFORE?)
SPEAK> I seem to see him there a lot.

(DO YOU FEEL  STRONGLY ABOUT DISCUSSING SUCH THINGS?)
SPEAK> I am not sure you are that interested.

(IN WHAT WAY ARE YOU NOT SURE I AM THAT INTERESTED)
SPEAK> You are not helpful.

(WHAT MAKES YOU THINK I AM NOT HELPFUL ?)
SPEAK> I'm going to report you. What's your name?

(I PREFER TO BE AN ANONYMOUS DOCTOR CLARE)
SPEAK> I am not surprised.

(IN WHAT WAY ARE YOU NOT SURPRISED)
SPEAK> Bye

---

Vanilla Eliza in action using the extended rule-set (about 50 rules). The conversation would flow a lot more smoothly if I kept adding rules to capture the many, many diverse possibilities for input. But in the end, it's all reflecting back what the user said.

If you look at the rules, you will see that Eliza (the generic program - it's specific rules which create an actor like Doctor) is snatching at a couple of key words in the user's input, and is basically praying that the rest will make sense when bounced back. It's like when you speak a foreign language really badly.

To do any better will take knowledge and inference (to come).

---

A 'Doctor' rule-set. A basic set of rules for test purposes, and an extended set.

The Eliza code in Common Lisp.

I don't promise bug-free, but it mostly works OK.