From 81e8979e374c43f139504fc93a1ad41bf88be634 Mon Sep 17 00:00:00 2001 From: Nick Walton Date: Tue, 10 Dec 2019 12:06:30 -0700 Subject: [PATCH] Pruned censor list to get rid of words that shouldn't be censored. Also added ability to turn censor on and off (#94) --- generator/gpt2/gpt2_generator.py | 6 +- play.py | 7 +++ story/censored_words.txt | 100 +++++++++++++++++++++++++++++++ story/extra_censored_words.txt | 3 - story/utils.py | 8 +-- 5 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 story/censored_words.txt delete mode 100644 story/extra_censored_words.txt diff --git a/generator/gpt2/gpt2_generator.py b/generator/gpt2/gpt2_generator.py index cd74562..b9ad4ea 100644 --- a/generator/gpt2/gpt2_generator.py +++ b/generator/gpt2/gpt2_generator.py @@ -13,11 +13,12 @@ tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) class GPT2Generator: - def __init__(self, generate_num=60, temperature=0.4, top_k=40, top_p=0.9): + def __init__(self, generate_num=60, temperature=0.4, top_k=40, top_p=0.9, censor=True): self.generate_num = generate_num self.temp = temperature self.top_k = top_k self.top_p = top_p + self.censor = censor self.model_name = "model_v5" self.model_dir = "generator/gpt2/models" @@ -79,7 +80,8 @@ class GPT2Generator: result = result.replace("*", "") result = result.replace("\n\n", "\n") # result = first_to_second_person(result) - result = remove_profanity(result) + if self.censor: + result = remove_profanity(result) if not first_letter_capitalized: result = result[0].lower() + result[1:] diff --git a/play.py b/play.py index c4e811d..31cd2bd 100644 --- a/play.py +++ b/play.py @@ -88,6 +88,7 @@ def instructions(): text += '\n "load" Asks for a save ID and loads the game if the ID is valid' text += '\n "print" Prints a transcript of your adventure (without extra newline formatting)' text += '\n "help" Prints these instructions again' + text += '\n "censor off/on" to turn censoring off or on.' return text @@ -159,6 +160,12 @@ def play_aidungeon_2(): elif action == "help": console_print(instructions()) + elif action == "censor off": + generator.censor = False + + elif action == "censor on": + generator.censor = True + elif action == "save": if upload_story: id = story_manager.story.save_to_storage() diff --git a/story/censored_words.txt b/story/censored_words.txt new file mode 100644 index 0000000..ea7467c --- /dev/null +++ b/story/censored_words.txt @@ -0,0 +1,100 @@ +BlowJob +Clit +Cock +CockSucker +Goddamned +MothaFucker +MothaFuker +MothaFukkah +MothaFukker +MotherFucker +MotherFukah +MotherFuker +MotherFukkah +MotherFukker +MuthaFucker +MuthaFukah +MuthaFuker +MuthaFukkah +MuthaFukker +Shitty +Shity +anus +ass +asshole +assholes +assrammer +asswipe +b1tch +bastard +bastards +bitch +bitches +blowjob +boobs +bullshit +butthole +buttwipe +clit +clits +cock +cockhead +cocks +cocksucker +cum +cunt +cunts +damn +dick +dildo +dildos +ejackulate +ejakulate +fatass +foreskin +fuck +fucka +fucker +fuckin +fucking +fucks +fuk +hell +hells +jackoff +jerkoff +jizz +masturbate +motherfucker +nigga +niggas +nigger +nigur +niiger +niigr +nutsack +orgasm +penis +pussy +rectum +scrotum +semen +sexy +shit +shits +testical +testicle +tit +tits +titt +vag1na +vagiina +vagina +vaj1na +vajina +whore +xrated +xxx +rape +shitting +raped diff --git a/story/extra_censored_words.txt b/story/extra_censored_words.txt deleted file mode 100644 index af81c80..0000000 --- a/story/extra_censored_words.txt +++ /dev/null @@ -1,3 +0,0 @@ -rape -shitting -raped \ No newline at end of file diff --git a/story/utils.py b/story/utils.py index 801dcf6..73e3047 100644 --- a/story/utils.py +++ b/story/utils.py @@ -8,10 +8,10 @@ from profanityfilter import ProfanityFilter YAML_FILE = "story/story_data.yaml" -with open("story/extra_censored_words.txt", "r") as f: - more_words = [l.replace("\n", "") for l in f.readlines()] +with open("story/censored_words.txt", "r") as f: + censored_words = [l.replace("\n", "") for l in f.readlines()] -pf = ProfanityFilter(extra_censor_list=more_words) +pf = ProfanityFilter(custom_censor_list=censored_words) def console_print(text, width=75): @@ -285,4 +285,4 @@ def second_to_first_person(text): for variation in variations: text = replace_outside_quotes(text, variation[0], variation[1]) - return capitalize_first_letters(text[1:]) + return capitalize_first_letters(text[1:]) \ No newline at end of file