Giter VIP home page Giter VIP logo

facebookresearch / minirts Goto Github PK

View Code? Open in Web Editor NEW
155.0 11.0 31.0 7.53 MB

We release dataset collected for our research, code that implement neural network models described in the paper, and scripts to reproduce all of our results, and visualization tool for visualize dataset.

License: Other

CMake 0.57% Shell 1.99% C++ 54.67% Python 28.86% C 0.03% Lua 4.41% JavaScript 8.44% HTML 0.56% CSS 0.47%

minirts's Introduction

Hierarchical Decision Making by Generating and Following Natural Language Instructions

This is the repo for paper Hierarchical Decision Making by Generating and Following Natural Language Instructions.

Dependencies

conda install lua numpy tqdm
conda install -c conda-forge tensorboardx

Get Started

Clone repo

git clone ...
git submodule sync && git submodule update --init --recursive

Download dataset & pretrained models

To downalod and unzip the original replays, processed json files, and dataset, from the following command. Note that it will take a while for the command to finish.

cd data
sh download.sh

To download some pretrained models used in the paper:

cd pretrained_models
sh download.sh
python update_path.py

Visualize dataset

We build a visualization tool that works directly with json file so that people can get a more intuitive view of the dataset and start working on it without compiling the game. Please go to the visual folder for detailed instructions on how to use it.

Train models

We put the shell scripts that can be used to re-train the model with configurations used in the paper in scripts/behavior_clone/scripts. Simply run command like

sh scripts/coach_rnn500.sh

to start training. The command needs to be run under behavior_clone folder. Normally it will take quite a while to load the dataset. For quick testing and debugging, one can add --dev at the end of the shell script to use the dev dataset instead, which contains only 2000 entries and thus much faster to load.

Run matches between models

To run matches between trained models, we first need to compile the game. Please see the "Build" and "Set env var" section for details. After the game is compiled, the following command can be used to launch matches between an RNN coach + RNN executor and zero executor (the one that does not use latent language).

python match2.py --coach1 rnn500 --executor1 rnn \
        --coach2 rnn500 --executor2 zero \
        --num_thread 500 --seed 9999

Structure

scripts

This is the main folder for our algorithm, containing code for data processing, model definition & training, and evaluation. See the readme file for each subfolder for more details.

visual

This contains a web tool for visualizing dataset from json so that we can have a peek of the dataset without compiling the game.

game

This folder contains the implementation of the game, including game logic, some built-in AIs used for collecting data, as well as necessary backends to extract features from game state for model evaluation.

tube

This folder defines a set of infra that dynamically batches data from various C++ game threads and transfer them between C++ and Python.

Build

mkdir build
cd build
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
cmake ..
make

Set Env Variables

Note that we need to set the following before running any multi-threading program that uses the C++ torch::Tensor. Otherwise a simple tensor operation will use all cores by default.

export OMP_NUM_THREADS=1

Control Executor with Text

We can control the executor ourselves by inputting text command to the trained executor. First we need to set up the web server for the backend so that we can watch the gameplay in browser while controlling the executor.

We provide a script to install apache without root access. If you have root privilege, you can simply run sudo apt-get update & sudo apt-get install apache2

cd ROOT
sh install_apache.sh

After installation finishes, edit ROOT/apache/httpd/conf/httpd.conf to change the Listen 80 (line52) to Listen 8000 or any number >1024. The reason is that the ports with lower numbers are reserved by system and requires sudo to use them.

Then we need to link our frontend code to the apache root directory & start server

cd ROOT
ln -s $PWD/game/frontend $PWD/apache/httpd/htdocs/game
cd apache/httpd
./bin/apachectl start

Now open a browser and navigate to http://localhost:8000/. You should see It Works. Otherwise there are some issue with the server set up.

Then we can start a human game!

cd ROOT/scripts/behavior_clone
python human_coach.py --resource 500 --verbose
# it should show 'Waiting for websocket client ...'

On the browser, navigate to http://localhost:8000/game/minirts.html?player_type=spectator&port=8002 and wait for the model to be loaded. The command line will prompt the top 500 instructions the model was trained on. If you are using RNN executor (by default), you don't have to choose from these instructions as the RNN can ideally handle unseen combinations. If you are using OneHot executor, you should input an instruction from the list.

