From b0bdf41783fbef396eb5cbabe1660b0462f354df Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 10:55:30 -0600 Subject: [PATCH 01/19] update --- console_play.py | 2 +- generator/ctrl/ctrl_generator.py | 2 +- story/story_data.yaml | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/console_play.py b/console_play.py index 496ffc8..e60d3c6 100644 --- a/console_play.py +++ b/console_play.py @@ -24,7 +24,7 @@ def play_unconstrained(): generator = CTRLGenerator() #generator = WebGenerator(CRED_FILE) prompt = get_story_start("apocalypse") - context = get_context("apocalypse") + context = get_context("zombies") story_manager = UnconstrainedStoryManager(generator) story_manager.start_new_story(prompt, context=context) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index d325d5e..cb8a10f 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -219,7 +219,7 @@ class CTRLGenerator(): forbidden_tokens = ['', 'Sco@@', "&@@", "1]@@", "2]@@", "3]@@", "4]@@", "https://www.@@", "[@@", ":@@", "Edit", "&@@", "2:","1:", ":", "Edit@@", "EDI@@", "EDIT@@", "edit", "TL@@", "tl@@", ";@@", '**', "http://@@", "Redd@@", "UP@@", "mom", "Up@@", "Me:", "Update", "mom@@", "Part", - "http://www.@@", "edit@@", "*@@", "Writing", "Text@@", "\\@@", "
@@", "@@", " Date: Thu, 31 Oct 2019 11:08:21 -0600 Subject: [PATCH 02/19] update --- generator/ctrl/ctrl_generator.py | 13 +++++++------ story/utils.py | 11 ++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 91be38a..8b89832 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -20,7 +20,7 @@ def loss(labels, logits): class CTRLGenerator(): - def __init__(self, control_code="Apocalypse ", generate_num=28, temperature=0.5, topk=40, nucleus_prob=0): + def __init__(self, control_code="Apocalypse ", generate_num=28, temperature=0.3, topk=40, nucleus_prob=0): self.generate_num=generate_num model_dir = "generator/ctrl/training_utils/seqlen256_v1.ckpt/" @@ -135,7 +135,7 @@ class CTRLGenerator(): self.temperature=temperature self.nucleusprob = nucleus_prob - self.penalty = 1.1 + self.penalty = 1.2 self.topk=topk def configure_verb_probs(self, probabilities, options): @@ -212,14 +212,15 @@ class CTRLGenerator(): penalized_so_far = set() for _ in range(token + 1): generated_token = tokens_generated[0][_] - penalized_so_far.add(generated_token) - prompt_logits[_token][generated_token] /= self.penalty + if generated_token not in penalized_so_far: + penalized_so_far.add(generated_token) + prompt_logits[_token][generated_token] /= self.penalty # disallow some tokens forbidden_tokens = ['', 'Sco@@', "&@@", "1]@@", "2]@@", "3]@@", "4]@@", "https://www.@@", "[@@", ":@@", "Edit", "&@@", "2:","1:", ":", "Edit@@", "EDI@@", "EDIT@@", "edit", "TL@@", "tl@@", ";@@", '**', "http://@@", "Redd@@", "UP@@", "mom", "Up@@", "Me:", "Update", "mom@@", "Part", - "http://www.@@", "edit@@", "*@@", "Writing", "Text@@", "\\@@", "
@@", "@@", " last_period: - text = text[0:last_exclamation+1] - elif last_period > 0: - text = text[0:last_period+1] + last_punc = max(text.rfind('.'), text.rfind("!"), text.rfind("?")) + + if last_punc > 0: + text = text[0:last_punc+1] return cut_trailing_quotes(text) From 776279d914a3b6284f7137f223eff3854c847442 Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 11:13:09 -0600 Subject: [PATCH 03/19] update --- console_play.py | 2 +- generator/ctrl/ctrl_generator.py | 4 ++-- story/story_data.yaml | 2 ++ story/utils.py | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/console_play.py b/console_play.py index e60d3c6..545ae69 100644 --- a/console_play.py +++ b/console_play.py @@ -23,7 +23,7 @@ def console_print(str, pycharm=False): def play_unconstrained(): generator = CTRLGenerator() #generator = WebGenerator(CRED_FILE) - prompt = get_story_start("apocalypse") + prompt = get_story_start("zombies") context = get_context("zombies") story_manager = UnconstrainedStoryManager(generator) story_manager.start_new_story(prompt, context=context) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 8b89832..95c9a3d 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -20,7 +20,7 @@ def loss(labels, logits): class CTRLGenerator(): - def __init__(self, control_code="Apocalypse ", generate_num=28, temperature=0.3, topk=40, nucleus_prob=0): + def __init__(self, control_code="Apocalypse ", generate_num=28, temperature=0.4, topk=40, nucleus_prob=0): self.generate_num=generate_num model_dir = "generator/ctrl/training_utils/seqlen256_v1.ckpt/" @@ -271,7 +271,7 @@ class CTRLGenerator(): def generate(self, prompt, options=None): prompt = self.prompt_replace(prompt) - debug_print = False + debug_print = True if debug_print: print("\n\n*****DEBUG*****") diff --git a/story/story_data.yaml b/story/story_data.yaml index 0f1c5d0..18215b7 100644 --- a/story/story_data.yaml +++ b/story/story_data.yaml @@ -9,6 +9,8 @@ prompts: apocalypse: "You walk for two hours and take a break. You've left the town you were in and are now in a more rural area. There's a building to your right and you see " + zombies: "You're on top of a building. You look over the city and see roaming undead everywhere. " + action_verbs: classic: ["You tell", "You use", "You go", "You"] diff --git a/story/utils.py b/story/utils.py index 6f2e4f5..a6453ea 100644 --- a/story/utils.py +++ b/story/utils.py @@ -118,6 +118,7 @@ first_to_second_mappings = [ ("Ive", "you've"), ("I am", "you are"), ("I", "you"), + ("i", "you"), ("I've", "you've"), ("my", "your"), ("we","you"), From 98eb3c6c8fa5a9094a2f59534aa30a23d00b906b Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 11:17:59 -0600 Subject: [PATCH 04/19] update --- console_play.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/console_play.py b/console_play.py index 545ae69..496ffc8 100644 --- a/console_play.py +++ b/console_play.py @@ -23,8 +23,8 @@ def console_print(str, pycharm=False): def play_unconstrained(): generator = CTRLGenerator() #generator = WebGenerator(CRED_FILE) - prompt = get_story_start("zombies") - context = get_context("zombies") + prompt = get_story_start("apocalypse") + context = get_context("apocalypse") story_manager = UnconstrainedStoryManager(generator) story_manager.start_new_story(prompt, context=context) From 435d2c02097ff4b0035f4540f6f16a768146a735 Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 11:20:28 -0600 Subject: [PATCH 05/19] update --- story/story_data.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/story/story_data.yaml b/story/story_data.yaml index 18215b7..13a9782 100644 --- a/story/story_data.yaml +++ b/story/story_data.yaml @@ -7,7 +7,7 @@ prompts: vague_police: "You are a police officer. You get to work and " - apocalypse: "You walk for two hours and take a break. You've left the town you were in and are now in a more rural area. There's a building to your right and you see " + apocalypse: "You are " zombies: "You're on top of a building. You look over the city and see roaming undead everywhere. " From e9c05c89bd4183d1e65dad05edbb89d8b3b63ab5 Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 11:20:45 -0600 Subject: [PATCH 06/19] update --- generator/ctrl/ctrl_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 95c9a3d..1126a61 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -20,7 +20,7 @@ def loss(labels, logits): class CTRLGenerator(): - def __init__(self, control_code="Apocalypse ", generate_num=28, temperature=0.4, topk=40, nucleus_prob=0): + def __init__(self, control_code="Apocalypse ", generate_num=28, temperature=0.6, topk=40, nucleus_prob=0): self.generate_num=generate_num model_dir = "generator/ctrl/training_utils/seqlen256_v1.ckpt/" From 6b09c9fe00df8e7537ce6e9079a28c8f30528a07 Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 12:08:29 -0600 Subject: [PATCH 07/19] update --- generator/ctrl/ctrl_generator.py | 2 +- story/story_data.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 1126a61..8f2ce14 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -20,7 +20,7 @@ def loss(labels, logits): class CTRLGenerator(): - def __init__(self, control_code="Apocalypse ", generate_num=28, temperature=0.6, topk=40, nucleus_prob=0): + def __init__(self, control_code="Apocalypse ", generate_num=28, temperature=0.5, topk=40, nucleus_prob=0): self.generate_num=generate_num model_dir = "generator/ctrl/training_utils/seqlen256_v1.ckpt/" diff --git a/story/story_data.yaml b/story/story_data.yaml index 13a9782..71bce64 100644 --- a/story/story_data.yaml +++ b/story/story_data.yaml @@ -7,7 +7,7 @@ prompts: vague_police: "You are a police officer. You get to work and " - apocalypse: "You are " + apocalypse: "You walk for two hours and take a break. You've left the town you were in and are now in a more rural area. You look around you and see " zombies: "You're on top of a building. You look over the city and see roaming undead everywhere. " From 0bb9bfff3e637531b0eb23edd246b285921df6bc Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 12:26:20 -0600 Subject: [PATCH 08/19] update --- console_play.py | 37 +++++++------------------------- generator/ctrl/ctrl_generator.py | 3 ++- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/console_play.py b/console_play.py index 496ffc8..771406a 100644 --- a/console_play.py +++ b/console_play.py @@ -34,6 +34,14 @@ def play_unconstrained(): action = input("> ") if action != "": + + if action[-1] == "." or action[-1] == "?" or action[-1] == "!": + action = action[:-1] + if "you " == action.lower()[0:4]: + action = action[4:] + if "i " == action.lower()[0:2]: + action = action[2:] + action = " You " + action + ". " action = first_to_second_person(action) @@ -91,35 +99,6 @@ def play_cached(): console_print(result) -def play_cached_hospital(): - print("\n") - generator = CTRLGenerator() - story_start = "haunted" - prompt = get_story_start(story_start) - story_manager = CTRLStoryManager(generator) - story_manager.enable_caching(CRED_FILE, bucket_name="haunted-hospital") - - story_manager.start_new_story(prompt) - - console_print("\n") - console_print(str(story_manager.story)) - possible_actions = story_manager.get_possible_actions() - while (True): - console_print("\nOptions:") - for i, action in enumerate(possible_actions): - console_print(str(i) + ") " + action) - - result = None - while (result == None): - action_choice = input("Which action do you choose? ") - if action_choice is "print story": - print(story_manager.story) - continue - print("\n") - result, possible_actions = story_manager.act(action_choice) - - console_print(result) - if __name__ == '__main__': play_unconstrained() diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 8f2ce14..ef50cef 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -220,7 +220,8 @@ class CTRLGenerator(): forbidden_tokens = ['', 'Sco@@', "&@@", "1]@@", "2]@@", "3]@@", "4]@@", "https://www.@@", "[@@", ":@@", "Edit", "&@@", "2:","1:", ":", "Edit@@", "EDI@@", "EDIT@@", "edit", "TL@@", "tl@@", ";@@", '**', "http://@@", "Redd@@", "UP@@", "mom", "Up@@", "Me:", "Update", "mom@@", "Part", - "http://www.@@", "edit@@", "*@@", "Writing", "Text@@", "\\@@", "
@@", "@@", " Date: Thu, 31 Oct 2019 12:41:51 -0600 Subject: [PATCH 09/19] fix --- generator/ctrl/ctrl_generator.py | 2 +- generator/pytorch/pytorch_generator.py | 155 ------------------------- {data => other}/storytree.py | 0 3 files changed, 1 insertion(+), 156 deletions(-) delete mode 100644 generator/pytorch/pytorch_generator.py rename {data => other}/storytree.py (100%) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index ef50cef..31239c9 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -221,7 +221,7 @@ class CTRLGenerator(): "Edit", "&@@", "2:","1:", ":", "Edit@@", "EDI@@", "EDIT@@", "edit", "TL@@", "tl@@", ";@@", '**', "http://@@", "Redd@@", "UP@@", "mom", "Up@@", "Me:", "Update", "mom@@", "Part", "http://www.@@", "edit@@", "*@@", "Writing", "Text@@", "\\@@", "
@@", " """ - - -def set_seed(seed, n_gpu=1): - np.random.seed(seed) - torch.manual_seed(seed) - if n_gpu > 0: - torch.cuda.manual_seed_all(seed) - - -def top_k_top_p_filtering(logits, top_k=0, top_p=0.0, filter_value=-float('Inf')): - """ Filter a distribution of logits using top-k and/or nucleus (top-p) filtering - Args: - logits: logits distribution shape (vocabulary size) - top_k > 0: keep only top k tokens with highest probability (top-k filtering). - top_p > 0.0: keep the top tokens with cumulative probability >= top_p (nucleus filtering). - Nucleus filtering is described in Holtzman et al. (http://arxiv.org/abs/1904.09751) - From: https://gist.github.com/thomwolf/1a5a29f6962089e871b94cbd09daf317 - """ - assert logits.dim() == 1 # batch size 1 for now - could be updated for more but the code would be less clear - top_k = min(top_k, logits.size(-1)) # Safety check - if top_k > 0: - # Remove all tokens with a probability less than the last token of the top-k - indices_to_remove = logits < torch.topk(logits, top_k)[0][..., -1, None] - logits[indices_to_remove] = filter_value - - if top_p > 0.0: - sorted_logits, sorted_indices = torch.sort(logits, descending=True) - cumulative_probs = torch.cumsum(F.softmax(sorted_logits, dim=-1), dim=-1) - - # Remove tokens with cumulative probability above the threshold - sorted_indices_to_remove = cumulative_probs > top_p - # Shift the indices to the right to keep also the first token above the threshold - sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone() - sorted_indices_to_remove[..., 0] = 0 - - indices_to_remove = sorted_indices[sorted_indices_to_remove] - logits[indices_to_remove] = filter_value - return logits - - -def sample_sequence(model, length, context, num_samples=1, temperature=1, top_k=0, top_p=0.0, is_xlnet=False, device='cpu'): - context = torch.tensor(context, dtype=torch.long, device=device) - context = context.unsqueeze(0).repeat(num_samples, 1) - generated = context - with torch.no_grad(): - for _ in trange(length): - - inputs = {'input_ids': generated} - if is_xlnet: - # XLNet is a direct (predict same token, not next token) and bi-directional model by default - # => need one additional dummy token in the input (will be masked), attention mask and target mapping (see model docstring) - input_ids = torch.cat((generated, torch.zeros((1, 1), dtype=torch.long, device=device)), dim=1) - perm_mask = torch.zeros((1, input_ids.shape[1], input_ids.shape[1]), dtype=torch.float, device=device) - perm_mask[:, :, -1] = 1.0 # Previous tokens don't see last token - target_mapping = torch.zeros((1, 1, input_ids.shape[1]), dtype=torch.float, device=device) - target_mapping[0, 0, -1] = 1.0 # predict last token - inputs = {'input_ids': input_ids, 'perm_mask': perm_mask, 'target_mapping': target_mapping} - - outputs = model(**inputs) # Note: we could also use 'past' with GPT-2/Transfo-XL/XLNet (cached hidden-states) - next_token_logits = outputs[0][0, -1, :] / temperature - filtered_logits = top_k_top_p_filtering(next_token_logits, top_k=top_k, top_p=top_p) - next_token = torch.multinomial(F.softmax(filtered_logits, dim=-1), num_samples=1) - generated = torch.cat((generated, next_token.unsqueeze(0)), dim=1) - return generated - - -def main(): - - device = torch.device("cuda" if torch.cuda.is_available() else "cpu") - seed = 150 - set_seed(seed) - - model_type = "gpt2" - model_name = "gpt2-medium" - model_class, tokenizer_class = MODEL_CLASSES[model_type] - tokenizer = tokenizer_class.from_pretrained(model_name) - model = model_class.from_pretrained(model_name) - model.to(device) - model.eval() - - temperature = 0.9 - top_k = 40 - top_p = 1.0 - - length = 100 - while True: - raw_text = input("Model prompt >>> ") - if model_type in ["transfo-xl", "xlnet"]: - # Models with memory likes to have a long prompt for short inputs. - raw_text = (PADDING_TEXT) + raw_text - context_tokens = tokenizer.encode(raw_text) - out = sample_sequence( - model=model, - context=context_tokens, - length=length, - temperature=temperature, - top_k=top_k, - top_p=top_p, - device=device, - is_xlnet=bool(model_type == "xlnet") - ) - out = out[0, len(context_tokens):].tolist() - text = tokenizer.decode(out, clean_up_tokenization_spaces=True) - print(text) - - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/data/storytree.py b/other/storytree.py similarity index 100% rename from data/storytree.py rename to other/storytree.py From 7b6aff5bdada9be24decee77f72ba472b1452fe5 Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 12:51:17 -0600 Subject: [PATCH 10/19] fixthethe --- generator/ctrl/ctrl_generator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 31239c9..4dabc24 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -226,6 +226,10 @@ class CTRLGenerator(): for forbidden_token in forbidden_tokens: prompt_logits[_token][self.word2idx[forbidden_token]] = -1e8 + last_ind = tokens_generated[0][token] + if self.idx2word[last_ind] == "the": + prompt_logits[_token][self.word2idx["the"]] = -1e8 + if forbid_newline: prompt_logits[_token][self.word2idx['\n']] = -1e8 else: @@ -305,7 +309,6 @@ class CTRLGenerator(): elif self.idx2word[idx] == '\n': 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: From cc450d1fdce630c011f155a59785d7a66fcff19c Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 12:52:01 -0600 Subject: [PATCH 11/19] fixthethe --- generator/ctrl/ctrl_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 4dabc24..575724c 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -221,7 +221,7 @@ class CTRLGenerator(): "Edit", "&@@", "2:","1:", ":", "Edit@@", "EDI@@", "EDIT@@", "edit", "TL@@", "tl@@", ";@@", '**', "http://@@", "Redd@@", "UP@@", "mom", "Up@@", "Me:", "Update", "mom@@", "Part", "http://www.@@", "edit@@", "*@@", "Writing", "Text@@", "\\@@", "
@@", " Date: Thu, 31 Oct 2019 13:22:13 -0600 Subject: [PATCH 12/19] fixthethe --- generator/ctrl/ctrl_generator.py | 12 +++++------- story/utils.py | 4 +++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 575724c..80739ae 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -166,8 +166,8 @@ class CTRLGenerator(): return prompt def result_replace(self, result): - # print("\n\nBEFORE RESULT_REPLACE:") - # print(repr(result)) + print("\n\nBEFORE RESULT_REPLACE:") + print(repr(result)) result = cut_trailing_sentence(result) first_letter_capitalized = result[0].isupper() @@ -180,11 +180,9 @@ class CTRLGenerator(): if not first_letter_capitalized: result = result[0].lower() + result[1:] - while("\n \n \n " in result): - result = result.replace("\n \n \n ", "\n \n ") - # print("\n\nAFTER RESULT_REPLACE:") - # print(repr(result)) + print("\n\nAFTER RESULT_REPLACE:") + print(repr(result)) return result @@ -221,7 +219,7 @@ class CTRLGenerator(): "Edit", "&@@", "2:","1:", ":", "Edit@@", "EDI@@", "EDIT@@", "edit", "TL@@", "tl@@", ";@@", '**', "http://@@", "Redd@@", "UP@@", "mom", "Up@@", "Me:", "Update", "mom@@", "Part", "http://www.@@", "edit@@", "*@@", "Writing", "Text@@", "\\@@", "
@@", " 0: @@ -84,6 +85,7 @@ def cut_trailing_sentence(text): def replace_outside_quotes(text, current_word, repl_word): + text = standardize_punctuation(text) reg_expr = re.compile(current_word + '(?=([^"]*"[^"]*")*[^"]*$)') @@ -104,7 +106,7 @@ def mapping_variation_pairs(mapping): # Change you it's before a punctuation if mapping[0] is "you": mapping = ("you", "me") - mapping_list.append((" " + mapping[0]+"\,", " " + mapping[1]+",")) + mapping_list.append((" " + mapping[0]+",", " " + mapping[1]+",")) mapping_list.append((" " + mapping[0]+"\?", " " + mapping[1]+"\?")) mapping_list.append((" " + mapping[0]+"\!", " " + mapping[1]+"\!")) mapping_list.append((" " + mapping[0] + "\.", " " + mapping[1] + ".")) From 8b36b3a0730c6451a26cc74ca1b388d12bc29b9e Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 13:29:45 -0600 Subject: [PATCH 13/19] fixthethe --- generator/ctrl/ctrl_generator.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 80739ae..d61bfde 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -303,11 +303,14 @@ class CTRLGenerator(): idx = self.generate_next_token(token, tokens_generated, options, num_new_lines, token_num, first_token=first_token, forbid_newline=False) is_nothing = len(cut_trailing_sentence(result)) == 0 or len(cut_trailing_quotes(result)) == 0 if self.idx2word[idx] == '\n' and token_num > 7 and not is_nothing: + if debug_print: + print("Early stop") return self.result_replace(result) elif self.idx2word[idx] == '\n': 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="_") From b01125e984b3ddcd024ddf5161074a1dcea58d13 Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 13:38:22 -0600 Subject: [PATCH 14/19] fixthethe --- generator/ctrl/ctrl_generator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index d61bfde..3cd8fec 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -310,7 +310,7 @@ 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="_") @@ -319,6 +319,7 @@ class CTRLGenerator(): tokens_generated_so_far = re.sub('(@@ )', '', string=tokens_generated_so_far) tokens_generated_so_far = re.sub('(@@ ?$)', '', string=tokens_generated_so_far) result = tokens_generated_so_far + print("\n\nGenerated so far, ", result, "\n\n") token_num += 1 if debug_print: From a060b2e6918e1edf1b4a2c67e62098e8ff3a1581 Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 13:41:16 -0600 Subject: [PATCH 15/19] fixthethe --- generator/ctrl/ctrl_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 3cd8fec..3f1a32b 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -315,7 +315,7 @@ class CTRLGenerator(): if debug_print: print(repr(self.idx2word[idx]), end="_") - tokens_generated_so_far = ' '.join([self.idx2word[c] for c in tokens_generated[0][len(text):].squeeze()[:token + 2]]) + tokens_generated_so_far = ' '.join([self.idx2word[c] for c in tokens_generated[0][len(text):token+2].squeeze()[:token + 2]]) tokens_generated_so_far = re.sub('(@@ )', '', string=tokens_generated_so_far) tokens_generated_so_far = re.sub('(@@ ?$)', '', string=tokens_generated_so_far) result = tokens_generated_so_far From 725e68aeea8a4040aea8bf4987770cdcde01c04d Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 13:43:37 -0600 Subject: [PATCH 16/19] fixthethe --- generator/ctrl/ctrl_generator.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 3f1a32b..890a25c 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -315,7 +315,9 @@ class CTRLGenerator(): if debug_print: print(repr(self.idx2word[idx]), end="_") - tokens_generated_so_far = ' '.join([self.idx2word[c] for c in tokens_generated[0][len(text):token+2].squeeze()[:token + 2]]) + import pdb + pdb.set_trace() + tokens_generated_so_far = ' '.join([self.idx2word[c] for c in tokens_generated[0][len(text):].squeeze()[:token + 2]]) tokens_generated_so_far = re.sub('(@@ )', '', string=tokens_generated_so_far) tokens_generated_so_far = re.sub('(@@ ?$)', '', string=tokens_generated_so_far) result = tokens_generated_so_far From bbe0a89ab3a21c27a616496d3688c1ada788f97e Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 13:49:30 -0600 Subject: [PATCH 17/19] fixthethe --- generator/ctrl/ctrl_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index 890a25c..c90a48d 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -317,7 +317,7 @@ class CTRLGenerator(): import pdb pdb.set_trace() - tokens_generated_so_far = ' '.join([self.idx2word[c] for c in tokens_generated[0][len(text):].squeeze()[:token + 2]]) + tokens_generated_so_far = ' '.join([self.idx2word[c] for c in tokens_generated[0][len(text):token+2].squeeze()]) tokens_generated_so_far = re.sub('(@@ )', '', string=tokens_generated_so_far) tokens_generated_so_far = re.sub('(@@ ?$)', '', string=tokens_generated_so_far) result = tokens_generated_so_far From 67a958c81b9f0eef5c6396e562b8f5d87a9e01ec Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 13:53:40 -0600 Subject: [PATCH 18/19] fixthethe --- generator/ctrl/ctrl_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index c90a48d..f655fcf 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -317,7 +317,7 @@ class CTRLGenerator(): import pdb pdb.set_trace() - tokens_generated_so_far = ' '.join([self.idx2word[c] for c in tokens_generated[0][len(text):token+2].squeeze()]) + tokens_generated_so_far = ' '.join([self.idx2word[c] for c in tokens_generated[0][len(text):token+2]]) tokens_generated_so_far = re.sub('(@@ )', '', string=tokens_generated_so_far) tokens_generated_so_far = re.sub('(@@ ?$)', '', string=tokens_generated_so_far) result = tokens_generated_so_far From 16ca6dea8f0875cbf2934a96f696963818f19c2f Mon Sep 17 00:00:00 2001 From: nickwalton Date: Thu, 31 Oct 2019 13:56:14 -0600 Subject: [PATCH 19/19] fixthethe --- generator/ctrl/ctrl_generator.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/generator/ctrl/ctrl_generator.py b/generator/ctrl/ctrl_generator.py index f655fcf..0c64180 100644 --- a/generator/ctrl/ctrl_generator.py +++ b/generator/ctrl/ctrl_generator.py @@ -166,8 +166,8 @@ class CTRLGenerator(): return prompt def result_replace(self, result): - print("\n\nBEFORE RESULT_REPLACE:") - print(repr(result)) + # print("\n\nBEFORE RESULT_REPLACE:") + # print(repr(result)) result = cut_trailing_sentence(result) first_letter_capitalized = result[0].isupper() @@ -180,9 +180,9 @@ class CTRLGenerator(): if not first_letter_capitalized: result = result[0].lower() + result[1:] - - print("\n\nAFTER RESULT_REPLACE:") - print(repr(result)) + # + # print("\n\nAFTER RESULT_REPLACE:") + # print(repr(result)) return result @@ -225,8 +225,6 @@ class CTRLGenerator(): prompt_logits[_token][self.word2idx[forbidden_token]] = -1e8 last_ind = tokens_generated[0][token] - if self.idx2word[last_ind] == "the": - prompt_logits[_token][self.word2idx["the"]] = -1e8 if forbid_newline: prompt_logits[_token][self.word2idx['\n']] = -1e8 @@ -303,8 +301,6 @@ class CTRLGenerator(): idx = self.generate_next_token(token, tokens_generated, options, num_new_lines, token_num, first_token=first_token, forbid_newline=False) is_nothing = len(cut_trailing_sentence(result)) == 0 or len(cut_trailing_quotes(result)) == 0 if self.idx2word[idx] == '\n' and token_num > 7 and not is_nothing: - if debug_print: - print("Early stop") return self.result_replace(result) elif self.idx2word[idx] == '\n': idx = self.generate_next_token(token, tokens_generated, options, num_new_lines, token_num, @@ -321,7 +317,6 @@ class CTRLGenerator(): tokens_generated_so_far = re.sub('(@@ )', '', string=tokens_generated_so_far) tokens_generated_so_far = re.sub('(@@ ?$)', '', string=tokens_generated_so_far) result = tokens_generated_so_far - print("\n\nGenerated so far, ", result, "\n\n") token_num += 1 if debug_print: