请在 github.com/heiner/nle 的新家找到 NLE
NetHack 学习环境 (NLE) 是 NeurIPS 2020 上提出的强化学习环境。NLE 基于 NetHack 3.6.6,旨在为游戏提供标准 RL 接口,并附带作为评估代理的第一步的任务在这个新环境下。
NetHack 是历史上最古老、可以说是最具影响力的电子游戏之一,也是目前人类玩的最难的 Roguelike 游戏之一。它是按程序生成的,具有丰富的实体和动态,总体而言,对于当前最先进的 RL 代理来说,这是一个极具挑战性的环境,同时与其他具有挑战性的测试床相比,运行成本要低得多。通过 NLE,我们希望将 NetHack 打造为决策和机器学习研究的下一个挑战之一。
您可以在 NeurIPS 2020 论文中阅读有关 NLE 的更多信息,并在 nethack.org 和 NetHack wiki 上阅读其原始自述文件中了解有关 NetHack 的更多信息。
我们感谢 ngoodger 实现了 NLE 语言包装器,该包装器将 NetHack 任务中的非语言观察结果转换为类似的语言表示。还可以选择以文本形式提供操作,并将其转换为 NLE 的离散操作。
NetHack 学习数据集 (NLD) 代码现在随NLE
一起提供,允许用户加载《地下城与数据:大型 NetHack 数据集》中的大型数据集,同时还生成和加载自己的数据集。
import nle . dataset as nld
if not nld . db . exists ():
nld . db . create ()
# NB: Different methods are used for data based on NLE and data from NAO.
nld . add_nledata_directory ( "/path/to/nld-aa" , "nld-aa-v0" )
nld . add_altorg_directory ( "/path/to/nld-nao" , "nld-nao-v0" )
dataset = nld . TtyrecDataset ( "nld-aa-v0" , batch_size = 128 , ...)
for i , mb in enumerate ( dataset ):
foo ( mb ) # etc...
有关如何下载 NLD-AA 和 NLD-NAO 的信息,请参阅此处的数据集文档。
否则,请在此处查看 Colab 笔记本教程。
打开拉取请求以添加论文。
只要熟悉其他健身房/强化学习环境,从 NLE 环境开始就非常简单。
NLE 需要安装python>=3.5
、 cmake>=3.15
并在构建包时和运行时可用。
在MacOS上,可以按如下方式使用Homebrew
:
$ brew install cmake
在普通的Ubuntu 18.04发行版上,可以通过执行以下操作来安装cmake
和其他依赖项:
# Python and most build deps
$ sudo apt-get install -y build-essential autoconf libtool pkg-config
python3-dev python3-pip python3-numpy git flex bison libbz2-dev
# recent cmake version
$ wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2> /dev/null | sudo apt-key add -
$ sudo apt-add-repository ' deb https://apt.kitware.com/ubuntu/ bionic main '
$ sudo apt-get update && apt-get --allow-unauthenticated install -y
cmake
kitware-archive-keyring
然后就是设置环境的问题了。我们建议为此使用 conda 环境:
$ conda create -y -n nle python=3.8
$ conda activate nle
$ pip install nle
注意:如果您想扩展/开发 NLE,请按如下方式安装软件包:
$ git clone https://github.com/facebookresearch/nle --recursive
$ pip install -e " .[dev] "
$ pre-commit install
我们提供了一些 docker 镜像。请参阅相关的自述文件。
安装后,可以尝试以下提供的任何任务:
>> > import gym
>> > import nle
>> > env = gym . make ( "NetHackScore-v0" )
>> > env . reset () # each reset generates a new dungeon
>> > env . step ( 1 ) # move agent '@' north
>> > env . render ()
NLE 还附带了一些脚本,允许进行一些环境部署,并使用动作空间:
# Play NetHackStaircase-v0 as a human
$ python -m nle.scripts.play
# Use a random agent
$ python -m nle.scripts.play --mode random
# Play the full game using directly the NetHack internal interface
# (Useful for debugging outside of the gym environment)
$ python -m nle.scripts.play --env NetHackScore-v0 # works with random agent too
# See all the options
$ python -m nle.scripts.play --help
请注意,如果已正确安装软件包,则nle.scripts.play
也可以与nle-play
一起运行。
此外,TorchBeast 代理与一个简单的模型捆绑在nle.agent
中,为实验提供起点:
$ pip install " nle[agent] "
$ python -m nle.agent.agent --num_actors 80 --batch_size 32 --unroll_length 80 --learning_rate 0.0001 --entropy_cost 0.0001 --use_lstm --total_steps 1000000000
绘制过去 100 集的平均回报:
$ python -m nle.scripts.plot
averaged episode return
140 +---------------------------------------------------------------------+
| + + ++-+ ++++++++++++++++++++++++|
| : : ++++++++||||||||||||||||||||||||
120 |-+...........:.............:...+-+.++++|||||||||||||||||||||||||||||||
| : +++++++++++++++||||||||||AAAAAAAAAAAAAAAAAAAAAA|
| +++++++++++++||||||||||||||AAAAAAAAAAAA|||||||||||||||||||
100 |-+......+++++|+|||||||||||||||||||||||AA||||||||||||||||||||||||||||||
| +++|||||||||||||||AAAAAAAAAAAAAA|||||||||||+++++++++++++++++++|
| ++++|||||AAAAAAAAAAAAAA||||||||||||++++++++++++++-+: |
80 |-++++|||||AAAAAA|||||||||||||||||||||+++++-+...........:...........+-|
| ++|||||AAA|||||||||||||||++++++++++++-+ : : |
60 |++||AAAAA|||||+++++++++++++-+............:.............:...........+-|
|++|AA||||++++++-|-+ : : : |
|+|AA|||+++-+ : : : : |
40 |+|A+++++-+...:.............:.............:.............:...........+-|
|+AA+-+ : : : : |
|AA-+ : : : : |
20 |AA-+.........:.............:.............:.............:...........+-|
|++-+ : : : : |
|+-+ : : : : |
0 |-+...........:.............:.............:.............:...........+-|
|+ : : : : |
|+ + + + + |
-20 +---------------------------------------------------------------------+
0 2e+08 4e+08 6e+08 8e+08 1e+09
steps
我们欢迎对 NLE 做出贡献。如果您有兴趣做出贡献,请参阅此文档。
NLE 是 NetHack 的直接分支,因此包含在许多不同抽象级别上运行的代码。其范围从低级游戏逻辑到重复网络黑客游戏的高级管理,最后到将这些游戏绑定到 Python gym
环境。
如果您想了解有关nle
架构及其幕后工作原理的更多信息,请查看架构文档。对于任何希望为 NLE 较低级别元素做出贡献的人来说,这可能是一个有用的起点。
Facebook AI Research 的 Tim 和 Heiner 致力于让强化学习研究民主化。
如果您在任何工作中使用 NLE,请引用:
@inproceedings{kuettler2020nethack,
author = {Heinrich K{"{u}}ttler and
Nantas Nardelli and
Alexander H. Miller and
Roberta Raileanu and
Marco Selvatici and
Edward Grefenstette and
Tim Rockt{"{a}}schel},
title = {{The NetHack Learning Environment}},
booktitle = {Proceedings of the Conference on Neural Information Processing Systems (NeurIPS)},
year = {2020},
}
如果您在任何工作中使用 NLD 或数据集,请引用:
@article{hambro2022dungeons,
title={Dungeons and Data: A Large-Scale NetHack Dataset},
author={Hambro, Eric and Raileanu, Roberta and Rothermel, Danielle and Mella, Vegard and Rockt{"a}schel, Tim and K{"u}ttler, Heinrich and Murray, Naila},
journal={Advances in Neural Information Processing Systems},
volume={35},
pages={24864--24878},
year={2022}
}