Skip to content

Commit

Permalink
changed dropout to placeholder, resolved #27
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik committed Feb 9, 2017
1 parent ce726d3 commit b5877eb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions models/sentiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, vocab_size, hidden_size, dropout,
num_layers, max_gradient_norm, max_seq_length,
learning_rate, lr_decay,batch_size, forward_only=False):
self.num_classes =2
self.dropout = dropout
self.vocab_size = vocab_size
self.learning_rate = tf.Variable(float(learning_rate), trainable=False)
self.learning_rate_decay_op = self.learning_rate.assign(
Expand All @@ -45,9 +46,12 @@ def __init__(self, vocab_size, hidden_size, dropout,
self.seq_lengths = tf.placeholder(tf.int32, shape=[None],
name="early_stop")

self.dropout_keep_prob_embedding = tf.constant(self.dropout)
self.dropout_keep_prob_lstm_input = tf.constant(self.dropout)
self.dropout_keep_prob_lstm_output = tf.constant(self.dropout)
self.dropout_keep_prob_embedding = tf.placeholder(tf.float32,
name="dropout_keep_prob_embedding")
self.dropout_keep_prob_lstm_input = tf.placeholder(tf.float32,
name="dropout_keep_prob_lstm_input")
self.dropout_keep_prob_lstm_output = tf.placeholder(tf.float32,
name="dropout_keep_prob_lstm_output")

with tf.variable_scope("embedding"), tf.device("/cpu:0"):
W = tf.get_variable(
Expand Down Expand Up @@ -199,6 +203,10 @@ def step(self, session, inputs, targets, seq_lengths, forward_only=False):
input_feed[self.seq_input.name] = inputs
input_feed[self.target.name] = targets
input_feed[self.seq_lengths.name] = seq_lengths
input_feed[self.dropout_keep_prob_embedding.name] = self.dropout
input_feed[self.dropout_keep_prob_lstm_input.name] = self.dropout
input_feed[self.dropout_keep_prob_lstm_output.name] = self.dropout

if not forward_only:
input_feed[self.str_summary_type.name] = "train"
output_feed = [self.merged, self.mean_loss, self.update]
Expand Down

4 comments on commit b5877eb

@prolearner
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error is still there, you need to set the dropout to 1 when forward_only (i.e during the testing step)

@domerin0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed this comment somehow. I will take a look more closely into that. Any fix I make will likely be later this week.

@prolearner
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reopen the issue meanwhile? I think it's important to know

@domerin0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point I'll reopen.

Please sign in to comment.