#### Archived

This topic is now archived and is closed to further replies.

# natural language with NPCs

This topic is 5561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi folks! Please do not answer this post to tell me this can't be done. That's exactly what they said about faster-than-light travel I am a student of Cognitive Science, with an emphasis on linguistics. I'm looking at ways to incorporate natural language processing in games. I can't see any reason you can't type in English and communicate with the NPC's. The best I've found (Google) are some experiments from the 80's that yield more or less the following:
You are walking through the forest, vision in any direction
is blocked by the trees, except for the bright blue sky which
is clearly visible above.
>continue walking
I don't know the word 'continue'.
I don't know the word 'walking'.
I don't quite understand you.

Assuming I can do better, how would this factor intelligently into the design of my game? I would like to write some kind of (offline) game where you need to convince the characters to help you, and instruct them about your mission. The challenge, then, is not to complete the mission really but to talk the locals (I'm giving away some of my intended storyline here, but that's ok) into helping you. Ideas and comments, general or specific, are wanted. Ideas such as: - They are too afraid, busy, or religiously uninclined to help you - They don't speak your language - They have a very simplistic grammar Thanks for reading. Tom [edited by - ParadigmShift on December 4, 2002 12:04:35 AM]

##### Share on other sites
I''ts not impossible dude. We might not be able to do it yet but sure as hell it''s not impossible. The way I see it is that there''s two ways to do what you want to do
1. Accept pre generated phrases that must be perfect or if you want add a little checkig in
problem. Speach isn''t natural. It''s all pregenerated. This is the style used in REALLY REALLY old games.
2. Scan for key words and build up a grammatical structure of a sentence and then attempt to disern the perpuse of parts of it as well as how it is in context with previous or later parts of the mono-logue.
I''m no expert in this sort of thing but I reackon it''s possible and the second approach is probably the way to go. My advice is just write some simple little apps and try and do it. If you fail. Who cares. I fail at things all the time, I know there next to impossible when I start, but do I care? No. If you succeed. COOL! You''ll have a not original idea that might work pretty well. And even if you don''t succeed your game will be no worse off than any others because you don''t have it as no other games I see have it either.

##### Share on other sites

If what I was driving at was how to go about processing language, then this post would be off-topic. I think I have the academic resources and programming skill to do this. My point is, what happens to the game design when instead of a side "feature" in an RPG, natural, unscripted communication with characters is a central driving point of the story?

I can imagine how the conversations would work, I just don''t really know how to set up the interactions. Is it realtime (as opposed to turn-based) conversation? Can the characters ignore you? Can they walk up to you and start a conversation? None of this ever happens in games I''ve seen.

If I have enough of these kinds of ideas, I think I *will* have an original game.

Tom

##### Share on other sites
Interesting point. I don''t see why characters shouldn''t come up and talk to you for some reason, preferably NOT preset, although that could be tricky. I think that you would almost HAVE to have the conversation turn based because a. some people are slow typers and b. the computer types instantly. Yeah you can make the computer talk slower but who cares. What would be better is if you used voice translation used a mic and then converted it to text and then ran you speech thingy on it. That would be pretty cool. The only problem I see is managing to keep the conversation in bounds. I mean let''s say you''re suppose to talk to a charachter about something but you just talk about something else or heck I''m rambling about nothing here. But you have some valid questions. probably go with the mic or if not avaible, as in you don''t have speech recognition software, then go for turn based. I think the major hard part will actualy making the NPC''s say something interesting. Like let''s say you started talking about the weather. Sure they might understand the words but will they understand what weather is and how to give you feedback. This would require checking the actuall games weather setup and stuff. You know if you started talking about stuff that''s hapening how are they suppose to actualy now about it. Sure you could put a check in for the weather and that but there are infinite things you could find to talk about. I''m talking about making small talk with NPC''s. Maybe you don''t want to do this but I think that would be exceptionaly cool just being able to rock up to an NPC and start talking to him about his job and that.
Give me your thoughts because I''m interested in this.

