From 11d54e21cf4b324c32f73616bbb211b8cd78ca69 Mon Sep 17 00:00:00 2001 From: wassname Date: Wed, 25 Dec 2019 08:09:35 +0800 Subject: [PATCH] fixes --- gpt2generator.py | 3 ++- story/story_manager.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gpt2generator.py b/gpt2generator.py index 3baf8fa..802da01 100644 --- a/gpt2generator.py +++ b/gpt2generator.py @@ -66,7 +66,7 @@ def sample_sequence( context = torch.tensor(context, dtype=torch.long, device=device) context = context.unsqueeze(0).repeat(num_samples, 1) generated = context - USE_PAST = False + USE_PAST = True next_token = context outputs = None with torch.no_grad(): @@ -194,6 +194,7 @@ class GPT2Generator: truncate_multiple_sequences(context_tokens, self.max_history_tokens) context_tokens = list(itertools.chain(*context_tokens)) + if os.environ.get("DEBUG_GPT2", False): logger.debug("Text passing into model %s", self.tokenizer.decode(context_tokens, clean_up_tokenization_spaces=True, skip_special_tokens=True)) generated = 0 diff --git a/story/story_manager.py b/story/story_manager.py index cc52a69..73c9cdf 100644 --- a/story/story_manager.py +++ b/story/story_manager.py @@ -81,9 +81,9 @@ class Story: # When we have to much history we will take the last 10, and sample randomly from the rest # first take last mem_ind//2 all_inds = list(range(len(self.results))) + first = all_inds[:-mem_ind//2] last = all_inds[-mem_ind//2:] - first = all_inds[:mem_ind//2] - inds = sorted(last + random.sample(first, mem_ind//2)) + inds = sorted(random.sample(first, mem_ind//2)+last) else: inds = range(len(self.results)) logger.debug("Using history indices %s", inds)