This commit is contained in:
Nick Walton
2019-11-18 18:29:38 -07:00
parent 8a049cef10
commit 55da36426a
3 changed files with 61 additions and 4 deletions
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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
+57
View File
@@ -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()