From 842d89d496b9d9c76fba47e513349630daf62dc5 Mon Sep 17 00:00:00 2001 From: Benjamin Bay <48391872+ben-bay@users.noreply.github.com> Date: Mon, 9 Dec 2019 20:50:36 -0800 Subject: [PATCH] Terminal state logic (#84) * Update AIDungeon_2.ipynb * Update AIDungeon_2.ipynb * Update AIDungeon_2.ipynb * Fix "Notebook loading error" on colab (#81) * Fix "Notebook loading error" on colab There was a missing comma after the array element on line 46, so I added it. From what I can tell, this was causing the colab to be unable to load. * Update AIDungeon_2.ipynb * Update requirements.txt * improved terminal state logic. --- AIDungeon_2.ipynb | 7 ++++--- requirements.txt | 3 ++- story/utils.py | 51 +++++++++++++++++++---------------------------- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/AIDungeon_2.ipynb b/AIDungeon_2.ipynb index 49c66a1..12f9341 100644 --- a/AIDungeon_2.ipynb +++ b/AIDungeon_2.ipynb @@ -32,7 +32,7 @@ "If you want to help, best thing you can do is to **[download this torrent file with game files](https://github.com/nickwalton/AIDungeon/files/3935881/model_v5.torrent.zip)** and **seed it** indefinitely to the best of your ability. This will help new players download this game faster, and discover the vast worlds of AIDungeon2!\n", "\n", "- Follow @nickwalton00 on Twitter for updates on when it will be available again.\n", - "- **[Support AI Dungeon 2](https://www.patreon.com/posts/update-32193930) on Patreon**\n", + "- **[Support AI Dungeon 2](https://www.patreon.com/AIDungeon) on Patreon to help me to continue improving the game with all the awesome ideas I have for its future!**\n", "\n", "## How to play\n", "1. Click \"Tools\"-> \"Settings...\" -> \"Theme\" -> \"Dark\" (optional but recommended)\n", @@ -43,7 +43,8 @@ "\n", "## About\n", "* While you wait you can [read adventures others have had](https://aidungeon.io/)\n", - "* [Read more](https://pcc.cs.byu.edu/2019/11/21/ai-dungeon-2-creating-infinitely-generated-text-adventures-with-deep-learning-language-models/) about how AI Dungeon 2 is made." + "* [Read more](https://pcc.cs.byu.edu/2019/11/21/ai-dungeon-2-creating-infinitely-generated-text-adventures-with-deep-learning-language-models/) about how AI Dungeon 2 is made.", + "- **[Support AI Dungeon 2](https://www.patreon.com/bePatron?u=19115449) on Patreon to help me to continue improving the game with all the awesome ideas I have for its future!**\n" ] }, { @@ -80,4 +81,4 @@ "outputs": [] } ] -} \ No newline at end of file +} diff --git a/requirements.txt b/requirements.txt index 670bb7a..fcaa7a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ google-cloud-storage +gsutil numpy -regex profanityfilter pyyaml +regex tensorflow==1.15 diff --git a/story/utils.py b/story/utils.py index 0a33dfc..6728cff 100644 --- a/story/utils.py +++ b/story/utils.py @@ -48,41 +48,30 @@ def get_num_options(num): def player_died(text): - - # reg_phrases = ["You[a-zA-Z ]* die.", "you[a-zA-Z ]* die.", "You[a-zA-Z ]* die ", "you[a-zA-Z ]* die ",] - # - # for phrase in reg_phrases: - # reg_expr = re.compile(phrase) - # matches = re.findall(reg_expr, text) - # if len(matches) > 0: - # return True - - dead_phrases = [ - "you die", - "You die", - "you died", - "you are dead", - "You died", - "You are dead", - "You're dead", - "you're dead", - "you have died", - "You have died", - "you bleed out", + """ + TODO: Add in more sophisticated NLP, maybe a custom classifier + trained on hand-labelled data that classifies second-person + statements as resulting in death or not. + """ + lower_text = text.lower() + you_dead_regexps = [ + "you('re| are) (dead|killed|slain|no more|nonexistent)", + "you (die|pass away|perish|suffocate|drown|bleed out)", + "you('ve| have) (died|perished|suffocated|drowned|been (killed|slain))", + "you \w* to death", + "you \w+ yourself to death", ] - for phrase in dead_phrases: - if phrase in text: - return True - return False + return any(re.search(regexp, lower_text) for regexp in you_dead_regexps) def player_won(text): - - won_phrases = ["live happily ever after", "you live forever"] - for phrase in won_phrases: - if phrase in text: - return True - return False + lower_text = text.lower() + won_phrases = [ + "live happily ever after", + "(you)? live (forever|eternally|for eternity)", + "you (are|become|turn into) (a)? (deity|god)", + ] + return any(re.search(regexp, lower_text) for regexp in won_phrases) def remove_profanity(text):