Skip to main content

MarioGPT: Open-Ended Text2Level Generation through Large Language Models

Paper PyPi version HuggingFace Spaces Open In Colab

Playing Generated Level Generated Level
alt text alt text

How does it work?

Architecture Example Prompt Generations
alt text alt text

MarioGPT is a finetuned GPT2 model (specifically, distilgpt2), that is trained on a subset Super Mario Bros and Super Mario Bros: The Lost Levels levels, provided by The Video Game Level Corpus. MarioGPT is able to generate levels, guided by a simple text prompt. This generation is not perfect, but we believe this is a great first step more controllable and diverse level / environment generation. Forward generation:

alt text

Requirements

  • python3.8+

Installation

from pypi

pip install mario-gpt

or from source

git clone git@github.com:shyamsn97/mario-gpt.git
python setup.py install

Generating Levels

Since our models are built off of the amazing transformers library, we host our model in https://huggingface.co/shyamsn97/Mario-GPT2-700-context-length

This code snippet is the minimal code you need to generate a mario level!

from mario_gpt import MarioLM, SampleOutput

# pretrained_model = shyamsn97/Mario-GPT2-700-context-length

mario_lm = MarioLM()

# use cuda to speed stuff up
# import torch
# device = torch.device('cuda')
# mario_lm = mario_lm.to(device)

prompts = ["many pipes, many enemies, some blocks, high elevation"]

# generate level of size 1400, pump temperature up to ~2.4 for more stochastic but playable levels
generated_level = mario_lm.sample(
    prompts=prompts,
    num_steps=1400,
    temperature=2.0,
    use_tqdm=True
)

# show string list
generated_level.level

# show PIL image
generated_level.img

# save image
generated_level.img.save("generated_level.png")

# save text level to file
generated_level.save("generated_level.txt")

# play in interactive
generated_level.play()

# run Astar agent
generated_level.run_astar()

# Continue generation
generated_level_continued = mario_lm.sample(
    seed=generated_level,
    prompts=prompts,
    num_steps=1400,
    temperature=2.0,
    use_tqdm=True
)

# load from text file
loaded_level = SampleOutput.load("generated_level.txt")

# play from loaded (should be the same level that we generated)
loaded_level.play()
...
See notebook for a more in depth tutorial to generate levels

Interacting with Levels

Right now there are two ways to interact with generated levels:

  1. Huggingface demo -- Thanks to the amazing work by multimodalart, you can generate and play levels interactively in the browser! In addition, gpus are provided so you don't have to own one yourself.
  2. Using the play and astar methods. These require you to have java installed on your computer (Java 8+ tested). For interactive, use the play() method and for astar use the run_astar method. Example:
from mario_gpt import MarioLM

mario_lm = MarioLM()

prompts = ["many pipes, many enemies, some blocks, high elevation"]

generated_level = mario_lm.sample(
    prompts=prompts,
    num_steps=1400,
    temperature=2.0,
    use_tqdm=True
)

# play in interactive
generated_level.play()

# run Astar agent
generated_level.run_astar()

Future Plans

Here's a list of some stuff that will be added to the codebase!

  • Basic inference code
  • Add MarioBert Model
  • Add Interactive simulator
  • Inpainting functionality from paper
  • Open-ended level generation code
  • Training code from paper
  • Different generation methods (eg. constrained beam search, etc.)

Authors

Shyam Sudhakaran shyamsnair@protonmail.com, https://github.com/shyamsn97

Miguel González-Duque migd@itu.dk, https://github.com/miguelgondu

Claire Glanois clgl@itu.dk, https://github.com/claireaoi

Matthias Freiberger matfr@itu.dk, https://github.com/matfrei

Elias Najarro enaj@itu.dk, https://github.com/enajx

Sebastian Risi sebr@itu.dk, https://github.com/sebastianrisi

Citation

If you use the code for academic or commecial use, please cite the associated paper:

@misc{https://doi.org/10.48550/arxiv.2302.05981,
  doi = {10.48550/ARXIV.2302.05981},
  
  url = {https://arxiv.org/abs/2302.05981},
  
  author = {Sudhakaran, Shyam and González-Duque, Miguel and Glanois, Claire and Freiberger, Matthias and Najarro, Elias and Risi, Sebastian},
  
  keywords = {Artificial Intelligence (cs.AI), Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
  
  title = {MarioGPT: Open-Ended Text2Level Generation through Large Language Models},
  
  publisher = {arXiv},
  
  year = {2023},
  
  copyright = {arXiv.org perpetual, non-exclusive license}
}

Metadata

Release files for mario-gpt 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mario-gpt 0.1.3
File Size Uploaded Provenance Actions
mario-gpt-0.1.3.tar.gz 970.1 kB Without provenance Details for mario-gpt-0.1.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for mario-gpt 0.1.3
File Interpreter ABI Platform Actions
mario_gpt-0.1.3-py3.9.egg Legacy Egg format - - Details for mario_gpt-0.1.3-py3.9.egg
mario_gpt-0.1.3-py3-none-any.whl Python 3 none any Details for mario_gpt-0.1.3-py3-none-any.whl

Total release size: 3.0 MB

Release files / mario-gpt-0.1.3.tar.gz

Download URL mario-gpt-0.1.3.tar.gz
Size 970.1 kB
Tags Source
SHA-256 checksum
How to use checksums
29d91fb3ea7d9b39ea4202cacd012a88454e17047e91943dc6b4fcf6df937195
BLAKE2b-256 checksum
How to use checksums
38cedfc35103aafc63060ace25d5afee4fd2628f2fab6310ddb2c55f57df7e5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / mario_gpt-0.1.3-py3.9.egg

Download URL mario_gpt-0.1.3-py3.9.egg
Size 1.0 MB
Tags Egg
SHA-256 checksum
How to use checksums
1d4c6c768d9e1cc8e1d1a5d3e015c4b81471e01d47a6b9bbf935dd243b1f9ee0
BLAKE2b-256 checksum
How to use checksums
1e58075faed419ed75181127d1d68780ee5e0cb80ad9edfac6cc49757c5931f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / mario_gpt-0.1.3-py3-none-any.whl

Download URL mario_gpt-0.1.3-py3-none-any.whl
Size 984.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d16e4f878e37c186489902e75c51949db606196d718be7ead0ff5c15d828f6f
BLAKE2b-256 checksum
How to use checksums
b897d76dbad8c0316ee5234a97607dd0368e9da46c82b5dd7ce1de42fd3326f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for mario-gpt 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page