Merge pull request #85 from AIDungeon/develop

Develop -> master
This commit is contained in:
Benjamin Bay
2019-12-09 22:44:03 -08:00
committed by GitHub
13 changed files with 62 additions and 57 deletions
+1
View File
@@ -1,5 +1,6 @@
import csv
import json
from story.utils import *
+2 -1
View File
@@ -1,7 +1,8 @@
import json
from story.utils import *
import os
from story.utils import *
def load_stories(file):
+4 -2
View File
@@ -1,7 +1,9 @@
import json
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import json
"""
format of tree is
+1
View File
@@ -1,5 +1,6 @@
import os
import sys
import requests
from tqdm import tqdm
+7 -6
View File
@@ -1,14 +1,15 @@
from story.utils import *
import json
import os
import warnings
warnings.filterwarnings("ignore")
import os
import numpy as np
import tensorflow as tf
from generator.gpt2.src import encoder, model, sample
from story.utils import *
warnings.filterwarnings("ignore")
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
from generator.gpt2.src import sample, encoder, model
import json
import numpy as np
class GPT2Generator:
+3 -2
View File
@@ -1,10 +1,11 @@
"""Byte pair encoding utilities"""
import os
import json
import regex as re
import os
from functools import lru_cache
import regex as re
@lru_cache()
def bytes_to_unicode():
-1
View File
@@ -1,5 +1,4 @@
import tensorflow as tf
from generator.gpt2.src import model
+2 -2
View File
@@ -1,7 +1,7 @@
import tarfile
import os
import gpt_2_simple as gpt2
import tarfile
import gpt_2_simple as gpt2
model_name = "1558M"
if not os.path.isdir(os.path.join("models", model_name)):
+2 -1
View File
@@ -1,6 +1,7 @@
from google.cloud import storage
import os
from google.cloud import storage
class Cacher:
def __init__(self, credentials_file, bucket_name="dungeon-cache"):
+5 -2
View File
@@ -1,7 +1,10 @@
from story.story_manager import *
import os
import sys
import time
from generator.gpt2.gpt2_generator import *
from story.story_manager import *
from story.utils import *
import time, sys, os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
+7 -4
View File
@@ -1,9 +1,12 @@
from story.story_manager import *
from generator.human_dm import *
import os
import sys
import time
from generator.gpt2.gpt2_generator import *
from story.utils import *
from generator.human_dm import *
from play import *
import time, sys, os
from story.story_manager import *
from story.utils import *
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
+4 -3
View File
@@ -1,9 +1,10 @@
from story.utils import *
import json
import os
import subprocess
import uuid
from subprocess import Popen
import subprocess
import os
from story.utils import *
class Story:
+24 -33
View File
@@ -1,11 +1,12 @@
# coding: utf-8
import re
import yaml
from difflib import SequenceMatcher
import yaml
from profanityfilter import ProfanityFilter
YAML_FILE = "story/story_data.yaml"
from profanityfilter import ProfanityFilter
with open("story/extra_censored_words.txt", "r") as f:
more_words = [l.replace("\n", "") for l in f.readlines()]
@@ -47,41 +48,31 @@ 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)",
"you ((go|get) (in)?to|arrive (at|in)) (heaven|paradise)",
]
return any(re.search(regexp, lower_text) for regexp in won_phrases)
def remove_profanity(text):