Article
files/QUESTIONS

Chat Bots and Natural Language Technology in Games

Alex J. Champandard on November 23, 2007

Every year, chatbot enthusiasts get together and compete in a simplified Turing test. These contests aren’t at the cutting edge of natural language (NL) technology, but this kind of technology is perfectly suitable for mainstream games — both in terms of simplicity to implement and runtime efficiency.

Nathan asks “I saw the post on the Loebner Competition and it got me thinking. Is there any development to integrate this technology into games such as RPGs for NPCs (Non-Player Characters) and what problems could there be?”

Many games already integrate chatbot-like technology, but it has its limitations and there hasn’t been much visible progress in chatbots since Alice and AIML. Academic research in NL generally (outside of such politically-loaded contests) is proving to be much more fruitful, but this technology requires more dedication from game developers, and as such, remains only an option for independent games.

Generally speaking, there are two aspects of chatbots and NL research, both of which are applicable to different types of games:

  • Understanding — Requires parsing text, and extracting meaning from it.

  • Generating Language — Focuses on generating dialog from current knowledge.

I’ll give you a quick overview of two ways to approach these problems: the simple chatbot way, and the more “academic” NL way.

Pattern Matching

One of the simplest ways to get started with chat-bot technology is to use pattern matching to figure out an appropriate response, as made popular by AIML, the markup language that Alice uses.

Technology
The idea is to write a huge database of patterns in one big XML file. Each pattern contains specific words and wildcards, so different variations of the same text are recognized. Then the response associated with the pattern is output.
Integration
To integrate this kind of technology, you need a pattern recognition engine: something like regular expressions or a variation of AIML. Then it’s just a matter of connecting this engine to the console where the player inputs text — like in Quake 3.
Problems
The problem is that pattern matching is really just a reactive AI, and at best, it can only respond accurately to your last statement. It’s the reason why chat bots aren’t very logical! This limits the applicability of the technology to specific parts of games that don’t feature much interaction.

Effectively, this approach is limited to the classic bots in multiplayer shooters. It’s not meant for meaningful conversations, but it does the trick of keeping the player stimulated! So it’d only be appropriate for RPG characters that don’t have much to say.

Natural Language Understanding

You can take pattern matching technology to the next level by going beyond reactive AI.

Technology
The idea is to use the patterns to update a logical model of the conversation, and use that to create dialog. So you still use patterns like in AIML, but these are connected to logical rules which update facts. It’ll take a bit more knowledge of first-order logic to pull this off.
Integration
This kind of technology has been integrated into Façade. The major difference here is that the developers don’t write simple text patterns, they implement logical rules and behaviors that deal with the text written.
Problems
It’s an open field of research, and a different set of skills is required. Don’t expect to be able to deal with open-ended conversations yet though; like for AIML patterns, it’s still important to edit the correct rules for the kinds of situations encountered in your game.

This approach seems like the best known NL understanding technology to have been integrated into games. Anything beyond remains experimental… However, there’s a huge potential here for creating more intelligent RPG characters.

Text Templates

Unreal Tournament 3

Screenshot 1: Unreal Tournament use a form of templates to generate dialog.

Now, moving on to very simple NL generation. The patterns for matching text is only one half of AIML; the other half contains templates that specify how to output text.

Technology
Instead of making each response out of English words only, you can use a template sentence which includes logic to fill in words dynamically based on the context. This works very much like printf in traditional programming languages, where you can specify variables to expand like: “You are in %location%, at %health% health.
Integration
You need to be able to parse and process templates with string substitutions, but that’s about it. This works very well in team FPS games for the bots to communicate vital information to the player like in Unreal Tournament. The advantage of templates is that they also work for piecing together segments of voice recording, so it’s not limited to text output.
Problems
Ultimately, the templates are still very limited and don’t contain any more variation than what’s in the database. It’s a very author-intensive approach.

Many games in practice use such templates, whether they are text based or simply combine audio fragments together to generate voices. RPGs with typical dialog trees could benefit from such templates. They are simple to implement and efficient, but they certainly have their limitations…

Natural Language Generation

Many academic and commercial projects have successfully managed to beyond patterns for NL generation. This research topic is better understood.

Technology
The key insight is to use a better model of the English language. This would typically be a hand-edited graph that explains how sentences are built from components, and the same recursively. Then at runtime, you’d traverse this data-structure to generate sentences according to the current goal of the AI. (See the NLP Group at Columbia University for a starting point.)
Integration
In terms of integrating this technology into games, Interactive Fiction is the best place to look for inspiration. Many of the independent games in the recent IF 2007 competition are built from detailed NL models of the storyworld, and the logic necessary to output the correct text according to the player’s actions.
Problems
There’s existing technology to help you build IF games (e.g. Z-Code), but going beyond that and doing better NL generation requires a fair bit of experience with classical AI techniques. Also note that this technology would be very hard to hook up to a traditional audio system with recorded voices.

That covers the variety of different chatbot and natural language technology that’s applicable to games, and the different problems you can encounter while integrating it. Keep in mind that this kind of technology is still author-intensive, so you’ll need to allocate a lot of time to model your NL domain and/or storyworld. On the bright side, there are lots of opportunities to design innovative games using these ideas!

Discussion 1 Comments

ckromero on January 2nd, 2008

While at Nickelodeon we used an AIML interpreter behind animated characters such as SpongeBob in the Virtual World Nicktropolis to some success. Advantages we had were: 1. The audience used a white-listed dictionary, meaning there was a limited set of things they could say. 2. The audience (kids) are much more willing to suspend disbelief in terms of what SpongeBob might or might not know... 3. Therefore SpongeBob only had to know about his world and understand when someone asked about it - he didn't need to know about the Boston Red Sox for instance. We were reasonably happy with how kids reacted to the chatbots, it was still a lot of work to get them to respond reaonsably but it was a tractable problem. Next steps? - Use chatbots to launch players on quests as well as to judge where a player is in a quest. Honestly I'm surprised that more games don't use chatbots, it's certainly more appealing than multiple-choice text. - Pull limits in to help build the richness of it - if an NPC speaks a foreign (alien?) language intelligibly but only a few words of English, they could translate the few words they understand. - NLU as discussed above (with lots of limits) does seem possible. - Check out Rob Zubek's work, he's got great ideas for enhancing characterization of bots.

If you'd like to add a comment or question on this page, simply log-in to the site. You can create an account from the sign-up page if necessary... It takes less than a minute!