Skip to content

Commit

Permalink
fix bug and remove f strings
Browse files Browse the repository at this point in the history
  • Loading branch information
WuTheFWasThat committed Feb 14, 2019
1 parent e33295b commit 7cdac14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/generate_unconditional_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def sample_model(
if length is None:
length = hparams.n_ctx
elif length > hparams.n_ctx:
raise ValueError(f"can't get samples longer than window size: {hparams.n_ctx}")
raise ValueError("Can't get samples longer than window size: %s" % hparams.n_ctx)

with tf.Session(graph=tf.Graph()) as sess:
output = sample.sample_sequence(
Expand All @@ -49,7 +49,7 @@ def sample_model(
generated += batch_size
text = enc.decode(out[i])
print("=" * 40 + " SAMPLE " + str(generated) + " " + "=" * 40)
print(f"{text}")
print(text)

if __name__ == '__main__':
fire.Fire(sample_model)
Expand Down
11 changes: 7 additions & 4 deletions src/interactive_conditional_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def interact_model(
if length is None:
length = hparams.n_ctx // 2
elif length > hparams.n_ctx:
raise ValueError(f"can't get samples longer than window size: {hparams.n_ctx}")
raise ValueError("Can't get samples longer than window size: %s" % hparams.n_ctx)

with tf.Session(graph=tf.Graph()) as sess:
context = tf.placeholder(tf.int32, [batch_size, None])
Expand All @@ -40,25 +40,28 @@ def interact_model(
context=context,
batch_size=batch_size,
temperature=temperature, top_k=top_k
)[:, 1:]
)

saver = tf.train.Saver()
ckpt = tf.train.latest_checkpoint(os.path.join('models', model_name))
saver.restore(sess, ckpt)

while True:
raw_text = input("Model prompt >>> ")
while not raw_text:
print('Prompt should not be empty!')
raw_text = input("Model prompt >>> ")
context_tokens = enc.encode(raw_text)
generated = 0
for _ in range(nsamples // batch_size):
out = sess.run(output, feed_dict={
context: [context_tokens for _ in range(batch_size)]
})
})[:, len(context_tokens):]
for i in range(batch_size):
generated += 1
text = enc.decode(out[i])
print("=" * 40 + " SAMPLE " + str(generated) + " " + "=" * 40)
print(f"{text}")
print(text)
print("=" * 80)

if __name__ == '__main__':
Expand Down

0 comments on commit 7cdac14

Please sign in to comment.