SophiaBot: What I’ve been working on for the past month…

I have been busy in my basement constructing a robot with which I can have conversations and play games.  Except that the robot is more of a program, and I didn’t build the whole thing up from scratch, but instead cobbled together pieces that other people have created.  I took an Eliza-style interpreter written by Nicholas H.Tollervey (this is the conversation part) along with some scripted dialogs by Dr. Richard S. Wallace and threw it together with a Z-machine program written by Jason Follas, which allows my bot to play old Infocom games like Zork and The Hitchhiker’s Guide to the Galaxy.  I then wrapped these up in a simple workflow and added some new Vista\.NET 3.0 speech recognition and speech synthesis code so the robot can understand me.

I wrote an article about it for CodeProject, a very nice resource that allows developers from around the world to share their code and network.  The site requires registration to download code however, so if you want to play with the demo or look at the source code, you can also download them from this site.

Mr. Tollervey has a succint article about the relationship between chatterboxes and John Searle’s Chinese Box problem, which obviates me from responsibility for discussing the same.

Instead, I’ll just add some quick instructions:

 

The application is made up of a text output screen, a text entry field, and a default enter button. The initial look and feel is that of an IBX XT theme (the first computer I ever played on). This can be changed using voice commands, which I will cover later. There are three menus initially available. The File menu allows the user to save a log of the conversation as a text file. The Select Voice menu allows the user to select from any of the synthetic voices installed on her machine. Vista initially comes with “Anna”. Windows XP comes with “Sam”. Other XP voices are available depending on which versions of Office have been installed over the lifetime of that particular instance of the OS. If the user is running Vista, then the Speech menu will allow him to toggle speech synthesis, dictation, and the context-free grammars. By doing so, the user will have the ability to speak to the application, as well as have the application speak back to him. If the user is running XP, then only speech synthesis is available, since some of the features provided by .NET 3.0 and consumed by this application do not work on XP.

