{"id":19611930,"url":"https://github.com/princeton-nlp/calm-textgame","last_synced_at":"2025-04-27T22:33:51.699Z","repository":{"id":38841319,"uuid":"298597738","full_name":"princeton-nlp/calm-textgame","owner":"princeton-nlp","description":"[EMNLP 2020] Keep CALM and Explore: Language Models for Action Generation in Text-based Games","archived":false,"fork":false,"pushed_at":"2021-02-22T18:59:46.000Z","size":19196,"stargazers_count":69,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T04:31:46.591Z","etag":null,"topics":["calm","gpt","n-gram","nlp","rl","text-based-game"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/princeton-nlp.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-25T14:34:18.000Z","updated_at":"2025-02-16T18:32:08.000Z","dependencies_parsed_at":"2022-08-09T06:15:50.645Z","dependency_job_id":null,"html_url":"https://github.com/princeton-nlp/calm-textgame","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princeton-nlp%2Fcalm-textgame","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princeton-nlp%2Fcalm-textgame/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princeton-nlp%2Fcalm-textgame/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princeton-nlp%2Fcalm-textgame/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/princeton-nlp","download_url":"https://codeload.github.com/princeton-nlp/calm-textgame/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251219600,"owners_count":21554444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["calm","gpt","n-gram","nlp","rl","text-based-game"],"created_at":"2024-11-11T10:45:06.333Z","updated_at":"2025-04-27T22:33:46.690Z","avatar_url":"https://github.com/princeton-nlp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Contextual Action Language Model (CALM) and the ClubFloyd Dataset\n\nCode and data for paper [Keep CALM and Explore: Language Models for Action Generation in Text-based Games](https://arxiv.org/pdf/2010.02903.pdf) at EMNLP 2020.\n\n## Overview\nOur **ClubFloyd dataset** (`calm/lm_data.zip`) is crawled from [the ClubFloyd website](http://www.allthingsjacq.com/interactive_fiction.html) and contains 426 human gameplay transcripts, which cover 590 text-based games of diverse genres and styles. \n\nThe data consists of 223,527 context-action pairs in the format `[CLS] observation [SEP] action [SEP] next observation [SEP] next action [SEP]`. We use `[CLS] observation [SEP] action [SEP] next observation [SEP]` as the context to train language models (n-gram, GPT-2) to predict `next action [SEP]`, and show that this action generation ability generalizes to **unseen games** and supports gameplay when combined with reinforcement learning. \n\n##  Getting Started\n- Clone repo and install dependencies:\n\n```bash\npip install torch==1.4 transformers==2.5.1 jericho fasttext wandb importlib_metadata\ngit clone https://github.com/princeton-nlp/calm-textgame \u0026\u0026 cd calm-textgame\nln -s ../lm calm \u0026\u0026 ln -s ../lm drrn\n```\n\n(If the pip installation fails for fasttext, try the build steps here: https://github.com/facebookresearch/fastText#building-fasttext-for-python)\n\n- Train CALM:\n```bash\ncd calm\nunzip lm_data.zip\npython train.py\n```\n\nTrained model weights can be downloaded [here](https://drive.google.com/file/d/1PBAXq4LW9pdVdLFyF_donwCV46wBX1zD/view?usp=sharing) for both GPT-2 and n-gram models. \n\n- Then train DRRN using the trained CALM:\n```bash\ncd ../drrn\npython train.py --rom_path ../games/${GAME} --lm_path ${PATH_TO_CALM} --lm_type ${gpt_or_ngram}\n```\n\n- To quickly try out the GPT-2 CALM model:\n```python\nfrom lm import GPT2LM\nmodel = GPT2LM(\"model_weights/gpt2\")\nprint(model.generate(\"[CLS] observation [SEP] action [SEP] next observation [SEP]\", k=30))\n```\n## Citation\n```\n@inproceedings{yao2020calm,\n    title={Keep CALM and Explore: Language Models for Action Generation in Text-based Games},\n    author={Yao, Shunyu and Rao, Rohan and Hausknecht, Matthew and Narasimhan, Karthik},\n    booktitle={Empirical Methods in Natural Language Processing (EMNLP)},\n    year={2020}\n}\n```\n## Acknowledgements\nThanks Jacqueline for hosting the wonderful ClubFloyd website and granting our use!\n\nThe code borrows from [TDQN](https://github.com/microsoft/tdqn) (for the RL part) and [Huggingface Transformers](https://github.com/huggingface/transformers) (for the CALM part). \n\nFor any questions please contact Shunyu Yao `\u003cshunyuyao.cs@gmail.com\u003e`.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinceton-nlp%2Fcalm-textgame","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprinceton-nlp%2Fcalm-textgame","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinceton-nlp%2Fcalm-textgame/lists"}