Skip to main content

Microsoft Textworld - A Text-based Learning Environment.

Project description

TextWorld

Build Status PyPI version Documentation Status Join the chat at https://gitter.im/Microsoft/TextWorld

A text-based game generator and extensible sandbox learning environment for training and testing reinforcement learning (RL) agents. Also check out aka.ms/textworld for more info about TextWorld and its creators. Have questions or feedback about TextWorld? Send them to textworld@microsoft.com or use the Gitter channel listed above.

Installation

TextWorld supports Python 3.7/3.8/3.9 for Linux and macOS systems only at the moment. For Windows users, docker can be used as a workaround (see Docker section below).

Requirements

TextWorld requires some system libraries for its native components. On a Debian/Ubuntu-based system, these can be installed with

sudo apt update && sudo apt install build-essential libffi-dev python3-dev curl git

And on macOS, with

brew install libffi curl git

Note: We advise our users to use virtual environments to avoid Python packages from different projects to interfere with each other. Popular choices are Conda Environments and Virtualenv

Installing TextWorld

The easiest way to install TextWorld is via pip:

pip install textworld

Or, after cloning the repo, go inside the root folder of the project (i.e. alongside setup.py) and run

pip install .

Visualization

TextWorld comes with some tools to visualize game states. Make sure all dependencies are installed by running

pip install textworld[vis]

Then, you will need to install either the Chrome or Firefox webdriver (depending on which browser you have currently installed). If you have Chrome already installed you can use the following command to install chromedriver

pip install chromedriver_installer

Current visualization tools include: take_screenshot, visualize and show_graph from textworld.render.

Docker

A docker container with the latest TextWorld release is available on DockerHub.

docker pull marccote19/textworld
docker run -p 8888:8888 -it --rm marccote19/textworld

Then, in your browser, navigate to the Jupyter notebook's link displayed in your terminal. The link should look like this

http://127.0.0.1:8888/?token=8d7aaa...e95

Note: See README.md in the docker folder for troubleshooting information.

Usage

Generating a game

TextWorld provides an easy way of generating simple text-based games via the tw-make script. For instance,

tw-make custom --world-size 5 --nb-objects 10 --quest-length 5 --seed 1234 --output tw_games/custom_game.z8

where custom indicates we want to customize the game using the following options: --world-size controls the number of rooms in the world, --nb-objects controls the number of objects that can be interacted with (excluding doors) and --quest-length controls the minimum number of commands that is required to type in order to win the game. Once done, the game custom_game.z8 will be saved in the tw_games/ folder.

Playing a game (terminal)

To play a game, one can use the tw-play script. For instance, the command to play the game generated in the previous section would be

tw-play tw_games/custom_game.z8

Note: Only Z-machine's games (*.z1 through .z8) and Glulx's games (.ulx) are supported.

To visualize the game state while playing, use the --viewer [port] option.

tw-play tw_games/custom_game.z8 --viewer

A new browser tab should open and track your progress in the game.

Playing a game (Python + Gym)

Here's how you can interact with a text-based game from within Python using OpenAI's Gym framework.

import gym
import textworld.gym

# Register a text-based game as a new Gym's environment.
env_id = textworld.gym.register_game("tw_games/custom_game.z8",
                                     max_episode_steps=50)

env = gym.make(env_id)  # Start the environment.

obs, infos = env.reset()  # Start new episode.
env.render()

score, moves, done = 0, 0, False
while not done:
    command = input("> ")
    obs, score, done, infos = env.step(command)
    env.render()
    moves += 1

env.close()
print("moves: {}; score: {}".format(moves, score))

Note: To play text-based games without Gym, see Playing text-based games with TextWorld.ipynb

Documentation

For more information about TextWorld, check the documentation.

Visual Studio Code

You can install the textworld-vscode extension that enables syntax highlighting for editing .twl and .twg TextWorld files.

Notebooks

Check the notebooks provided with the framework to see what you can do with it. You will need the Jupyter Notebook to run them. You can install it with

pip install jupyter

Citing TextWorld

If you use TextWorld, please cite the following BibTex:

@Article{cote18textworld,
  author = {Marc-Alexandre C\^ot\'e and
            \'Akos K\'ad\'ar and
            Xingdi Yuan and
            Ben Kybartas and
            Tavian Barnes and
            Emery Fine and
            James Moore and
            Ruo Yu Tao and
            Matthew Hausknecht and
            Layla El Asri and
            Mahmoud Adada and
            Wendy Tay and
            Adam Trischler},
  title = {TextWorld: A Learning Environment for Text-based Games},
  journal = {CoRR},
  volume = {abs/1806.11532},
  year = {2018}
}

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textworld-1.5.4rc6.tar.gz (689.8 kB view details)

Uploaded Source

Built Distributions

textworld-1.5.4rc6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.24+ x86-64

textworld-1.5.4rc6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.24+ x86-64

textworld-1.5.4rc6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.24+ x86-64

textworld-1.5.4rc6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.24+ x86-64

File details

Details for the file textworld-1.5.4rc6.tar.gz.

File metadata

  • Download URL: textworld-1.5.4rc6.tar.gz
  • Upload date:
  • Size: 689.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for textworld-1.5.4rc6.tar.gz
Algorithm Hash digest
SHA256 545d41ce4e059bf8ee4ab16bb56ea2c4727c485da3636e6d22d45e209ac03ff2
MD5 4bef66dadfce29145a2ef70af18dbdbc
BLAKE2b-256 0c64bd406f8acce02ed41ba91a0a0f60809196f9efa879c48822606df80ac8a4

See more details on using hashes here.

File details

Details for the file textworld-1.5.4rc6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for textworld-1.5.4rc6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 ab258cac3666957e7fe0dad566935f0765223a25613b026c91c88e90ed93ef01
MD5 cc3dd06f17122ae73bd5dad7f3e4d2e5
BLAKE2b-256 9a6fd0fc5d2be94044c1a98527a49682f518510fc8161c1fc7ec1b168be4a66a

See more details on using hashes here.

File details

Details for the file textworld-1.5.4rc6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for textworld-1.5.4rc6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 b2878690ba53217b43dbd5505b961d4104b569c74079ce72a83b7b2c0fd03d54
MD5 7b642d7e0a497bb3ab91edf4d5b417c6
BLAKE2b-256 0ae7eeeddffb8f6bfa3a17d4225fb430120bf42dac9523ad9f79593547b308c7

See more details on using hashes here.

File details

Details for the file textworld-1.5.4rc6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for textworld-1.5.4rc6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 1470dc01848e7ff20fce23eddaaf1730cef78658bfa5ffed16fb1479ab4955d9
MD5 5159bed1de6b92f822c34027c4c54b34
BLAKE2b-256 54180bdefcb6548ef74403e097a2a8536e0f8867aed8d17744d2a1ad49eaadbc

See more details on using hashes here.

File details

Details for the file textworld-1.5.4rc6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for textworld-1.5.4rc6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 ce2c48d1508d4532e968b66b0a7f60f56c2b426508b50cc323bb6fc0ce973d6e
MD5 eeb0fda3c08a3c38850d07f812de2d05
BLAKE2b-256 ddff53b92ff27bfdf1837d3dc3ca8fe71f441fd68b8b8aa418a5271e1a477467

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page