##### Share on other sites
I know how you might go about it. In your code you can make a check to see if the user input a bunch of key terms. Like this for example here's a sample of a conversation in ancient times:

NPC: address me by my proper name!

User: what's your name you foolfaceldlfk. Key terms (what, name)

NPC: My name is arid the woodsman.

User: f**k Y*u you a.

NPC: I dont know what you're talking about. Key terms (none)

you get the idea. if what I just said is irrelevant to your subject then forgive me because I havent slept and these damn programming books are boooooooring.

[edited by - wazzoo on December 5, 2002 1:10:40 AM]

##### Share on other sites
Some thoughts on how you could do it: NPCs can walk up to the player and indicate they want to talk; you could show this with an icon or a sound clip or something. However, the player would have to start the conversation each time. Another choice is to actually bring up the conversation interface each time the NPC walks up. But, what if the player is in a hurry? They wouldn''t want to bother with getting out of conversations, although this may be more realistic.

A possible compromise would be an ''ignore'' option. If the player is in a hurry, they just check the box, and it automatically ignores conversations.

The actual conversation engine should be mostly turn-based. You could have it watch for idle time and make the NPC prompt the player.

"Are you paying attention to me?"
"Are you still alive?"
"Earth to stupid person!"

##### Share on other sites
quote:

If what I was driving at was how to go about processing language, then this post would be off-topic. I think I have the academic resources and programming skill to do this. My point is, what happens to the game design when instead of a side "feature" in an RPG, natural, unscripted communication with characters is a central driving point of the story?

quote:

Original post from Wazzoo:
I know how you might go about it. In your code you can make a check to see if the user input a bunch of key terms. Like this for example here''s a sample of a conversation in ancient times:

Get the picture!!!!

quote:

Some thoughts on how you could do it: NPCs can walk up to the player and indicate they want to talk; you could show this with an icon or a sound clip or something. However, the player would have to start the conversation each time. Another choice is to actually bring up the conversation interface each time the NPC walks up. But, what if the player is in a hurry? They wouldn''t want to bother with getting out of conversations, although this may be more realistic.

Some good points there. I personally think that they just start talking to you, as in saying stuff, and then you can choose to talk back or simply keep going. Then they can get pissed and that.

##### Share on other sites
Ramboboner, I''m not quite sure what you mean, if it''s a good thing then I''m not mad, if it''s a bad thing then I''m sorry for tryin'' to help. it''s freakin'' 1 a.m and I''m tired. nice idea paradigm I want you to check out www.GeneticAnomalies.com download ChronX, that game has an incredible AI, They''ve done what you''re currently trying to do. But there''s always room for improvement. Good luck

##### Share on other sites
What I meant was that ParadigmShift had just said that we don''t want to discuss HOW to work out the conversation but more how to use it in games and stuff like that. Basically what you said was good but ParadigmShift had just said that that wasn''t what this topic was suppose to be about

##### Share on other sites
All good ideas.

Wazzoo: Thanks for the link, but as to your previous comment looking for keywords is exactly what I don''t want to do. Simple directive counterexamples: "GET me everything but the SHOVEL" "WALK FORWARD, avoiding the wall" etc.

I like the idea of smalltalk. My idea is to have the NPCs interact with ALL of the world simulation. If there is weather, then they can potentially notice it. Of course, they might not notice (processing constraints) until you actually ask them about it, but that applies to people as well.

##### Share on other sites
COOL!!! I think that if you can get small talk to work like that your game will kick butt!

##### Share on other sites
Take a look at Narrative Interpolation (disclaimer: started by yours truly). It''s long and abstract and somewhat disjoint, but you might get some interesting ideas.

##### Share on other sites
ParadigmShift: old Infocom games actually DID understand phrases like "get me everything but the shovel". That was because they understood not only the key terms, but the basic structure of the sentence. I believe they had some template system built in, like for the mentioned phrase it was

