Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch for the group_index issue #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions models/clockwork_rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class ClockworkRNN(object):
each processing inputs at its own temporal granularity, making computations only at its prescribed clock rate.
Rather than making the standard RNN models more complex, CW-RNN reduces the number of RNN parameters,
improves the performance significantly in the tasks tested, and speeds up the network evaluation

'''


Expand All @@ -26,6 +25,9 @@ def __init__(self, config):
# divided over the higher frequency groups.
assert self.config.num_hidden % len(self.config.periods) == 0

# The size of each group(number of neuron of each Group)
self.group_size = self.config.num_hidden // len(self.config.periods)

# Global training step
self.global_step = tf.Variable(0, name='global_step', trainable=False)

Expand Down Expand Up @@ -102,6 +104,9 @@ def _build_model(self):
if time_step % self.clockwork_periods[i] == 0:
group_index = i+1 # note the +1

# the real index of group in matrix
group_index = self.group_size * group_index

# Compute (W_I*x_t + b_I)
WI_x = tf.matmul(x_list[time_step], tf.slice(self.input_W, [0, 0], [-1, group_index]))
WI_x = tf.nn.bias_add(WI_x, tf.slice(self.input_b, [0], [group_index]), name="WI_x")
Expand Down Expand Up @@ -203,4 +208,4 @@ def _build_summary_ops(self):

# Combine the training summaries with the gradient summaries
self.train_summary_op = tf.summary.merge(
[training_summaries, self.gradient_summaries_merged])
[training_summaries, self.gradient_summaries_merged])