In the earliest text adventure games, parsers used exact string matching. If a command wasn’t in either the form
verb object, the parser would not recognize it. However, parsers and natural language processing (NLP) in general have evolved tremendously since the 1970s. NLP is a vibrant subfield of artificial intelligence. One of the goals of NLP is to allow computers to understand commands spoken in human language. This enables technologies like Amazon Alexa, Apple’s Siri or Google’s Assistant.
Early interactive fiction games, as well as the games you implemented for Homework 1, force players to enter commands following a strict syntax, often using the
verb object form. Players can only say things like
pick rose or
smell rose if those commands have been specifically programmed into the parser.
In this homework you will using advancements in NLP to improve your game. Using different NLP methods, you will
The first two parts are structured walkthroughs. The 3rd part is open-ended and allows you to apply your creativity. The homework deliverables are in italics; make sure to read these carefully.
We will start by improving the coverage of the parser in your text adventure game, so that it can handle a variety of user input instead of just a single hard-coded command. This will allow the player to use other words than what you used when you wrote the command. For example, “Toss/throw/chuck the stick” will all resolve to the same command.
In part 1, we will introduce you to the WordNet resource. WordNet is a classic resource for natural language processing. It encodes information about synonyms, antonyms, and is-a relationships between words like troll is-a monster. In NLP, is-a relationships are called hypernyms or hyponyms.
For this task you should work through the “NLP for Text Adventure Games - part 1” Python notebook, which will introduce you to WordNet and will have you use WordNet to annotate several commands from Action Castle with their word senses, and their hypernyms and hyponyms. This will allow you to expand out the number of possible commands that your parser can recognize. After completing the Python notebook, I expanded the number of commands from 7 to several thousand.
Upon completion, the notebook saves a file called
word-sense-annotations.json. You should submit this file to be graded.
Word embeddings are another NLP technology that will allow you to improving the coverage your game’s parser. Word embeddings are a way of representing the meaning of words using vectors. This style of meaning representation is different than WordNet. Intead of having structured relationships between words like troll is-a monster, word word vector give us a way of computing the similarity of words. This let us compute the most similar words for troll, which are goblins, ogres, elves, troll, ghouls, hobbits, centaurs, unicorns, humanoids, undead, and witches.
The notebook has one part that you are required to implement. You should write code that uses word embeddings to find the most similar command to a player’s input.
Modify Action Castle from Homework 1 to support recognizing an expanded set of user inputs via WordNet and word embeddings. You can implement this support however you would like, but it should include the
find_most_similar_command function from the Part 2 IPython Notebook. Write up a short explanation of how you decided to implement your expanded parser support.
Free choice! Modify your own game from Homework 1 to make it more fun to play. You can either (1) integrate some other NLP technology into your parser, or (2) use NLP to create a new game playing experience.
Some ideas can be found in the “NLP for Text Adventure Games - part 3” Python notebook. This notebook doesn’t have any concrete deliverables - it’s just ideas for you. A few suggestions are:
In your homework submission, include a discussion of how you implemented this improvement, and what concepts from NLP you are using. Copy and paste several example interactions with your game that showcase the new parser feature.
NLP can facilitate gameplay that experiences that wouldn’t be possible otherwise. Use your creativity to create a new character, puzzle, or obstacle that incorporates NLP. A few suggestions are:
More suggestions can be found in the demo Colab.
In your homework submission, include a discussion of how you implemented your new gameplay feature, what concepts from NLP it uses, and why you think it makes your game more fun. Copy and paste several example interactions with your game that showcase the new feature.
word-sense-annotations.jsoncontaining your annotations of the Action Castle commands with their WordNet synsents, hypernyms and hyponyms. This will be saved in your Google Drive after you complete the Python notebook from Part 1 of this HW.
action_castle_improved.ipynbcontaining an updated version of your Action Castle game that uses word embeddings and WordNet in its parser.
my_game_improved.ipynbthat runs the new version of your custom game with your improvements from Part 3.
playthrough.txtwith all of the commands that we need to issue to complete your game. It should be a plain text file with one command per line. (This may or may not be identical to Homework 1.)
README.md. It should include your explanation from Part 2 and your discussion from Part 3.
IMPORTANT: We will not run or grade your code if the files are not named as described above.
Dan Jurafsky and James H. Martin, Vector Semantics and Embeddings.
Ajay Patel, Alexander Sands, Chris Callison-Burch, Marianna Apidianaki, Magnitude - A Fast, Efficient Universal Vector Embedding Utility Package.