*multverb everything but *multitem

where *multverb designates a verb that can work with multiple items ("take" or "drop", but usually not "examine" - you had to examine each object separately), and *multitem is a bunch of items like "the shovel and the dead body" or "3 little pigs".

You can turn that mechanism "inside out" to make the NPC say different phrases based on the same template, like

If we have some set for interjections (they may not be exactly interjections, but since I'm not that good at English, for the purpose of the example let's call them that) for given character, like "well", "ya", "so" or void; we have some basic variants for introductory phrase, like "my name is", "they call me", or, if we want a character with an attitude, we may put the following template "my *badword name is", where *badword in turn corresponds to any of "f*cking", "bloody", "goddam" (you got the picture).

So, when the NPC first introduces himself, he may say any of the following:

Well, my name is John Badmouth.
Ya, they call me John Badmouth.
Well, my f*cking name is John Badmouth.
My goddam name is John Badmouth.

(Of course, it assumes that the sentence is "cleaned" after it's created, so that the first letter becomes capital, and puinctuation marks at the beginning are cut).

Suppose now that the user asks the NPCs name again. We may create a template for the repetition. In may be almost the same:

Where repeat may correspond to "(as) I said", "(as) I already told (you)", "didn't you hear". Also, we may increase the value of the NPCs anger if he is asked the same thing multiple times, and if the character is angry, he may start to use more bad words, or even refuse to speak to such a dumb player.

Some of those templates may be common, and some may belong to certain characters.

Also, there's another way - give your NPCs some simplified language and make the player learn it as a part of gameplay. (Since I'm tired an hungry, I'm leaving the example as your homework)

[edited by - Chentzilla on December 5, 2002 10:34:22 AM]

##### Share on other sites
Hi all!

ParadigmShift: I would like to encourage you and share some ideas.

I get nauseous these days when I read reviews for MMORPGs. Asherons call 2, for example, seems to pride itself on having negated all ''unneccessary'' interaction with anything but monsters, you can even cash in goods while in a dungeon. All that counts seems to be the graphics.

We need meaningful interaction to move on, not just fancy shadows! The foremost arena of social interaction is dialogue so this is a natural thing to focus on. The thing is: its hard.

If you are a student of Cognitive science you probably know that the problem of natural language dialogue is an AI-complete problem. Basically we have to build a complete human intelligence to make it work effectively.

In the context of games the situation is a bit simpler because the game world is smaller and more quantifiable. Even so it is a daunting task both to formulate the way to interact with the NPCs and to create the back-end intelligence or ''dialogue manager''.

For the last few years I have been working on an approach to meet both these problems, especially the interaction/interface part. I was fortunate to be allowed to write my master''s thesis (in computer linguistics) on this subject.

The interface between the user and NPC could be text as you propose. But even in the context of games this approach is riddled with problems such as typos, language/meaning ambiguity and lack of knowledge about the available (or viable) options in every situation. (Try talking with Eliza to get a feel of what I''m talking about.)

Daggerfall/Morrowind has presented an interesting semi-graphical or iconic way to execute dialogue. It is however both scripted and course-grained and soon feels very shallow and transparent.

In my dialogue tool utterances are constructed sort of backwards by selecting ''token words'' in a left to right fashion from a series of dynamic situation-dependant menus. You narrow it down by going from utterance type - such as question - to the type of question, the concerned object(s), action and possible property.

When enough token words are selected for the system to match against its list of ''raw utterances'' the user is presented with the actual parameterized text rendering of the utterance that will be spoken. This rendering is further varied depending on the users demeanor etc, making it interesting for two or more humans to engage in dialogue.

Well, I could go on about this, but my point was simply to encourage a graphical approach for building utterances. It is fast, removes ambiguity and typos and brings with it a whole slew of other advantages.

##### Share on other sites
Assuming your NPCs can understand natural language (and that''s quite an assumption), and that your game includes some graphical representation of your character and his environs (unlike the text-based games which you refer to as your game''s predecessors), then it might be a good idea to dispense with the manual dialogue interface entirely: that is, you needn''t walk up to somebody and press a button to begin a conversation.

Instead, you could allow a player to get within hearing range of an NPC, face him, and say something aloud, and if the NPC is interested he''ll say something back, and conversation proceeds in that way. Further, NPCs could engage in conversation with each other, or attempt to speak to the PC depending on who the PC appears to be and what the NPC wants. Conversations could even be joined by interested third parties; a conversation between two NPCs could be overheard by a third NPC, who finds the subject of interest and puts in his two cents. Many options would be opened up if conversation were handled in this more realistic fashion rather than by manually opening a dedicated line of communication to one individual at a time.

Just a thought.

---------------------------------------------------
-SpittingTrashcan

You can''t have "civilization" without "civil".

##### Share on other sites
quote:
I can imagine how the conversations would work, I just don''t really know how to set up the interactions. Is it realtime (as opposed to turn-based) conversation?
What do you mean by real-time conversation? I''ve brought up my own ideas about real-time conversation a few times in this forum but didn''t seem to generate much interest.
quote:
The interface between the user and NPC could be text as you propose. But even in the context of games this approach is riddled with problems such as typos, language/meaning ambiguity and lack of knowledge about the available (or viable) options in every situation.
My approach to the "what communication does the player really want the PC to convey" problem is to simply treat all player input as a command rather than a phrase which needs to be parsed as grammatically correct sentence. The player has such commands as "ask", "inform", "small talk", which take appropriate arguments. After the command is parsed, the command then passes the information to the same routines which generate the NPC dialogue, which constructs the sentence/question which is inserted into the conversation.
quote:
Where repeat may correspond to "(as) I said", "(as) I already told (you)", "didn''t you hear". Also, we may increase the value of the NPCs anger if he is asked the same thing multiple times, and if the character is angry, he may start to use more bad words, or even refuse to speak to such a dumb player.
I''m doing almost the exact same thing. I also have the reverse situation taken into accoutnt: the NPC may have to repeat himself to the player (or other NPC), and if no response is forthcoming, things could get ugly.

Sean

##### Share on other sites
A friend and I did some pen and paper experimentation with a heirarchical language system. I treated words as functions that accepted a certain number of arguments of certain data types (noun, verb, clauses, etc), and returned a type. I never coded anything, but it was an interesting idea to toy with. The biggest problems had to do with words like "because," "so," "that," "which," and "whose," and the fact that very often these "connecting words" are left out in sentences (particularly casual ones).

What I ended up concluding from these thought experiments is that it''s a heck of a lot easier to generate speech than it is to understand it. In the process, I invented a subset of English that could be easily written and read by computers. Although it could communicate anything, the reading part was pretty useless, since it would have constrained to user to a specific subset of English. Also, again, it was all only on paper.

I still think there''s a lot of promise in this type of system, that generates a parse tree. I know it''s representational rather than connectionalist AI, and is therefore "passe," but I think you really can get some rather decent results.

Still, the best efforts of chatbot writers prove that natural language processing is no easy task. Then again, chatterbots might seem so bad because all they can do is smalltalk - and real live human smalltalk is often pretty nonsensical and stupid too. Combine natural language processing with some sort of representational database of all kinds of knowledge (including common sense!), and you might have something halfway decent. Chances are it''s been tried though and I don''t know about it.

So you see I''ve been rambling a little, but hopefully something I''ve said may have planted the seed of a good idea somewhere.

##### Share on other sites
I was kind of thinkig that you might be able to do something similar to the auto-type thing in MSVC++ where a little list box comes up when you start typing a word. It would start with giving you a list of words to start with and then give you another list of words for possible 2n words and so on. you can group all of the words into catagories such as nouns, adjective, ad-verbs, question words, ect. Then when for exaple, the previous word was a verb, it would give you a list containing of adverbs and words like "this", "and", "that", and "or". Pretty sure this system would work fairly well, but have never implemented it so am not completely sure.

Tazzel3d ~ dwiel

##### Share on other sites
I''m sorry but I have to rant here.

You say you''re a student in Cognitive science with an emphasis on Linguistics, yet the best example of a Natural Language Processor in a game you could find comes from something written in the early 80''s that nobodys ever heard of..... How long have you been at this? Since September? This your first year?

You''ve also noted that the NLP part of your project should be no problem, considering the vast resources you have access to and your programming skill. Not that I like bursting bubbles, but don''t you think that at least, ohh I don''t know, once in the past 20 years somebody else hasn''t tried this very same thing?

The ''game'' aspect should be dead simple compared to the NLP (considering you don''t want to use command words). If you are able to accomplish what I think your setting out too, why bother with a game? You could sell this amazing technology to just about anybody on the planet. Why not have it write books all by itself?? You could have them published, make millions, and drop out of skewl.

Sorry, but what you''re trying to do is probably beyond you at this stage. Maybe you are a genius and in four months will discover something that everybody else has over looked.

But, until you do I would suggest doing a bit more research in to the natural language processing part.

Go download some of the ''Quest games, by Sierra. These include, but are not limitd to, Kings Quest, Space Quest, and Leisure Suite Larry.... They may not have the language processing capabilites that you desire, but they effectivley integrate a graphical-lexical interface in to a game environment.

Will

##### Share on other sites
RPGeezus: Did you read the first line of my post or didn''t you? I''m not saying I''m a genius and I''m going to do what Chomsky and Lakoff and Searle (all of whom seem to like to hang out at my school) have failed to do. But it seems to me that the next generation of linguists and the next set of breakthroughs will have to be by students of these pioneers.

To address your veiled insults: I am a third year student. I know that there are better Natural Language Processors, I haven''t had time to really get into the background research, but I''ve noticed that no one game I''ve seen has stepped up to the challenge of making natural language the driving force of the story.

Finally, I''m not saying that I''m going to have an AI that perfectly understands English, or I would indeed be a very wealthy man by now. Like TerranFury suggested, there are very large subsets of English that can be easily processed. Other, more complicated phrase structures might be better handled by neural nets or genetic algorithms.

In a game situation a clever designer can work this into the "feel" of the game... e.g., simple natives who are just learning English. I have a program working now (with about a week''s worth of work put into it) that can break down most declarative sentences ("my dog was barking by the lake but i did not hear him") into sentence trees using only a dictionary and a set of generative rules. The responses don''t have to be as robust as the comprehension, I think, for an AI to impress people. And since sentences are usually fairly short (or else humans lose the ability to break them down) a brute-force approach to aiding interpretation is feasable.

So I''d really appreciate if you kept the discussion on possible game designs. If everybody just accepts that this job is too hard to do, then nobody is ever going to do it.

Tom

##### Share on other sites
Hi. I just wanted to mention that I have studied linguistics, and I'd be willing to advise anyone who wanted to try to make a natural language engine. Have you studied transformational generative grammar? Oh, I see from a later post that you have, that's good. Have you looked at the AI programming language SOAR? Have you found an opensource Eliza or essay generator and looked at the code? That's the way to go, IMO. Check out the threads in the writing forum on nonlinear games, the links will be helpful particularly the one to Wavinator's old ezboard where Bishop_Pass made all his informational posts about what SOAR is and how it works.

[edited by - sunandshadow on December 5, 2002 10:09:26 PM]

##### Share on other sites
quote:
RPGeezus: Did you read the first line of my post or didn''t you?

Is this a rhetorical question?

quote:

I''m not saying I''m a genius and I''m going to do what Chomsky and Lakoff and Searle (all of whom seem to like to hang out at my school) have failed to do. But it seems to me that the next generation of linguists and the next set of breakthroughs will have to be by students of these pioneers.

Throwing other peoples names around doesn''t impress me. Parrots can remember names, as well as many words, too.

quote:

To address your veiled insults: I am a third year student. I know that there are better Natural Language Processors, I haven''t had time to really get into the background research, but I''ve noticed that no one game I''ve seen has stepped up to the challenge of making natural language the driving force of the story.

I suspected as much. Which is what started me on this rant. I [may have been/ am being] a bit harsh, I admit, however after three years of University the best you can come up with in your research is some obscure 80''s text adventure?? Sorry, it''s down right insulting. That''s like going to Egypt, looking at a handful of sand, then returing home to tell your friends that theres nothing in Egypt but sand. In my view, you''re essentially urinating on 20 years worth of game development by stateing so boldy that you''re about to show the world how it''s really supposed to be done.

quote:

Finally, I''m not saying that I''m going to have an AI that perfectly understands English, or I would indeed be a very wealthy man by now.

I agree. If you had invested in Microsoft when the game you found was written, you would also be wealthy.

quote:

In a game situation a clever designer can work this into the "feel" of the game... e.g., simple natives who are just learning English.

How would you know? You only looked at ONE game from the early 80''s..

quote:

I have a program working now (with about a week''s worth of work put into it) that can break down most declarative sentences ("my dog was barking by the lake but i did not hear him") into sentence trees using only a dictionary and a set of generative rules.

How does it make you feel to "I have a program working now (with about a week''s worth of work put into it) that can break down most declartive sentences ("my dog was barking by the lake but i did not hear him") into sentence trees using only a dictionary and a set of generative rules."? Tell me more.

quote:

So I''d really appreciate if you kept the discussion on possible game designs. If everybody just accepts that this job is too hard to do, then nobody is ever going to do it.

As I mentioned earlier, look at the original Quest games by Sierra (not the remakes). The integrate text based commands/chatting in to a graphical walk-around world.

There are HUNDREDS of games that incorporate text based interfaces, and you look at ONE and decide it is somehow representative of 1980-2002.

I''ll stop now..

ELIZA, MD,
-or-
Dr. SBaitso.

They will answer any questions you may have regarding this post.

Tom

##### Share on other sites
This is the last time I respond to you, RPGeezus. You''re still not getting the point of this post at all. I''m not interested in natural language command processing at all, my example from the first post illustrated two things:

1) limitations on subject matter / format
2) limited comprehension

