This commit is contained in:
nickwalton
2019-10-31 10:55:42 -06:00
3 changed files with 16 additions and 6 deletions
+2 -3
View File
@@ -265,9 +265,6 @@ class CTRLGenerator():
tf.random.categorical(np.expand_dims(prompt_logits[_token][pruned_list], 0), num_samples=1).numpy())
idx = pruned_list[chosen_idx]
# assign the token for generation
tokens_generated[0][token + 1] = idx
return idx
def generate(self, prompt, options=None):
@@ -307,6 +304,8 @@ class CTRLGenerator():
idx = self.generate_next_token(token, tokens_generated, options, num_new_lines, token_num,
first_token=first_token, forbid_newline=True)
# assign the token for generation
tokens_generated[0][token + 1] = idx
if debug_print:
print(repr(self.idx2word[idx]), end="_")
+1 -1
View File
@@ -214,7 +214,7 @@ class CTRLStoryManager(ConstrainedStoryManager):
for phrase in self.action_phrases:
result = self.generate_action_result(self.story_context(), phrase, options=options)
action_verb = result[0].split()[1]
print("blacklisted verb is ", action_verb)
options["word_blacklist"][0].append(action_verb)
results.append(result)
return results
+13 -2
View File
@@ -188,5 +188,16 @@ def second_to_first_person(text):
return capitalize_first_letters(text[1:])
if __name__ == '__main__':
text = 'You wake up in an old rundown hospital with no memory of how you got there. You look around and see a nurse standing over me. "Hey buddy, you okay?" she asks. She looks at me like I\'m crazy. '
print(first_to_second_person(text))
result = 'The only thing they can tell you is, "We have nowhere else to…"'
result = result.replace('."', '".')
result = result.replace("#", "")
result = result.replace("*", "")
result = first_to_second_person(result)
result = remove_profanity(result)
while ("\n \n \n " in result):
result = result.replace("\n \n \n ", "\n \n ")
print(result)