The appearance menu will let you change the look and feel of the text screen.  I’ve also added some pre-made themes at the bottom of the appearnce menu.  If, after chatting with SophiaBot for a while, you want to play a game, just type or say “Play game.”  SophiaBot will present you with a list of the games available (you can add more, actually, simply by dropping additional game files you find on the internet into the Program Files\Imaginative Universal\SophiaBot\Game Data\DATA folder (Jason’s Z-Machine implementation plays games that use version 3 and below of the game engine.  I’m looking (rather lazily) into how to support later versions.  You can go here to download more Zork-type games.  During a game, type or say “Quit” to end your session. “Save” and “Restore” keep track of your current position in the game, so you can come back later and pick up where you left off.

Speech recognition in Vista has two modes: dictation and context-free recognition. Dictation uses context, that is, an analysis of preceding words and words following a given target of speech recognition, in order to determine what word was intended by the speaker. Context-free speech recognition, by way of contrast, uses exact matches and some simple patterns in order to determine if certain words or phrases have been uttered. This makes context-free recognition particularly suited to command and control scenarios, while dictation is particularly suited to situations where we are simply attempting to translate the user’s utterances into text.

You should begin by trying to start up a conversation with Sophia using the textbox, just to see how it works, as well as her limitations as a conversationalist. Sophia uses certain tricks to appear more lifelike. She throws out random typos, for one thing. She also is a bit slower than a computer should really be. This is because one of the things that distinguish computers from people is the way they process information — computers do it quickly, and people do it at a more leisurely pace. By typing slowly, Sophia helps the user maintain his suspension of disbelief. Finally, if a text-to-speech engine is installed on your computer, Sophia reads along as she types out her responses. I’m not certain why this is effective, but it is how computer terminals are shown to communicate in the movies, and it seems to work well here, also. I will go over how this illusion is created below.

In Command\AIML\Game Lexicon mode, the application generates several grammar rules that help direct speech recognition toward certain expected results. Be forewarned: initially loading the AIML grammars takes about two minutes, and occurs in the background. You can continue to touch type conversations with Sophia until the speech recognition engine has finished loading the grammars and speech recognition is available. Using the command grammar, the user can make the computer do the following things: LIST COLORS, LIST GAMES, LIST FONTS, CHANGE FONT TO…, CHANGE FONT COLOR TO…, CHANGE BACKGROUND COLOR TO…. Besides the IBM XT color scheme, a black papyrus font on a linen background also looks very nice. To see a complete list of keywords used by the text-adventure game you have chosen, say “LIST GAME KEYWORDS.” When the game is initially selected, a new set of rules is created based on different two word combinations of the keywords recognized by the game, in order to help speech recognition by narrowing down the total number of phrases it must look for.

In dictation mode, the underlying speech engine simply converts your speech into words and has the core SophiaBot code process it in the same manner that it processes text that is typed in. Dictation mode is sometimes better than context-free mode for non-game speech recognition, depending on how well the speech recognition engine installed on your OS has been trained to understand your speech patterns. Context-free mode is typically better for game mode. Command and control only works in context-free mode.

The Topsy-Turvy World: Spy Versus Spy


Ian Fleming’s spy novels are often compared to John Le Carré’s.  The comparisons often find James Bond to be wanting.  In contrast to the emotional richness of Le Carré’s internally conflicted heroes, Bond is often presented by his critics as a cardboard cutout with an overly simplistic view of the world.  Bond fights for crown and country.  Alec Leamas and George Smiley, on the other hand, realize that things are much more complicated than that.  Fleming presented a 50’s version of the world where we all had just left off making the world safe for democracy, and still naively saw the cold war in black and white terms.  Le Carré, on the other hand, by drawing attention to the moral ambiguity at the heart of our conflict with the Soviets, turns James Bond on his head.


Or does he?  Written in 1953, ten years before The Spy Who Came In From The Cold, Ian Fleming’s first Bond novel Casino Royale includes this surprising piece of introspection from 007:



“Well, in the last few years I’ve killed two villians.  The first was in New York — a Japanese cipher expert cracking our codes on the thirty-sixth floor of the RCA building in the Rockefeller centre…. It was a pretty sound job.  Nice and clean too.  Three hundred yards away.  No personal contact.  The next time in Stockholm wasn’t so pretty.  I had to kill a Norwegian who was doubling against us for the Germans…. For various reasons it had to be an absolutely silent job.  I chose the bedroom of his flat and a knife.  And, well, he just didn’t die very quickly.


“For those two jobs I was awarded a Double O number in the Service.  Felt pretty clever and got a reputation for being good and tough.  A Double O number in our Service means you’ve had to kill a chap in cold blood in the course of some job.


“Now,” he looked up again at Mathis, “that’s all very fine.  The hero kills two villians, but when the hero Le Chiffre starts to kill the villain Bond and the villain Bond knows he isn’t a vilain at all, you see the other side of the medal.  The villains and heroes get all mixed up.


“Of course,” he added, as Mathis started to expostulate, “patriotism comes along and makes it seem fairly all right, but this country-right-or-wrong business is getting a little out-of-date.  Today we are fighting Communism.  Okay.  If I’d been alive fifty years ago, the brand of Conservatism we have today would have been damn near called Communism and we should have been told to go and fight that.  History is moving pretty quickly these days and the heroes and villains keep on changing parts.”


Mathis stared at him aghast.  Then he tapped his head and put a calming hand on Bond’s arm.


“You mean to say that this precious Le Chiffre who did his best to turn you into a eunuch doesn’t qualify as a villain?” he asked…. “And what about SMERSH?  I can tell you I don’t like the idea of these chaps running around France killing anyone they feel has been a traitor to their precious political system.  You’re a bloody anarchist.”


He threw his arms in the air and let them fall helplessly to his sides.


Bond laughed.


“All right,” he said.  “Take our friend Le Chiffre.  It’s simple enough to say he was an evil man, at least it’s simple enough for me because he did evil things to me.  If he was here now, I wouldn’t hesitate to kill him, but out of personal revenge and not, I’m afraid, for some high moral reason or for the sake of my country.”


He looked up at Mathis to see how bored he was getting with these introspective refinements of what, to Mathis, was a simple question of duty.


Mathis smiled back at him.


 



Le Carré attempts to preserve us from full surrender to the topsy-turvy world by making it asymptotic to ourselves.  it is a point of evil, or the transvaluation of all morals, that his heroes are always approaching but also always stay just to this side of.  In this way, the Cold War becomes a metaphor for life itself.


Fleming’s hero actually goes beyond this point, in the very first 007 novel, and comes out the other side.  The lack of moral ambiguity for which Bond is so frequently criticized is not due to the fact that he doesn’t see it. Rather he sees it and surpasses it.


In order to keep Bond out of this topsy-turvy world, where good is evil and evil good, Fleming is obliged to provide his hero with a series of sufficiently evil villains.  First there was SMERSH, the Soviet counterintelligence and murder agency whose job it was to keep the people of the Eastern Block in line through intimidation and fear.  After a time, this was in turn replaced by SPECTRE, a world-wide terrorist organization bent on world domination (perhaps an example of art anticipating life).


Le Carré similarly requires the latticework of the Cold War in order to sustain his aesthetic-moral structure, and it is telling that following the collapse of the Soviet empire, his novels have become more simple David versus Goliath narratives with clear good guys (whistleblowers) and clear bad guys (international corporations) — in a sense, more like the traditional Bond narrative.


 



“So” continued Bond, warming to his argument, “Le Chiffre was serving a wonderful purpose, a really vital purpose, perhaps the best and the highest purpose of all.  By his evil existence, which foolishly I have helped to destroy, he was creating a norm of badness by which, and by which alone, an opposite norm of goodness could exist.  We were privileged, in our short knowledge of him, to see and estimate his wickedness and we emerge from the acquaintanceship better and more virtuous men.”


“Bravo,” said Mathis. “I’m proud of you.  You ought to be tortured every day…. That was enjoyable, my dear James.  you really ought to go on the halls.  Now about that little problem of yours, this business of not knowing good men from bad men and villains from heroes, and so forth.  It is, of course, a difficult problem in the abstract.  The secret lies in personal experience, whether you’re a Chinaman or an Englishman.”


He paused at the door.


“You admit that Le Chiffre did you personal evil and that you would kill him if he appeared in front of you now?


“Well, when you get back to London you will find there are other Le Chiffres seeking to destroy you and your friends and your country.  M will tell you about them.  And now that you have seen a really evil man, you will know how evil they can be and you will go after them to destroy them in order to protect yourself and the people you love.   you won’t wait to argue about it.  You know what they look like now and what they can do to people.  You may be a bit more choosy about the jobs you take on.  You may want to be certain that the target really is black, but there are plenty of really black targets around.  There’s still penty for you to do.  And you’ll do it….”


Mathis opened the door and stopped on the threshold.


“Surround yourself with human beings, my dear James.  They are easier to fight for than principles.”

The Bond Martini


 


We all know that James Bond drinks his martinis “shaken, not stirred.”  In the first Bond novel by Ian Fleming, we are actually given directions for making a very large martini, which Bond invents and later dubs ‘The Vesper,’ after Vesper Lynd, the heroine of Casino Royale


 




Bond insisted on ordering Leiter’s Haig-and-Haig ‘on the rocks’ and then he looked carefully at the barman.


‘A dry martini,’ he said. ‘One. In a deep champagne goblet.’



‘Oui, monsieur.’



‘Just a moment. Three measures of Gordon’s, one of vodka, half a measure of Kina Lillet.  Shake it very well until it’s ice-cold, then add a large thin slice of lemon-peel. Got it?’



‘Certainly, monsieur.’ The barman seemed pleased with the idea.



‘Gosh, that’s certainly a drink,’ said Leiter.


Bond laughed. ‘When I’m … er … concentrating,’ he explained, ‘I never have more than one drink before dinner. But I do like that one drink to be large and very strong and very cold and very well-made. I hate small portions of anything, particularly when they taste bad. This drink’s my own invention. I’m going to patent it when I can think of a good name.’


He watched carefully as the deep glass became frosted with the pale golden drink, slightly aerated by the bruising of the shaker. He reached for it and took a long sip.


‘Excellent,’ he said to the barman, ‘but if you can get a vodka made with grain instead of potatoes, you will find it still better.’


‘Mais n’enculons pas des mouches,’ he added in an aside to the barman. The barman grinned.


‘That’s a vulgar way of saying “we won’t split hairs”,’ explained Bond.