Create translation model and initialize or load parameters in session.
(session, forward_only)
| 100 | |
| 101 | |
| 102 | def create_model(session, forward_only): |
| 103 | """Create translation model and initialize or load parameters in session.""" |
| 104 | dtype = tf.float32 |
| 105 | model = seq2seq_model.Seq2SeqModel( |
| 106 | FLAGS.input_vocab_size, |
| 107 | FLAGS.output_vocab_size, |
| 108 | _buckets, |
| 109 | FLAGS.size, |
| 110 | FLAGS.num_layers, |
| 111 | FLAGS.max_gradient_norm, |
| 112 | FLAGS.batch_size, |
| 113 | FLAGS.learning_rate, |
| 114 | FLAGS.learning_rate_decay_factor, |
| 115 | forward_only=forward_only, |
| 116 | dtype=dtype) |
| 117 | ckpt = tf.train.get_checkpoint_state(FLAGS.train_dir) |
| 118 | if ckpt and tf.train.checkpoint_exists(ckpt.model_checkpoint_path): |
| 119 | print("Reading model parameters from %s" % ckpt.model_checkpoint_path) |
| 120 | model.saver.restore(session, ckpt.model_checkpoint_path) |
| 121 | else: |
| 122 | print("Created model with fresh parameters.") |
| 123 | session.run(tf.global_variables_initializer()) |
| 124 | return model |
| 125 | |
| 126 | |
| 127 | def train(): |