Citation

If you use this repo in your research, please consider citing the paper as follows:

@article{DBLP:journals/corr/abs-1906-00744,
  author    = {Hengyuan Hu and
               Denis Yarats and
               Qucheng Gong and
               Yuandong Tian and
               Mike Lewis},
  title     = {Hierarchical Decision Making by Generating and Following Natural Language
               Instructions},
  journal   = {CoRR},
  volume    = {abs/1906.00744},
  year      = {2019},
  url       = {http://arxiv.org/abs/1906.00744},
  archivePrefix = {arXiv},
  eprint    = {1906.00744},
  timestamp = {Thu, 13 Jun 2019 13:36:00 +0200},
  biburl    = {https://dblp.org/rec/bib/journals/corr/abs-1906-00744},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}

Copyright

Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.

This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.

minirts's People

Contributors

hengyuan-hu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minirts's Issues

How to reset the environment?

The example in minirts/scripts/behavior_clone/match2.py only shows one episode of the game at each thread. So how can I reset the game state at the end of an episode? I want to train RL algorithms with it.

Import Error for sh scrips/coach_rnn500.sh

Hi, I have the following error when I tried to run sh scripts/coach_rnn500.sh, I can't tell exactly where that google module is from, any help is appreciated.
Traceback (most recent call last): File "train_coach.py", line 18, in <module> from coach_dataset import CoachDataset, compute_cache File "/home/km/myagent/minirts/scripts/behavior_clone/coach_dataset.py", line 13, in <module> from dataset import BehaviorCloneDataset File "/home/km/myagent/minirts/scripts/behavior_clone/dataset.py", line 14, in <module> from common_utils import assert_eq, assert_neq File "/home/km/myagent/minirts/scripts/behavior_clone/common_utils/__init__.py", line 11, in <module> from .multi_counter import MultiCounter File "/home/km/myagent/minirts/scripts/behavior_clone/common_utils/multi_counter.py", line 10, in <module> from tensorboardX import SummaryWriter File "/home/km/anaconda3/envs/minirts/lib/python3.5/site-packages/tensorboardX/__init__.py", line 5, in <module> from .torchvis import TorchVis File "/home/km/anaconda3/envs/minirts/lib/python3.5/site-packages/tensorboardX/torchvis.py", line 11, in <module> from .writer import SummaryWriter File "/home/km/anaconda3/envs/minirts/lib/python3.5/site-packages/tensorboardX/writer.py", line 15, in <module> from .event_file_writer import EventFileWriter File "/home/km/anaconda3/envs/minirts/lib/python3.5/site-packages/tensorboardX/event_file_writer.py", line 28, in <module> from .proto import event_pb2 File "/home/km/anaconda3/envs/minirts/lib/python3.5/site-packages/tensorboardX/proto/event_pb2.py", line 6, in <module> from google.protobuf import descriptor as _descriptor File "/home/km/anaconda3/envs/minirts/lib/python3.5/site-packages/google/protobuf/descriptor.py", line 47, in <module> from google.protobuf.pyext import _message ImportError: /home/km/anaconda3/envs/minirts/lib/python3.5/site-packages/google/protobuf/pyext/_message.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _ZNK6google8protobuf10TextFormat17FieldValuePrinter9PrintBoolEb

Import error for minirts

We have successfully build minirts (and built pytorch v1.2 from source), but am having trouble running match2.py.

When we import minirts, this is the import error:
ImportError: generic_type: type "RTSGame" referenced unknown base type "tube::EnvThread"

Any help with this would be greatly appreciated!

how can I start a game between human-text-input and AI ?

I can run this game by scripts/behavior_clone/match2.py between two AI, but I want a version that one side is an AI guided by human with keyboard text input, another side is a simple ai.
And I think text-input should be an important form to test the whole project( or even the final form). I found that ./minirts humanplay --vis_after 0 can not work anymore, the latest version even removed binary file ./minirts, left only ./minirts-backend.
So, where can I find a user-frontend for human-text-input, is there some parameters I can pass to ./minirts-backend. to get the frontend, or I should implement one by myself?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.