I realise that I may be offending those working on the problem with this obvious caricature, and maybe that is why your replies are so emotional. I want to stress that I''m not trying to dismiss all the work that''s been done, but trying to determine what other kind of game designs might be different enough to merit a novel approach to sentence generation but still narrow enough so that I don''t have to solve the entire problem overnight. I''m not trying to do what''s already been done, only better. I''m trying to do something different. That''s the whole point of this exercise.

I played with the likes of Eliza and Dr. SBaitso when I was a kid. Now my question is this: Is it so hard to program the thing to have a single, personal OPINION about ANYTHING? All they do is repeat what you say back. What is their motivation? Who is Eliza? Does she like chocolate? Is she allergic to things? Does she have relatives?

My idea is, if you restrict the grammar of the language considerably, you can spend your development time worrying about things like mental representations, salience, and spreading activation of connected concepts. Children have simple (sometimes incorrect) grammar, but their speech is still considered natural. There''s a HUGE gap between scripted conversations and even the rudimentary "W. Bush" English.

It irritates me when someone tries to solve the whole problem in one go. I''m not trying to do what Eliza purports to do; I''m just trying to use my knowledge and personal experience to make a fun game. If you don''t have any positive comments, go start your own thread.

Tom

##### Share on other sites
ParadigmShift: the answer is yes. You CAN create program that has personal opinion about SOME things (not everything). Just decide what these opinions are (or generate them) and make the program understand when it''s asked about the thing it has an opinion about, then display this opinion. It''s that easy.