-
Notifications
You must be signed in to change notification settings - Fork 15
/
generate.py
executable file
·40 lines (28 loc) · 1.09 KB
/
generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import tensorflow as tf
import os
import sys
import cPickle
from model import Model
import config as c
START = '''A butterfly in ''' # start from this text - can be multiline
COUNT = 400 # number of characters to generate
TEMPERATURE = .5 # try values between 0.1 and 1.5
if __name__ == '__main__':
print('Sampling %s chars at diversity %s\n' % (COUNT, TEMPERATURE))
c.load(c.work_dir)
with open(os.path.join(c.work_dir, 'chars_vocab.pkl'), 'rb') as f:
chars, vocab = cPickle.load(f)
model = Model(c.rnn_size, c.num_layers, len(vocab), c.grad_clip)
with tf.Session() as sess:
tf.initialize_all_variables().run()
saver = tf.train.Saver(tf.all_variables())
ckpt = tf.train.get_checkpoint_state(c.work_dir)
saver.restore(sess, ckpt.model_checkpoint_path)
sys.stdout.write(START)
for ch in model.sample(sess, chars, vocab, COUNT, START, TEMPERATURE):
sys.stdout.write(ch)
sys.stdout.flush()
sys.stdout.write('\n')