From 55da36426a71f67feede042900a0331682330065 Mon Sep 17 00:00:00 2001 From: Nick Walton Date: Mon, 18 Nov 2019 18:29:38 -0700 Subject: [PATCH] update --- generator/gpt2/gpt2_generator.py | 4 +-- install.sh | 4 +-- play.py | 57 ++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 play.py diff --git a/generator/gpt2/gpt2_generator.py b/generator/gpt2/gpt2_generator.py index e257269..02df39a 100644 --- a/generator/gpt2/gpt2_generator.py +++ b/generator/gpt2/gpt2_generator.py @@ -11,13 +11,13 @@ tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) class GPT2Generator: - def __init__(self, generate_num=80, temperature=0.3, top_k=40, top_p=0.8): + def __init__(self, generate_num=80, temperature=0.4, top_k=40, top_p=0.8): self.generate_num=generate_num self.temp = temperature self.top_k = top_k self.top_p = top_p - self.model_name = "model_v2" + self.model_name = "model_v1" self.model_dir = "generator/gpt2/models" self.checkpoint_path = os.path.join(self.model_dir, self.model_name) diff --git a/install.sh b/install.sh index 8da8d0d..5fb1acb 100755 --- a/install.sh +++ b/install.sh @@ -1,10 +1,10 @@ -MODEL_DIRECTORY=aidungeon/generator/gpt2/models/model_v2 +MODEL_DIRECTORY=aidungeon/generator/gpt2/models/model_v1 if [ -d "$MODEL_DIRECTORY" ]; then echo "AIDungeon2 is already installed" else echo "Downloading AIDungeon2 Model" - gsutil -m cp -r gs://aidungeon2model/model_v2 ./generator/gpt2/models + gsutil -m cp -r gs://aidungeon2model/model_v1 ./generator/gpt2/models pip install -r requirements.txt > /dev/null fi diff --git a/play.py b/play.py new file mode 100644 index 0000000..b225920 --- /dev/null +++ b/play.py @@ -0,0 +1,57 @@ +from story.story_manager import * +from generator.gpt2.gpt2_generator import * + +def console_print(text, width=75): + last_newline = 0 + i = 0 + while i < len(text): + if text[i] == "\n": + last_newline = 0 + elif last_newline > width and text[i] == " ": + text = text[:i] + "\n" + text[i:] + last_newline = 0 + else: + last_newline += 1 + i += 1 + print(text) + + +def play_aidungeon_2(): + + print("Initializing AI Dungeon! (This might take a few minutes)") + generator = GPT2Generator() + prompt = get_story_start("knight") + context = get_context("knight") + story_manager = UnconstrainedStoryManager(generator) + story_manager.start_new_story(prompt, context=context) + + with open('opening.txt', 'r') as file: + starter = file.read() + + print(starter) + + print("\n") + console_print(context + str(story_manager.story)) + while True: + action = input("> ") + + if action != "": + action = action.strip() + + action = action[0].upper() + action[1:] + + action = "\n> " + action + "\n" + # action = remove_profanity(action) + # action = first_to_second_person(action) + + result = "\n" + story_manager.act(action) + if player_died(result): + console_print(result + "\nGAME OVER") + break + else: + console_print(result) + + +if __name__ == '__main__': + play_aidungeon_2() +