Skip to content

Commit

Permalink
train_model.py is the training script in tensorflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshsamarth committed Jul 6, 2019
1 parent 2f57697 commit 17c0249
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
Binary file added __pycache__/build_model.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/data_clean.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/data_manip.cpython-35.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion build_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#building the model in tensorflow
#from data_clean.py import *
from data_clean import *
import tensorflow as tf

def model_inputs():
Expand Down
54 changes: 54 additions & 0 deletions train_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# training the built model_inputs

from build_model import *
# Set the Hyperparameters
epochs = 100
batch_size = 64
rnn_size = 256
num_layers = 2
learning_rate = 0.005
keep_probability = 0.75

# Build the graph
train_graph = tf.Graph()
# Set the graph to default to ensure that it is ready for training
with train_graph.as_default():

# Load the model inputs
input_data, targets, lr, keep_prob, summary_length, max_summary_length, text_length = model_inputs()

# Create the training and inference logits
training_logits, inference_logits = seq2seq_model(tf.reverse(input_data, [-1]),
targets,
keep_prob,
text_length,
summary_length,
max_summary_length,
len(vocab_to_int)+1,
rnn_size,
num_layers,
vocab_to_int,
batch_size)

# Create tensors for the training logits and inference logits
training_logits = tf.identity(training_logits.rnn_output, 'logits')
inference_logits = tf.identity(inference_logits.sample_id, name='predictions')

# Create the weights for sequence_loss
masks = tf.sequence_mask(summary_length, max_summary_length, dtype=tf.float32, name='masks')

with tf.name_scope("optimization"):
# Loss function
cost = tf.contrib.seq2seq.sequence_loss(
training_logits,
targets,
masks)

# Optimizer
optimizer = tf.train.AdamOptimizer(learning_rate)

# Gradient Clipping
gradients = optimizer.compute_gradients(cost)
capped_gradients = [(tf.clip_by_value(grad, -5., 5.), var) for grad, var in gradients if grad is not None]
train_op = optimizer.apply_gradients(capped_gradients)
print("Graph is built.")

0 comments on commit 17c0249

Please sign in to comment.