This commit is contained in:
wassname
2019-12-25 08:09:35 +08:00
parent 2cc4b96807
commit 11d54e21cf
2 changed files with 4 additions and 3 deletions
+2 -1
View File
@@ -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
+2 -2
View File
@@ -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)